parasail.py 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. """
  2. pygments.lexers.parasail
  3. ~~~~~~~~~~~~~~~~~~~~~~~~
  4. Lexer for ParaSail.
  5. :copyright: Copyright 2006-present by the Pygments team, see AUTHORS.
  6. :license: BSD, see LICENSE for details.
  7. """
  8. import re
  9. from pygments.lexer import RegexLexer, include, words
  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 source code.
  16. """
  17. name = 'ParaSail'
  18. url = 'http://www.parasail-lang.org'
  19. aliases = ['parasail']
  20. filenames = ['*.psi', '*.psl']
  21. mimetypes = ['text/x-parasail']
  22. version_added = '2.1'
  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. (words(('abs', 'abstract', 'all', 'block', 'class', 'concurrent',
  34. 'const', 'continue', 'each', 'end', 'exit',
  35. 'extends', 'exports', 'forward', 'func',
  36. 'global', 'implements', 'import', 'in',
  37. 'interface', 'is', 'lambda', 'locked',
  38. 'new', 'not', 'null', 'of', 'op',
  39. 'optional', 'private', 'queued', 'ref',
  40. 'return', 'reverse', 'separate', 'some',
  41. 'type', 'until', 'var', 'with', 'if',
  42. 'then', 'else', 'elsif', 'case', 'for',
  43. 'while', 'loop'), prefix=r'\b', suffix=r'\b'),
  44. Keyword.Reserved),
  45. (r'(abstract\s+)?(interface|class|op|func|type)',
  46. Keyword.Declaration),
  47. # Literals
  48. (r'"[^"]*"', String),
  49. (r'\\[\'ntrf"0]', String.Escape),
  50. (r'#[a-zA-Z]\w*', Literal), # Enumeration
  51. include('numbers'),
  52. (r"'[^']'", String.Char),
  53. (r'[a-zA-Z]\w*', Name),
  54. # Operators and Punctuation
  55. (r'(<==|==>|<=>|\*\*=|<\|=|<<=|>>=|==|!=|=\?|<=|>=|'
  56. r'\*\*|<<|>>|=>|:=|\+=|-=|\*=|\|=|\||/=|\+|-|\*|/|'
  57. r'\.\.|<\.\.|\.\.<|<\.\.<)',
  58. Operator),
  59. (r'(<|>|\[|\]|\(|\)|\||:|;|,|.|\{|\}|->)',
  60. Punctuation),
  61. (r'\n+', Text),
  62. ],
  63. 'numbers': [
  64. (r'\d[0-9_]*#[0-9a-fA-F][0-9a-fA-F_]*#', Number.Hex), # any base
  65. (r'0[xX][0-9a-fA-F][0-9a-fA-F_]*', Number.Hex), # C-like hex
  66. (r'0[bB][01][01_]*', Number.Bin), # C-like bin
  67. (r'\d[0-9_]*\.\d[0-9_]*[eE][+-]\d[0-9_]*', # float exp
  68. Number.Float),
  69. (r'\d[0-9_]*\.\d[0-9_]*', Number.Float), # float
  70. (r'\d[0-9_]*', Number.Integer), # integer
  71. ],
  72. }