build: set version to 0.5
[vis.git] / lua / lexers / ada.lua
blob24ec8a5173fbed9209aad99704e4bf5b2125f443
1 -- Copyright 2006-2017 Mitchell mitchell.att.foicica.com. See LICENSE.
2 -- Ada 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 = 'ada'}
10 -- Whitespace.
11 local ws = token(l.WHITESPACE, l.space^1)
13 -- Comments.
14 local comment = token(l.COMMENT, '--' * l.nonnewline^0)
16 -- Strings.
17 local string = token(l.STRING, l.delimited_range('"', true, true))
19 -- Numbers.
20 local hex_num = 'O' * S('xX') * (l.xdigit + '_')^1
21 local integer = l.digit^1 * ('_' * l.digit^1)^0
22 local float = integer^1 * ('.' * integer^0)^-1 * S('eE') * S('+-')^-1 * integer
23 local number = token(l.NUMBER, hex_num + S('+-')^-1 * (float + integer) *
24 S('LlUuFf')^-3)
26 -- Keywords.
27 local keyword = token(l.KEYWORD, word_match{
28 'abort', 'abs', 'accept', 'all', 'and', 'begin', 'body', 'case', 'declare',
29 'delay', 'do', 'else', 'elsif', 'end', 'entry', 'exception', 'exit', 'for',
30 'generic', 'goto', 'if', 'in', 'is', 'loop', 'mod', 'new', 'not', 'null',
31 'or', 'others', 'out', 'protected', 'raise', 'record', 'rem', 'renames',
32 'requeue', 'reverse', 'select', 'separate', 'subtype', 'task', 'terminate',
33 'then', 'type', 'until', 'when', 'while', 'xor',
34 -- Preprocessor.
35 'package', 'pragma', 'use', 'with',
36 -- Function
37 'function', 'procedure', 'return',
38 -- Storage class.
39 'abstract', 'access', 'aliased', 'array', 'at', 'constant', 'delta', 'digits',
40 'interface', 'limited', 'of', 'private', 'range', 'tagged', 'synchronized',
41 -- Boolean.
42 'true', 'false'
45 -- Types.
46 local type = token(l.TYPE, word_match{
47 'boolean', 'character', 'count', 'duration', 'float', 'integer', 'long_float',
48 'long_integer', 'priority', 'short_float', 'short_integer', 'string'
51 -- Identifiers.
52 local identifier = token(l.IDENTIFIER, l.word)
54 -- Operators.
55 local operator = token(l.OPERATOR, S(':;=<>&+-*/.()'))
57 M._rules = {
58 {'whitespace', ws},
59 {'keyword', keyword},
60 {'type', type},
61 {'identifier', identifier},
62 {'string', string},
63 {'comment', comment},
64 {'number', number},
65 {'operator', operator},
68 return M