ui: fall back to xterm-256color if term initialization fails
[vis.git] / lexers / pascal.lua
blob20a780066da8cace6b513c1ad01ab950c4975190
1 -- Copyright 2006-2015 Mitchell mitchell.att.foicica.com. See LICENSE.
2 -- Pascal LPeg lexer.
4 local l = require('lexer')
5 local token, word_match = l.token, l.word_match
6 local P, R, S = lpeg.P, lpeg.R, lpeg.S
8 local M = {_NAME = 'pascal'}
10 -- Whitespace.
11 local ws = token(l.WHITESPACE, l.space^1)
13 -- Comments.
14 local line_comment = '//' * l.nonnewline_esc^0
15 local bblock_comment = '{' * (l.any - '}')^0 * P('}')^-1
16 local pblock_comment = '(*' * (l.any - '*)')^0 * P('*)')^-1
17 local comment = token(l.COMMENT, line_comment + bblock_comment + pblock_comment)
19 -- Strings.
20 local string = token(l.STRING, S('uUrR')^-1 *
21 l.delimited_range("'", true, true))
23 -- Numbers.
24 local number = token(l.NUMBER, (l.float + l.integer) * S('LlDdFf')^-1)
26 -- Keywords.
27 local keyword = token(l.KEYWORD, word_match({
28 'and', 'array', 'as', 'at', 'asm', 'begin', 'case', 'class', 'const',
29 'constructor', 'destructor', 'dispinterface', 'div', 'do', 'downto', 'else',
30 'end', 'except', 'exports', 'file', 'final', 'finalization', 'finally', 'for',
31 'function', 'goto', 'if', 'implementation', 'in', 'inherited',
32 'initialization', 'inline', 'interface', 'is', 'label', 'mod', 'not',
33 'object', 'of', 'on', 'or', 'out', 'packed', 'procedure', 'program',
34 'property', 'raise', 'record', 'repeat', 'resourcestring', 'set', 'sealed',
35 'shl', 'shr', 'static', 'string', 'then', 'threadvar', 'to', 'try', 'type',
36 'unit', 'unsafe', 'until', 'uses', 'var', 'while', 'with', 'xor',
37 'absolute', 'abstract', 'assembler', 'automated', 'cdecl', 'contains',
38 'default', 'deprecated', 'dispid', 'dynamic', 'export', 'external', 'far',
39 'forward', 'implements', 'index', 'library', 'local', 'message', 'name',
40 'namespaces', 'near', 'nodefault', 'overload', 'override', 'package',
41 'pascal', 'platform', 'private', 'protected', 'public', 'published', 'read',
42 'readonly', 'register', 'reintroduce', 'requires', 'resident', 'safecall',
43 'stdcall', 'stored', 'varargs', 'virtual', 'write', 'writeln', 'writeonly',
44 'false', 'nil', 'self', 'true'
45 }, nil, true))
47 -- Functions.
48 local func = token(l.FUNCTION, word_match({
49 'chr', 'ord', 'succ', 'pred', 'abs', 'round', 'trunc', 'sqr', 'sqrt',
50 'arctan', 'cos', 'sin', 'exp', 'ln', 'odd', 'eof', 'eoln'
51 }, nil, true))
53 -- Types.
54 local type = token(l.TYPE, word_match({
55 'shortint', 'byte', 'char', 'smallint', 'integer', 'word', 'longint',
56 'cardinal', 'boolean', 'bytebool', 'wordbool', 'longbool', 'real', 'single',
57 'double', 'extended', 'comp', 'currency', 'pointer'
58 }, nil, true))
60 -- Identifiers.
61 local identifier = token(l.IDENTIFIER, l.word)
63 -- Operators.
64 local operator = token(l.OPERATOR, S('.,;^@:=<>+-/*()[]'))
66 M._rules = {
67 {'whitespace', ws},
68 {'keyword', keyword},
69 {'function', func},
70 {'type', type},
71 {'string', string},
72 {'identifier', identifier},
73 {'comment', comment},
74 {'number', number},
75 {'operator', operator},
78 return M