import experiment
parent
a5eca9916c
commit
05964ee0c7
|
@ -12,10 +12,10 @@ from antlr4 import CommonTokenStream, InputStream
|
||||||
from stix2.patterns import _BooleanExpression
|
from stix2.patterns import _BooleanExpression
|
||||||
|
|
||||||
# need to import all classes because we need to access them via globals()
|
# need to import all classes because we need to access them via globals()
|
||||||
from .patterns import (BinaryConstant, BooleanConstant, FloatConstant,
|
# from .patterns import (BinaryConstant, BooleanConstant, FloatConstant,
|
||||||
FollowedByObservationExpression, HexConstant,
|
# FollowedByObservationExpression, HexConstant,
|
||||||
IntegerConstant, RepeatQualifier, StartStopQualifier,
|
# IntegerConstant, RepeatQualifier, StartStopQualifier,
|
||||||
StringConstant, TimestampConstant, WithinQualifier)
|
# StringConstant, TimestampConstant, WithinQualifier)
|
||||||
from .patterns import * # noqa
|
from .patterns import * # noqa
|
||||||
|
|
||||||
|
|
||||||
|
@ -29,9 +29,9 @@ def collapse_lists(lists):
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
def values_only(things):
|
def remove_terminal_nodes(parse_tree_nodes):
|
||||||
values = []
|
values = []
|
||||||
for x in things:
|
for x in parse_tree_nodes:
|
||||||
if not isinstance(x, TerminalNode):
|
if not isinstance(x, TerminalNode):
|
||||||
values.append(x)
|
values.append(x)
|
||||||
return values
|
return values
|
||||||
|
@ -152,7 +152,7 @@ class STIXPatternVisitorForSTIX2(STIXPatternVisitor):
|
||||||
def visitPropTestEqual(self, ctx):
|
def visitPropTestEqual(self, ctx):
|
||||||
children = self.visitChildren(ctx)
|
children = self.visitChildren(ctx)
|
||||||
operator = children[1].symbol.type
|
operator = children[1].symbol.type
|
||||||
negated = negated = operator != STIXPatternParser.EQ
|
negated = operator != STIXPatternParser.EQ
|
||||||
return self.instantiate("EqualityComparisonExpression", children[0], children[3 if len(children) > 3 else 2],
|
return self.instantiate("EqualityComparisonExpression", children[0], children[3 if len(children) > 3 else 2],
|
||||||
negated)
|
negated)
|
||||||
|
|
||||||
|
@ -274,7 +274,7 @@ class STIXPatternVisitorForSTIX2(STIXPatternVisitor):
|
||||||
# Visit a parse tree produced by STIXPatternParser#setLiteral.
|
# Visit a parse tree produced by STIXPatternParser#setLiteral.
|
||||||
def visitSetLiteral(self, ctx):
|
def visitSetLiteral(self, ctx):
|
||||||
children = self.visitChildren(ctx)
|
children = self.visitChildren(ctx)
|
||||||
return self.instantiate("ListConstant", values_only(children))
|
return self.instantiate("ListConstant", remove_terminal_nodes(children))
|
||||||
|
|
||||||
# Visit a parse tree produced by STIXPatternParser#primitiveLiteral.
|
# Visit a parse tree produced by STIXPatternParser#primitiveLiteral.
|
||||||
def visitPrimitiveLiteral(self, ctx):
|
def visitPrimitiveLiteral(self, ctx):
|
||||||
|
|
Loading…
Reference in New Issue