Class: Dhaka::LexerSupport::StateMachine

### Home Classes Methods

### In Files

- lib/dhaka/lexer/state_machine.rb

### Parent

Object

### Methods

- ::new
- #to_dot

### Class/Module Index

Quicksearch

- Dhaka
- Dhaka::CompiledLexer
- Dhaka::CompiledParser
- Dhaka::Evaluator
- Dhaka::Grammar
- Dhaka::GrammarSymbol
- Dhaka::Lexeme
- Dhaka::Lexer
- Dhaka::LexerRun
- Dhaka::LexerSpecification
- Dhaka::LexerSupport
- Dhaka::LexerSupport::AcceptAction
- Dhaka::LexerSupport::CheckpointAction
- Dhaka::LexerSupport::DFARun
- Dhaka::LexerSupport::InvalidRegexException
- Dhaka::LexerSupport::LookaheadAcceptAction
- Dhaka::LexerSupport::RegexParser
- Dhaka::LexerSupport::RegexTokenizer
- Dhaka::LexerSupport::State
- Dhaka::LexerSupport::StateMachine
- Dhaka::NoStartProductionsError
- Dhaka::ParseErrorResult
- Dhaka::ParseSuccessResult
- Dhaka::ParseTreeCompositeNode
- Dhaka::ParseTreeLeafNode
- Dhaka::Parser
- Dhaka::ParserMethods
- Dhaka::PrecedenceBuilder
- Dhaka::Production
- Dhaka::ProductionBuilder
- Dhaka::Token
- Dhaka::Tokenizer
- Dhaka::TokenizerErrorResult
- Dhaka::TokenizerState
- Dhaka::TokenizerSuccessResult

No matching classes.

# Dhaka::LexerSupport::StateMachine

### Attributes

start_state[R]

### Public Class Methods

new(start_key) click to toggle source

    # File lib/dhaka/lexer/state_machine.rb, line 6
    def initialize start_key
      @states = Hash.new do |hash, key|
        new_state = new_state_for_key key
        hash[key] = new_state
        transition_characters(key).each do |char|
          dest_key                    = dest_key_for(key, char)
          dest_state                  = hash[dest_key]
          new_state.transitions[char] = dest_state
        end
        new_state
      end
      @start_state = @states[start_key]
    end

### Public Instance Methods

to_dot() click to toggle source

    # File lib/dhaka/lexer/state_machine.rb, line 20
    def to_dot
      Dot::Digraph.new(:fontsize => 10, :shape => :circle, :size => 5) do |g|
        start = 'Start'
        g.node(start, :label => start)
        g.edge(start, @start_state)
        @states.values.each do |state|
          state_attributes = {}
          state_attributes.merge!(:shape => :doublecircle, :label => state.action.to_dot) if state.accepting?
          g.node(state, state_attributes)
          state.transitions.each do |transition_key, dest_state|
            g.edge(state, dest_state, :label => transition_key.inspect)
          end
        end
      end.to_dot
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.