Sha256: f49ba018fab1a8d1ab6fbadc0fa482a44bf7748a8df6ff78bda3fb8bc2198cb7
Contents?: true
Size: 1.71 KB
Versions: 4
Compression:
Stored size: 1.71 KB
Contents
require_relative 'ios/document' module IOSParser class IOS attr_accessor :document attr_accessor :lexer attr_accessor :source attr_writer :tokens def initialize(parent: nil, lexer: IOSParser::Lexer.new) @document = Document.new(nil) @parent = parent @lexer = lexer end def tokens @tokens ||= lexer.call(@source) end def call(source) unless source.respond_to? :each_char raise ArgumentError, 'Provided configuration source is invalid.' end @source = source @document.source = source @document.push(*section) until tokens.empty? @document end def section(parent = nil) [].tap do |commands| until tokens.empty? || tokens.first.last == :DEDENT commands.push(command(parent, @document)) end tokens.shift # discard :DEDENT end end def command(parent = nil, document = nil) pos = tokens.first.first opts = { args: arguments, parent: parent, document: document, pos: pos } Command.new(opts).tap do |cmd| cmd.commands = subsections(cmd) end end def arguments_to_discard [:INDENT, :DEDENT, :CERTIFICATE_BEGIN, :CERTIFICATE_END, :BANNER_BEGIN, :BANNER_END] end def arguments [].tap do |args| until tokens.empty? || tokens.first.last == :EOL _, arg = tokens.shift args << arg unless arguments_to_discard.include?(arg) end tokens.shift # discard :EOL end end def subsections(parent = nil) if !tokens.empty? && tokens.first.last == :INDENT tokens.shift # discard :INDENT section(parent) else [] end end end end
Version data entries
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
ios_parser-0.5.2-java | lib/ios_parser/ios.rb |
ios_parser-0.5.2 | lib/ios_parser/ios.rb |
ios_parser-0.5.1 | lib/ios_parser/ios.rb |
ios_parser-0.5.1-java | lib/ios_parser/ios.rb |