comal.py 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. """
  2. pygments.lexers.comal
  3. ~~~~~~~~~~~~~~~~~~~~~
  4. Lexer for COMAL-80.
  5. :copyright: Copyright 2006-2024 by the Pygments team, see AUTHORS.
  6. :license: BSD, see LICENSE for details.
  7. """
  8. import re
  9. from pygments.lexer import RegexLexer, words
  10. from pygments.token import Comment, Whitespace, Operator, Keyword, String, \
  11. Number, Name, Punctuation
  12. __all__ = ["Comal80Lexer"]
  13. class Comal80Lexer(RegexLexer):
  14. """
  15. For COMAL-80 source code.
  16. """
  17. name = 'COMAL-80'
  18. url = 'https://en.wikipedia.org/wiki/COMAL'
  19. aliases = ['comal', 'comal80']
  20. filenames = ['*.cml', '*.comal']
  21. version_added = ''
  22. flags = re.IGNORECASE
  23. #
  24. # COMAL allows for some strange characters in names which we list here so
  25. # keywords and word operators will not be recognized at the start of an
  26. # identifier.
  27. #
  28. _suffix = r"\b(?!['\[\]←£\\])"
  29. _identifier = r"[a-z]['\[\]←£\\\w]*"
  30. tokens = {
  31. 'root': [
  32. (r'//.*\n', Comment.Single),
  33. (r'\s+', Whitespace),
  34. (r':[=+-]|\<\>|[-+*/^↑<>=]', Operator),
  35. (r'(and +then|or +else)' + _suffix, Operator.Word),
  36. (words([
  37. 'and', 'bitand', 'bitor', 'bitxor', 'div', 'in', 'mod', 'not',
  38. 'or'], suffix=_suffix,), Operator.Word),
  39. (words([
  40. 'append', 'at', 'case', 'chain', 'close', 'copy', 'create', 'cursor',
  41. 'data', 'delete', 'dir', 'do', 'elif', 'else', 'end', 'endcase', 'endif',
  42. 'endfor', 'endloop', 'endtrap', 'endwhile', 'exec', 'exit', 'file',
  43. 'for', 'goto', 'handler', 'if', 'input', 'let', 'loop', 'mount', 'null',
  44. 'of', 'open', 'otherwise', 'output', 'page', 'pass', 'poke', 'print',
  45. 'random', 'read', 'repeat', 'report', 'return', 'rename', 'restore',
  46. 'select', 'step', 'stop', 'sys', 'then', 'to', 'trap', 'unit', 'unit$',
  47. 'until', 'using', 'when', 'while', 'write', 'zone'], suffix=_suffix),
  48. Keyword.Reserved),
  49. (words([
  50. 'closed', 'dim', 'endfunc', 'endproc', 'external', 'func', 'import',
  51. 'proc', 'ref', 'use'], suffix=_suffix), Keyword.Declaration),
  52. (words([
  53. 'abs', 'atn', 'chr$', 'cos', 'eod', 'eof', 'err', 'errfile', 'errtext',
  54. 'esc', 'exp', 'int', 'key$', 'len', 'log', 'ord', 'peek', 'randomize',
  55. 'rnd', 'sgn', 'sin', 'spc$', 'sqr', 'status$', 'str$', 'tab', 'tan',
  56. 'time', 'val'], suffix=_suffix), Name.Builtin),
  57. (words(['false', 'pi', 'true'], suffix=_suffix), Keyword.Constant),
  58. (r'"', String, 'string'),
  59. (_identifier + r":(?=[ \n/])", Name.Label),
  60. (_identifier + r"[$#]?", Name),
  61. (r'%[01]+', Number.Bin),
  62. (r'\$[0-9a-f]+', Number.Hex),
  63. (r'\d*\.\d*(e[-+]?\d+)?', Number.Float),
  64. (r'\d+', Number.Integer),
  65. (r'[(),:;]', Punctuation),
  66. ],
  67. 'string': [
  68. (r'[^"]+', String),
  69. (r'"[0-9]*"', String.Escape),
  70. (r'"', String, '#pop'),
  71. ],
  72. }