-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpygments_snowball.py
65 lines (60 loc) · 2.15 KB
/
pygments_snowball.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import re
from pygments.lexer import RegexLexer, bygroups, include
from pygments.token import *
class SnowballLexer(RegexLexer):
"""
For Snowball source code.
Note that this lexer assumes stringescapes brackets are {}.
"""
name = 'Snowball'
aliases = ['snowball']
filenames = ['*.sbl']
mimetypes = ['text/x-snowball']
flags = re.MULTILINE | re.DOTALL
tokens = {
'root': [
(r'[^\S\n]+', Text),
(r'//.*?\n', Comment.Single),
(r'/\*.*?\*/', Comment.Multiline),
(r'(get)\b', Keyword.Namespace),
(r'(stringescapes)(\s+)(\{)(\s*)(\})',
bygroups(Keyword.Declaration,
Text, Punctuation, Text, Punctuation)),
include('declaration'),
(r'(backwardmode)\b', Keyword.Declaration),
(r'(stringdef)(\s+)(\S+)',
bygroups(Keyword.Declaration, Text, Name)),
(r'(define)\b', Keyword.Declaration),
(r'(true|false)\b', Keyword.Constant),
(r"'", String, 'string'),
(r'[\(\)\[\]]', Punctuation),
(r'[0-9]+?', Number),
(r'[+-<>=\*!/\$]', Operator),
(r'hex\b', Number.Hex),
(r'decimal\b', Number.Integer),
include('command'),
(r'(maxint|minint|cursor|limit|size|sizeof)\b',
Operator.Word),
(r'(among|for|as)\b', Keyword),
(r'([a-zA-Z][a-zA-Z0-9_]*)', Name),
(r'\n', Text),
],
'declaration' : [
(r'(strings|integers|booleans|routines|externals|'
r'groupings)\b', Keyword.Declaration),
],
'command': [
(r'(or|and|not|test|try|do|fail|goto|gopast|'
r'repeat|loop|atleast|insert|attach|delete|'
r'hop|next|setmark|tomark|atmark|tolimit|'
r'atlimit|setlimit|backwards|reverse|substring|'
r'set|unset|non\-|non|\?)\b',
Operator.Word),
],
'string': [
(r'\{\S*?\}', String),
(r"[^'^\{]+", String),
(r".*?'", String, '#pop'),
(r'\n', Text, '#pop'),
],
}