vis
a vi-like editor based on Plan 9's structural regular expressions
git clone https://9o.is/git/vis.git
ada.lua
(1779B)
1 -- Copyright 2006-2025 Mitchell. See LICENSE.
2 -- Ada 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('ada')
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 'abort', 'abs', 'abstract', 'accept', 'access', 'aliased', 'all', 'and', 'array', 'at', 'begin',
16 'body', 'case', 'constant', 'declare', 'delay', 'delta', 'digits', 'do', 'else', 'elsif', 'end',
17 'entry', 'exception', 'exit', 'for', 'function', 'generic', 'goto', 'if', 'in', 'interface', 'is',
18 'limited', 'loop', 'mod', 'new', 'not', 'null', 'of', 'or', 'others', 'out', 'overriding',
19 'package', 'parallel', 'pragma', 'private', 'procedure', 'protected', 'raise', 'range', 'record',
20 'rem', 'renames', 'requeue', 'return', 'reverse', 'select', 'separate', 'some', 'subtype',
21 'synchronized', 'tagged', 'task', 'terminate', 'then', 'type', 'until', 'use', 'when', 'while',
22 'with', 'xor', --
23 'true', 'false'
24 }, true)))
25
26 -- Types.
27 lex:add_rule('type', token(lexer.TYPE, word_match({
28 'boolean', 'character', 'count', 'duration', 'float', 'integer', 'long_float', 'long_integer',
29 'priority', 'short_float', 'short_integer', 'string'
30 }, true)))
31
32 -- Identifiers.
33 lex:add_rule('identifier', token(lexer.IDENTIFIER, lexer.word))
34
35 -- Strings.
36 lex:add_rule('string', token(lexer.STRING, lexer.range('"', true, false)))
37
38 -- Comments.
39 lex:add_rule('comment', token(lexer.COMMENT, lexer.to_eol('--')))
40
41 -- Numbers.
42 lex:add_rule('number', token(lexer.NUMBER, lexer.number_('_')))
43
44 -- Operators.
45 lex:add_rule('operator', token(lexer.OPERATOR, S(':;=<>&+-*/.()')))
46
47 lexer.property['scintillua.comment'] = '--'
48
49 return lex