Skip to content

Commit

Permalink
Merge pull request rails#52654 from kamipo/fix_rubocop_offences
Browse files Browse the repository at this point in the history
Fix rubocop offences for actionpack/lib/action_dispatch/journey/parser.rb
  • Loading branch information
kamipo authored Aug 20, 2024
2 parents ac10452 + 98b93cd commit 429f400
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 62 deletions.
1 change: 0 additions & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ AllCops:
- '**/tmp/**/*'
- '**/templates/**/*'
- '**/vendor/**/*'
- 'actionpack/lib/action_dispatch/journey/parser.rb'
- 'actionmailbox/test/dummy/**/*'
- 'activestorage/test/dummy/**/*'
- 'actiontext/test/dummy/**/*'
Expand Down
120 changes: 60 additions & 60 deletions actionpack/lib/action_dispatch/journey/parser.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: true

require "action_dispatch/journey/scanner"
require "action_dispatch/journey/nodes/node"
Expand All @@ -23,81 +24,80 @@ def parse(string)
end

private
def advance_token
@next_token = @scanner.next_token
end

def advance_token
@next_token = @scanner.next_token
end
def do_parse
parse_expressions
end

def do_parse
parse_expressions
end
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

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

while @next_token
case @next_token
when :RPAREN
break
when :OR
node = parse_or(node)
def parse_expression
if @next_token == :STAR
parse_star
elsif @next_token == :LPAREN
parse_group
else
node = Cat.new(node, parse_expressions)
parse_terminal
end
end

node
end

def parse_or(lhs)
advance_token
node = parse_expression
Or.new([lhs, node])
end
def parse_star
node = Star.new(Symbol.new(@scanner.last_string, Symbol::GREEDY_EXP))
advance_token
node
end

def parse_expression
if @next_token == :STAR
parse_star
elsif @next_token == :LPAREN
parse_group
else
parse_terminal
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
end

def parse_star
node = Star.new(Symbol.new(@scanner.last_string, Symbol::GREEDY_EXP))
advance_token
node
end
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

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

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
end
end
end
2 changes: 1 addition & 1 deletion guides/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ The editing files for the Guides rebuild reside in `stylesrc` and use SCSS to im

## Building the Guides in Development

To generate new guides into static files, type `rake guides:generate` from inside the `guides` folder. If you make changes to the HTML or ERB, you'll need to remove the "output" directory before running this command. The master SCSS files (style.scss, highlight.scss) will compile as part of this process.
To generate new guides into static files, type `rake guides:generate` from inside the `guides` folder. If you make changes to the HTML or ERB, you'll need to remove the "output" directory before running this command. The master SCSS files (style.scss, highlight.scss) will compile as part of this process.

## FAQ

Expand Down

0 comments on commit 429f400

Please sign in to comment.