Class: BELParser::Language::ApplyNamespaceEncoding
- Inherits:
-
Object
- Object
- BELParser::Language::ApplyNamespaceEncoding
show all
- Includes:
- AST::Processor::Mixin
- Defined in:
- lib/bel_parser/language/apply_namespace_encoding.rb
Overview
Instance Method Summary
collapse
#handler_missing, #process, #process_all
Constructor Details
#initialize(language_spec, namespace_hash, uri_reader, url_reader) ⇒ ApplyNamespaceEncoding
Returns a new instance of ApplyNamespaceEncoding.
8
9
10
11
12
13
|
# File 'lib/bel_parser/language/apply_namespace_encoding.rb', line 8
def initialize(language_spec, namespace_hash, uri_reader, url_reader)
@language_spec = language_spec
@namespace_hash = namespace_hash
@uri_reader = uri_reader
@url_reader = url_reader
end
|
Instance Method Details
#on_argument(argument_node) ⇒ Object
47
48
49
|
# File 'lib/bel_parser/language/apply_namespace_encoding.rb', line 47
def on_argument(argument_node)
process(argument_node.child)
end
|
#on_nested_statement(nested_statement_node) ⇒ Object
23
24
25
|
# File 'lib/bel_parser/language/apply_namespace_encoding.rb', line 23
def on_nested_statement(nested_statement_node)
process(nested_statement_node.statement)
end
|
#on_object(object_node) ⇒ Object
36
37
38
|
# File 'lib/bel_parser/language/apply_namespace_encoding.rb', line 36
def on_object(object_node)
process(object_node.child)
end
|
#on_observed_term(observed_term_node) ⇒ Object
15
16
17
|
# File 'lib/bel_parser/language/apply_namespace_encoding.rb', line 15
def on_observed_term(observed_term_node)
process(observed_term_node.statement)
end
|
#on_parameter(parameter_node) ⇒ Object
51
52
53
54
55
56
57
|
# File 'lib/bel_parser/language/apply_namespace_encoding.rb', line 51
def on_parameter(parameter_node)
@type = nil
@namespace = nil
@prefix = nil
process(parameter_node.prefix)
process(parameter_node.value)
end
|
#on_prefix(prefix_node) ⇒ Object
59
60
61
62
63
64
65
66
67
68
|
# File 'lib/bel_parser/language/apply_namespace_encoding.rb', line 59
def on_prefix(prefix_node)
return prefix_node unless prefix_node.identifier
@prefix = prefix_node.identifier.string_literal
@namespace = @namespace_hash[@prefix]
return prefix_node unless @namespace
prefix_node.namespace = @namespace
prefix_node
end
|
#on_simple_statement(simple_statement_node) ⇒ Object
19
20
21
|
# File 'lib/bel_parser/language/apply_namespace_encoding.rb', line 19
def on_simple_statement(simple_statement_node)
process(simple_statement_node.statement)
end
|
#on_statement(statement_node) ⇒ Object
27
28
29
30
|
# File 'lib/bel_parser/language/apply_namespace_encoding.rb', line 27
def on_statement(statement_node)
process(statement_node.subject)
process(statement_node.object) if statement_node.object?
end
|
#on_subject(subject_node) ⇒ Object
32
33
34
|
# File 'lib/bel_parser/language/apply_namespace_encoding.rb', line 32
def on_subject(subject_node)
process(subject_node.term)
end
|
#on_term(term_node) ⇒ Object
Called when visiting nodes of type term
.
41
42
43
44
45
|
# File 'lib/bel_parser/language/apply_namespace_encoding.rb', line 41
def on_term(term_node)
term_node.arguments.each do |argument_node|
process(argument_node)
end
end
|
#on_value(value_node) ⇒ Object
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
# File 'lib/bel_parser/language/apply_namespace_encoding.rb', line 70
def on_value(value_node)
return value_node unless @namespace
value_node.prefix = @prefix
value_node.namespace = @namespace
string_literal = value_literal(value_node.children[0])
value = @namespace[string_literal]
if value
value_node.encoding =
value.encoding &&
value.encoding.map(&@language_spec.method(:value_encoding))
value_node.namespace_value = value
else
value_node.encoding = nil
value_node.namespace_value = nil
end
value_node
end
|