@@ -371,12 +371,17 @@ make_parser!(
371
371
) ;
372
372
373
373
make_parser ! (
374
- ValueParser ( input: char , variable : & bool ) -> Value {
374
+ ValueParser ( input: char , constant : & bool ) -> Value {
375
375
376
376
let mut constants = try( FloatValue :: new( ) )
377
- . or( IntValue :: new( ) ) ;
378
-
379
- if * variable {
377
+ . or( IntValue :: new( ) )
378
+ . or( BooleanValue :: new( ) )
379
+ . or( NullValue :: new( ) )
380
+ //.or(EnumValue::new())
381
+ . or( ListValue :: new( constant) )
382
+ . or( ObjectValue :: new( constant) ) ;
383
+
384
+ if * constant {
380
385
VariableParser :: new( )
381
386
. map( Value :: Variable )
382
387
. or( constants)
@@ -416,6 +421,7 @@ make_parser!(
416
421
}
417
422
} )
418
423
. map( Value :: Int )
424
+ . skip( many:: <Vec <_>, _>( or( WhiteSpace :: new( ) , LineTerminator :: new( & true ) ) ) )
419
425
. parse_lazy( input)
420
426
}
421
427
) ;
@@ -467,6 +473,7 @@ make_parser!(
467
473
result. parse:: <f32 >( ) . unwrap( )
468
474
} )
469
475
. map( Value :: Float )
476
+ . skip( many:: <Vec <_>, _>( or( WhiteSpace :: new( ) , LineTerminator :: new( & true ) ) ) )
470
477
. parse_lazy( input)
471
478
}
472
479
) ;
@@ -501,6 +508,66 @@ make_parser!(
501
508
}
502
509
) ;
503
510
511
+ make_parser ! (
512
+ BooleanValue ( input: char ) -> Value {
513
+ string( "true" ) . map( |_| Value :: Boolean ( true ) )
514
+ . or( string( "false" ) . map( |_| Value :: Boolean ( false ) ) )
515
+ . skip( many:: <Vec <_>, _>( or( WhiteSpace :: new( ) , LineTerminator :: new( & true ) ) ) )
516
+ . parse_lazy( input)
517
+ }
518
+ ) ;
519
+
520
+ make_parser ! (
521
+ NullValue ( input: char ) -> Value {
522
+ string( "null" )
523
+ . skip( many:: <Vec <_>, _>( or( WhiteSpace :: new( ) , LineTerminator :: new( & true ) ) ) )
524
+ . map( |_| Value :: Null )
525
+ . parse_lazy( input)
526
+ }
527
+ ) ;
528
+
529
+ // TODO enum parser: Name but not true or false or null
530
+
531
+ make_parser ! (
532
+ ListValue ( input: char , constant: & bool ) -> Value {
533
+ between( char ( '[' ) , char ( ']' ) , many( ValueParser :: new( constant) ) )
534
+ . skip( many:: <Vec <_>, _>( or( WhiteSpace :: new( ) , LineTerminator :: new( & true ) ) ) )
535
+ . map( Value :: List )
536
+ . parse_lazy( input)
537
+ }
538
+ ) ;
539
+
540
+ make_parser ! (
541
+ ObjectField ( input: char , constant: & bool ) -> ( String , Value ) {
542
+ NameParser :: new( )
543
+ . skip( char ( ':' ) )
544
+ . skip( many:: <Vec <_>, _>( or( WhiteSpace :: new( ) , LineTerminator :: new( & true ) ) ) )
545
+ . and( ValueParser :: new( constant) )
546
+ . parse_lazy( input)
547
+ }
548
+ ) ;
549
+
550
+ make_parser ! (
551
+ ObjectValue ( input: char , constant: & bool ) -> Value {
552
+ between( char ( '{' ) , char ( '}' ) , many:: <Vec <_>, _>( ObjectField :: new( constant) ) )
553
+ . skip( many:: <Vec <_>, _>( or( WhiteSpace :: new( ) , LineTerminator :: new( & true ) ) ) )
554
+ . map( |fields| {
555
+ let mut result = HashMap :: new( ) ;
556
+
557
+ for ( name, value) in fields. into_iter( ) {
558
+ // TODO complain about same name fields?
559
+ result. insert( name, value) ;
560
+ }
561
+
562
+ Value :: Object ( result)
563
+ } )
564
+ . parse_lazy( input)
565
+ }
566
+ ) ;
567
+
568
+ // TODO .skip(many::<Vec<_>,_>(or(WhiteSpace::new(), LineTerminator::new(&true))))
569
+ // TODO add commas to this thing
570
+
504
571
make_parser ! (
505
572
Alias ( input: char ) -> Name {
506
573
NameParser :: new( )
@@ -509,6 +576,7 @@ make_parser!(
509
576
. parse_lazy( input)
510
577
}
511
578
) ;
579
+
512
580
#[ cfg( test) ]
513
581
mod tests {
514
582
use super :: * ;
@@ -636,4 +704,7 @@ mod tests {
636
704
assert_successful_parse ! ( FloatValue , "10e+1" , Value :: Float ( 10.0e1 ) ) ;
637
705
assert_successful_parse ! ( FloatValue , "10.0e-1" , Value :: Float ( 10.0e-1 ) ) ;
638
706
}
707
+
708
+ // TODO add tests for object value
709
+ // TODO add tests for list values
639
710
}
0 commit comments