lib/fig/grammar.treetop in fig-0.1.57 vs lib/fig/grammar.treetop in fig-0.1.59
- old
+ new
@@ -1,7 +1,8 @@
require 'fig/package'
require 'fig/packagedescriptor'
+require 'fig/parser'
require 'fig/statement/archive'
require 'fig/statement/command'
require 'fig/statement/configuration'
require 'fig/statement/include'
require 'fig/statement/override'
@@ -13,19 +14,19 @@
module Fig
grammar Fig
rule package
- ws statements:(package_statement*) {
- def to_package(package_name, version_name, directory)
+ optional_ws statements:(package_statement*) optional_ws {
+ def to_package(descriptor, directory)
Package.new(
- package_name,
- version_name,
+ descriptor.name,
+ descriptor.version,
directory,
statements.elements.map do
|statement|
- statement.to_package_statement(package_name)
+ statement.to_package_statement(descriptor)
end
)
end
}
end
@@ -33,29 +34,37 @@
rule package_statement
archive / resource / retrieve / config
end
rule archive
- "archive" ws url {
- def to_package_statement(package_name)
- Statement::Archive.new(url.value.text_value)
+ statement_start:"archive" ws url {
+ def to_package_statement(descriptor)
+ Statement::Archive.new(
+ Parser.node_location(statement_start), url.value.text_value
+ )
end
}
end
rule resource
- "resource" ws url {
- def to_package_statement(package_name)
- Statement::Resource.new(url.value.text_value)
+ statement_start:"resource" ws url {
+ def to_package_statement(descriptor)
+ Statement::Resource.new(
+ Parser.node_location(statement_start), url.value.text_value
+ )
end
}
end
rule retrieve
- "retrieve" ws var:retrieve_variable "->" path:retrieve_path ws {
- def to_package_statement(package_name)
- Statement::Retrieve.new(var.text_value, path.text_value)
+ statement_start:"retrieve" ws var:retrieve_variable "->" path:retrieve_path ws {
+ def to_package_statement(descriptor)
+ Statement::Retrieve.new(
+ Parser.node_location(statement_start),
+ var.text_value,
+ path.text_value
+ )
end
}
end
rule retrieve_variable
@@ -65,17 +74,18 @@
rule retrieve_path
[a-zA-Z0-9_/.\[\]-]+
end
rule config
- "config" ws config_name ws statements:config_statement* "end" ws {
- def to_package_statement(package_name)
+ statement_start:"config" ws config_name ws statements:config_statement* "end" ws {
+ def to_package_statement(descriptor)
Statement::Configuration.new(
+ Parser.node_location(statement_start),
config_name.text_value,
statements.elements.map do
|statement|
- statement.to_config_statement(package_name)
+ statement.to_config_statement(descriptor)
end
)
end
}
end
@@ -83,33 +93,42 @@
rule config_statement
include / command / path / set
end
rule include
- "include" ws descriptor overrides:(override*) {
- def to_config_statement(package_name)
+ statement_start:"include" ws descriptor overrides:(override*) {
+ def to_config_statement(containing_package_descriptor)
Statement::Include.new(
+ Parser.node_location(statement_start),
PackageDescriptor.parse(descriptor.text_value.strip),
overrides.elements.map{ |e| e.to_override },
- package_name
+ containing_package_descriptor
)
end
}
end
rule override
- "override" ws package_name "/" version_name ws {
+ statement_start:"override" ws package_name "/" version_name ws {
def to_override
- return Statement::Override.new(package_name.text_value, version_name.text_value)
+ return Statement::Override.new(
+ Parser.node_location(statement_start),
+ 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(package_name)
- Statement::Path.new(name.text_value, value.text_value)
+ statement_start:("append" / "path" / "add") ws name:path_name "=" value:path_value ws {
+ def to_config_statement(descriptor)
+ Statement::Path.new(
+ Parser.node_location(statement_start),
+ name.text_value,
+ value.text_value
+ )
end
}
end
rule path_name
@@ -119,13 +138,17 @@
rule path_value
[@a-zA-Z0-9/\\._-]+
end
rule set
- "set" ws name:set_name "=" value:set_value ws {
- def to_config_statement(package_name)
- Statement::Set.new(name.text_value, value.text_value)
+ statement_start:"set" ws name:set_name "=" value:set_value ws {
+ def to_config_statement(descriptor)
+ Statement::Set.new(
+ Parser.node_location(statement_start),
+ name.text_value,
+ value.text_value
+ )
end
}
end
rule set_name
@@ -135,13 +158,15 @@
rule set_value
[@a-zA-Z0-9/\\._-]*
end
rule command
- "command" ws string {
- def to_config_statement(package_name)
- Statement::Command.new(string.value.text_value)
+ statement_start:"command" ws string {
+ def to_config_statement(descriptor)
+ Statement::Command.new(
+ Parser.node_location(statement_start), string.value.text_value
+ )
end
}
end
rule string
@@ -181,19 +206,19 @@
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
+
+ rule optional_ws
+ [ \n\r\t]*
end
end
end