lib/fig/grammar.treetop in fig-0.1.69 vs lib/fig/grammar.treetop in fig-0.1.71
- old
+ new
@@ -1,75 +1,47 @@
# Treetop (http://treetop.rubyforge.org/) grammar for package definitions.
-require 'fig/package'
-require 'fig/package_descriptor'
-require 'fig/parser'
-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/resource'
-require 'fig/statement/retrieve'
-require 'fig/statement/set'
-
module Fig
grammar Fig
rule package
optional_ws statements:(package_statement*) optional_ws {
def to_package(directory, build_state)
- Package.new(
- build_state.descriptor.name,
- build_state.descriptor.version,
- directory,
- statements.elements.map do
- |statement|
- statement.to_package_statement(build_state)
- end
- )
+ return build_state.new_package_statement(directory, statements)
end
}
end
rule package_statement
archive / resource / retrieve / config
end
+ # Note that these are being parsed like they allow globbing despite
+ # globbing not being performed.
rule archive
statement_start:"archive" ws resource_url {
def to_package_statement(build_state)
- Statement::Archive.new(
- build_state.node_location(statement_start),
- build_state.source_description,
- resource_url.value.text_value
+ return build_state.new_asset_statement(
+ Statement::Archive, statement_start, resource_url
)
end
}
end
rule resource
statement_start:"resource" ws resource_url {
def to_package_statement(build_state)
- Statement::Resource.new(
- build_state.node_location(statement_start),
- build_state.source_description,
- resource_url.value.text_value
+ return build_state.new_asset_statement(
+ Statement::Resource, statement_start, resource_url
)
end
}
end
rule retrieve
statement_start:"retrieve" ws var:environment_variable_name "->" path:retrieve_path ws {
def to_package_statement(build_state)
- Statement::Retrieve.new(
- build_state.node_location(statement_start),
- build_state.source_description,
- var.text_value,
- path.text_value
- )
+ return build_state.new_retrieve_statement(statement_start, var, path)
end
}
end
rule retrieve_path
@@ -77,18 +49,12 @@
end
rule config
statement_start:"config" ws config_name ws statements:config_statement* "end" ws {
def to_package_statement(build_state)
- Statement::Configuration.new(
- build_state.node_location(statement_start),
- build_state.source_description,
- config_name.text_value,
- statements.elements.map do
- |statement|
- statement.to_config_statement(build_state)
- end
+ return build_state.new_configuration_statement(
+ statement_start, config_name, statements
)
end
}
end
@@ -101,44 +67,22 @@
end
rule include
statement_start:"include" ws descriptor_string ws {
def to_config_statement(build_state)
- include_descriptor =
- Statement::Include.parse_descriptor(
- descriptor_string.text_value.strip,
- :source_description =>
- build_state.node_location_description(descriptor_string),
- :validation_context => ' for an include statement'
- )
-
- Statement::Include.new(
- build_state.node_location(statement_start),
- build_state.source_description,
- include_descriptor,
- build_state.descriptor
+ return build_state.new_include_statement(
+ statement_start, descriptor_string
)
end
}
end
rule override
statement_start:"override" ws descriptor_string ws {
def to_config_statement(build_state)
- descriptor =
- Statement::Override.parse_descriptor(
- descriptor_string.text_value.strip,
- :source_description =>
- build_state.node_location_description(descriptor_string),
- :validation_context => ' for an override statement'
- )
-
- return Statement::Override.new(
- build_state.node_location(statement_start),
- build_state.source_description,
- descriptor.name,
- descriptor.version
+ return build_state.new_override_statement(
+ statement_start, descriptor_string
)
end
}
end
@@ -167,15 +111,11 @@
end
rule command
statement_start:"command" ws string {
def to_config_statement(build_state)
- Statement::Command.new(
- build_state.node_location(statement_start),
- build_state.source_description,
- string.value.text_value
- )
+ return build_state.new_command_statement(statement_start, string)
end
}
end
rule string
@@ -184,32 +124,24 @@
rule descriptor_string
[\S]+
end
- rule package_name
- [a-zA-Z0-9_.-]+
- end
-
- rule version_name
- [a-zA-Z0-9_.-]+
- end
-
rule resource_url
# Unquoted allows globbing for files, quoted does not.
#
# Unquoted, anything but:
# @ - To allow for package substitution
# "<>| - Characters not allowed in filenames on Windows
# \s - Necessary for the "ws" token to work
- (value:[^@"<>|\s]+ ws)
+ (url:[^@"<>|\s]+ ws)
# Quoted, anything but:
# @ - To allow for package substitution
# "<>| - Characters not allowed in filenames on Windows
# *?\[\]{} - Characters significant to Dir.glob()
# \s - We just don't want these. :] (May need to allow space.)
- / ('"' value:[^@"<>|*?\[\]{}\s]+ '"' ws)
+ / ('"' url:[^@"<>|*?\[\]{}\s]+ '"' ws)
end
rule ws
[ \n\r\t]+
end