module Kleene::DSL

Extended Modules

Direct including types

Defined in:

dsl.cr

Instance Method Summary

Instance Method Detail

def any(token_collection, alphabet = DEFAULT_ALPHABET) #

two states: start state and final state structure: start state -> transitions for each token in the token collection -> final state


[View source]
def append(a, b) #

Append b onto a Appending produces a machine that matches all the strings in machine a followed by all the strings in machine b. This differs from #seq in that the composite machine's final states are the union of machine a's final states and machine b's final states.


[View source]
def append!(a, b) #

Destructively append b onto a Appending produces a machine that matches all the strings in machine a followed by all the strings in machine b. This differs from #seq in that the composite machine's final states are the union of machine a's final states and machine b's final states.


[View source]
def dot(alphabet = DEFAULT_ALPHABET) #

two states: start state and final state structure: start state -> transitions for every token in the alphabet -> final state


[View source]
def kleene(machine) #

Implements Kleene Star, as defined in the Ragel manual in section 2.5.6 of http://www.colm.net/files/ragel/ragel-guide-6.10.pdf: The machine resulting from the Kleene Star operator will match zero or more repetitions of the machine it is applied to. It creates a new start state and an additional final state. Epsilon transitions are drawn between the new start state and the old start state, between the new start state and the new final state, and between the final states of the machine and the new start state.


[View source]
def literal(token_stream : String, alphabet = DEFAULT_ALPHABET) #

############## The following methods create FSAs given a stream of input tokens ################# given a string with N characters in it: N+1 states: start state and N other states structure: start state -> transition for first character in the string -> state for having observed first character in the string -> transition for second character in the string -> state for having observed second character in the string -> ... transition for last character in the string -> state for having observed last character in the string (marked final)


[View source]
def optional(machine) #

[View source]
def plus(machine) #

[View source]
def range(c_begin : Char, c_end : Char, alphabet = DEFAULT_ALPHABET) #

This implements a character class, and is specifically for use with matching strings


[View source]
def seq(a : NFA, b : NFA) #

Implements concatenation, as defined in the Ragel manual in section 2.5.5 of http://www.colm.net/files/ragel/ragel-guide-6.10.pdf: Seq produces a machine that matches all the strings in machine a followed by all the strings in machine b. Seq draws epsilon transitions from the final states of thefirst machine to the start state of the second machine. The final states of the first machine lose their final state status, unless the start state of the second machine is final as well.


[View source]
def seq(nfas : Array(NFA)) #

[View source]
def seq(*nfa_splat_tuple) #

[View source]
def union(nfas : Array(NFA)) #

Build a new machine consisting of a new start state with epsilon transitions to the start state of all the given NFAs in nfas. The resulting machine's final states are the set of final states from all the NFAs in nfas.

Implements Union, as defined in the Ragel manual in section 2.5.1 of http://www.colm.net/files/ragel/ragel-guide-6.10.pdf: The union operation produces a machine that matches any string in machine one or machine two. The operation first creates a new start state. Epsilon transitions are drawn from the new start state to the start states of both input machines. The resulting machine has a final state setequivalent to the union of the final state sets of both input machines.


[View source]
def union(*nfa_splat_tuple) #

[View source]
def union!(nfas : Array(NFA)) #

same as union, but doesn't deep clone the constituent nfas


[View source]
def with_err(nfa, alphabet = nfa.alphabet) #

############## The following methods create FSAs given other FSAs ################# always clones the given nfa and returns a new nfa with a non-final error state


[View source]
def with_err!(nfa, alphabet = nfa.alphabet) #

adds and error state to the NFA, create error transitions from all non-error states to the error state on any unhandled token. the error state transitions to itself on any token.


[View source]
def with_err_dead_end(nfa, alphabet = nfa.alphabet) #

always clones the given nfa and returns a new nfa with a non-final error state


[View source]
def with_err_dead_end!(nfa, alphabet = nfa.alphabet) #

adds and error state to the NFA, create error transitions from all non-error states to the error state on any unhandled token. the error state doesn't have any outbound transitions.


[View source]