-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.txt
198 lines (186 loc) · 4.81 KB
/
test.txt
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
// ---------------------------------------------------------
// This file was generated by parol.
// It is not intended for manual editing and changes will be
// lost after next build.
// ---------------------------------------------------------
use parol_runtime::once_cell::sync::Lazy;
#[allow(unused_imports)]
use parol_runtime::parser::{LLKParser, LookaheadDFA, ParseTreeType, ParseType, Production, Trans};
use parol_runtime::{ParolError, ParseTree};
use parol_runtime::{TokenStream, Tokenizer};
use std::cell::RefCell;
use std::path::Path;
use crate::list_grammar::ListGrammar;
use crate::list_grammar_trait::ListGrammarAuto;
use parol_runtime::lexer::tokenizer::{
ERROR_TOKEN, NEW_LINE_TOKEN, UNMATCHABLE_TOKEN, WHITESPACE_TOKEN,
};
pub const TERMINALS: &[&str; 8] = &[
/* 0 */ UNMATCHABLE_TOKEN,
/* 1 */ UNMATCHABLE_TOKEN,
/* 2 */ UNMATCHABLE_TOKEN,
/* 3 */ UNMATCHABLE_TOKEN,
/* 4 */ UNMATCHABLE_TOKEN,
/* 5 */ r###","###,
/* 6 */ r###"0|[1-9][0-9]*"###,
/* 7 */ ERROR_TOKEN,
];
pub const TERMINAL_NAMES: &[&str; 8] = &[
/* 0 */ "EndOfInput",
/* 1 */ "Newline",
/* 2 */ "Whitespace",
/* 3 */ "LineComment",
/* 4 */ "BlockComment",
/* 5 */ "Comma",
/* 6 */ "Num",
/* 7 */ "Error",
];
/* SCANNER_0: "INITIAL" */
const SCANNER_0: (&[&str; 5], &[usize; 2]) = (
&[
/* 0 */ UNMATCHABLE_TOKEN,
/* 1 */ NEW_LINE_TOKEN,
/* 2 */ WHITESPACE_TOKEN,
/* 3 */ UNMATCHABLE_TOKEN,
/* 4 */ UNMATCHABLE_TOKEN,
],
&[5 /* Comma */, 6 /* Num */],
);
const MAX_K: usize = 2;
pub const NON_TERMINALS: &[&str; 7] = &[
/* 0 */ "Items",
/* 1 */ "ItemsList",
/* 2 */ "List",
/* 3 */ "ListOpt",
/* 4 */ "Num",
/* 5 */ "TrailingComma",
/* 6 */ "TrailingCommaOpt",
];
pub const LOOKAHEAD_AUTOMATA: &[LookaheadDFA; 7] = &[
/* 0 - "Items" */
LookaheadDFA {
prod0: 3,
transitions: &[],
k: 0,
},
/* 1 - "ItemsList" */
LookaheadDFA {
prod0: -1,
transitions: &[
Trans(0, 0, 3, 5),
Trans(0, 5, 1, -1),
Trans(1, 0, 3, 5),
Trans(1, 6, 2, 4),
],
k: 2,
},
/* 2 - "List" */
LookaheadDFA {
prod0: 0,
transitions: &[],
k: 0,
},
/* 3 - "ListOpt" */
LookaheadDFA {
prod0: -1,
transitions: &[Trans(0, 0, 2, 2), Trans(0, 5, 2, 2), Trans(0, 6, 1, 1)],
k: 1,
},
/* 4 - "Num" */
LookaheadDFA {
prod0: 6,
transitions: &[],
k: 0,
},
/* 5 - "TrailingComma" */
LookaheadDFA {
prod0: 7,
transitions: &[],
k: 0,
},
/* 6 - "TrailingCommaOpt" */
LookaheadDFA {
prod0: -1,
transitions: &[Trans(0, 0, 2, 9), Trans(0, 5, 1, 8)],
k: 1,
},
];
pub const PRODUCTIONS: &[Production; 10] = &[
// 0 - List: ListOpt /* Option */ TrailingComma^ /* Clipped */;
Production {
lhs: 2,
production: &[ParseType::N(5), ParseType::N(3)],
},
// 1 - ListOpt: Items : crate::list_grammar::Numbers ;
Production {
lhs: 3,
production: &[ParseType::N(0)],
},
// 2 - ListOpt: ;
Production {
lhs: 3,
production: &[],
},
// 3 - Items: Num ItemsList /* Vec */;
Production {
lhs: 0,
production: &[ParseType::N(1), ParseType::N(4)],
},
// 4 - ItemsList: ","^ /* Clipped */ Num ItemsList;
Production {
lhs: 1,
production: &[ParseType::N(1), ParseType::N(4), ParseType::T(5)],
},
// 5 - ItemsList: ;
Production {
lhs: 1,
production: &[],
},
// 6 - Num: "0|[1-9][0-9]*";
Production {
lhs: 4,
production: &[ParseType::T(6)],
},
// 7 - TrailingComma: TrailingCommaOpt /* Option */;
Production {
lhs: 5,
production: &[ParseType::N(6)],
},
// 8 - TrailingCommaOpt: ","^ /* Clipped */;
Production {
lhs: 6,
production: &[ParseType::T(5)],
},
// 9 - TrailingCommaOpt: ;
Production {
lhs: 6,
production: &[],
},
];
static TOKENIZERS: Lazy<Vec<(&'static str, Tokenizer)>> = Lazy::new(|| {
vec![(
"INITIAL",
Tokenizer::build(TERMINALS, SCANNER_0.0, SCANNER_0.1).unwrap(),
)]
});
pub fn parse<'t, T>(
input: &'t str,
file_name: T,
user_actions: &mut ListGrammar,
) -> Result<ParseTree<'t>, ParolError>
where
T: AsRef<Path>,
{
let mut llk_parser = LLKParser::new(
2,
LOOKAHEAD_AUTOMATA,
PRODUCTIONS,
TERMINAL_NAMES,
NON_TERMINALS,
);
let token_stream =
RefCell::new(TokenStream::new(input, file_name, &TOKENIZERS, MAX_K).unwrap());
// Initialize wrapper
let mut user_actions = ListGrammarAuto::new(user_actions);
llk_parser.parse(token_stream, &mut user_actions)
}