Skip to content

Commit

Permalink
Size the lists of nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
fpavageau committed Apr 19, 2018
1 parent 5841761 commit d863c02
Showing 1 changed file with 8 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,28 +76,29 @@ private Object visitNonTerminal(ParseNode node) {

Object result;

List<ParseNode> children = node.getChildren();
if (mapping.hasMethodForRuleKey(ruleKey)) {

// TODO Drop useless intermediate nodes
if (node.getChildren().size() != 1) {
if (children.size() != 1) {
throw new IllegalStateException();
}
result = visit(node.getChildren().get(0));
result = visit(children.get(0));

} else if (mapping.isOptionalRule(ruleKey)) {

if (node.getChildren().size() > 1) {
if (children.size() > 1) {
throw new IllegalStateException();
}
if (node.getChildren().isEmpty()) {
if (children.isEmpty()) {
result = Optional.absent();
} else {
result = Optional.of(visit(node.getChildren().get(0)));
result = Optional.of(visit(children.get(0)));
}

} else {
List<Object> convertedChildren = new ArrayList<>();
for (ParseNode child : node.getChildren()) {
List<Object> convertedChildren = new ArrayList<>(children.size());
for (ParseNode child : children) {
convertedChildren.add(visit(child));
}
if (mapping.isOneOrMoreRule(ruleKey)) {
Expand Down

0 comments on commit d863c02

Please sign in to comment.