2 from pygments.token import *
3 from pygments.lexer import RegexLexer, include, bygroups, using, this
5 class PseudoCodeLexer(RegexLexer):
8 filenames = ['*.pcode']
10 #: optional Comment or Whitespace
11 _ws = r'(?:\s|//.*?\n|/[*].*?[*]/)+'
17 (r'\\\n', Text), # line continuation
18 (r'//(\n|(.|\n)*?[^\\]\n)', Comment.Single),
19 (r'/(\\\n)?[*](.|\n)*?[*](\\\n)?/', Comment.Multiline),
22 (r'L?"', String, 'string'),
23 (r"L?'(\\.|\\[0-7]{1,3}|\\x[a-fA-F0-9]{1,2}|[^\\\'\n])'", String.Char),
24 (r'(\d+\.\d*|\.\d+|\d+)[eE][+-]?\d+[lL]?', Number.Float),
25 (r'(\d+\.\d*|\.\d+|\d+[fF])[fF]?', Number.Float),
26 (r'0x[0-9a-fA-F]+[Ll]?', Number.Hex),
27 (r'0[0-7]+[Ll]?', Number.Oct),
28 (r'\d+[Ll]?', Number.Integer),
30 (r'[~!%^&*+=|?:<>/-]', Operator),
31 (r'[()\[\],.]', Punctuation),
32 (r'(auto|break|continue|else|function|is|in|not|and|or|while|'
33 r'foreach|if|return|throw|do|cast|global)\b', Keyword),
34 (r'(true|false|null|exit|fflush|fork|wait|try_wait|void|byte|'
35 r'thread_self|get_stack_top|pause|resume)\b', Name.Builtin),
36 ('[a-zA-Z_][a-zA-Z0-9_]*', Name),
39 include('whitespace'),
40 ('', Text, 'statement'),
43 include('whitespace'),
44 include('statements'),
45 ('[{}]', Punctuation),
46 (';', Punctuation, '#pop'),
49 (r'"', String, '#pop'),
50 (r'\\([\\abfnrtv"\']|x[a-fA-F0-9]{2,4}|[0-7]{1,3})', String.Escape),
51 (r'[^\\"\n]+', String), # all other characters
52 (r'\\\n', String), # line continuation
53 (r'\\', String), # stray backslash
58 from sphinx.highlighting import lexers
59 lexers['pcode'] = PseudoCodeLexer()
61 # vim: set et sw=4 sts=4 :