Skip to content

Commit

Permalink
created <quoted_word> to be shared by <list>
Browse files Browse the repository at this point in the history
- add in error handling for quoted list elements followed by stuff
- untodo all related tests
  • Loading branch information
coke committed Apr 13, 2010
1 parent 294435d commit 9eaaf7a
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 13 deletions.
4 changes: 3 additions & 1 deletion src/Partcl/Actions.pm
Expand Up @@ -73,7 +73,7 @@ method word:sym<{*}>($/) {
make PAST::Op.new( :name<EXPAND>, $<word>.ast, :flat);
}
method word:sym<{ }>($/) { make $<braced_word>.ast; }
method word:sym<" ">($/) { make concat_atoms($<quoted_atom>); }
method word:sym<" ">($/) { make $<quoted_word>.ast; }
method word:sym<bare>($/) { make concat_atoms($<bare_atom>); }
method braced_word($/) { make concat_atoms($<braced_atom>); }
Expand All @@ -84,6 +84,8 @@ method braced_atom:sym<back}>($/) { make "\\" ~ '}'; }
method braced_atom:sym<back>($/) { make "\\"; }
method braced_atom:sym<chr>($/) { make ~$/; }
method quoted_word($/) { make concat_atoms($<quoted_atom>); }
method quoted_atom:sym<[ ]>($/) { make $<script>.ast; }
method quoted_atom:sym<var>($/) { make $<variable>.ast; }
method quoted_atom:sym<$>($/) { make '$'; }
Expand Down
6 changes: 5 additions & 1 deletion src/Partcl/Grammar.pm
Expand Up @@ -28,7 +28,7 @@ token word:sym<{*}> { '{*}' <word> }

token word:sym<{ }> { <braced_word> }

token word:sym<" "> { '"' <quoted_atom>* '"' }
token word:sym<" "> { <quoted_word> }

token word:sym<bare> { <bare_atom>+ }

Expand All @@ -41,6 +41,8 @@ token braced_atom:sym<back}> { \\ \} }
token braced_atom:sym<back> { \\ }
token braced_atom:sym<chr> { <-[ \\ { } ]>+ }

token quoted_word { '"' <quoted_atom>* '"'}

proto token quoted_atom { <...> }
token quoted_atom:sym<[ ]> { '[' ~ ']' <script> }
token quoted_atom:sym<var> { <variable> }
Expand Down Expand Up @@ -72,6 +74,8 @@ token backslash:sym<backu> { \\ u $<u>=[<.xdigit> ** 1..4] }
token list {
\s*
[
| <EXPR=.quoted_word>
[ $<extra>=(\S+) { $/.CURSOR.badList('quotes', $<extra><sym>); }]?
| <EXPR=.braced_word>
[ $<extra>=(\S+) { $/.CURSOR.badList('braces', $<extra><sym>); }]?
| <EXPR=.list_word>
Expand Down
12 changes: 6 additions & 6 deletions t/tcl_backslash.t
Expand Up @@ -20,15 +20,15 @@ b" "a b" {backslash/newline subst}

# octal
is \7 \x07 {octal single}
is \79 [join {"\x07" 9} ""] {octal single extra} {TODO NQPRX}
is \79 [join {"\x07" 9} ""] {octal single extra}
is \12 \x0a {octal double}
is \129 [join {"\x0a" 9} ""] {octal double extra} {TODO NQPRX}
is \129 [join {"\x0a" 9} ""] {octal double extra}
is \123 S {octal triple}
is \1234 S4 {octal triple extra}

is \xq xq {hex single invalid}
is \x7 \7 {hex single}
is \x7q [join {"\7" q} ""] {hex single, extra} {TODO NQPRX}
is \x7q [join {"\7" q} ""] {hex single, extra}
is \x6a j {hex double}
is \x6aq jq {hex double, extra}
is \xb6a j {hex triple, skip ok?}
Expand All @@ -47,11 +47,11 @@ is \u6aq jq {unicode double, extra}
# to insure we parsed it properly.

is \u39b [string toupper \u3bb] {unicode three}
is \u39bq [join {"\u39b" q} ""] {unicode three, extra} {TODO NQPRX}
is \u39bq [join {"\u39b" q} ""] {unicode three, extra}
is \u0453 [string tolower \u0403] {unicode four}
is \u0453q [join {"\u0453" q} ""] {unicode four,extra} {TODO NQPRX}
is \u0453q [join {"\u0453" q} ""] {unicode four,extra}

is \\\a\007\xaaaa07\u0007\uq \
[join {"\x5c" "\7" "\7" "\7" "\7" u q} ""] {multiple per word} {TODO NQPRX}
[join {"\x5c" "\7" "\7" "\7" "\7" u q} ""] {multiple per word}

# vim: filetype=tcl:
10 changes: 5 additions & 5 deletions t/tcl_conversion.t
Expand Up @@ -6,12 +6,12 @@ plan 12
is [llength {a
"a b"
b {b c} c {c d}
}] 6 {{} conversion to list" } {TODO NQPRX}
}] 6 {{} conversion to list" }
is [llength "a
\"a b\"
b {b c} c {c d}
"] 6 {"\ conversion to list} {TODO NQPRX}
"] 6 {"\ conversion to list}

set a "a {b c} d"
is [ llength $a ] 3 {" conversion to list 1}
Expand All @@ -29,16 +29,16 @@ eval_is { lindex {{a b}3} 1} \
eval_is {lindex {"a b"3 4} 1} \
{list element in quotes followed by "3" instead of space} \
{non space after "} {TODO NQPRX}
{non space after "}

eval_is {lindex {"a b"3} 1} \
{list element in quotes followed by "3" instead of space} \
{non space after "} {TODO NQPRX}
{non space after "}
is [list \{\[] {\{\[} {[ in list}
is [lindex {"a \" b"} 0] {a " b} {escaped quote in quotes in list} {TODO NQPRX}
is [lindex {"a \" b"} 0] {a " b} {escaped quote in quotes in list}

is [lindex {{a \" b}} 0] {a \" b} {escaped quote in sub-list}

Expand Down

0 comments on commit 9eaaf7a

Please sign in to comment.