Simple strings

Author: Aaron Sherman

A trivial parser that handles quoted strings with backslash-escaped quotes and either single or double quotes used to delimit.

Source code: SimpleStrings.pm

use v6;

grammar String::Simple::Grammar {
    rule TOP {^  $}
    # Note for now, {} gets around a rakudo binding issue
    token string {  {} )> $ }
    token quote { '"' | "'" }
    token quotebody($quote) { (  |  . )* }
    token escaped($quote) { '\\' ( $quote | '\\' ) }
}

# The parse-tree builder ultimately returns the string itself.
class String::Simple::Actions {
    method TOP($/) { make $.made }
    method string($/) { make $.made }
    method quotebody($/) { make [~] $0.map: {..made or ~$_} }
    method escaped($/) { make ~$0 }
}