lib/junoser/ruler.rb in junoser-0.2.4 vs lib/junoser/ruler.rb in junoser-0.2.5

- old
+ new

@@ -161,10 +161,33 @@ <<-EOS require 'parslet' module Junoser class Parser < Parslet::Parser + def parse_lines(config) + lines = config.split("\\n") + lines_without_deactivate = lines.reject {|l| l =~ /^deactivate/ } + + lines.inject(true) do |passed, line| + if line =~ /^deactivate/ + if lines_without_deactivate.grep(/^\#{line.sub(/^deactivate/, 'set')}/).empty? + next false + else + next passed + end + end + + begin + parse line + passed + rescue Parslet::ParseFailed + $stderr.puts "Invalid syntax: \#{line}" + false + end + end + end + # block with children maybe def b(object, *children) children.inject(object) {|rule, child| rule.as(:label) >> (space >> child.as(:child) | eos) } end @@ -205,10 +228,10 @@ rule(:quote) { str('"') >> match('[^"]').repeat(1) >> str('"') } rule(:address) { match('[0-9a-fA-F:\.]').repeat(1) } rule(:prefix ) { address >> (str('/') >> match('[0-9]').repeat(1)).maybe } root(:set) - rule(:set) { (str('set') | str('deactivate')) >> space >> configuration.as(:config) >> comment.maybe } + rule(:set) { str('set') >> 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('*/') }