logo

oasis-root

Compiled tree of Oasis Linux based on own branch at <https://hacktivis.me/git/oasis/> git clone https://anongit.hacktivis.me/git/oasis-root.git

vhdl.lua (3178B)


  1. -- Copyright 2006-2024 Mitchell. See LICENSE.
  2. -- VHDL LPeg lexer.
  3. local lexer = require('lexer')
  4. local token, word_match = lexer.token, lexer.word_match
  5. local P, S = lpeg.P, lpeg.S
  6. local lex = lexer.new('vhdl')
  7. -- Whitespace.
  8. lex:add_rule('whitespace', token(lexer.WHITESPACE, lexer.space^1))
  9. -- Keywords.
  10. lex:add_rule('keyword', token(lexer.KEYWORD, word_match{
  11. 'access', 'after', 'alias', 'all', 'architecture', 'array', 'assert', 'attribute', 'begin',
  12. 'block', 'body', 'buffer', 'bus', 'case', 'component', 'configuration', 'constant', 'disconnect',
  13. 'downto', 'else', 'elsif', 'end', 'entity', 'exit', 'file', 'for', 'function', 'generate',
  14. 'generic', 'group', 'guarded', 'if', 'impure', 'in', 'inertial', 'inout', 'is', 'label',
  15. 'library', 'linkage', 'literal', 'loop', 'map', 'new', 'next', 'null', 'of', 'on', 'open',
  16. 'others', 'out', 'package', 'port', 'postponed', 'procedure', 'process', 'pure', 'range',
  17. 'record', 'register', 'reject', 'report', 'return', 'select', 'severity', 'signal', 'shared',
  18. 'subtype', 'then', 'to', 'transport', 'type', 'unaffected', 'units', 'until', 'use', 'variable',
  19. 'wait', 'when', 'while', 'with', --
  20. 'note', 'warning', 'error', 'failure', --
  21. 'and', 'nand', 'or', 'nor', 'xor', 'xnor', 'rol', 'ror', 'sla', 'sll', 'sra', 'srl', 'mod', 'rem', --
  22. 'abs', 'not', 'false', 'true'
  23. }))
  24. -- Functions.
  25. lex:add_rule('function', token(lexer.FUNCTION, word_match{
  26. 'rising_edge', 'shift_left', 'shift_right', 'rotate_left', 'rotate_right', 'resize', 'std_match',
  27. 'to_integer', 'to_unsigned', 'to_signed', 'unsigned', 'signed', 'to_bit', 'to_bitvector',
  28. 'to_stdulogic', 'to_stdlogicvector', 'to_stdulogicvector'
  29. }))
  30. -- Types.
  31. lex:add_rule('type', token(lexer.TYPE, word_match{
  32. 'bit', 'bit_vector', 'character', 'boolean', 'integer', 'real', 'time', 'string',
  33. 'severity_level', 'positive', 'natural', 'signed', 'unsigned', 'line', 'text', 'std_logic',
  34. 'std_logic_vector', 'std_ulogic', 'std_ulogic_vector', 'qsim_state', 'qsim_state_vector',
  35. 'qsim_12state', 'qsim_12state_vector', 'qsim_strength', 'mux_bit', 'mux_vectory', 'reg_bit',
  36. 'reg_vector', 'wor_bit', 'wor_vector'
  37. }))
  38. -- Constants.
  39. lex:add_rule('constant', token(lexer.CONSTANT, word_match{
  40. 'EVENT', 'BASE', 'LEFT', 'RIGHT', 'LOW', 'HIGH', 'ASCENDING', 'IMAGE', 'VALUE', 'POS', 'VAL',
  41. 'SUCC', 'VAL', 'POS', 'PRED', 'VAL', 'POS', 'LEFTOF', 'RIGHTOF', 'LEFT', 'RIGHT', 'LOW', 'HIGH',
  42. 'RANGE', 'REVERSE', 'LENGTH', 'ASCENDING', 'DELAYED', 'STABLE', 'QUIET', 'TRANSACTION', 'EVENT',
  43. 'ACTIVE', 'LAST', 'LAST', 'LAST', 'DRIVING', 'DRIVING', 'SIMPLE', 'INSTANCE', 'PATH'
  44. }))
  45. -- Identifiers.
  46. lex:add_rule('identifier', token(lexer.IDENTIFIER, (lexer.alpha + "'") * (lexer.alnum + S("_'"))^1))
  47. -- Strings.
  48. local sq_str = lexer.range("'", true, false)
  49. local dq_str = lexer.range('"', true)
  50. lex:add_rule('string', token(lexer.STRING, sq_str + dq_str))
  51. -- Comments.
  52. lex:add_rule('comment', token(lexer.COMMENT, lexer.to_eol('--')))
  53. -- Numbers.
  54. lex:add_rule('number', token(lexer.NUMBER, lexer.number))
  55. -- Operators.
  56. lex:add_rule('operator', token(lexer.OPERATOR, S('=/!:;<>+-/*%&|^~()')))
  57. lexer.property['scintillua.comment'] = '--'
  58. return lex