lib/junoser/ruler.rb in junoser-0.3.3 vs lib/junoser/ruler.rb in junoser-0.3.4
- old
+ new
@@ -10,30 +10,35 @@
rule_header << rule << rule_footer
end
def rule
str = @rule.read
+ str = remove_comments(str)
str = process_reserved_element(str)
str = str.split(/\n/).map {|l| format(process_line(l)) }.join("\n")
end
private
+ def remove_comments(str)
+ str.gsub(%r(\s*/\*.*\*/), '')
+ end
+
def process_line(str)
return str if str =~ /^(.* do|end)$/
str.gsub!(/("[^"]+")/) { "str(#$1)" } # "foo" -> str("foo")
str.gsub!(/^(\s*)arg(\.as\(:\S+\))? \($/) { "#{$1}b(arg#$2," } # arg ( -> b(arg,
str.gsub!(/^(\s*)(str\(\S+\)) ([^ \t\n\r\f\(|,]+)(\.as\(:\S+\))?(,?)$/) { "#{$1}a(#$2, #$3)#$4#$5" } # str("foo") bar -> a(str("foo"), bar)
- str.gsub!(/^(\s*)(str\(\S+\)) \((.*)\)(,?)$/) { "#{$1}a(#$2, #$3)#$4" } # str("foo") (a | b) -> a(str("foo"), a | b)
+ str.gsub!(/^(\s*)(str\(\S+\)) (enum)?\((.*)\)(,?)$/) { "#{$1}a(#$2, #$3#$4)#$5" } # str("foo") (a | b) -> a(str("foo"), a | b)
str.gsub!(/^(\s*)(str\(\S+\)) \($/) { "#{$1}b(#$2," } # str("foo") ( -> b(str("foo"),
- str.gsub!(/^(\s*)(\(.*\))(\.as\(:\S\))? \($/) { "#{$1}b(#$2#$3," } # (a | b) ( -> b((a | b),
+ str.gsub!(/^(\s*)(enum)?(\(.*\))(\.as\(:\S\))? \($/) { "#{$1}b(#$2#$3#$4," } # (a | b) ( -> b((a | b),
str.gsub!(/^(\s*)(str\(\S+\)) ([^ \t\n\r\f\(|,]+) \($/) { "#{$1}b(a(#$2, #$3)," } # str("foo") bar ( -> b(a(str("foo"), bar),
- str.gsub!(/^(\s*)(str\(\S+\)) \((.*)\) \($/) { "#{$1}a(#$2, #$3," } # str("foo") (a | b) ( -> a(str("foo"), a | b,
+ str.gsub!(/^(\s*)(str\(\S+\)) (enum)?\((.*)\) \($/) { "#{$1}a(#$2, #$3#$4," } # str("foo") (a | b) ( -> a(str("foo"), a | b,
str
end
def process_reserved_element(str)
@@ -228,9 +233,13 @@
(c(*objects) >> space.maybe).repeat(0)
end
def sca(*objects)
(c(*objects, arg) >> space.maybe).repeat(0)
+ end
+
+ def enum(object)
+ (object.as(:enum))
end
rule(:arg) { match('\\S').repeat(1) }
rule(:space) { match('\\s').repeat(1) }
rule(:any) { match('.').repeat(1) }