require 'fig/package' require 'fig/packagedescriptor' require 'fig/statement/archive' require 'fig/statement/command' require 'fig/statement/configuration' require 'fig/statement/include' require 'fig/statement/override' require 'fig/statement/path' require 'fig/statement/publish' require 'fig/statement/resource' require 'fig/statement/retrieve' require 'fig/statement/set' module Fig grammar Fig rule package ws statements:(package_statement*) { def to_package(package_name, version_name, directory) Package.new( package_name, version_name, directory, statements.elements.map { |statement| statement.to_package_statement } ) end } end rule package_statement archive / resource / retrieve / config end rule archive "archive" ws url { def to_package_statement Statement::Archive.new(url.value.text_value) end } end rule resource "resource" ws url { def to_package_statement Statement::Resource.new(url.value.text_value) end } end rule retrieve "retrieve" ws var:retrieve_variable "->" path:retrieve_path ws { def to_package_statement Statement::Retrieve.new(var.text_value, path.text_value) end } end rule retrieve_variable [@a-zA-Z0-9/._]+ end rule retrieve_path [a-zA-Z0-9_/.\[\]-]+ end rule config "config" ws config_name ws statements:config_statement* "end" ws { def to_package_statement Statement::Configuration.new(config_name.text_value, statements.elements.map { |statement| statement.to_config_statement }) end } end rule config_statement include / command / path / set end rule include "include" ws descriptor overrides:(override*) { def to_config_statement Statement::Include.new( PackageDescriptor.parse(descriptor.text_value.strip), overrides.elements.map{ |e| e.to_override } ) end } end rule override "override" ws package_name "/" version_name ws { def to_override return Statement::Override.new(package_name.text_value, version_name.text_value) end } end rule path ("append" / "path" / "add") ws name:path_name "=" value:path_value ws { def to_config_statement Statement::Path.new(name.text_value, value.text_value) end } end rule path_name [a-zA-Z0-9_]+ end rule path_value [@a-zA-Z0-9/\\._-]+ end rule set "set" ws name:set_name "=" value:set_value ws { def to_config_statement Statement::Set.new(name.text_value, value.text_value) end } end rule set_name [a-zA-Z0-9_]+ end rule set_value [@a-zA-Z0-9/\\._-]* end rule command "command" ws string { def to_config_statement Statement::Command.new(string.value.text_value) end } end rule string '"' value:(!'"' . )* '"' ws end rule descriptor ((package:package_name ("/" version:version_name)? (":" config:config_name)? ws) / (":" config:config_name ws)) { def get_version elements.each do |element| if element.respond_to?(:version) return element.version.text_value end end nil end def get_config return self.config.text_value if self.respond_to?(:config) elements.each do |element| if element.respond_to?(:config) return element.config.text_value end end nil end } end rule package_name [a-zA-Z0-9.-]+ end rule version_name [a-zA-Z0-9_.-]+ end rule config_name [a-zA-Z0-9_.-]+ end rule name value:[a-zA-Z0-9]+ ws end rule url (value:[a-zA-Z0-9:/\\._*-]+ ws) / ('"' value:[a-zA-Z0-9:/\\._-]+ '"' ws) end rule ws [ \n\r\t]+ end end end