Sha256: ee4032a122b9c678a9a137b7dd745cc1759b34598d22e6de4f2b0d5bbde73032
Contents?: true
Size: 1.89 KB
Versions: 1
Compression:
Stored size: 1.89 KB
Contents
require 'parslet' require 'junoser/display/base' module Junoser module Display class Set include Base def transform process do |current_stack, str| @output.puts transform_line(current_stack, str) end end def commit_check(&block) parser = Junoser::Parser.new passed = true process do |current_stack, str| config = transform_line(current_stack, str) begin parser.parse config rescue Parslet::ParseFailed $stderr.puts "Invalid syntax: #{config}" passed = false end end rescue $stderr.puts $! passed = false ensure return passed end private def process(&block) stack = [] read_io_or_string.split("\n").each do |line| case line when /(.*){/ stack.push $1.strip when '}' stack.pop when /((?!\[).*)\[(.*)\];/ $2.split("\s").each do |i| yield stack, "#{$1.strip} #{i}" end when /(.*);/ yield stack, $1 else raise "ERROR: unknown statement: #{line}" end end end def transform_line(current_stack, str) statement = if current_stack.empty? str else statement = "#{current_stack.join(' ')} #{str}" end if statement.gsub!('inactive: ', '') "deactivate #{statement}" else "set #{statement}" end end def struct(stack, statement, offset=2) width = 2 if label = stack.shift %[#{" "*offset}#{label} { #{struct(stack, statement, width+offset)} #{" "*offset}}] else %[#{" "*offset}#{statement};] end end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
junoser-0.1.2 | lib/junoser/display/set.rb |