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

dot.lua (2060B)


  1. -- Copyright 2006-2024 Brian "Sir Alaran" Schott. See LICENSE.
  2. -- Dot LPeg lexer.
  3. -- Based off of lexer code by Mitchell.
  4. local lexer = require('lexer')
  5. local token, word_match = lexer.token, lexer.word_match
  6. local P, S = lpeg.P, lpeg.S
  7. local lex = lexer.new('dot')
  8. -- Whitespace.
  9. lex:add_rule('whitespace', token(lexer.WHITESPACE, lexer.space^1))
  10. -- Keywords.
  11. lex:add_rule('keyword', token(lexer.KEYWORD, word_match{
  12. 'graph', 'node', 'edge', 'digraph', 'fontsize', 'rankdir', 'fontname', 'shape', 'label',
  13. 'arrowhead', 'arrowtail', 'arrowsize', 'color', 'comment', 'constraint', 'decorate', 'dir',
  14. 'headlabel', 'headport', 'headURL', 'labelangle', 'labeldistance', 'labelfloat', 'labelfontcolor',
  15. 'labelfontname', 'labelfontsize', 'layer', 'lhead', 'ltail', 'minlen', 'samehead', 'sametail',
  16. 'style', 'taillabel', 'tailport', 'tailURL', 'weight', 'subgraph'
  17. }))
  18. -- Types.
  19. lex:add_rule('type', token(lexer.TYPE, word_match{
  20. ' box', 'polygon', 'ellipse', 'circle', 'point', 'egg', 'triangle', 'plaintext', 'diamond',
  21. 'trapezium', 'parallelogram', 'house', 'pentagon', 'hexagon', 'septagon', 'octagon',
  22. 'doublecircle', 'doubleoctagon', 'tripleoctagon', 'invtriangle', 'invtrapezium', 'invhouse',
  23. 'Mdiamond', 'Msquare', 'Mcircle', 'rect', 'rectangle', 'none', 'note', 'tab', 'folder', 'box3d',
  24. 'record'
  25. }))
  26. -- Identifiers.
  27. lex:add_rule('identifier', token(lexer.IDENTIFIER, lexer.word))
  28. -- Strings.
  29. local sq_str = lexer.range("'")
  30. local dq_str = lexer.range('"')
  31. lex:add_rule('string', token(lexer.STRING, sq_str + dq_str))
  32. -- Comments.
  33. local line_comment = lexer.to_eol('//', true)
  34. local block_comment = lexer.range('/*', '*/')
  35. lex:add_rule('comment', token(lexer.COMMENT, line_comment + block_comment))
  36. -- Numbers.
  37. lex:add_rule('number', token(lexer.NUMBER, lexer.dec_num + lexer.float))
  38. -- Operators.
  39. lex:add_rule('operator', token(lexer.OPERATOR, S('->()[]{};')))
  40. -- Fold points.
  41. lex:add_fold_point(lexer.OPERATOR, '{', '}')
  42. lex:add_fold_point(lexer.COMMENT, '/*', '*/')
  43. lexer.property['scintillua.comment'] = '//'
  44. return lex