parasail.py 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. # -*- coding: utf-8 -*-
  2. """
  3. pygments.lexers.parasail
  4. ~~~~~~~~~~~~~~~~~~~~~~~~
  5. Lexer for ParaSail.
  6. :copyright: Copyright 2006-2019 by the Pygments team, see AUTHORS.
  7. :license: BSD, see LICENSE for details.
  8. """
  9. import re
  10. from pygments.lexer import RegexLexer, include
  11. from pygments.token import Text, Comment, Operator, Keyword, Name, String, \
  12. Number, Punctuation, Literal
  13. __all__ = ['ParaSailLexer']
  14. class ParaSailLexer(RegexLexer):
  15. """
  16. For `ParaSail <http://www.parasail-lang.org>`_ source code.
  17. .. versionadded:: 2.1
  18. """
  19. name = 'ParaSail'
  20. aliases = ['parasail']
  21. filenames = ['*.psi', '*.psl']
  22. mimetypes = ['text/x-parasail']
  23. flags = re.MULTILINE
  24. tokens = {
  25. 'root': [
  26. (r'[^\S\n]+', Text),
  27. (r'//.*?\n', Comment.Single),
  28. (r'\b(and|or|xor)=', Operator.Word),
  29. (r'\b(and(\s+then)?|or(\s+else)?|xor|rem|mod|'
  30. r'(is|not)\s+null)\b',
  31. Operator.Word),
  32. # Keywords
  33. (r'\b(abs|abstract|all|block|class|concurrent|const|continue|'
  34. r'each|end|exit|extends|exports|forward|func|global|implements|'
  35. r'import|in|interface|is|lambda|locked|new|not|null|of|op|'
  36. r'optional|private|queued|ref|return|reverse|separate|some|'
  37. r'type|until|var|with|'
  38. # Control flow
  39. r'if|then|else|elsif|case|for|while|loop)\b',
  40. Keyword.Reserved),
  41. (r'(abstract\s+)?(interface|class|op|func|type)',
  42. Keyword.Declaration),
  43. # Literals
  44. (r'"[^"]*"', String),
  45. (r'\\[\'ntrf"0]', String.Escape),
  46. (r'#[a-zA-Z]\w*', Literal), # Enumeration
  47. include('numbers'),
  48. (r"'[^']'", String.Char),
  49. (r'[a-zA-Z]\w*', Name),
  50. # Operators and Punctuation
  51. (r'(<==|==>|<=>|\*\*=|<\|=|<<=|>>=|==|!=|=\?|<=|>=|'
  52. r'\*\*|<<|>>|=>|:=|\+=|-=|\*=|\|=|\||/=|\+|-|\*|/|'
  53. r'\.\.|<\.\.|\.\.<|<\.\.<)',
  54. Operator),
  55. (r'(<|>|\[|\]|\(|\)|\||:|;|,|.|\{|\}|->)',
  56. Punctuation),
  57. (r'\n+', Text),
  58. ],
  59. 'numbers': [
  60. (r'\d[0-9_]*#[0-9a-fA-F][0-9a-fA-F_]*#', Number.Hex), # any base
  61. (r'0[xX][0-9a-fA-F][0-9a-fA-F_]*', Number.Hex), # C-like hex
  62. (r'0[bB][01][01_]*', Number.Bin), # C-like bin
  63. (r'\d[0-9_]*\.\d[0-9_]*[eE][+-]\d[0-9_]*', # float exp
  64. Number.Float),
  65. (r'\d[0-9_]*\.\d[0-9_]*', Number.Float), # float
  66. (r'\d[0-9_]*', Number.Integer), # integer
  67. ],
  68. }