snobol.py 2.7 KB

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