-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparser.y
74 lines (61 loc) · 924 Bytes
/
parser.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
74
%{
package sql
import (
"fmt"
)
%}
%union {
str string
arrstr []string
}
%token COMMA SELECT FROM AS
%token <str> STRING
%type <str> command, select_stmt, base_select, table_reference, field
%type <arrstr> list_fields
%start any_command
%%
any_command:
command semicolon_opt
{
fmt.Println("command", $1)
};
semicolon_opt:
/*empty*/ {}
| ';' {};
command:
select_stmt
{
$$ = $1
};
select_stmt:
base_select
{
$$ = $1
};
base_select:
SELECT list_fields FROM table_reference
{
$$ = fmt.Sprintf("fields: %v, table: %v", $2, $4)
};
list_fields: field
{
$$ = []string{$1}
}
| list_fields COMMA field
{
$$ = append($$, $3)
};
field:
STRING
{
$$ = fmt.Sprintf("field name = %q", $1)
}
| STRING AS STRING
{
$$ = fmt.Sprintf("field name = %q (as %q)", $1, $3)
}
table_reference:
STRING
{
$$ = fmt.Sprintf("table name = %q", $1)
};