floscript.py 2.6 KB

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