diff options
author | Adrian Thurston <thurston@complang.org> | 2013-03-29 22:50:16 -0400 |
---|---|---|
committer | Adrian Thurston <thurston@complang.org> | 2013-03-29 22:50:16 -0400 |
commit | 8e40a19fe788d8dc3ce8ad4475c545eadf1251ba (patch) | |
tree | 002917e93b500e4dccdcb3f290e6a607a6cabd6b | |
parent | d86ef75da71e07a489a0769e3860359f9a2cd5a1 (diff) | |
download | colm-8e40a19fe788d8dc3ce8ad4475c545eadf1251ba.tar.gz |
unified string and accumulate
Now have pattern, constructor and accumulate grammar sections.
-rw-r--r-- | colm/colm.lm | 42 | ||||
-rw-r--r-- | colm/load.cc | 107 |
2 files changed, 11 insertions, 138 deletions
diff --git a/colm/colm.lm b/colm/colm.lm index 37fb2531..930fde49 100644 --- a/colm/colm.lm +++ b/colm/colm.lm @@ -463,7 +463,7 @@ def code_factor | [Cons: CONS OptCapture: opt_capture TypeRef: type_ref OptFieldInit: opt_field_init Constructor: constructor] | [MATCH MatchVarRef: var_ref Pattern: pattern] -| [String: cstring] +| [String: accumulate] | [TypeRef: type_ref IN InVarRef: var_ref] | [MAKE_TREE POPEN MakeTreeExprList: code_expr* PCLOSE] | [MAKE_TOKEN POPEN MakeTokenExprList: code_expr* PCLOSE] @@ -503,6 +503,10 @@ def field_init # Pattern # +def opt_tilde_data + [tilde_data] +| [] + def litpat_term [CONS_DQ] | [Nl: CONS_NL] @@ -517,7 +521,7 @@ def opt_label def pattern_el [OptLabel: opt_label TypeOrLit: pattern_el_lel] | [DQ LitpatElList: litpat_el* Term: litpat_term] -| [TILDE TildeData: tilde_data Nl: TILDE_NL] +| [TILDE TildeData: opt_tilde_data Nl: TILDE_NL] def litpat_el [ConsData: cons_data] @@ -565,36 +569,6 @@ def constructor [ConsList: cons_list] # -# String List -# - -def opt_tilde_data - [tilde_data] -| [] - -def string_el - [DQ LitStringElList: lit_string_el* Term: lit_cons_term] -| [TILDE TildeData: opt_tilde_data Nl: TILDE_NL] -| [CodeExpr: code_expr] - -def lit_string_el - [ConsData: cons_data] -| [CONS_SQOPEN StringElList: string_el* CONS_SQCLOSE] - -def string_top_el - [DQ LitStringElList: lit_string_el* Term: lit_cons_term] -| [TILDE TildeData: opt_tilde_data Nl: TILDE_NL] -| [SQOPEN StringElList: string_el* SQCLOSE] - -def string_list - [StringTopEl: string_top_el StringList: string_list] -| [StringTopEl: string_top_el] - -def cstring - [StringList: string_list] - - -# # Accumulate # @@ -619,6 +593,10 @@ def accum_list def accumulate [AccumList: accum_list] +# +# VarRef +# + def var_ref [Qual: qual Id: id] diff --git a/colm/load.cc b/colm/load.cc index f79babb4..d58c58d5 100644 --- a/colm/load.cc +++ b/colm/load.cc @@ -1155,111 +1155,6 @@ struct LoadSource } /* - * String - */ - - ConsItemList *walkLitStringEl( lit_string_el litStringEl ) - { - ConsItemList *list = 0; - if ( litStringEl.ConsData() != 0 ) { - String consData = unescape( litStringEl.ConsData().text().c_str() ); - ConsItem *stringItem = ConsItem::cons( litStringEl.ConsData().loc(), - ConsItem::InputText, consData ); - list = ConsItemList::cons( stringItem ); - } - else if ( litStringEl.StringElList() != 0 ) { - list = walkStringElList( litStringEl.StringElList() ); - } - return list; - } - - ConsItemList *walkLitStringElList( _repeat_lit_string_el litStringElList, CONS_NL Nl ) - { - ConsItemList *list = new ConsItemList; - while ( !litStringElList.end() ) { - ConsItemList *extension = walkLitStringEl( litStringElList.value() ); - list = consListConcat( list, extension ); - litStringElList = litStringElList.next(); - } - - if ( Nl != 0 ) { - String consData = unescape( Nl.text().c_str() ); - ConsItem *consItem = ConsItem::cons( Nl.loc(), ConsItem::InputText, consData ); - ConsItemList *term = ConsItemList::cons( consItem ); - list = consListConcat( list, term ); - } - return list; - } - - ConsItemList *walkStringEl( string_el stringEl ) - { - ConsItemList *list = 0; - if ( stringEl.LitStringElList() != 0 ) { - list = walkLitStringElList( stringEl.LitStringElList(), stringEl.Term().Nl() ); - } - else if ( stringEl.TildeData() != 0 ) { - String consData = stringEl.TildeData().text().c_str(); - consData += '\n'; - ConsItem *consItem = ConsItem::cons( stringEl.TildeData().loc(), - ConsItem::InputText, consData ); - list = ConsItemList::cons( consItem ); - } - else if ( stringEl.CodeExpr() != 0 ) { - LangExpr *consExpr = walkCodeExpr( stringEl.CodeExpr() ); - ConsItem *consItem = ConsItem::cons( consExpr->loc, ConsItem::ExprType, consExpr ); - list = ConsItemList::cons( consItem ); - } - return list; - } - - ConsItemList *walkStringElList( _repeat_string_el stringElList ) - { - ConsItemList *list = new ConsItemList; - while ( !stringElList.end() ) { - ConsItemList *extension = walkStringEl( stringElList.value() ); - list = consListConcat( list, extension ); - stringElList = stringElList.next(); - } - return list; - } - - ConsItemList *walkStringTopEl( string_top_el stringTopEl ) - { - ConsItemList *list = 0; - if ( stringTopEl.LitStringElList() != 0 ) - list = walkLitStringElList( stringTopEl.LitStringElList(), stringTopEl.Term().Nl() ); - else if ( stringTopEl.TildeData() != 0 ) { - String consData = stringTopEl.TildeData().text().c_str(); - consData += '\n'; - ConsItem *consItem = ConsItem::cons( stringTopEl.TildeData().loc(), - ConsItem::InputText, consData ); - list = ConsItemList::cons( consItem ); - } - else if ( stringTopEl.StringElList() != 0 ) { - list = walkStringElList( stringTopEl.StringElList() ); - } - return list; - } - - ConsItemList *walkStringList( string_list stringList ) - { - ConsItemList *list = walkStringTopEl( stringList.StringTopEl() ); - - if ( stringList.StringList() != 0 ) { - ConsItemList *extension = walkStringList( stringList.StringList() ); - consListConcat( list, extension ); - } - - return list; - } - - ConsItemList *walkString( cstring String ) - { - ConsItemList *list = walkStringList( String.StringList() ); - return list; - } - - /* * Accum */ @@ -1466,7 +1361,7 @@ struct LoadSource expr = walkCodeExpr( codeFactor.ParenCodeExpr() ); } else if ( codeFactor.String() != 0 ) { - ConsItemList *list = walkString( codeFactor.String() ); + ConsItemList *list = walkAccumulate( codeFactor.String() ); expr = LangExpr::cons( LangTerm::cons( codeFactor.String().loc(), list ) ); } else if ( codeFactor.MatchVarRef() != 0 ) { |