diff options
author | Adrian Thurston <thurston@colm.net> | 2019-12-28 15:32:53 +0200 |
---|---|---|
committer | Adrian Thurston <thurston@colm.net> | 2019-12-28 15:32:53 +0200 |
commit | a1028d7f79c71a1e52ae11071b69adaec593cbdb (patch) | |
tree | 684fd7114a7bd67df1140c15a0accbfbe66bc624 /colm/loadfinal.cc | |
parent | f2bbad18a77fc52ba64d6bf4a14338fec8061d1f (diff) | |
download | colm-literal-concatenation.tar.gz |
colm: testing a new grammar where string concatenations are allowedliteral-concatenation
This commit brings back string concatenations in match/cons/string literals at
the top level. It does not bring back concatenation of [] lists. For example,
you can write:
match Foo
"hi
"there
BUT NOT:
match Foo
[Hi] [There]
The concatenation (of both forms) was removed when bare sends were added, due
to the ambiguity created. However, removing these concatenations has proven
quite annoying.
This change re-introduces the ambiguity, which maybe we should do something
about by detecting when it is likely via mis-alignments of the strings, or
making some other change to sends.
refs #95
Diffstat (limited to 'colm/loadfinal.cc')
-rw-r--r-- | colm/loadfinal.cc | 64 |
1 files changed, 39 insertions, 25 deletions
diff --git a/colm/loadfinal.cc b/colm/loadfinal.cc index 4162140d..29f5205b 100644 --- a/colm/loadfinal.cc +++ b/colm/loadfinal.cc @@ -645,28 +645,29 @@ struct LoadColm patternTopEl.opt_tilde_data().loc(), patternData ); list = PatternItemList::cons( patternItem ); break; - } - case pattern_top_el::SubList: { - list = walkPatternElList( patternTopEl.PatternElList(), patternVarRef ); - break; }} return list; } PatternItemList *walkPatternList( pattern_list patternList, LangVarRef *patternVarRef ) { - PatternItemList *list = 0; - switch ( patternList.prodName() ) { - case pattern_list::Base: { - list = walkPattternTopEl( patternList.pattern_top_el(), patternVarRef ); - break; - }} - return list; + PatternItemList *ret = new PatternItemList; + RepeatIter<pattern_top_el> patternTopElIter ( patternList ); + while ( !patternTopElIter.end() ) { + PatternItemList *list = walkPattternTopEl( patternTopElIter.value(), patternVarRef ); + ret->append( *list ); + delete list; + patternTopElIter.next(); + } + return ret; } PatternItemList *walkPattern( pattern Pattern, LangVarRef *patternVarRef ) { - return walkPatternList( Pattern.pattern_list(), patternVarRef ); + if ( Pattern.prodName() == pattern::TopList ) + return walkPatternList( Pattern.pattern_list(), patternVarRef ); + else + return walkPatternElList( Pattern.PatternElList(), patternVarRef ); } LangExpr *walkOptDefInit( opt_def_init optDefInit ) @@ -1560,22 +1561,29 @@ struct LoadColm ConsItem::InputText, consData ); list = ConsItemList::cons( consItem ); break; - } - case cons_top_el::SubList: { - list = walkConsElList( consTopEl.ConsElList(), consTypeRef ); - break; }} return list; } ConsItemList *walkConsList( cons_list consList, TypeRef *consTypeRef ) { - return walkConsTopEl( consList.cons_top_el(), consTypeRef ); + ConsItemList *ret = new ConsItemList; + RepeatIter<cons_top_el> consTopElIter ( consList ); + while ( !consTopElIter.end() ) { + ConsItemList *list = walkConsTopEl( consTopElIter.value(), consTypeRef ); + ret->append( *list ); + delete list; + consTopElIter.next(); + } + return ret; } ConsItemList *walkConstructor( constructor Constructor, TypeRef *consTypeRef ) { - return walkConsList( Constructor.cons_list(), consTypeRef ); + if ( Constructor.prodName() == constructor::TopList ) + return walkConsList( Constructor.cons_list(), consTypeRef ); + else + return walkConsElList( Constructor.ConsElList(), consTypeRef ); } /* @@ -1691,23 +1699,29 @@ struct LoadColm ConsItem::InputText, consData ); list = ConsItemList::cons( consItem ); break; - } - case string_top_el::SubList: { - list = walkStringElList( stringTopEl.StringElList() ); - break; }} return list; } ConsItemList *walkStringList( string_list stringList ) { - return walkStringTopEl( stringList.string_top_el() ); + ConsItemList *ret = new ConsItemList; + RepeatIter<string_top_el> stringTopElIter( stringList ); + while ( !stringTopElIter.end() ) { + ConsItemList *list = walkStringTopEl( stringTopElIter.value() ); + ret->append( *list ); + delete list; + stringTopElIter.next(); + } + return ret; } ConsItemList *walkString( string String ) { - ConsItemList *list = walkStringList( String.string_list() ); - return list; + if ( String.prodName() == string::TopList ) + return walkStringList( String.string_list() ); + else + return walkStringElList( String.StringElList() ); } /* |