forked from ruby/lrama
-
Notifications
You must be signed in to change notification settings - Fork 0
/
stdlib.y
122 lines (106 loc) · 2.86 KB
/
stdlib.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
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
/**********************************************************************
stdlib.y
This is lrama's standard library. It provides a number of
parameterizing rule definitions, such as options and lists,
that should be useful in a number of situations.
**********************************************************************/
// -------------------------------------------------------------------
// Options
/*
* program: option(number)
*
* =>
*
* program: option_number
* option_number: %empty
* option_number: number
*/
%rule option(X): /* empty */
| X
;
// -------------------------------------------------------------------
// Sequences
/*
* program: preceded(opening, X)
*
* =>
*
* program: preceded_opening_X
* preceded_opening_X: opening X
*/
%rule preceded(opening, X): opening X { $$ = $2; }
;
/*
* program: terminated(X, closing)
*
* =>
*
* program: terminated_X_closing
* terminated_X_closing: X closing
*/
%rule terminated(X, closing): X closing { $$ = $1; }
;
/*
* program: delimited(opening, X, closing)
*
* =>
*
* program: delimited_opening_X_closing
* delimited_opening_X_closing: opening X closing
*/
%rule delimited(opening, X, closing): opening X closing { $$ = $2; }
;
// -------------------------------------------------------------------
// Lists
/*
* program: list(number)
*
* =>
*
* program: list_number
* list_number: %empty
* list_number: list_number number
*/
%rule list(X): /* empty */
| list(X) X
;
/*
* program: nonempty_list(number)
*
* =>
*
* program: nonempty_list_number
* nonempty_list_number: number
* nonempty_list_number: nonempty_list_number number
*/
%rule nonempty_list(X): X
| nonempty_list(X) X
;
/*
* program: separated_nonempty_list(comma, number)
*
* =>
*
* program: separated_nonempty_list_comma_number
* separated_nonempty_list_comma_number: number
* separated_nonempty_list_comma_number: separated_nonempty_list_comma_number comma number
*/
%rule separated_nonempty_list(separator, X): X
| separated_nonempty_list(separator, X) separator X
;
/*
* program: separated_list(comma, number)
*
* =>
*
* program: separated_list_comma_number
* separated_list_comma_number: option_separated_nonempty_list_comma_number
* option_separated_nonempty_list_comma_number: %empty
* option_separated_nonempty_list_comma_number: separated_nonempty_list_comma_number
* separated_nonempty_list_comma_number: number
* separated_nonempty_list_comma_number: comma separated_nonempty_list_comma_number number
*/
%rule separated_list(separator, X): option(separated_nonempty_list(separator, X))
;
%%
%union{};