@@ -1490,47 +1490,80 @@ pub mod statement {
14901490 _ => ( )
14911491 }
14921492 let previous_symbol = symbols. insert( name. clone( ) , if ( matches!( dec_type, SingleDataDeclarationType :: List ( _) ) || ( dec_type == SingleDataDeclarationType :: Unset && default_type == DefaultDataDeclarationType :: List ) ) {
1493- context :: TargetSymbolDescriptor :: List ( context :: ListDescriptor {
1494- name : name . clone ( ) , canonical_name : canonical_identifier . as_ref ( ) . map ( |value|value . name . clone ( ) ) , value_is_initial_value : values_are_initial_values , value : match & value {
1493+ let value = if values_are_initial_values {
1494+ match & value {
14951495 DeclarationValue :: List ( _, _, value, _) => {
14961496 let mut expressions = Vec :: with_capacity( value. len( ) ) ;
14971497 for entry in value {
14981498 match entry {
1499- ListEntry :: Expression ( expression) => expressions. push( expression. calculate_value( ) . map_err( |source| {
1500- ParseError :: InvalidConstantExpression {
1501- expression: Box :: new( expression. clone( ) ) ,
1502- source
1503- }
1504- } ) ?) ,
1505- ListEntry :: Unwrap ( literal, _) => literal. get_string_value( ) . as_str( ) . chars( ) . for_each( |c| expressions. push( grazelang_types:: project_json:: Sb3PrimitiveOrBool :: String ( c. to_string( ) ) ) ) ,
1499+ ListEntry :: Expression ( expression) => {
1500+ expressions. push( expression. calculate_value( ) . map_err( |source| {
1501+ ParseError :: InvalidConstantExpression {
1502+ expression: Box :: new( expression. clone( ) ) ,
1503+ source,
1504+ }
1505+ } ) ?) ;
1506+ }
1507+ ListEntry :: Unwrap ( literal, _) => literal
1508+ . get_string_value( )
1509+ . as_str( )
1510+ . chars( )
1511+ . for_each( |c| {
1512+ expressions. push(
1513+ grazelang_types:: project_json:: Sb3PrimitiveOrBool :: String (
1514+ c. to_string( ) ,
1515+ ) ,
1516+ )
1517+ } ) ,
15061518 }
15071519 }
15081520 expressions
1509- } ,
1521+ }
15101522 DeclarationValue :: None => Vec :: new( ) ,
1511- DeclarationValue :: Var ( ..) => unreachable!( )
1523+ DeclarationValue :: Var ( ..) => unreachable!( ) ,
15121524 }
1513- } )
1514- } else {
1515- context:: TargetSymbolDescriptor :: Var ( context:: VarDescriptor {
1525+ } else {
1526+ Vec :: new( )
1527+ } ;
1528+ context:: TargetSymbolDescriptor :: List ( context:: ListDescriptor {
15161529 name: name. clone( ) ,
1517- canonical_name: canonical_identifier. as_ref( ) . map( |value|value. name. clone( ) ) ,
1530+ canonical_name: canonical_identifier
1531+ . as_ref( )
1532+ . map( |value| value. name. clone( ) ) ,
15181533 value_is_initial_value: values_are_initial_values,
1519- value: match & value {
1520- DeclarationValue :: None => grazelang_types:: project_json:: Sb3PrimitiveOrBool :: String ( "" . to_string( ) ) ,
1534+ value,
1535+ } )
1536+ } else {
1537+ let value = if values_are_initial_values {
1538+ match & value {
1539+ DeclarationValue :: None => {
1540+ grazelang_types:: project_json:: Sb3PrimitiveOrBool :: String ( String :: new( ) )
1541+ }
15211542 DeclarationValue :: Var ( _, value) => {
15221543 value. calculate_value( ) . map_err( |source| {
15231544 ParseError :: InvalidConstantExpression {
1524- expression: Box :: new( value. clone( ) ) , source
1545+ expression: Box :: new( value. clone( ) ) ,
1546+ source,
15251547 }
15261548 } ) ?
1527- } ,
1528- DeclarationValue :: List ( ..) => unreachable!( )
1529- } ,
1549+ }
1550+ DeclarationValue :: List ( ..) => unreachable!( ) ,
1551+ }
1552+ } else {
1553+ grazelang_types:: project_json:: Sb3PrimitiveOrBool :: String ( String :: new( ) )
1554+ } ;
1555+ context:: TargetSymbolDescriptor :: Var ( context:: VarDescriptor {
1556+ name: name. clone( ) ,
1557+ canonical_name: canonical_identifier
1558+ . as_ref( )
1559+ . map( |value| value. name. clone( ) ) ,
1560+ value_is_initial_value: values_are_initial_values,
1561+ value,
15301562 is_cloud: matches!(
15311563 ( default_scope, & scope) ,
1532- ( DataDeclarationScope :: Cloud ( _) , DataDeclarationScope :: Unset ) | ( _, DataDeclarationScope :: Cloud ( _) )
1533- )
1564+ ( DataDeclarationScope :: Cloud ( _) , DataDeclarationScope :: Unset )
1565+ | ( _, DataDeclarationScope :: Cloud ( _) )
1566+ ) ,
15341567 } )
15351568 } ) ;
15361569 if let Some ( previous_symbol) = previous_symbol {
@@ -1943,52 +1976,79 @@ pub mod statement {
19431976 let previous_symbol = symbols. insert(
19441977 name. clone( ) ,
19451978 if matches!( dec_type, SingleDataDeclarationType :: List ( _) ) {
1946- context:: TargetSymbolDescriptor :: List ( context:: ListDescriptor {
1947- name: name. clone( ) ,
1948- canonical_name: canonical_identifier. as_ref( ) . map( |value| value. name. clone( ) ) ,
1949- value_is_initial_value: values_are_initial_values,
1950- value: match & value {
1979+ let value = if values_are_initial_values {
1980+ match & value {
19511981 DeclarationValue :: List ( _, _, value, _) => {
19521982 let mut expressions = Vec :: with_capacity( value. len( ) ) ;
19531983 for entry in value {
19541984 match entry {
1955- ListEntry :: Expression ( expression) => expressions. push( expression. calculate_value( ) . map_err( |source| {
1956- ParseError :: InvalidConstantExpression {
1957- expression: Box :: new( expression. clone( ) ) , source
1958- }
1959- } ) ?) ,
1985+ ListEntry :: Expression ( expression) => {
1986+ expressions. push( expression. calculate_value( ) . map_err( |source| {
1987+ ParseError :: InvalidConstantExpression {
1988+ expression: Box :: new( expression. clone( ) ) ,
1989+ source,
1990+ }
1991+ } ) ?) ;
1992+ }
19601993 ListEntry :: Unwrap ( literal, _) => literal
19611994 . get_string_value( )
19621995 . as_str( )
19631996 . chars( )
1964- . for_each( |c| expressions. push(
1965- grazelang_types:: project_json:: Sb3PrimitiveOrBool :: String ( c. to_string( ) )
1966- ) ) ,
1997+ . for_each( |c| {
1998+ expressions. push(
1999+ grazelang_types:: project_json:: Sb3PrimitiveOrBool :: String (
2000+ c. to_string( ) ,
2001+ ) ,
2002+ )
2003+ } ) ,
19672004 }
19682005 }
19692006 expressions
1970- } ,
2007+ }
19712008 DeclarationValue :: None => Vec :: new( ) ,
1972- DeclarationValue :: Var ( ..) => unreachable!( )
2009+ DeclarationValue :: Var ( ..) => unreachable!( ) ,
19732010 }
1974- } )
1975- } else {
1976- context:: TargetSymbolDescriptor :: Var ( context:: VarDescriptor {
2011+ } else {
2012+ Vec :: new( )
2013+ } ;
2014+ context:: TargetSymbolDescriptor :: List ( context:: ListDescriptor {
19772015 name: name. clone( ) ,
1978- canonical_name: canonical_identifier. as_ref( ) . map( |value| value. name. clone( ) ) ,
2016+ canonical_name: canonical_identifier
2017+ . as_ref( )
2018+ . map( |value| value. name. clone( ) ) ,
19792019 value_is_initial_value: values_are_initial_values,
1980- value: match & value {
1981- DeclarationValue :: None => grazelang_types:: project_json:: Sb3PrimitiveOrBool :: String ( "" . to_string( ) ) ,
2020+ value,
2021+ } )
2022+ } else {
2023+ let value = if values_are_initial_values {
2024+ match & value {
2025+ DeclarationValue :: None => {
2026+ grazelang_types:: project_json:: Sb3PrimitiveOrBool :: String ( String :: new( ) )
2027+ }
19822028 DeclarationValue :: Var ( _, value) => {
19832029 value. calculate_value( ) . map_err( |source| {
19842030 ParseError :: InvalidConstantExpression {
1985- expression: Box :: new( value. clone( ) ) , source
2031+ expression: Box :: new( value. clone( ) ) ,
2032+ source,
19862033 }
19872034 } ) ?
1988- } ,
1989- DeclarationValue :: List ( ..) => unreachable!( )
1990- } ,
1991- is_cloud: matches!( scope, DataDeclarationScope :: Cloud ( _) )
2035+ }
2036+ DeclarationValue :: List ( ..) => unreachable!( ) ,
2037+ }
2038+ } else {
2039+ grazelang_types:: project_json:: Sb3PrimitiveOrBool :: String ( String :: new( ) )
2040+ } ;
2041+ context:: TargetSymbolDescriptor :: Var ( context:: VarDescriptor {
2042+ name: name. clone( ) ,
2043+ canonical_name: canonical_identifier
2044+ . as_ref( )
2045+ . map( |value| value. name. clone( ) ) ,
2046+ value_is_initial_value: values_are_initial_values,
2047+ value,
2048+ is_cloud: matches!(
2049+ & scope,
2050+ DataDeclarationScope :: Cloud ( _)
2051+ ) ,
19922052 } )
19932053 }
19942054 ) ;
0 commit comments