floscript.py 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. """
  2. pygments.lexers.floscript
  3. ~~~~~~~~~~~~~~~~~~~~~~~~~
  4. Lexer for FloScript
  5. :copyright: Copyright 2006-2024 by the Pygments team, see AUTHORS.
  6. :license: BSD, see LICENSE for details.
  7. """
  8. from pygments.lexer import RegexLexer, include, bygroups
  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. (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.Single),
  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. }