@@ -624,9 +624,6 @@ pub struct AstNode {
624624#[ derive( Debug , Clone ) ]
625625#[ cfg_attr( test, derive( Eq , PartialEq ) ) ]
626626pub enum AstNodeInner {
627- Evaluated {
628- value : NumOrStr ,
629- } ,
630627 Leaf {
631628 value : MaybeNonUtf8String ,
632629 } ,
@@ -650,15 +647,6 @@ impl AstNode {
650647 Parser :: new ( input) . parse ( )
651648 }
652649
653- pub fn evaluated ( self ) -> ExprResult < Self > {
654- Ok ( Self {
655- id : get_next_id ( ) ,
656- inner : AstNodeInner :: Evaluated {
657- value : self . eval ( ) ?,
658- } ,
659- } )
660- }
661-
662650 pub fn eval ( & self ) -> ExprResult < NumOrStr > {
663651 // This function implements a recursive tree-walking algorithm, but uses an explicit
664652 // stack approach instead of native recursion to avoid potential stack overflow
@@ -669,9 +657,6 @@ impl AstNode {
669657
670658 while let Some ( node) = stack. pop ( ) {
671659 match & node. inner {
672- AstNodeInner :: Evaluated { value, .. } => {
673- result_stack. insert ( node. id , Ok ( value. clone ( ) ) ) ;
674- }
675660 AstNodeInner :: Leaf { value, .. } => {
676661 result_stack. insert ( node. id , Ok ( value. to_owned ( ) . into ( ) ) ) ;
677662 }
@@ -896,9 +881,7 @@ impl<'a, S: AsRef<MaybeNonUtf8Str>> Parser<'a, S> {
896881 value : self . next ( ) ?. into ( ) ,
897882 } ,
898883 b"(" => {
899- // Evaluate the node just after parsing to we detect arithmetic
900- // errors before checking for the closing parenthesis.
901- let s = self . parse_expression ( ) ?. evaluated ( ) ?;
884+ let s = self . parse_expression ( ) ?;
902885
903886 match self . next ( ) {
904887 Ok ( b")" ) => { }
@@ -1070,9 +1053,7 @@ mod test {
10701053 AstNode :: parse( & [ "(" , "1" , "+" , "2" , ")" , "*" , "3" ] ) ,
10711054 Ok ( op(
10721055 BinOp :: Numeric ( NumericOp :: Mul ) ,
1073- op( BinOp :: Numeric ( NumericOp :: Add ) , "1" , "2" )
1074- . evaluated( )
1075- . unwrap( ) ,
1056+ op( BinOp :: Numeric ( NumericOp :: Add ) , "1" , "2" ) ,
10761057 "3"
10771058 ) )
10781059 ) ;
0 commit comments