lib/junoser/ruler.rb in junoser-0.1.2 vs lib/junoser/ruler.rb in junoser-0.1.3
- old
+ new
@@ -37,10 +37,11 @@
end
def process_reserved_element(str)
str.gsub! /"\$\S+"/, 'arg'
str.gsub! '"as-number" arg', 'arg'
+ str.gsub! '"confederation-as" arg', 'arg'
str.gsub! '"equal-literal"', '"="'
str.gsub! '"plus-literal"', '"+"'
str.gsub! '"minus-literal"', '"-"'
str.gsub!(/\((.*) \| "name"\)/) { "(#$1 | arg)" }
@@ -77,10 +78,18 @@
' quote,',
' arg',
' )'], $1)
end
+ str.gsub!(/^rule\(:regular_expression\) do\s*((?!end).)*\s*end/) do
+ "rule(:regular_expression) do
+ (quote | arg).as(:arg)
+end"
+ end
+
+ str.gsub!(/("next-hop" \(\s*sc\(\s*c\(\s*[^)]*)"address" \(\s*ipaddr\s*\)/) { "#{$1}ipaddr" }
+
%w[metric metric2 metric3 metric4 tag tag2 preference preference2 color color2 local-preference].each do |key|
str.gsub!(/^(\s*"#{key}" \(\s*sc\(\s*c\(\s*)"#{key}" arg/) { "#{$1}arg" }
end
str.gsub!(/(s\(\s*)"address" \(\s*arg\s*\)/) { "#{$1}arg" }
@@ -149,16 +158,20 @@
rule(:arg) { match('\\S').repeat(1) }
rule(:space) { match('\\s').repeat(1) }
rule(:any) { match('.').repeat(1) }
rule(:eos) { match('$') }
- rule(:dotted) { match('[^. \\t\\n\\r\\f]').repeat(1) >> match('\.') >> match('[^. \\t\\n\\r\\f]').repeat(1) }
- rule(:quote) { match('"') >> match('[^"]').repeat(1) >> match('"') }
+ rule(:dotted) { match('[^. \\t\\n\\r\\f]').repeat(1) >> str('.') >> match('[^. \\t\\n\\r\\f]').repeat(1) }
+ rule(:quote) { str('"') >> match('[^"]').repeat(1) >> str('"') }
rule(:address) { match('[0-9a-fA-F:\.]').repeat(1) }
- rule(:prefix ) { address >> (match('/') >> match('[0-9]').repeat(1)).maybe }
+ rule(:prefix ) { address >> (str('/') >> match('[0-9]').repeat(1)).maybe }
root(:set)
- rule(:set) { (str('set') | str('deactivate')) >> space >> configuration.as(:config) }
+ rule(:set) { (str('set') | str('deactivate')) >> space >> configuration.as(:config) >> comment.maybe }
+
+ rule(:comment) { space.maybe >> (hash_comment | slash_asterisk) }
+ rule(:hash_comment) { str('#') >> any.maybe }
+ rule(:slash_asterisk) { str('/*') >> match('(?!\\*\\/).').repeat(0) >> str('*/') }
EOS
end
def rule_footer