-
Notifications
You must be signed in to change notification settings - Fork 0
/
ndp_lexer.py
45 lines (36 loc) · 1.06 KB
/
ndp_lexer.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
from sly import Lexer
class NDPLexer(Lexer):
# Set of token names.
tokens = {COMMA, VAR, COMMENT, EOL, ROUND_OPEN, ROUND_CLOSE, CURLY_OPEN, CURLY_CLOSE, SQUARE_OPEN, SQUARE_CLOSE, NOT, OR, AND, THEN, IFF, SCOPE, RULE, BY, USING, ASSN, HYPO, QED, COLON, INFERS, PROVE, ADMIT}
# String containing ignored characters between tokens
ignore = ' \t'
# Regular expression rules for tokens
COMMA = r','
# LABEL = r'[0-9]+'
VAR = r'[a-zA-Z0-9_]+' #change
COMMENT = r'//.*'
EOL = r'\n'
ROUND_OPEN = r'\('
ROUND_CLOSE = r'\)'
CURLY_OPEN = r'\{'
CURLY_CLOSE = r'\}'
SQUARE_OPEN = r'\['
SQUARE_CLOSE = r'\]'
RULE = r'(~E|~I|&E|&I|\|E|\|I|>E|>I|<>E|<>I)'
NOT = r'(\~|\!)'
INFERS = r'\|-'
OR = r'\|'
AND = r'\&'
THEN = r'\>'
IFF = r'\<\>'
SCOPE = r'-'
COLON = r':'
# Base ID rule
# Special cases
VAR['by'] = BY
VAR['using'] = USING
VAR['Assumption'] = ASSN
VAR['Hypothesis'] = HYPO
VAR['Qed'] = QED
VAR['Prove'] = PROVE
VAR['Admit'] = ADMIT