123456789_123456789_123456789_123456789_123456789_

Class: ActionDispatch::Journey::Parser

Do not use. This class is for internal use only.
Relationships & Source Files
Super Chains via Extension / Inclusion / Inheritance
Instance Chain:
self, Nodes
Inherits: Object
Defined in: actionpack/lib/action_dispatch/journey/parser.rb

Class Method Summary

Instance Method Summary

Constructor Details

.newParser

[ GitHub ]

  
# File 'actionpack/lib/action_dispatch/journey/parser.rb', line 15

def initialize
  @scanner = Scanner.new
  @next_token = nil
end

Class Method Details

.parse(string)

[ GitHub ]

  
# File 'actionpack/lib/action_dispatch/journey/parser.rb', line 11

def self.parse(string)
  new.parse string
end

Instance Method Details

#advance_token (private)

[ GitHub ]

  
# File 'actionpack/lib/action_dispatch/journey/parser.rb', line 27

def advance_token
  @next_token = @scanner.next_token
end

#do_parse (private)

[ GitHub ]

  
# File 'actionpack/lib/action_dispatch/journey/parser.rb', line 31

def do_parse
  parse_expressions
end

#parse(string)

[ GitHub ]

  
# File 'actionpack/lib/action_dispatch/journey/parser.rb', line 20

def parse(string)
  @scanner.scan_setup(string)
  advance_token
  do_parse
end

#parse_expression (private)

[ GitHub ]

  
# File 'actionpack/lib/action_dispatch/journey/parser.rb', line 58

def parse_expression
  if @next_token == :STAR
    parse_star
  elsif @next_token == :LPAREN
    parse_group
  else
    parse_terminal
  end
end

#parse_expressions (private)

[ GitHub ]

  
# File 'actionpack/lib/action_dispatch/journey/parser.rb', line 35

def parse_expressions
  node = parse_expression

  while @next_token
    case @next_token
    when :RPAREN
      break
    when :OR
      node = parse_or(node)
    else
      node = Cat.new(node, parse_expressions)
    end
  end

  node
end

#parse_group (private)

[ GitHub ]

  
# File 'actionpack/lib/action_dispatch/journey/parser.rb', line 74

def parse_group
  advance_token
  node = parse_expressions
  if @next_token == :RPAREN
    node = Group.new(node)
    advance_token
    node
  else
    raise ArgumentError, "missing right parenthesis."
  end
end

#parse_or(lhs) (private)

[ GitHub ]

  
# File 'actionpack/lib/action_dispatch/journey/parser.rb', line 52

def parse_or(lhs)
  advance_token
  node = parse_expression
  Or.new([lhs, node])
end

#parse_star (private)

[ GitHub ]

  
# File 'actionpack/lib/action_dispatch/journey/parser.rb', line 68

def parse_star
  node = Star.new(Symbol.new(@scanner.last_string, Symbol::GREEDY_EXP))
  advance_token
  node
end

#parse_terminal (private)

[ GitHub ]

  
# File 'actionpack/lib/action_dispatch/journey/parser.rb', line 86

def parse_terminal
  node = case @next_token
  when :SYMBOL
    Symbol.new(@scanner.last_string)
  when :LITERAL
    Literal.new(@scanner.last_literal)
  when :SLASH
    Slash.new("/")
  when :DOT
    Dot.new(".")
  end

  advance_token
  node
end