in reply to Re: Parsing spaces and curly braces
in thread Parsing spaces and curly braces
Your parser is really just a tokenizer. m/.../gc lends itself well to writting tokenizers, as seen in the following snippet:
while (my $line = <>) { chomp($line); my @tokens; foreach ($line) { /\G ( [^{\s]+ )/xgc && do { push(@tokens, $1); redo }; /\G ( {[^}]*} )/xgc && do { push(@tokens, $1); redo }; /\G \s+/xgc; redo; } ...process split line... }
Cases not specified by the OP behave as follows:
"xxx{yyy zzz}" is split into "xxx" and "{yyy zzz}".
"{xxx yyy}zzz" is split into "{xxx yyy}" and "zzz".
|
|---|