Skip to content

Commit

Permalink
Dequote strings during parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
bacek committed Mar 28, 2011
1 parent 4a04e0f commit 77d0dcf
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
5 changes: 4 additions & 1 deletion compilers/opsc/src/Ops/Compiler/Actions.pm
Expand Up @@ -246,6 +246,9 @@ method op_body($/) {
make $<blockoid>.ast;
}

method quote:sym<apos>($/) { make $<quote_EXPR>.ast; }
method quote:sym<dblq>($/) { make $<quote_EXPR>.ast; }

method op_macro:sym<expr offset>($/) {
make PAST::Op.new(
:pasttype<macro>,
Expand Down Expand Up @@ -521,7 +524,7 @@ method term:sym<int> ($/) {

method term:sym<str> ($/) {
make PAST::Val.new(
:value(~$<quote>),
:value($<quote>.ast.value),
:returns<string>
);
}
Expand Down
2 changes: 1 addition & 1 deletion compilers/opsc/src/Ops/Compiler/Grammar.pm
Expand Up @@ -93,7 +93,7 @@ token op_body {

proto token quote { <...> }
token quote:sym<apos> { <?[']> <quote_EXPR: ':q'> }
token quote:sym<dblq> { <?["]> <quote_EXPR: ':q'> }
token quote:sym<dblq> { <?["]> <quote_EXPR: ':qq'> }

proto rule op_macro { <...> }
rule op_macro:sym<goto offset> { 'goto' 'OFFSET' '(' <arg=.EXPR> ')' }
Expand Down
4 changes: 3 additions & 1 deletion compilers/opsc/src/Ops/Op.pm
Expand Up @@ -286,7 +286,9 @@ method get_body( %context ) {

# Recursively process body chunks returning string.
our multi method to_c(PAST::Val $val, %c) {
$val.value;
$val.returns eq 'string'
?? '"' ~ subst($val.value, /\n/, '\n', :global) ~ '"' # FIXME other quoted
!! $val.value;
}

our multi method to_c(PAST::Var $var, %c) {
Expand Down

0 comments on commit 77d0dcf

Please sign in to comment.