Commits

Thomas Aglassinger  committed 6fec9e9

Cleaned up handling of Rexx functions, keywords and operators.

  • Participants
  • Parent commits 2d2f9b4

Comments (0)

Files changed (2)

File pygments/lexers/other.py

     mimetypes = ['text/x-rexx']
     flags = re.IGNORECASE
 
+    _FUNCTIONS_PATTERN = sorted_keywords_pattern([
+        'abbrev', 'abs', 'address', 'arg', 'b2x', 'bitand', 'bitor', 'bitxor',
+        'c2d', 'c2x', 'center', 'charin', 'charout', 'chars', 'compare',
+        'condition', 'copies', 'd2c', 'd2x', 'datatype', 'date', 'delstr',
+        'delword', 'digits', 'errortext', 'form', 'format', 'fuzz', 'insert',
+        'lastpos', 'left', 'length', 'linein', 'lineout', 'lines', 'max',
+        'min', 'overlay', 'pos', 'queued', 'random', 'reverse', 'right',
+        'sign', 'sourceline', 'space', 'stream', 'strip', 'substr', 'subword',
+        'symbol', 'time', 'trace', 'translate', 'trunc', 'value', 'verify',
+        'word', 'wordindex', 'wordlength', 'wordpos', 'words', 'x2b', 'x2c',
+        'x2d', 'xrange'])
+    _KEYWORDS_PATTERN = sorted_keywords_pattern([
+        'address', 'arg', 'by', 'call', 'do', 'drop', 'else', 'end', 'exit',
+        'for', 'forever', 'if', 'interpret', 'iterate', 'leave', 'nop',
+        'numeric', 'off', 'on', 'options', 'parse', 'pull', 'push', 'queue',
+        'return', 'say', 'select', 'signal', 'then', 'to', 'trace', 'until',
+        'while'])
+    _OPERATORS_PATTERN = sorted_keywords_pattern([
+        '%', '&', '&&', '(', ')', '*', '**', '+', ',', '-', '.', '/', '//',
+        '<', '<<', '<<=', '<=', '<>', '=', '==', '>', '><', '>=', '>>', '>>=',
+        '\\', '\\<', '\\<<', '\\=', '\\==', '\\>', '\\>>', '|', '||', u'¬',
+        u'¬<', u'¬<<', u'¬=', u'¬==', u'¬>', u'¬>>'])
     tokens = {
         'root': [
             (r'\s', Whitespace),
                       Keyword.Declaration)),
             (r'([a-z_][a-z0-9_]*)(\s*)(:)',
              bygroups(Name.Label, Whitespace, Operator)),
-            include('function'),
-            include('keyword'),
-            include('operator'),
+            (_FUNCTIONS_PATTERN + r'(\s*)(\()',
+             bygroups(Name.Builtin, Whitespace, Operator)),
+            (_KEYWORDS_PATTERN + r'\b', Keyword.Reserved),
+            (_OPERATORS_PATTERN, Operator),
             (r'[a-z_][a-z0-9_]*', Text),
         ],
-        'function': [
-            (r'(abbrev|abs|address|arg|b2x|bitand|bitor|bitxor|c2d|c2x|'
-             r'center|charin|charout|chars|compare|condition|copies|d2c|'
-             r'd2x|datatype|date|delstr|delword|digits|errortext|form|'
-             r'format|fuzz|insert|lastpos|left|length|linein|lineout|lines|'
-             r'max|min|overlay|pos|queued|random|reverse|right|sign|'
-             r'sourceline|space|stream|strip|substr|subword|symbol|time|'
-             r'trace|translate|trunc|value|verify|word|wordindex|'
-             r'wordlength|wordpos|words|x2b|x2c|x2d|xrange)(\s*)(\()',
-             bygroups(Name.Builtin, Whitespace, Operator)),
-        ],
-        'keyword': [
-            (r'(address|arg|by|call|do|drop|else|end|exit|for|forever|if|'
-             r'interpret|iterate|leave|nop|numeric|off|on|options|parse|'
-             r'pull|push|queue|return|say|select|signal|to|then|trace|until|'
-             r'while)\b', Keyword.Reserved),
-        ],
-        'operator': [
-            (ur'(-|//|/|\(|\)|\*\*|\*|\\<<|\\<|\\==|\\=|\\>>|\\>|\\|\|\||\||'
-             ur'&&|&|%|\+|<<=|<<|<=|<>|<|==|=|><|>=|>>=|>>|>|¬<<|¬<|¬==|¬=|'
-             ur'¬>>|¬>|¬|\.|,)', Operator),
-        ],
         'string_double': [
             (r'[^"\n]+', String),
             (r'""', String),

File pygments/util.py

     '''
     Pattern for a regular expression that matches any word in ``keywords`` even if
     some of them are prefixes of others. This is particular useful if '\b' cannot be
-    use as delimiter after a keyword.
+    used as delimiter after a keyword.
 
     >>> sorted_keywords_pattern(['a', 'aa', 'aaa', 'b', 'cc'])
     u'(aaa|aa|cc|a|b)'
     escaped_keywords = [re.escape(keyword) for keyword in keywords]
     sort_key = lambda keyword: (-len(keyword), keyword)
     sorted_keywords = sorted(escaped_keywords, key=sort_key)
-    return u'(' + '|'.join(sorted_keywords) + u')'
+    return u'(' + u'|'.join(sorted_keywords) + u')'
 
 # Python 2/3 compatibility