forked from clarkenheim/tykeScript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtykescript.jison
132 lines (106 loc) · 2.56 KB
/
tykescript.jison
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
/* typescript grammar */
%lex
%%
[\n\r] return 'NEWLINE'
[^\n\S]+ {/* skip whitespace except \n */}
[0-9]+ return 'NUMBER'
"+" return '+'
"aye" return 'aye'
"nay" return 'nay'
"in't" return 'isnt'
"is" return 'is'
"eyup" return 'VAR'
"wa" return 'EQ'
"nowthen" return 'nowthen'
"tara" return 'tara'
"do" return 'do'
"wi" return 'wi'
"on" return 'on'
"t'" return 't'
"av" return 'av'
[A-Za-z][A-Za-z_0-9-]* return 'NAME'
('"'.*'"')|("'".*"'") return 'STR'
<<EOF>> return 'EOF'
/lex
%start document
%%
document
: SOURCE EOF {yy.add($1); return yy}
;
SOURCE
: STATEMENTS
| STATEMENTS NEWLINES
;
STATEMENTS
: STATEMENT { $$ = yy.statement($1)}
| STATEMENTS NEWLINES STATEMENT {$$ = yy.add_statement($1, $3)}
;
STATEMENT
: ASSIGNMENT
| EXPR
| FUNCTION
| FUNC_CALL
;
ASSIGNMENT
: VAR LABEL EQ EXPR
{$$ = yy.assignment($2, $4)}
;
FUNCTION
: nowthen LABEL NEWLINE STATEMENTS NEWLINE tara
{$$ = yy.function($2, $4)}
| nowthen LABEL NEWLINE wi LABELS NEWLINE STATEMENTS NEWLINE tara
{$$ = yy.function($2, $7, $5)}
;
FUNC_CALL
: do NAMESPACE {$$ = yy.function_call($2)}
| do NAMESPACE wi ARGS
{$$ = yy.function_call($2, $4)}
;
EXPR
: BOOL
| NUM
| STRING
| LABEL
| BOOL COMPARISON BOOL
{$$ = yy.bool_compare($1, $2, $3)}
| LABEL COMPARISON LABEL
{$$ = yy.bool_compare($1, $2, $3)}
;
BOOL
: BOOL_LITERAL
{$$ = yy.bool_literal($1)}
| NUM COMPARISON NUM
{$$ = yy.bool_compare($1, $2, $3)}
;
BOOL_LITERAL
: aye
{$$ = $1}
| nay
{$$ = $1}
;
COMPARISON
: isnt
{$$ = $1}
| is
{$$ = $1}
;
NEWLINES
: NEWLINE
| NEWLINES NEWLINE
;
ARGS
: EXPR {$$ = yy.args($1)}
| ARGS EXPR {$$ = yy.add_args($1, $2)}
;
NAMESPACE
: LABEL
| LABEL on t LABEL
;
LABELS
: LABEL {$$ = yy.labels($1)}
| LABELS LABEL {yy.add_label($1, $2)}
;
STRING : STR {$$ = yy.string_literal($1)};
NUM : NUMBER {$$ = yy.number_literal($1)};
LABEL : NAME {$$ = yy.label($1)};
%%