-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSctLexer.py
78 lines (66 loc) · 2.85 KB
/
SctLexer.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
66
67
68
69
70
71
72
73
74
75
76
77
78
from pygments.lexer import RegexLexer, bygroups
from pygments.token import *
class CustomLexer(RegexLexer):
name = "sct"
aliases = [ "sct" ]
filenames = ['*.sct']
mimetypes = ['text/sct']
tokens = {
'root': [
(r'//[^\r\n]*', Comment.Single,),
(r'[ \t\r\n]+', Whitespace,),
(r'int', Keyword.Type),
(r'float', Keyword.Type),
(r'void', Keyword.Type),
(r'Predicate', Keyword.Type),
(r'if(?=\s*\()', Keyword.Reserved,),
(r'else if(?=\s*\()', Keyword.Reserved,),
(r'else(?=\s*\{)', Keyword.Reserved,),
(r'while(?=\s*\()', Keyword.Reserved,),
(r'return(?=\s+)', Keyword.Reserved,),
(r'create(?=\s+)', Keyword.Reserved,),
(r'destroy(?=\s*;)', Keyword.Reserved,),
(r'exit(?=\s*;)', Keyword.Reserved,),
(r'continue(?=\s*;)', Keyword.Reserved,),
(r'break(?=\s*;)', Keyword.Reserved,),
(r'#', Keyword.Reserved,),
(r'=', Operator,),
(r'\*', Operator,),
(r'/', Operator,),
(r'\+', Operator,),
(r'-', Operator,),
(r'%', Operator,),
(r'&&', Operator,),
(r'\|\|', Operator,),
(r'==', Operator,),
(r'!=', Operator,),
(r'>', Operator,),
(r'<', Operator,),
(r'>=', Operator,),
(r'<=', Operator,),
(r'!', Operator,),
(r'(species)(\s+)(\w+)', bygroups(Keyword.Declaration, Token.Text.Whitespace, Name.Constant),),
# predicates
(r'(\w+)(::)(\w+)', bygroups(Name.Constant, Punctuation, Name.Label),),
(r'(\w+)(::)(\?)', bygroups(Name.Constant, Punctuation, Keyword.Pseudo),),
(r'(state)(\s+)(\w+)', bygroups(Keyword.Declaration, Token.Text.Whitespace, Name.Label)),
(r'(enter)(\s+)(\w+)', bygroups(Keyword.Reserved, Token.Text.Whitespace, Name.Label)),
(r'(=>)(\s+)(\w+)', bygroups(Punctuation, Token.Text.Whitespace, Name.Label)),
(r'(decorator)(\s+)(\w+)', bygroups(Keyword.Declaration, Token.Text.Whitespace, Name.Decorator)),
(r'@\w+', Name.Decorator,),
(r'(function)(\s+)(\w+)', bygroups(Keyword.Declaration,Token.Text.Whitespace, Name.Function),),
(r'(?<!::)\w+(?=\()', Name.Function,), # invoke function
(r'->', Punctuation,),
(r'\(', Punctuation,),
(r'\)', Punctuation,),
(r'{', Punctuation,),
(r'}', Punctuation,),
(r';', Punctuation,),
(r',', Punctuation,),
(r'::', Punctuation,),
(r':', Punctuation,),
(r'[a-zA-Z_][a-zA-Z_0-9]*', Name.Variable,),
(r'[0-9]+.[0-9]+', Number.Float,),
(r'[0-9]+', Number.Integer,),
]
}