snobol.py 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. """
  2. pygments.lexers.snobol
  3. ~~~~~~~~~~~~~~~~~~~~~~
  4. Lexers for the SNOBOL language.
  5. :copyright: Copyright 2006-2021 by the Pygments team, see AUTHORS.
  6. :license: BSD, see LICENSE for details.
  7. """
  8. from pygments.lexer import RegexLexer, bygroups
  9. from pygments.token import Text, Comment, Operator, Keyword, Name, String, \
  10. Number, Punctuation
  11. __all__ = ['SnobolLexer']
  12. class SnobolLexer(RegexLexer):
  13. """
  14. Lexer for the SNOBOL4 programming language.
  15. Recognizes the common ASCII equivalents of the original SNOBOL4 operators.
  16. Does not require spaces around binary operators.
  17. .. versionadded:: 1.5
  18. """
  19. name = "Snobol"
  20. aliases = ["snobol"]
  21. filenames = ['*.snobol']
  22. mimetypes = ['text/x-snobol']
  23. tokens = {
  24. # root state, start of line
  25. # comments, continuation lines, and directives start in column 1
  26. # as do labels
  27. 'root': [
  28. (r'\*.*\n', Comment),
  29. (r'[+.] ', Punctuation, 'statement'),
  30. (r'-.*\n', Comment),
  31. (r'END\s*\n', Name.Label, 'heredoc'),
  32. (r'[A-Za-z$][\w$]*', Name.Label, 'statement'),
  33. (r'\s+', Text, 'statement'),
  34. ],
  35. # statement state, line after continuation or label
  36. 'statement': [
  37. (r'\s*\n', Text, '#pop'),
  38. (r'\s+', Text),
  39. (r'(?<=[^\w.])(LT|LE|EQ|NE|GE|GT|INTEGER|IDENT|DIFFER|LGT|SIZE|'
  40. r'REPLACE|TRIM|DUPL|REMDR|DATE|TIME|EVAL|APPLY|OPSYN|LOAD|UNLOAD|'
  41. r'LEN|SPAN|BREAK|ANY|NOTANY|TAB|RTAB|REM|POS|RPOS|FAIL|FENCE|'
  42. r'ABORT|ARB|ARBNO|BAL|SUCCEED|INPUT|OUTPUT|TERMINAL)(?=[^\w.])',
  43. Name.Builtin),
  44. (r'[A-Za-z][\w.]*', Name),
  45. # ASCII equivalents of original operators
  46. # | for the EBCDIC equivalent, ! likewise
  47. # \ for EBCDIC negation
  48. (r'\*\*|[?$.!%*/#+\-@|&\\=]', Operator),
  49. (r'"[^"]*"', String),
  50. (r"'[^']*'", String),
  51. # Accept SPITBOL syntax for real numbers
  52. # as well as Macro SNOBOL4
  53. (r'[0-9]+(?=[^.EeDd])', Number.Integer),
  54. (r'[0-9]+(\.[0-9]*)?([EDed][-+]?[0-9]+)?', Number.Float),
  55. # Goto
  56. (r':', Punctuation, 'goto'),
  57. (r'[()<>,;]', Punctuation),
  58. ],
  59. # Goto block
  60. 'goto': [
  61. (r'\s*\n', Text, "#pop:2"),
  62. (r'\s+', Text),
  63. (r'F|S', Keyword),
  64. (r'(\()([A-Za-z][\w.]*)(\))',
  65. bygroups(Punctuation, Name.Label, Punctuation))
  66. ],
  67. # everything after the END statement is basically one
  68. # big heredoc.
  69. 'heredoc': [
  70. (r'.*\n', String.Heredoc)
  71. ]
  72. }