ui: add support for blink style attribute
[vis.git] / lexers / vhdl.lua
blob6bbba111709b170405d0833154c6314e18c5614c
1 -- Copyright 2006-2016 Mitchell mitchell.att.foicica.com. See LICENSE.
2 -- VHDL 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 = 'vhdl'}
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 sq_str = l.delimited_range("'", true, true)
18 local dq_str = l.delimited_range('"', true)
19 local string = token(l.STRING, sq_str + dq_str)
21 -- Numbers.
22 local number = token(l.NUMBER, l.float + l.integer)
24 -- Keywords.
25 local keyword = token(l.KEYWORD, word_match{
26 'access', 'after', 'alias', 'all', 'architecture', 'array', 'assert',
27 'attribute', 'begin', 'block', 'body', 'buffer', 'bus', 'case', 'component',
28 'configuration', 'constant', 'disconnect', 'downto', 'else', 'elsif', 'end',
29 'entity', 'exit', 'file', 'for', 'function', 'generate', 'generic', 'group',
30 'guarded', 'if', 'impure', 'in', 'inertial', 'inout', 'is', 'label',
31 'library', 'linkage', 'literal', 'loop', 'map', 'new', 'next', 'null', 'of',
32 'on', 'open', 'others', 'out', 'package', 'port', 'postponed', 'procedure',
33 'process', 'pure', 'range', 'record', 'register', 'reject', 'report',
34 'return', 'select', 'severity', 'signal', 'shared', 'subtype', 'then', 'to',
35 'transport', 'type', 'unaffected', 'units', 'until', 'use', 'variable',
36 'wait', 'when', 'while', 'with', 'note', 'warning', 'error', 'failure',
37 'and', 'nand', 'or', 'nor', 'xor', 'xnor', 'rol', 'ror', 'sla', 'sll', 'sra',
38 'srl', 'mod', 'rem', 'abs', 'not',
39 'false', 'true'
42 -- Functions.
43 local func = token(l.FUNCTION, word_match{
44 'rising_edge', 'shift_left', 'shift_right', 'rotate_left', 'rotate_right',
45 'resize', 'std_match', 'to_integer', 'to_unsigned', 'to_signed', 'unsigned',
46 'signed', 'to_bit', 'to_bitvector', 'to_stdulogic', 'to_stdlogicvector',
47 'to_stdulogicvector'
50 -- Types.
51 local type = token(l.TYPE, word_match{
52 'bit', 'bit_vector', 'character', 'boolean', 'integer', 'real', 'time',
53 'string', 'severity_level', 'positive', 'natural', 'signed', 'unsigned',
54 'line', 'text', 'std_logic', 'std_logic_vector', 'std_ulogic',
55 'std_ulogic_vector', 'qsim_state', 'qsim_state_vector', 'qsim_12state',
56 'qsim_12state_vector', 'qsim_strength', 'mux_bit', 'mux_vectory', 'reg_bit',
57 'reg_vector', 'wor_bit', 'wor_vector'
60 -- Constants.
61 local constant = token(l.CONSTANT, word_match{
62 'EVENT', 'BASE', 'LEFT', 'RIGHT', 'LOW', 'HIGH', 'ASCENDING', 'IMAGE',
63 'VALUE', 'POS', 'VAL', 'SUCC', 'VAL', 'POS', 'PRED', 'VAL', 'POS', 'LEFTOF',
64 'RIGHTOF', 'LEFT', 'RIGHT', 'LOW', 'HIGH', 'RANGE', 'REVERSE', 'LENGTH',
65 'ASCENDING', 'DELAYED', 'STABLE', 'QUIET', 'TRANSACTION', 'EVENT', 'ACTIVE',
66 'LAST', 'LAST', 'LAST', 'DRIVING', 'DRIVING', 'SIMPLE', 'INSTANCE', 'PATH'
69 -- Identifiers.
70 local word = (l.alpha + "'") * (l.alnum + "_" + "'")^1
71 local identifier = token(l.IDENTIFIER, word)
73 -- Operators.
74 local operator = token(l.OPERATOR, S('=/!:;<>+-/*%&|^~()'))
76 M._rules = {
77 {'whitespace', ws},
78 {'keyword', keyword},
79 {'function', func},
80 {'type', type},
81 {'constant', constant},
82 {'identifier', identifier},
83 {'string', string},
84 {'comment', comment},
85 {'number', number},
86 {'operator', operator},
89 return M