diff options
author | Adrian Thurston <thurston@complang.org> | 2012-05-21 15:50:00 -0400 |
---|---|---|
committer | Adrian Thurston <thurston@complang.org> | 2012-05-21 15:50:00 -0400 |
commit | dd0f1865850106fd12f6f1f01e0639457f9dea4f (patch) | |
tree | dd3949056f70d6c98d0b8881084a67fa196cbaee | |
parent | 6b7f2d2af94a2e420d8f4c72dbc1b388faf6fbf9 (diff) | |
download | colm-dd0f1865850106fd12f6f1f01e0639457f9dea4f.tar.gz |
auto trim before $ string conversion
The $ operation automatically adds a TRIM. The '%' opertion was added, which is
the original $ conversion without the trim.
-rw-r--r-- | colm/compile.cc | 12 | ||||
-rw-r--r-- | colm/lmparse.kl | 4 | ||||
-rw-r--r-- | test/order2.lm | 2 |
3 files changed, 15 insertions, 3 deletions
diff --git a/colm/compile.cc b/colm/compile.cc index 453fcf2d..f948d33f 100644 --- a/colm/compile.cc +++ b/colm/compile.cc @@ -1720,14 +1720,22 @@ UniqueType *LangExpr::evaluate( ParseData *pd, CodeVect &code ) const return pd->uniqueTypeBool; } case '$': { - right->evaluate( pd, code ); + UniqueType *rt = right->evaluate( pd, code ); + if ( rt->typeId == TYPE_TREE && rt != pd->uniqueTypeInt && rt != pd->uniqueTypeStr && rt != pd->uniqueTypeBool ) + code.append( IN_TREE_TRIM ); code.append( IN_TREE_TO_STR ); return pd->uniqueTypeStr; } + case '%': { + right->evaluate( pd, code ); + code.append( IN_TREE_TO_STR ); + return pd->uniqueTypeStr; + } case '^': { UniqueType *rt = right->evaluate( pd, code ); - code.append( IN_TREE_TRIM ); + if ( rt->typeId == TYPE_TREE && rt != pd->uniqueTypeInt && rt != pd->uniqueTypeStr && rt != pd->uniqueTypeBool ) + code.append( IN_TREE_TRIM ); return rt; } case OP_Deref: { diff --git a/colm/lmparse.kl b/colm/lmparse.kl index 82b46062..3689b922 100644 --- a/colm/lmparse.kl +++ b/colm/lmparse.kl @@ -1690,6 +1690,10 @@ code_unary: '^' code_factor final { $$->expr = new LangExpr( $1->loc, '^', $2->expr ); }; +code_unary: '%' code_factor + final { + $$->expr = new LangExpr( $1->loc, '%', $2->expr ); + }; code_unary: code_factor final { $$->expr = $1->expr; diff --git a/test/order2.lm b/test/order2.lm index 1dd99987..33458524 100644 --- a/test/order2.lm +++ b/test/order2.lm @@ -88,7 +88,7 @@ Output: output Output = construct output [] # Take off the leading C from the input file and send it out. match P [C: c '%%' protocol*] -Output << [$C] +Output << [%C] Output << "#include <assert.h> " |