parasail.py 2.6 KB

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