oberon.py 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. # -*- coding: utf-8 -*-
  2. """
  3. pygments.lexers.oberon
  4. ~~~~~~~~~~~~~~~~~~~~~~
  5. Lexers for Oberon family languages.
  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, words
  11. from pygments.token import Text, Comment, Operator, Keyword, Name, String, \
  12. Number, Punctuation
  13. __all__ = ['ComponentPascalLexer']
  14. class ComponentPascalLexer(RegexLexer):
  15. """
  16. For `Component Pascal <http://www.oberon.ch/pdf/CP-Lang.pdf>`_ source code.
  17. .. versionadded:: 2.1
  18. """
  19. name = 'Component Pascal'
  20. aliases = ['componentpascal', 'cp']
  21. filenames = ['*.cp', '*.cps']
  22. mimetypes = ['text/x-component-pascal']
  23. flags = re.MULTILINE | re.DOTALL
  24. tokens = {
  25. 'root': [
  26. include('whitespace'),
  27. include('comments'),
  28. include('punctuation'),
  29. include('numliterals'),
  30. include('strings'),
  31. include('operators'),
  32. include('builtins'),
  33. include('identifiers'),
  34. ],
  35. 'whitespace': [
  36. (r'\n+', Text), # blank lines
  37. (r'\s+', Text), # whitespace
  38. ],
  39. 'comments': [
  40. (r'\(\*([^$].*?)\*\)', Comment.Multiline),
  41. # TODO: nested comments (* (* ... *) ... (* ... *) *) not supported!
  42. ],
  43. 'punctuation': [
  44. (r'[()\[\]{},.:;|]', Punctuation),
  45. ],
  46. 'numliterals': [
  47. (r'[0-9A-F]+X\b', Number.Hex), # char code
  48. (r'[0-9A-F]+[HL]\b', Number.Hex), # hexadecimal number
  49. (r'[0-9]+\.[0-9]+E[+-][0-9]+', Number.Float), # real number
  50. (r'[0-9]+\.[0-9]+', Number.Float), # real number
  51. (r'[0-9]+', Number.Integer), # decimal whole number
  52. ],
  53. 'strings': [
  54. (r"'[^\n']*'", String), # single quoted string
  55. (r'"[^\n"]*"', String), # double quoted string
  56. ],
  57. 'operators': [
  58. # Arithmetic Operators
  59. (r'[+-]', Operator),
  60. (r'[*/]', Operator),
  61. # Relational Operators
  62. (r'[=#<>]', Operator),
  63. # Dereferencing Operator
  64. (r'\^', Operator),
  65. # Logical AND Operator
  66. (r'&', Operator),
  67. # Logical NOT Operator
  68. (r'~', Operator),
  69. # Assignment Symbol
  70. (r':=', Operator),
  71. # Range Constructor
  72. (r'\.\.', Operator),
  73. (r'\$', Operator),
  74. ],
  75. 'identifiers': [
  76. (r'([a-zA-Z_$][\w$]*)', Name),
  77. ],
  78. 'builtins': [
  79. (words((
  80. 'ANYPTR', 'ANYREC', 'BOOLEAN', 'BYTE', 'CHAR', 'INTEGER', 'LONGINT',
  81. 'REAL', 'SET', 'SHORTCHAR', 'SHORTINT', 'SHORTREAL'
  82. ), suffix=r'\b'), Keyword.Type),
  83. (words((
  84. 'ABS', 'ABSTRACT', 'ARRAY', 'ASH', 'ASSERT', 'BEGIN', 'BITS', 'BY',
  85. 'CAP', 'CASE', 'CHR', 'CLOSE', 'CONST', 'DEC', 'DIV', 'DO', 'ELSE',
  86. 'ELSIF', 'EMPTY', 'END', 'ENTIER', 'EXCL', 'EXIT', 'EXTENSIBLE', 'FOR',
  87. 'HALT', 'IF', 'IMPORT', 'IN', 'INC', 'INCL', 'IS', 'LEN', 'LIMITED',
  88. 'LONG', 'LOOP', 'MAX', 'MIN', 'MOD', 'MODULE', 'NEW', 'ODD', 'OF',
  89. 'OR', 'ORD', 'OUT', 'POINTER', 'PROCEDURE', 'RECORD', 'REPEAT', 'RETURN',
  90. 'SHORT', 'SHORTCHAR', 'SHORTINT', 'SIZE', 'THEN', 'TYPE', 'TO', 'UNTIL',
  91. 'VAR', 'WHILE', 'WITH'
  92. ), suffix=r'\b'), Keyword.Reserved),
  93. (r'(TRUE|FALSE|NIL|INF)\b', Keyword.Constant),
  94. ]
  95. }