lib/bel_parser/parsers/ast/node.rb in bel_parser-1.0.0.alpha.5 vs lib/bel_parser/parsers/ast/node.rb in bel_parser-1.0.0.alpha.6
- old
+ new
@@ -375,10 +375,15 @@
#
# @see Node#initialize Node class for basic properties
def initialize(children = [], properties = {})
super(Relationship.ast_type, children, properties)
end
+
+ # Get the string literal.
+ def string_literal
+ children[0]
+ end
end
# AST node representing a set.
class Set < Node
# AST node type
@@ -418,12 +423,38 @@
super(Statement.ast_type, children, properties)
end
# Get the subject of the statement.
def subject
- # TODO: access children for content
+ children[0]
end
+
+ def has_relationship?
+ children[1] && children[1].is_a?(Relationship)
+ end
+
+ # Get the relationship of the nested statement.
+ def relationship
+ has_relationship? ? children[1] : nil
+ end
+
+ def has_object?
+ children[2] && children[2].is_a?(Object)
+ end
+
+ # Get the object of the nested statement.
+ def object
+ has_object? ? children[2] : nil
+ end
+
+ def has_comment?
+ children[-1] && children[-1].is_a?(Comment)
+ end
+
+ def comment
+ has_comment? ? children[-1] : nil
+ end
end
# AST node representing a nested statement.
class NestedStatement < Node
# AST node type
@@ -436,18 +467,23 @@
# @see Node#initialize Node class for basic properties
def initialize(children = [], properties = {})
super(NestedStatement.ast_type, children, properties)
end
+ # Get the subject of the statement.
+ def subject
+ children[0]
+ end
+
# Get the relationship of the nested statement.
- def relatitonship
- # TODO: access children for content
+ def relationship
+ children[1]
end
# Get the object of the nested statement.
def object
- # TODO: access children for content
+ children[2]
end
end
# AST node representing a observed term statement.
class ObservedTerm < Node
@@ -460,10 +496,15 @@
#
# @see Node#initialize Node class for basic properties
def initialize(children = [], properties = {})
super(ObservedTerm.ast_type, children, properties)
end
+
+ # Get the subject of the statement.
+ def subject
+ children[0]
+ end
end
# AST node representing a simple statement.
class SimpleStatement < Node
# AST node type
@@ -476,17 +517,22 @@
# @see Node#initialize Node class for basic properties
def initialize(children = [], properties = {})
super(SimpleStatement.ast_type, children, properties)
end
+ # Get the subject of the statement.
+ def subject
+ children[0]
+ end
+
# Get the relationship of the nested statement.
- def relatitonship
- # TODO: access children for content
+ def relationship
+ children[1]
end
# Get the object of the nested statement.
def object
- # TODO: access children for content
+ children[2]
end
end
# AST node representing the subject of a statement.
class Subject < Node