Skip to content
This repository has been archived by the owner on Dec 24, 2023. It is now read-only.

Commit

Permalink
Small refactor of sym, key and op rules
Browse files Browse the repository at this point in the history
  • Loading branch information
deathbeam committed Mar 21, 2016
1 parent 8cd8612 commit 325d003
Showing 1 changed file with 6 additions and 18 deletions.
24 changes: 6 additions & 18 deletions lib/spoon/parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,9 @@ module Spoon
class Spoon::Util::IndentParser
# Matches string and skips space after it
def sym(value)
if (value.kind_of?(Array))
if value.kind_of?(Array)
result = str(value.first)

value.each do |val|
result = result | str(val)
end

value.each { |val| result |= str(val) }
result >> space?
else
str(value) >> space?
Expand All @@ -23,13 +19,9 @@ def sym(value)

# Matches keyword and skips space after it
def key(value)
if (value.kind_of?(Array))
if value.kind_of?(Array)
result = keyword(value.first)

value.each do |val|
result = result | keyword(val)
end

value.each { |val| result |= keyword(val) }
result >> space?
else
keyword(value) >> space?
Expand All @@ -38,13 +30,9 @@ def key(value)

# Matches string or keyword, based on if it is word or not
def op(value)
if (value.kind_of?(Array))
if value.kind_of?(Array)
result = whitespace? >> (/\w/.match(value.first) ? key(value.first) : sym(value.first))

value.each do |val|
result = result | (/\w/.match(val) ? key(val) : sym(val))
end

value.each { |val| result |= (/\w/.match(val) ? key(val) : sym(val)) }
result >> whitespace?
else
trim(/\w/.match(value) ? key(value) : sym(value))
Expand Down

0 comments on commit 325d003

Please sign in to comment.