codekingpro/portable-devtools
114k
1"""2 pygments.lexers.comal3 ~~~~~~~~~~~~~~~~~~~~~4 5 Lexer for COMAL-80.6 7 :copyright: Copyright 2006-2024 by the Pygments team, see AUTHORS.8 :license: BSD, see LICENSE for details.9"""10 11import re12 13from pygments.lexer import RegexLexer, words14from pygments.token import Comment, Whitespace, Operator, Keyword, String, \15 Number, Name, Punctuation16 17__all__ = ["Comal80Lexer"]18 19 20class Comal80Lexer(RegexLexer):21 """22 For COMAL-80 source code.23 """24 25 name = 'COMAL-80'26 url = 'https://en.wikipedia.org/wiki/COMAL'27 aliases = ['comal', 'comal80']28 filenames = ['*.cml', '*.comal']29 version_added = ''30 flags = re.IGNORECASE31 #32 # COMAL allows for some strange characters in names which we list here so33 # keywords and word operators will not be recognized at the start of an34 # identifier.35 #36 _suffix = r"\b(?!['\[\]←£\\])"37 _identifier = r"[a-z]['\[\]←£\\\w]*"38 39 tokens = {40 'root': [41 (r'//.*\n', Comment.Single),42 (r'\s+', Whitespace),43 (r':[=+-]|\<\>|[-+*/^↑<>=]', Operator),44 (r'(and +then|or +else)' + _suffix, Operator.Word),45 (words([46 'and', 'bitand', 'bitor', 'bitxor', 'div', 'in', 'mod', 'not',47 'or'], suffix=_suffix,), Operator.Word),48 (words([49 'append', 'at', 'case', 'chain', 'close', 'copy', 'create', 'cursor',50 'data', 'delete', 'dir', 'do', 'elif', 'else', 'end', 'endcase', 'endif',51 'endfor', 'endloop', 'endtrap', 'endwhile', 'exec', 'exit', 'file',52 'for', 'goto', 'handler', 'if', 'input', 'let', 'loop', 'mount', 'null',53 'of', 'open', 'otherwise', 'output', 'page', 'pass', 'poke', 'print',54 'random', 'read', 'repeat', 'report', 'return', 'rename', 'restore',55 'select', 'step', 'stop', 'sys', 'then', 'to', 'trap', 'unit', 'unit$',56 'until', 'using', 'when', 'while', 'write', 'zone'], suffix=_suffix),57 Keyword.Reserved),58 (words([59 'closed', 'dim', 'endfunc', 'endproc', 'external', 'func', 'import',60 'proc', 'ref', 'use'], suffix=_suffix), Keyword.Declaration),61 (words([62 'abs', 'atn', 'chr$', 'cos', 'eod', 'eof', 'err', 'errfile', 'errtext',63 'esc', 'exp', 'int', 'key$', 'len', 'log', 'ord', 'peek', 'randomize',64 'rnd', 'sgn', 'sin', 'spc$', 'sqr', 'status$', 'str$', 'tab', 'tan',65 'time', 'val'], suffix=_suffix), Name.Builtin),66 (words(['false', 'pi', 'true'], suffix=_suffix), Keyword.Constant),67 (r'"', String, 'string'),68 (_identifier + r":(?=[ \n/])", Name.Label),69 (_identifier + r"[$#]?", Name),70 (r'%[01]+', Number.Bin),71 (r'\$[0-9a-f]+', Number.Hex),72 (r'\d*\.\d*(e[-+]?\d+)?', Number.Float),73 (r'\d+', Number.Integer),74 (r'[(),:;]', Punctuation),75 ],76 'string': [77 (r'[^"]+', String),78 (r'"[0-9]*"', String.Escape),79 (r'"', String, '#pop'),80 ],81 }82 