floscript.py 2.6 KB

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