diff options
author | Adrian Thurston <thurston@colm.net> | 2016-10-01 09:34:21 -0700 |
---|---|---|
committer | Adrian Thurston <thurston@colm.net> | 2016-10-01 09:34:21 -0700 |
commit | 84f764672525cd475114b76b104fc1bc0e6ce5b2 (patch) | |
tree | ff409ee3f52e08447b90af014f3ff5b8284c389c /src/synthesis.cc | |
parent | fb9e7b3b77657a7e2db63d7cd2d9cd4706715d21 (diff) | |
download | colm-84f764672525cd475114b76b104fc1bc0e6ce5b2.tar.gz |
auto-trim in print, send and construct, disable with @
Now automatically trimming when building trees and printing. This is consistent
with the $ operator. Rationale is to standardize on the most commonly desired
behaviour and provide options for the less-needed.
Also much less likely to result in surprising output. There are many cases
where test inputs won't have any surrounding ignores, making it easy to forget
a trim is required. Then the occasional tree with surrounding ignores will give
an undesired result. Better to standardize on trim, making the default
behaviour more consistent.
The trim can be turned off with the @ operator in front of an expression.
Diffstat (limited to 'src/synthesis.cc')
-rw-r--r-- | src/synthesis.cc | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/src/synthesis.cc b/src/synthesis.cc index 64178cae..bda6aece 100644 --- a/src/synthesis.cc +++ b/src/synthesis.cc @@ -30,6 +30,16 @@ using std::cout; using std::cerr; using std::endl; +bool isStr( UniqueType *ut ) +{ + return ut->typeId == TYPE_TREE && ut->langEl != 0 && ut->langEl->id == LEL_ID_STR; +} + +bool isTree( UniqueType *ut ) +{ + return ut->typeId == TYPE_TREE; +} + IterDef::IterDef( Type type ) : type(type), @@ -1344,6 +1354,11 @@ UniqueType *LangTerm::evaluateConstruct( Compiler *pd, CodeVect &code ) const "replacements must be trees" << endp; } + if ( !isStr( ut ) ) { + if ( item->trim ) + code.append( IN_TREE_TRIM ); + } + item->langEl = ut->langEl; } } @@ -1601,6 +1616,10 @@ void ConsItemList::evaluateSendStream( Compiler *pd, CodeVect &code ) code.append( IN_POP_TREE ); continue; } + else if ( ut->typeId == TYPE_TREE && !isStr( ut ) ) { + if ( item->trim ) + code.append( IN_TREE_TRIM ); + } if ( ut->typeId == TYPE_INT || ut->typeId == TYPE_BOOL ) code.append( IN_INT_TO_STR ); @@ -2504,6 +2523,9 @@ void LangStmt::compile( Compiler *pd, CodeVect &code ) const { code.append( IN_INT_TO_STR ); } + else if ( isTree( types[pex.pos()] ) && !isStr( types[pex.pos()] ) ) { + code.append( IN_TREE_TRIM ); + } } /* Run the printing forwards. */ |