ThirdParty/Pygments/pygments/lexers/snobol.py

changeset 4172
4f20dba37ab6
child 4697
c2e9bf425554
equal deleted inserted replaced
4170:8bc578136279 4172:4f20dba37ab6
1 # -*- coding: utf-8 -*-
2 """
3 pygments.lexers.snobol
4 ~~~~~~~~~~~~~~~~~~~~~~
5
6 Lexers for the SNOBOL language.
7
8 :copyright: Copyright 2006-2014 by the Pygments team, see AUTHORS.
9 :license: BSD, see LICENSE for details.
10 """
11
12 from pygments.lexer import RegexLexer, bygroups
13 from pygments.token import Text, Comment, Operator, Keyword, Name, String, \
14 Number, Punctuation
15
16 __all__ = ['SnobolLexer']
17
18
19 class SnobolLexer(RegexLexer):
20 """
21 Lexer for the SNOBOL4 programming language.
22
23 Recognizes the common ASCII equivalents of the original SNOBOL4 operators.
24 Does not require spaces around binary operators.
25
26 .. versionadded:: 1.5
27 """
28
29 name = "Snobol"
30 aliases = ["snobol"]
31 filenames = ['*.snobol']
32 mimetypes = ['text/x-snobol']
33
34 tokens = {
35 # root state, start of line
36 # comments, continuation lines, and directives start in column 1
37 # as do labels
38 'root': [
39 (r'\*.*\n', Comment),
40 (r'[+.] ', Punctuation, 'statement'),
41 (r'-.*\n', Comment),
42 (r'END\s*\n', Name.Label, 'heredoc'),
43 (r'[A-Za-z$][\w$]*', Name.Label, 'statement'),
44 (r'\s+', Text, 'statement'),
45 ],
46 # statement state, line after continuation or label
47 'statement': [
48 (r'\s*\n', Text, '#pop'),
49 (r'\s+', Text),
50 (r'(?<=[^\w.])(LT|LE|EQ|NE|GE|GT|INTEGER|IDENT|DIFFER|LGT|SIZE|'
51 r'REPLACE|TRIM|DUPL|REMDR|DATE|TIME|EVAL|APPLY|OPSYN|LOAD|UNLOAD|'
52 r'LEN|SPAN|BREAK|ANY|NOTANY|TAB|RTAB|REM|POS|RPOS|FAIL|FENCE|'
53 r'ABORT|ARB|ARBNO|BAL|SUCCEED|INPUT|OUTPUT|TERMINAL)(?=[^\w.])',
54 Name.Builtin),
55 (r'[A-Za-z][\w.]*', Name),
56 # ASCII equivalents of original operators
57 # | for the EBCDIC equivalent, ! likewise
58 # \ for EBCDIC negation
59 (r'\*\*|[?$.!%*/#+\-@|&\\=]', Operator),
60 (r'"[^"]*"', String),
61 (r"'[^']*'", String),
62 # Accept SPITBOL syntax for real numbers
63 # as well as Macro SNOBOL4
64 (r'[0-9]+(?=[^.EeDd])', Number.Integer),
65 (r'[0-9]+(\.[0-9]*)?([EDed][-+]?[0-9]+)?', Number.Float),
66 # Goto
67 (r':', Punctuation, 'goto'),
68 (r'[()<>,;]', Punctuation),
69 ],
70 # Goto block
71 'goto': [
72 (r'\s*\n', Text, "#pop:2"),
73 (r'\s+', Text),
74 (r'F|S', Keyword),
75 (r'(\()([A-Za-z][\w.]*)(\))',
76 bygroups(Punctuation, Name.Label, Punctuation))
77 ],
78 # everything after the END statement is basically one
79 # big heredoc.
80 'heredoc': [
81 (r'.*\n', String.Heredoc)
82 ]
83 }

eric ide

mercurial