Module: Parsr::Rules::String

Defined in:
lib/parsr/rules/string.rb

Defined Under Namespace

Classes: Unterminated

Constant Summary collapse

ESCAPED_CHARS =
{'\n' => "\n", '\b' => "\b", '\f' => "\f", '\r' => "\r", '\t' => "\t"}

Class Method Summary collapse

Class Method Details

.match(scanner) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/parsr/rules/string.rb', line 11

def match(scanner)
  if scanner.scan(/"/)
    buffer = ''
    while chunk = (parse_content(scanner) || parse_escape(scanner))
      buffer << chunk
    end
    raise Unterminated.new(scanner) unless terminated?(scanner)
    return Parsr::Token.new(buffer)
  end
  nil
end