Module: L43Peg::Parsers::StringParser
- Extended by:
- StringParser
- Includes:
- Combinators, L43Peg::Parsers
- Included in:
- StringParser
- Defined in:
- lib/l43_peg/parsers/string_parser.rb
Instance Method Summary collapse
Methods included from L43Peg::Parsers
#char_parser, #end_parser, #eol_parser, #escape_parser, #failure_parser, #int_parser, #list_parser, #literal_parser, #name_parser, #rgx_parser, #success_parser, #symbol_parser, #ws_parser
Methods included from Combinators
#boxed, #choice, #debug_parser, #ignore, #lazy, #many, #map, #map_error, #satisfy, #sequence
Instance Method Details
#string_parser(name: nil, escape: "\\", double_escape: false, quote: '"') ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/l43_peg/parsers/string_parser.rb', line 8 def string_parser(name: nil, escape: "\\", double_escape: false, quote: '"') name = name || "string_parser(escape: #{escape}, double_escape: #{double_escape})" choices = [ (literal_parser(quote + quote).map { quote } if double_escape), escape_parser(escape), char_parser.satisfy { |ast| ast != quote } ].compact parser = sequence( char_parser(quote).ignore, many( choice(choices) ), char_parser(quote).ignore).map(&:join) end |