Class: Dhaka::LexerSupport::State

### Home Classes Methods

### In Files

- lib/dhaka/lexer/state.rb

### Parent

Object

### Methods

- ::new
- #accept
- #accept_with_lookahead
- #accepting?
- #add_checkpoint
- #compile_to_ruby_source
- #for_characters
- #process
- #recognize

### 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::State

### Attributes

action[R]
checkpoint_actions[R]
transitions[R]

### Public Class Methods

new(state_machine, action=nil) click to toggle source

    # File lib/dhaka/lexer/state.rb, line 6
    def initialize(state_machine, action=nil)
      @state_machine      = state_machine
      @transitions        = {}
      @checkpoint_actions = []
      @action             = action
    end

### Public Instance Methods

accept(pattern) click to toggle source

    # File lib/dhaka/lexer/state.rb, line 33
    def accept(pattern)
      @action = AcceptAction.new(pattern)
    end

accept_with_lookahead(pattern) click to toggle source

    # File lib/dhaka/lexer/state.rb, line 37
    def accept_with_lookahead(pattern)
      @action = LookaheadAcceptAction.new(pattern)
    end

accepting?() click to toggle source

    # File lib/dhaka/lexer/state.rb, line 13
    def accepting?
      @action
    end

add_checkpoint(pattern) click to toggle source

    # File lib/dhaka/lexer/state.rb, line 29
    def add_checkpoint(pattern)
      checkpoint_actions << LexerSupport::CheckpointAction.new(pattern)
    end

compile_to_ruby_source() click to toggle source

    # File lib/dhaka/lexer/state.rb, line 45
    def compile_to_ruby_source
      result  = "  at_state(#{object_id}) {\n"
      result << "    #{action.compile_to_ruby_source}\n" if action
      checkpoint_actions.each do |checkpoint_action|
        result << "    #{checkpoint_action.compile_to_ruby_source}\n"
      end
      transition_keys_by_destination_state = Hash.new {|hash, key| hash[key] = []}
      transitions.each do |key, dest_state|
        transition_keys_by_destination_state[dest_state.object_id] << key
      end

      transition_keys_by_destination_state.keys.each do |state_id|
        transition_keys = transition_keys_by_destination_state[state_id].collect {|transition_key| "#{transition_key.inspect}"}.join(', ')
        result << "    for_characters(#{transition_keys}) { switch_to #{state_id} }\n"
      end

      result << "  }"
      result
    end

for_characters(*characters, &blk) click to toggle source

    # File lib/dhaka/lexer/state.rb, line 22
    def for_characters *characters, &blk
      dest_state = @state_machine.instance_eval(&blk)
      characters.each do |char|
        transitions[char] = dest_state
      end
    end

process(lexer_run) click to toggle source

    # File lib/dhaka/lexer/state.rb, line 17
    def process lexer_run
      checkpoint_actions.each {|action| action.call(lexer_run)}
      action.call(lexer_run) if accepting?
    end

recognize(pattern) click to toggle source

    # File lib/dhaka/lexer/state.rb, line 41
    def recognize pattern
      @pattern = pattern
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.