class CLTK::Parser

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.cr
cltk/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

Instance Method Summary

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

def self._parse(procs, lh_sides, symbols, states, token_hooks, tokens, opts : NamedTuple? = nil) #

[View source]
def self.add_state(state) #

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.


[View source]
def self.c(expression, precedence = nil, arg_type = @@default_arg_type, &action : Array(Type), Environment -> _) #

Shorthands for defining productions and clauses


[View source]
def self.crystalize(name : Symbol | String = self.name) #

[View source]
def self.each_state(&block) #

Iterate over the parser's states.

@yieldparam [State] state One of the parser automaton's state objects

@return [void]


[View source]
def self.env #

make these class attributes accessible from outside (for the Visitor to work on them)


[View source]
def self.grammar #

@return [CFG] The grammar that can be parsed by this Parser.


[View source]
def self.grammar_prime #

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]


[View source]
def self.inform_conflict(state_id, type, sym) #

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]


[View source]
def self.lh_sides #

make these class attributes accessible from outside (for the Visitor to work on them)


[View source]
def self.p(symbol, expression = nil, precedence = nil, arg_type = @@default_arg_type, &action : Array(Type), Environment -> _) #

[View source]
def self.parse(tokens, opts = nil) #

[View source]
def self.parse(tokens : Array, opts : NamedTuple? = nil) #

[View source]
def self.procs #

make these class attributes accessible from outside (for the Visitor to work on them)


[View source]
def self.setenv(env) #

[View source]
def self.start(symbol) #

Changes the starting symbol of the parser.

@param [Symbol] symbol The starting symbol of the grammar.

@return [void]


[View source]
def self.states #

make these class attributes accessible from outside (for the Visitor to work on them)


[View source]
def self.symbols #

make these class attributes accessible from outside (for the Visitor to work on them)


[View source]
def self.token_hook(sym, &proc : Proc(Environment, Nil)) #

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]


[View source]
def self.token_hooks #

make these class attributes accessible from outside (for the Visitor to work on them)


[View source]

Instance Method Detail

def env #

@return [Environment] Environment used by the instantiated parser.


[View source]
def parse(tokens) #

Parses the given token stream using the encapsulated environment.

@see .parse


[View source]

Macro Detail

macro class_getter(*attributes) #

[View source]