Skip to content

exception while parsing #228

@jnavila

Description

@jnavila

I'm trying to make a simple parser for synopsis quotes in asciidoc's manpages for git. The code is not functional yet, but I'm hitting an issue withing parslet.

require 'parslet'

class AsciidocQuote < Parslet::Parser
        # parse a string like "git add -p [--root=<path>]" as series of tokens keywords, grammar signs and placeholders
        # where placeholders are UTF-8 words separated by '-', enclosed in '<' and '>'
        rule(:space)      { match('\s').repeat(1) }
        rule(:space?)     { space.maybe }
        rule(:keyword) { match('[-a-zA-Z0-9:+=~@,\./_^\$]').repeat(1) >> :space? }
        rule(:placeholder) { str('<') >> match('[[:word:]]').repeat(1) >> str('>') >> :space? }
        rule(:opt_or_alt) { match('[\[\] |()]') >> :space? }
        rule(:ellipsis) { str('...') >> peek(match('[^\]$.]')) }
        rule(:grammar) { opt_or_alt | ellipsis }

        rule(:token) { grammar.as(:grammar) | keyword.as(:keyword) | placeholder.as(:placeholder) }
        rule(:tokens) { token.repeat(1) }
        root(:tokens)
end

def parse(str)
  quote = AsciidocQuote.new

  quote.parse(str)
rescue Parslet::ParseFailed => failure
  puts failure.parse_failure_cause.ascii_tree
end

parse("git add -p [--root=<path>]")
parse("--trailer <token>[(=|:)<value>]...")

The error reporting raises an exception:
parslet-2.0.0/lib/parslet/atoms/sequence.rb:46:in to_s': wrong number of arguments (given 1, expected 0) (ArgumentError)`

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions