vis
a vi-like editor based on Plan 9's structural regular expressions
git clone https://9o.is/git/vis.git
applescript.lua
(2808B)
1 -- Copyright 2006-2025 Mitchell. See LICENSE.
2 -- Applescript LPeg lexer.
3
4 local lexer = require('lexer')
5 local token, word_match = lexer.token, lexer.word_match
6 local P, S = lpeg.P, lpeg.S
7
8 local lex = lexer.new('applescript')
9
10 -- Whitespace.
11 lex:add_rule('whitespace', token(lexer.WHITESPACE, lexer.space^1))
12
13 -- Keywords.
14 lex:add_rule('keyword', token(lexer.KEYWORD, word_match({
15 'script', 'property', 'prop', 'end', 'copy', 'to', 'set', 'global', 'local', 'on', 'to', 'of',
16 'in', 'given', 'with', 'without', 'return', 'continue', 'tell', 'if', 'then', 'else', 'repeat',
17 'times', 'while', 'until', 'from', 'exit', 'try', 'error', 'considering', 'ignoring', 'timeout',
18 'transaction', 'my', 'get', 'put', 'into', 'is',
19 -- References.
20 'each', 'some', 'every', 'whose', 'where', 'id', 'index', 'first', 'second', 'third', 'fourth',
21 'fifth', 'sixth', 'seventh', 'eighth', 'ninth', 'tenth', 'last', 'front', 'back', 'st', 'nd',
22 'rd', 'th', 'middle', 'named', 'through', 'thru', 'before', 'after', 'beginning', 'the',
23 -- Commands.
24 'close', 'copy', 'count', 'delete', 'duplicate', 'exists', 'launch', 'make', 'move', 'open',
25 'print', 'quit', 'reopen', 'run', 'save', 'saving',
26 -- Operators.
27 'div', 'mod', 'and', 'not', 'or', 'as', 'contains', 'equal', 'equals', 'isn\'t'
28 }, true)))
29
30 -- Constants.
31 lex:add_rule('constant', token(lexer.CONSTANT, word_match({
32 'case', 'diacriticals', 'expansion', 'hyphens', 'punctuation',
33 -- Predefined variables.
34 'it', 'me', 'version', 'pi', 'result', 'space', 'tab', 'anything',
35 -- Text styles.
36 'bold', 'condensed', 'expanded', 'hidden', 'italic', 'outline', 'plain', 'shadow',
37 'strikethrough', 'subscript', 'superscript', 'underline',
38 -- Save options.
39 'ask', 'no', 'yes',
40 -- Booleans.
41 'false', 'true',
42 -- Date and time.
43 'weekday', 'monday', 'mon', 'tuesday', 'tue', 'wednesday', 'wed', 'thursday', 'thu', 'friday',
44 'fri', 'saturday', 'sat', 'sunday', 'sun', 'month', 'january', 'jan', 'february', 'feb', 'march',
45 'mar', 'april', 'apr', 'may', 'june', 'jun', 'july', 'jul', 'august', 'aug', 'september', 'sep',
46 'october', 'oct', 'november', 'nov', 'december', 'dec', 'minutes', 'hours', 'days', 'weeks'
47 }, true)))
48
49 -- Identifiers.
50 lex:add_rule('identifier', token(lexer.IDENTIFIER, lexer.alpha * (lexer.alnum + '_')^0))
51
52 -- Strings.
53 lex:add_rule('string', token(lexer.STRING, lexer.range('"', true)))
54
55 -- Comments.
56 local line_comment = lexer.to_eol('--')
57 local block_comment = lexer.range('(*', '*)')
58 lex:add_rule('comment', token(lexer.COMMENT, line_comment + block_comment))
59
60 -- Numbers.
61 lex:add_rule('number', token(lexer.NUMBER, lexer.number))
62
63 -- Operators.
64 lex:add_rule('operator', token(lexer.OPERATOR, S('+-^*/&<>=:,(){}')))
65
66 -- Fold points.
67 lex:add_fold_point(lexer.COMMENT, '(*', '*)')
68
69 lexer.property['scintillua.comment'] = '--'
70
71 return lex