class CLTK::Parser
- CLTK::Parser
- Reference
- Object
Overview
The Parser class may be sub-classed to produce new parsers. These parsers have a lot of features, and are described in the main documentation.
Included Modules
Direct Known Subclasses
Defined in:
cltk/parser/exceptions/bad_token_exception.crcltk/parser/exceptions/internal_parser_exception.cr
cltk/parser/exceptions/parser_construction_exception.cr
cltk/parser/exceptions/handled_error_exception.cr
cltk/parser/exceptions/not_in_language_exception.cr
cltk/parser/exceptions/useless_parser_exception.cr
cltk/parser/environment.cr
cltk/parser/type.cr
cltk/parser/parse_stack.cr
cltk/parser/state.cr
cltk/parser/prod_proc.cr
cltk/parser/actions.cr
cltk/parser/msgpack.cr
cltk/parser.cr
cltk/parser/prod_proc_debug.cr
cltk/parser/crystalize.cr
cltk/parser/parser_concern.cr
Class Method Summary
- ._parse(procs, lh_sides, symbols, states, token_hooks, tokens, opts : NamedTuple? = nil)
-
.add_state(state)
If state (or its equivalent) is not in the state list it is added and it's ID is returned.
-
.c(expression, precedence = nil, arg_type = @@default_arg_type, &action : Array(Type), Environment -> _)
Shorthands for defining productions and clauses
- .crystalize(name : Symbol | String = self.name)
-
.each_state(&block)
Iterate over the parser's states.
-
.env
make these class attributes accessible from outside (for the Visitor to work on them)
-
.grammar
@return [CFG] The grammar that can be parsed by this Parser.
-
.grammar_prime
This method generates and memoizes the G' grammar used to calculate the LALR(1) lookahead sets.
-
.inform_conflict(state_id, type, sym)
Inform the parser core that a conflict has been detected.
-
.lh_sides
make these class attributes accessible from outside (for the Visitor to work on them)
- .p(symbol, expression = nil, precedence = nil, arg_type = @@default_arg_type, &action : Array(Type), Environment -> _)
- .parse(tokens, opts = nil)
- .parse(tokens : Array, opts : NamedTuple? = nil)
-
.procs
make these class attributes accessible from outside (for the Visitor to work on them)
- .setenv(env)
-
.start(symbol)
Changes the starting symbol of the parser.
-
.states
make these class attributes accessible from outside (for the Visitor to work on them)
-
.symbols
make these class attributes accessible from outside (for the Visitor to work on them)
-
.token_hook(sym, &proc : Proc(Environment, Nil))
Add a hook that is executed whenever sym is seen.
-
.token_hooks
make these class attributes accessible from outside (for the Visitor to work on them)
Instance Method Summary
-
#env
@return [Environment] Environment used by the instantiated parser.
-
#parse(tokens)
Parses the given token stream using the encapsulated environment.
Macro Summary
Class methods inherited from module CLTK::Parser::Explain
explain(io : IO)
explain
Instance methods inherited from class Object
in?(collection : Array | Set)
in?
Class Method Detail
If state (or its equivalent) is not in the state list it is added and it's ID is returned. If there is already a state with the same items as state in the state list its ID is returned and state is discarded.
@param [State] state State to add to the parser.
@return [Integer] The ID of the state.
Shorthands for defining productions and clauses
Iterate over the parser's states.
@yieldparam [State] state One of the parser automaton's state objects
@return [void]
make these class attributes accessible from outside (for the Visitor to work on them)
This method generates and memoizes the G' grammar used to calculate the LALR(1) lookahead sets. Information about this grammar and its use can be found in the following paper:
Simple Computation of LALR(1) Lookahead Sets Manuel E. Bermudez and George Logothetis Information Processing Letters 31 - 1989
@return [CFG]
Inform the parser core that a conflict has been detected.
@param [Integer] state_id ID of the state where the conflict was encountered. @param [:RR, :SR] type Reduce/Reduce or Shift/Reduce conflict. @param [Symbol] sym Symbol that caused the conflict.
@return [void]
make these class attributes accessible from outside (for the Visitor to work on them)
make these class attributes accessible from outside (for the Visitor to work on them)
Changes the starting symbol of the parser.
@param [Symbol] symbol The starting symbol of the grammar.
@return [void]
make these class attributes accessible from outside (for the Visitor to work on them)
make these class attributes accessible from outside (for the Visitor to work on them)
Add a hook that is executed whenever sym is seen.
The sym must be a terminal symbol.
@param [Symbol] sym Symbol to hook into @param [Proc] proc Code to execute when the block is seen
@return [void]
make these class attributes accessible from outside (for the Visitor to work on them)