class Marpa::Parser
- Marpa::Parser
- Reference
- Object
Defined in:
marpa.crmarpa/helpers.cr
Constructors
Instance Method Summary
- #build_meta_grammar(actions)
-
#compile(grammar : String)
Convenience method to expose internals of grammar, lexer, symbols, rules, etc.
- #discard : Array(String)
- #discard=(discard : Array(String))
- #discards : Array({String, String})
- #discards=(discards : Array(Tuple(String, String)))
- #expected : Array(String)
- #expected=(expected : Array(String))
- #grammar : LibMarpa::MarpaGrammar
- #grammar=(grammar : LibMarpa::MarpaGrammar)
- #input : String
- #input=(input : String)
- #lexemes : Hash(Int32, Hash(String, String))
- #lexemes=(lexemes : Hash(Int32, Hash(String, String)))
- #lexer : Hash(String, Regex)
- #lexer=(lexer : Hash(String, Regex))
- #matches : Array({String, String})
- #matches=(matches : Array(Tuple(String, String)))
- #parse(input : String, grammar : String, actions : Actions = Actions.new, events : Events = Events.new)
-
#parse(input : String, builder : Builder, actions : Actions = Actions.new, events : Events = Events.new)
Internal method used to parse the given input given computed grammar, Notated here as
builder
- #position : Int32
- #position=(position : Int32)
- #recce : LibMarpa::MarpaRecognizer
- #recce=(recce : LibMarpa::MarpaRecognizer)
- #rules : Hash(Int32, Hash(String, String))
- #rules=(rules : Hash(Int32, Hash(String, String)))
- #symbols : Hash(String, Int32)
- #symbols=(symbols : Hash(String, Int32))
- #values : Hash(Int32, String)
- #values=(values : Hash(Int32, String))
Constructor Detail
Instance Method Detail
def compile(grammar : String)
#
Convenience method to expose internals of grammar, lexer, symbols, rules, etc.
Accepts #grammar
as BNF, and returns a builder object that can be used the same
as before:
parser = Marpa::Parser.new
grammar = <<-'END_BNF'
:start ::= A
A ::= a
a ~ 'a'
END_BNF
input = "a"
grammar = parser.compile(grammar)
parser.parse(input, grammar) # => ["a"]
def parse(input : String, grammar : String, actions : Actions = Actions.new, events : Events = Events.new)
#
Parse #input
given #grammar
in BNF format.
Accepts optional actions
that can be used to perform semantics
on given rules.
On successful parse, returns the parse tree