class CLTK::Parser::State

Overview

The State class is used to represent sets of items and actions to be used during parsing.

Defined in:

cltk/parser/state.cr
cltk/parser/msgpack.cr

Class Method Summary

Instance Method Summary

Instance methods inherited from class Object

in?(collection : Array | Set) in?

Class Method Detail

def self.new(id : Int32, actions : Hash(String, Array(CLTK::Parser::Action)), items : Array(CFG::Item)) #

[View source]
def self.new(tokens : Array(String), items = [] of CFG::Item) #

Instantiate a new State object.

@param [Array<Symbol>] tokens Tokens that represent this state @param [Array<CFG::Item>] items Items that make up this state


[View source]
def self.new(__temp_54 : MessagePack::Unpacker) #

[View source]

Instance Method Detail

def <<(item) #

[View source]
def ==(other) #

Compare one State to another. Two States are equal if they have the same items or, if the items have been cleaned, if the States have the same ID.

@param [State] other Another State to compare to

@return [Boolean]


[View source]
def actions : Hash(String, Array(CLTK::Parser::Action)) #

[View source]
def actions=(_actions : Hash(String, Array(CLTK::Parser::Action))) #

[View source]
def add_reduction(production) #

Add a Reduce action to the state.

@param [Production] production Production used to perform the reduction

@return [void]


[View source]
def append(item) #

@param [CFG::Item] item Item to add to this state.


[View source]
def clean #

Clean this State by removing the list of {CFG::Item} objects.

@return [void]


[View source]
def close(productions) #

Close this state using productions.

@param [Array<CFG::Production>] productions Productions used to close this state.

@return [vod]


[View source]
def conflict_on?(sym) #

Checks to see if there is a conflict in this state, given a input of sym. Returns :SR if a shift/reduce conflict is detected and :RR if a reduce/reduce conflict is detected. If no conflict is detected nil is returned.

@param [Symbol] sym Symbol to check for conflicts on.

@return [:SR, :RR, nil]


[View source]
def each(&block) #

Iterate over the state's items.

@return [void]


[View source]
def id : Int32 #

[View source]
def id=(id) #

@return [Integer] State's ID.


[View source]
def id=(_id : Int32) #

[View source]
def items : Array(CLTK::CFG::Item) #

[View source]
def items=(_items : Array(CFG::Item)) #

[View source]
def on(symbol, action : Action) #

Specify an Action to perform when the input token is symbol.

@param [Symbol] symbol Symbol to add action for. @param [Action] action Action for symbol.

@return [void]


[View source]
def on?(symbol) #

Returns that actions that should be taken when the input token is symbol.

@param [Symbol] symbol Symbol we want the actions for.

@return [Array<Action>] Actions that should be taken.


[View source]
def to_msgpack(packer : MessagePack::Packer) #

[View source]