@@ -3,9 +3,7 @@ use std::marker::PhantomData;
3
3
use nom:: { IResult , Err , Context , ErrorKind } ;
4
4
//use unicode_names;
5
5
6
- use helpers;
7
- use helpers:: { StrSpan , name} ;
8
- use helpers:: { AreNewlinesSpaces , NewlinesAreSpaces } ;
6
+ use helpers:: * ;
9
7
use functions:: varargslist;
10
8
use bytes:: bytes;
11
9
use strings:: string;
@@ -44,9 +42,9 @@ named!(pub test<StrSpan, Box<Expression>>,
44
42
| do_parse!(
45
43
left: call!( Self :: or_test) >>
46
44
right: opt!( do_parse!(
47
- ws3!( tag !( "if" ) ) >>
45
+ ws3!( keyword !( "if" ) ) >>
48
46
cond: call!( Self :: or_test) >>
49
- ws3!( tag !( "else" ) ) >>
47
+ ws3!( keyword !( "else" ) ) >>
50
48
right: call!( Self :: test) >> (
51
49
( cond, right)
52
50
)
@@ -70,23 +68,22 @@ named!(test_nocond<StrSpan, Box<Expression>>,
70
68
71
69
// lambdef: 'lambda' [varargslist] ':' test
72
70
named ! ( lambdef<StrSpan , Box <Expression >>,
73
- do_parse!(
74
- tag !( "lambda" ) >>
75
- args: opt!( preceded! ( space_sep! ( ) , varargslist) ) >>
71
+ ws3! ( do_parse!(
72
+ keyword !( "lambda" ) >>
73
+ args: opt!( varargslist) >>
76
74
spaces!( ) >>
77
75
char !( ':' ) >>
78
76
spaces!( ) >>
79
77
code: call!( Self :: test) >> (
80
78
Box :: new( Expression :: Lambdef ( args. unwrap_or_default( ) , code) )
81
79
)
82
- )
80
+ ) )
83
81
) ;
84
82
85
83
// lambdef_nocond: 'lambda' [varargslist] ':' test_nocond
86
84
named ! ( lambdef_nocond<StrSpan , Box <Expression >>,
87
85
do_parse!(
88
- tag!( "lambda" ) >>
89
- space_sep!( ) >>
86
+ keyword!( "lambda" ) >>
90
87
args: opt!( varargslist) >>
91
88
char !( ':' ) >>
92
89
code: call!( Self :: test_nocond) >> (
@@ -129,18 +126,18 @@ impl<ANS: AreNewlinesSpaces> ExpressionParser<ANS> {
129
126
130
127
// or_test: and_test ('or' and_test)*
131
128
bop ! ( or_test, Self :: and_test, alt!(
132
- tuple! ( tag! ( "or" ) , space_sep! ( ) ) => { |_| Bop :: Or }
129
+ keyword! ( "or" ) => { |_| Bop :: Or }
133
130
) ) ;
134
131
135
132
// and_test: not_test ('and' not_test)*
136
133
bop ! ( and_test, Self :: not_test, alt!(
137
- tuple! ( tag! ( "and" ) , space_sep! ( ) ) => { |_| Bop :: And }
134
+ keyword! ( "and" ) => { |_| Bop :: And }
138
135
) ) ;
139
136
140
137
// not_test: 'not' not_test | comparison
141
138
named ! ( not_test<StrSpan , Box <Expression >>,
142
139
alt!(
143
- preceded!( tuple!( tag !( "not" ) , space_sep !( ) ) , call!( Self :: comparison) ) => { |e| Box :: new( Expression :: Uop ( Uop :: Not , e) ) }
140
+ preceded!( tuple!( keyword !( "not" ) , spaces !( ) ) , call!( Self :: comparison) ) => { |e| Box :: new( Expression :: Uop ( Uop :: Not , e) ) }
144
141
| call!( Self :: comparison)
145
142
)
146
143
) ;
@@ -155,8 +152,8 @@ bop!(comparison, Self::expr, alt!(
155
152
| char !( '>' ) => { |_| Bop :: Gt }
156
153
| tag!( "!=" ) => { |_| Bop :: Neq }
157
154
| tag!( "in" ) => { |_| Bop :: In }
158
- | tuple!( tag!( "not" ) , space_sep!( ) , tag !( "in" ) , space_sep! ( ) ) => { |_| Bop :: NotIn }
159
- | tuple!( tag!( "is" ) , space_sep!( ) , tag !( "not" ) , space_sep! ( ) ) => { |_| Bop :: IsNot }
155
+ | tuple!( tag!( "not" ) , space_sep!( ) , keyword !( "in" ) ) => { |_| Bop :: NotIn }
156
+ | tuple!( tag!( "is" ) , space_sep!( ) , keyword !( "not" ) ) => { |_| Bop :: IsNot }
160
157
| tuple!( tag!( "is" ) , space_sep!( ) ) => { |_| Bop :: Is }
161
158
) ) ;
162
159
@@ -259,9 +256,9 @@ named!(atom_expr<StrSpan, Box<Expression>>,
259
256
named ! ( atom<StrSpan , Box <Expression >>,
260
257
map!( alt!(
261
258
tag!( "..." ) => { |_| Expression :: Ellipsis }
262
- | tag !( "None" ) => { |_| Expression :: None }
263
- | tag !( "True" ) => { |_| Expression :: True }
264
- | tag !( "False" ) => { |_| Expression :: False }
259
+ | keyword !( "None" ) => { |_| Expression :: None }
260
+ | keyword !( "True" ) => { |_| Expression :: True }
261
+ | keyword !( "False" ) => { |_| Expression :: False }
265
262
| separated_nonempty_list!( spaces!( ) , string) => { |s| Expression :: String ( s) }
266
263
| separated_nonempty_list!( spaces!( ) , bytes) => { |v| {
267
264
let mut v2 = Vec :: new( ) ;
@@ -270,12 +267,12 @@ named!(atom<StrSpan, Box<Expression>>,
270
267
} }
271
268
| number
272
269
| name => { |n| Expression :: Name ( n) }
273
- | ws3! ( tuple!( char !( '[' ) , ws4!( opt!( char !( ' ' ) ) ) , char !( ']' ) ) ) => { |_| Expression :: ListLiteral ( vec![ ] ) }
274
- | ws3! ( tuple!( char !( '{' ) , ws4!( opt!( char !( ' ' ) ) ) , char !( '}' ) ) ) => { |_| Expression :: DictLiteral ( vec![ ] ) }
275
- | ws3! ( tuple!( char !( '(' ) , ws4!( opt!( char !( ' ' ) ) ) , char !( ')' ) ) ) => { |_| Expression :: TupleLiteral ( vec![ ] ) }
276
- | ws3! ( delimited!( char !( '{' ) , ws4!( map!(
270
+ | tuple!( char !( '[' ) , ws4!( opt!( char !( ' ' ) ) ) , char !( ']' ) ) => { |_| Expression :: ListLiteral ( vec![ ] ) }
271
+ | tuple!( char !( '{' ) , ws4!( opt!( char !( ' ' ) ) ) , char !( '}' ) ) => { |_| Expression :: DictLiteral ( vec![ ] ) }
272
+ | tuple!( char !( '(' ) , ws4!( opt!( char !( ' ' ) ) ) , char !( ')' ) ) => { |_| Expression :: TupleLiteral ( vec![ ] ) }
273
+ | delimited!( char !( '{' ) , ws4!( map!(
277
274
call!( ExpressionParser :: <NewlinesAreSpaces >:: dictorsetmaker) , |e: Box <_>| * e
278
- ) ) , char !( '}' ) ) )
275
+ ) ) , char !( '}' ) )
279
276
| map_opt!( ws3!( delimited!( char !( '(' ) , ws4!(
280
277
call!( ExpressionParser :: <NewlinesAreSpaces >:: testlist_comp)
281
278
) , char !( ')' ) ) ) , |ret| {
@@ -290,12 +287,12 @@ named!(atom<StrSpan, Box<Expression>>,
290
287
TestlistCompReturn :: Single ( SetItem :: Star ( _) ) => None ,
291
288
}
292
289
} )
293
- | ws3! ( delimited!( char !( '(' ) , ws4!(
290
+ | delimited!( char !( '(' ) , ws4!(
294
291
call!( ExpressionParser :: <NewlinesAreSpaces >:: yield_expr)
295
- ) , char !( ')' ) ) )
296
- | ws3! ( delimited!( char !( '[' ) , ws4!(
292
+ ) , char !( ')' ) )
293
+ | delimited!( char !( '[' ) , ws4!(
297
294
call!( ExpressionParser :: <NewlinesAreSpaces >:: testlist_comp)
298
- ) , char !( ']' ) ) ) => { |ret| {
295
+ ) , char !( ']' ) ) => { |ret| {
299
296
match ret {
300
297
TestlistCompReturn :: Comp ( e, comp) => Expression :: ListComp ( e, comp) ,
301
298
TestlistCompReturn :: Lit ( v) => Expression :: ListLiteral ( v) ,
@@ -428,7 +425,7 @@ named_args!(dictmaker(item1: DictItem) <StrSpan, Box<Expression>>,
428
425
v. insert( 0 , item1. clone( ) ) ; // FIXME: do not clone
429
426
Box :: new( Expression :: DictLiteral ( v) )
430
427
} }
431
- | preceded!( peek!( tuple! ( tag! ( "for" ) , call! ( helpers :: space_sep ) ) ) , call!( Self :: comp_for) ) => { |comp| {
428
+ | preceded!( peek!( keyword! ( "for" ) ) , call!( Self :: comp_for) ) => { |comp| {
432
429
Box :: new( Expression :: DictComp ( Box :: new( item1. clone( ) ) , comp) ) // FIXME: do not clone
433
430
} }
434
431
) ) ,
@@ -570,11 +567,11 @@ named!(comp_for<StrSpan, Vec<ComprehensionChunk>>,
570
567
named_args ! ( comp_for2( acc: Vec <ComprehensionChunk >) <StrSpan , Vec <ComprehensionChunk >>,
571
568
do_parse!(
572
569
async : map!( opt!( terminated!( tag!( "async" ) , space_sep!( ) ) ) , |o| o. is_some( ) ) >>
573
- tag !( "for" ) >>
570
+ keyword !( "for" ) >>
574
571
spaces!( ) >>
575
572
item: call!( Self :: exprlist) >>
576
573
spaces!( ) >>
577
- tag !( "in" ) >>
574
+ keyword !( "in" ) >>
578
575
spaces!( ) >>
579
576
iterator: map!( call!( Self :: or_test) , |e| * e) >>
580
577
spaces!( ) >>
@@ -587,7 +584,7 @@ named_args!(comp_for2(acc: Vec<ComprehensionChunk>) <StrSpan, Vec<ComprehensionC
587
584
// comp_if: 'if' test_nocond [comp_iter]
588
585
named_args ! ( comp_if( acc: Vec <ComprehensionChunk >) <StrSpan , Vec <ComprehensionChunk >>,
589
586
do_parse!(
590
- tag !( "if" ) >>
587
+ keyword !( "if" ) >>
591
588
spaces!( ) >>
592
589
cond: map!( call!( Self :: test_nocond) , |e| * e) >>
593
590
spaces!( ) >>
@@ -601,14 +598,14 @@ named_args!(comp_if(acc: Vec<ComprehensionChunk>) <StrSpan, Vec<ComprehensionChu
601
598
// yield_expr: 'yield' [yield_arg]
602
599
// yield_arg: 'from' test | testlist
603
600
named ! ( pub yield_expr<StrSpan , Expression >,
604
- preceded!(
605
- tag !( "yield" ) ,
606
- alt!(
607
- preceded!( tuple! ( space_sep! ( ) , tag! ( "from" ) , space_sep! ( ) ) , call!( Self :: test) ) => { |e| Expression :: YieldFrom ( e) }
608
- | preceded! ( space_sep! ( ) , call!( Self :: testlist) ) => { |e| Expression :: Yield ( e) }
609
- | ws3! ( tag!( "" ) ) => { |_| Expression :: Yield ( Vec :: new( ) ) }
610
- )
611
- )
601
+ ws3! ( preceded!(
602
+ keyword !( "yield" ) ,
603
+ ws3! ( alt!(
604
+ preceded!( ws3! ( keyword! ( "from" ) ) , call!( Self :: test) ) => { |e| Expression :: YieldFrom ( e) }
605
+ | call!( Self :: testlist) => { |e| Expression :: Yield ( e) }
606
+ | tag!( "" ) => { |_| Expression :: Yield ( Vec :: new( ) ) }
607
+ ) )
608
+ ) )
612
609
) ;
613
610
614
611
} // End ExpressionParser
0 commit comments