floscript.py 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. """
  2. pygments.lexers.floscript
  3. ~~~~~~~~~~~~~~~~~~~~~~~~~
  4. Lexer for FloScript
  5. :copyright: Copyright 2006-present by the Pygments team, see AUTHORS.
  6. :license: BSD, see LICENSE for details.
  7. """
  8. from pygments.lexer import RegexLexer, include, bygroups, words
  9. from pygments.token import Text, Comment, Operator, Keyword, Name, String, \
  10. Number, Punctuation, Whitespace
  11. __all__ = ['FloScriptLexer']
  12. class FloScriptLexer(RegexLexer):
  13. """
  14. For FloScript configuration language source code.
  15. """
  16. name = 'FloScript'
  17. url = 'https://github.com/ioflo/ioflo'
  18. aliases = ['floscript', 'flo']
  19. filenames = ['*.flo']
  20. version_added = '2.4'
  21. def innerstring_rules(ttype):
  22. return [
  23. # the old style '%s' % (...) string formatting
  24. (r'%(\(\w+\))?[-#0 +]*([0-9]+|[*])?(\.([0-9]+|[*]))?'
  25. '[hlL]?[E-GXc-giorsux%]', String.Interpol),
  26. # backslashes, quotes and formatting signs must be parsed one at a time
  27. (r'[^\\\'"%\n]+', ttype),
  28. (r'[\'"\\]', ttype),
  29. # unhandled string formatting sign
  30. (r'%', ttype),
  31. # newlines are an error (use "nl" state)
  32. ]
  33. tokens = {
  34. 'root': [
  35. (r'\s+', Whitespace),
  36. (r'[]{}:(),;[]', Punctuation),
  37. (r'(\\)(\n)', bygroups(Text, Whitespace)),
  38. (r'\\', Text),
  39. (words(('to', 'by', 'with', 'from', 'per', 'for', 'cum', 'qua', 'via',
  40. 'as', 'at', 'in', 'of', 'on', 're', 'is',
  41. 'if', 'be', 'into', 'and', 'not'), suffix=r'\b'), Operator.Word),
  42. (r'!=|==|<<|>>|[-~+/*%=<>&^|.]', Operator),
  43. (words(('load', 'init', 'server', 'logger', 'log', 'loggee', 'first',
  44. 'over', 'under', 'next', 'done', 'timeout',
  45. 'repeat', 'native', 'benter', 'enter',
  46. 'recur', 'exit', 'precur', 'renter',
  47. 'rexit', 'print', 'put', 'inc', 'copy',
  48. 'set', 'aux', 'rear', 'raze', 'go', 'let',
  49. 'do', 'bid', 'ready', 'start', 'stop',
  50. 'run', 'abort', 'use', 'flo', 'give',
  51. 'take'), suffix=r'\b'), Name.Builtin),
  52. (r'(frame|framer|house)\b', Keyword),
  53. ('"', String, 'string'),
  54. include('name'),
  55. include('numbers'),
  56. (r'#.+$', Comment.Single),
  57. ],
  58. 'string': [
  59. ('[^"]+', String),
  60. ('"', String, '#pop'),
  61. ],
  62. 'numbers': [
  63. (r'(\d+\.\d*|\d*\.\d+)([eE][+-]?[0-9]+)?j?', Number.Float),
  64. (r'\d+[eE][+-]?[0-9]+j?', Number.Float),
  65. (r'0[0-7]+j?', Number.Oct),
  66. (r'0[bB][01]+', Number.Bin),
  67. (r'0[xX][a-fA-F0-9]+', Number.Hex),
  68. (r'\d+L', Number.Integer.Long),
  69. (r'\d+j?', Number.Integer)
  70. ],
  71. 'name': [
  72. (r'@[\w.]+', Name.Decorator),
  73. (r'[a-zA-Z_]\w*', Name),
  74. ],
  75. }