/
parser.go.y
73 lines (63 loc) · 1.23 KB
/
parser.go.y
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
%{
package expression
%}
%union{
token Token
expr Expression
}
%type<expr> license
%type<expr> simple
%type<expr> plus
%type<expr> compound
%token<token> IDENT OR AND WITH
%left OR
%left AND
%right WITH
%right '+'
%%
license
: compound
{
$$ = $1
if l, ok := yylex.(*Lexer); ok{
l.result = $$
}
}
simple
: IDENT
{
$$ = SimpleExpr{license: $1.literal}
}
| simple IDENT /* e.g. Public Domain */
{
$$ = SimpleExpr{license: $1.String() + " " + $2.literal}
}
plus
: simple '+'
{
$$ = SimpleExpr{license: $1.String(), hasPlus: true}
}
compound
: simple {
$$ = $1
}
| plus {
$$ = $1
}
| compound AND compound /* compound-expression "AND" compound-expression */
{
$$ = CompoundExpr{left: $1, conjunction: $2, right: $3}
}
| compound OR compound /* compound-expression "OR" compound-expression */
{
$$ = CompoundExpr{left: $1, conjunction: $2, right: $3}
}
| compound WITH compound /* simple-expression "WITH" license-exception-id */
{
$$ = CompoundExpr{left: $1, conjunction: $2, right: $3}
}
| '(' compound ')'
{
$$ = $2
}
%%