@@ -45,18 +45,25 @@ use super::*;
4545 return;
4646}"#
4747) ]
48+ #[ test_parser_error(
49+ "ifa > 1 {
50+ a = 1;
51+ } else {
52+ a = 2;
53+ }"
54+ ) ]
4855/// ```ebnf
4956/// if_statement = "if" logic_exp statement_block ("else" (if_statement | statement_block))? ;
5057/// ```
5158pub fn if_statement ( input : Span ) -> IResult < Span , Box < NodeEnum > > {
5259 map_res (
5360 delspace ( tuple ( (
54- tag_token ( TokenType :: IF ) ,
61+ tag_token_word ( TokenType :: IF ) ,
5562 parse_with_ex ( logic_exp, true ) ,
5663 statement_block,
5764 opt ( delspace ( comment) ) ,
5865 opt ( preceded (
59- tag_token ( TokenType :: ELSE ) ,
66+ tag_token_word ( TokenType :: ELSE ) ,
6067 alt ( (
6168 if_statement,
6269 map_res ( statement_block, |n| res_enum ( n. into ( ) ) ) ,
@@ -98,13 +105,19 @@ pub fn if_statement(input: Span) -> IResult<Span, Box<NodeEnum>> {
98105}
99106"
100107) ]
108+ #[ test_parser_error(
109+ "whiletrue {
110+ let a = b;
111+ }
112+ "
113+ ) ]
101114/// ```ebnf
102115/// while_statement = "while" logic_exp statement_block ;
103116/// ```
104117pub fn while_statement ( input : Span ) -> IResult < Span , Box < NodeEnum > > {
105118 map_res (
106119 delspace ( tuple ( (
107- tag_token ( TokenType :: WHILE ) ,
120+ tag_token_word ( TokenType :: WHILE ) ,
108121 alt_except (
109122 logic_exp,
110123 "{" ,
@@ -159,18 +172,22 @@ pub fn while_statement(input: Span) -> IResult<Span, Box<NodeEnum>> {
159172
160173 }"
161174) ]
162-
175+ #[ test_parser_error(
176+ "forlet i = 0; i < 5; i = i + 1{
177+
178+ }"
179+ ) ]
163180/// ```enbf
164181/// for_statement = "for" (assignment | new_variable) ";" logic_exp ";" assignment statement_block;
165182/// ```
166183pub fn for_statement ( input : Span ) -> IResult < Span , Box < NodeEnum > > {
167184 map_res (
168185 delspace ( tuple ( (
169- tag_token ( TokenType :: FOR ) ,
186+ tag_token_word ( TokenType :: FOR ) ,
170187 opt ( alt ( ( assignment, new_variable) ) ) ,
171- tag_token ( TokenType :: SEMI ) ,
188+ tag_token_symbol ( TokenType :: SEMI ) ,
172189 logic_exp,
173- tag_token ( TokenType :: SEMI ) ,
190+ tag_token_symbol ( TokenType :: SEMI ) ,
174191 opt ( assignment) ,
175192 statement_block,
176193 opt ( delspace ( comment) ) ,
@@ -204,8 +221,8 @@ pub fn for_statement(input: Span) -> IResult<Span, Box<NodeEnum>> {
204221pub fn break_statement ( input : Span ) -> IResult < Span , Box < NodeEnum > > {
205222 map_res (
206223 tuple ( (
207- tag_token ( TokenType :: BREAK ) ,
208- tag_token ( TokenType :: SEMI ) ,
224+ tag_token_word ( TokenType :: BREAK ) ,
225+ tag_token_symbol ( TokenType :: SEMI ) ,
209226 opt ( delspace ( comment) ) ,
210227 ) ) ,
211228 |( _, _, optcomment) | {
@@ -228,8 +245,8 @@ pub fn break_statement(input: Span) -> IResult<Span, Box<NodeEnum>> {
228245pub fn continue_statement ( input : Span ) -> IResult < Span , Box < NodeEnum > > {
229246 map_res (
230247 tuple ( (
231- tag_token ( TokenType :: CONTINUE ) ,
232- tag_token ( TokenType :: SEMI ) ,
248+ tag_token_word ( TokenType :: CONTINUE ) ,
249+ tag_token_symbol ( TokenType :: SEMI ) ,
233250 opt ( delspace ( comment) ) ,
234251 ) ) ,
235252 |( _, _, optcomment) | {
0 commit comments