Skip to content

Expand CCL to Support All Concourse Commands #48

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 9 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
789 changes: 780 additions & 9 deletions grammar/grammar.jjt

Large diffs are not rendered by default.

17 changes: 4 additions & 13 deletions src/main/java/com/cinchapi/ccl/Compiler.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import java.util.Set;
import java.util.function.Function;

import com.cinchapi.ccl.grammar.CommandSymbol;
import com.cinchapi.ccl.grammar.ConjunctionSymbol;
import com.cinchapi.ccl.grammar.ExpressionSymbol;
import com.cinchapi.ccl.grammar.KeySymbol;
Expand All @@ -32,16 +31,8 @@
import com.cinchapi.ccl.grammar.Symbol;
import com.cinchapi.ccl.grammar.TimestampSymbol;
import com.cinchapi.ccl.grammar.ValueTokenSymbol;
import com.cinchapi.ccl.syntax.AbstractSyntaxTree;
import com.cinchapi.ccl.syntax.CommandTree;
import com.cinchapi.ccl.syntax.ConditionTree;
import com.cinchapi.ccl.syntax.ConjunctionTree;
import com.cinchapi.ccl.syntax.ExpressionTree;
import com.cinchapi.ccl.syntax.FunctionTree;
import com.cinchapi.ccl.syntax.OrTree;
import com.cinchapi.ccl.syntax.OrderTree;
import com.cinchapi.ccl.syntax.PageTree;
import com.cinchapi.ccl.syntax.Visitor;
import com.cinchapi.ccl.grammar.command.ImplicitSymbol;
import com.cinchapi.ccl.syntax.*;
import com.cinchapi.ccl.type.Operator;
import com.cinchapi.common.base.Verify;
import com.cinchapi.common.function.TriFunction;
Expand Down Expand Up @@ -278,7 +269,7 @@ public final List<Symbol> tokenize(AbstractSyntaxTree ast) {
@Override
public List<Symbol> visit(CommandTree tree, Object... data) {
List<Symbol> symbols = (List<Symbol>) data[0];
if(tree.root() != CommandSymbol.IMPLICIT) {
if(!(tree.root() instanceof ImplicitSymbol)) {
symbols.add(tree.root());
}
for (AbstractSyntaxTree child : tree.children()) {
Expand Down Expand Up @@ -352,7 +343,7 @@ public List<Symbol> visit(PageTree tree, Object... data) {
@SuppressWarnings("unchecked")
@Override
public List<Symbol> visit(FunctionTree tree,
Object... data) {
Object... data) {
List<Symbol> symbols = (List<Symbol>) data[0];
symbols.add(tree.root());
return symbols;
Expand Down
60 changes: 37 additions & 23 deletions src/main/java/com/cinchapi/ccl/CompilerJavaCC.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,26 +20,10 @@
import java.nio.charset.StandardCharsets;
import java.util.function.Function;

import com.cinchapi.ccl.generated.ASTAnd;
import com.cinchapi.ccl.generated.ASTExpression;
import com.cinchapi.ccl.generated.ASTFunction;
import com.cinchapi.ccl.generated.ASTOr;
import com.cinchapi.ccl.generated.ASTOrder;
import com.cinchapi.ccl.generated.ASTPage;
import com.cinchapi.ccl.generated.ASTStart;
import com.cinchapi.ccl.generated.Grammar;
import com.cinchapi.ccl.generated.GrammarVisitor;
import com.cinchapi.ccl.generated.SimpleNode;
import com.cinchapi.ccl.syntax.AbstractSyntaxTree;
import com.cinchapi.ccl.syntax.AndTree;
import com.cinchapi.ccl.syntax.CommandTree;
import com.cinchapi.ccl.syntax.ConditionTree;
import com.cinchapi.ccl.syntax.ExpressionTree;
import com.cinchapi.ccl.syntax.FunctionTree;
import com.cinchapi.ccl.syntax.OrTree;
import com.cinchapi.ccl.syntax.OrderTree;
import com.cinchapi.ccl.syntax.PageTree;
import com.cinchapi.ccl.generated.*;
import com.cinchapi.ccl.syntax.*;
import com.cinchapi.ccl.type.Operator;
import com.cinchapi.concourse.lang.sort.Order;
import com.google.common.collect.Multimap;

/**
Expand Down Expand Up @@ -81,6 +65,7 @@ public Object visit(ASTStart node, Object data) {
PageTree pageTree = null;
OrderTree orderTree = null;
FunctionTree functionTree = null;
CommandTree commandTree = null;

for (int i = 0; i < node.jjtGetNumChildren(); i++) {
Object child = node.jjtGetChild(i).jjtAccept(this,
Expand All @@ -94,26 +79,33 @@ else if(child instanceof OrderTree) {
else if(child instanceof FunctionTree) {
functionTree = (FunctionTree) child;
}
else if(child instanceof CommandTree) {
commandTree = (CommandTree) child;
}
else {
conditionTree = (ConditionTree) child;
}
}
if(conditionTree != null && pageTree == null
&& orderTree == null && functionTree == null) {
&& orderTree == null && functionTree == null && commandTree == null) {
return conditionTree;
}
else if(pageTree != null && conditionTree == null
&& orderTree == null && functionTree == null) {
&& orderTree == null && functionTree == null && commandTree == null) {
return pageTree;
}
else if(orderTree != null && conditionTree == null
&& pageTree == null && functionTree == null) {
&& pageTree == null && functionTree == null && commandTree == null) {
return orderTree;
}
else if(functionTree != null && conditionTree == null
&& pageTree == null && orderTree == null) {
&& pageTree == null && orderTree == null && commandTree == null) {
return functionTree;
}
else if(functionTree == null && conditionTree == null
&& pageTree == null && orderTree == null && commandTree != null) {
return commandTree;
}
else {
// If the statement has multiple elements, it is
// implicitly a command.
Expand Down Expand Up @@ -160,6 +152,28 @@ public Object visit(ASTPage node, Object data) {
public Object visit(ASTFunction node, Object data) {
return new FunctionTree(node.function());
}

@Override
public Object visit(ASTCommand node, Object data) {
ConditionTree conditionTree = null;
OrderTree orderTree = null;
PageTree pageTree = null;

for(int i = 0; i < node.jjtGetNumChildren(); i++) {
Object child = node.jjtGetChild(i).jjtAccept(this, data);
if (child instanceof ConditionTree) {
conditionTree = (ConditionTree) child;
}
else if (child instanceof PageTree) {
pageTree = (PageTree) child;
}
else if (child instanceof OrderTree) {
orderTree = (OrderTree) child;
}
}

return new CommandTree(node.command(), conditionTree, pageTree, orderTree);
}
};

Grammar grammar = new Grammar(stream, valueParser, operatorParser,
Expand Down
7 changes: 1 addition & 6 deletions src/main/java/com/cinchapi/ccl/ConditionTreeVisitor.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,7 @@
*/
package com.cinchapi.ccl;

import com.cinchapi.ccl.syntax.CommandTree;
import com.cinchapi.ccl.syntax.ConditionTree;
import com.cinchapi.ccl.syntax.FunctionTree;
import com.cinchapi.ccl.syntax.OrderTree;
import com.cinchapi.ccl.syntax.PageTree;
import com.cinchapi.ccl.syntax.Visitor;
import com.cinchapi.ccl.syntax.*;

/**
* A {@link Visitor} that can only visit possible subtree types of a
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/cinchapi/ccl/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ public String ccl() {
* @return {@code true} if the data is described by the criteria that has
* been parsed
* @deprecated Use
* {@link com.cinchapi.ccl.syntax.ConditionTree#evaluate(Multimap, TriFunction)}
* {@link ConditionTree#evaluate(Multimap, TriFunction)}
* instead
*/
@Deprecated
Expand Down
81 changes: 81 additions & 0 deletions src/main/java/com/cinchapi/ccl/generated/ASTCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/*
* Copyright (c) 2013-2017 Cinchapi Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.cinchapi.ccl.generated;

import com.cinchapi.ccl.grammar.command.CommandSymbol;

/**
* The {@code ASTCommand} class represents a specific type of abstract syntax tree (AST)
* node for command expressions in the CCL (Concourse Command Language).
*
* <p>This class extends {@code SimpleNode} and adds functionality to handle
* {@link CommandSymbol} objects, which represent the command associated with
* the AST node.
*/
public class ASTCommand extends SimpleNode {
private CommandSymbol command;

/**
* Constructs an {@code ASTCommand} with the given node ID.
*
* @param id the unique identifier for this AST node
*/
public ASTCommand(int id) {
super(id);
}

/**
* Constructs an {@code ASTCommand} with the specified grammar and node ID.
*
* @param p the grammar parser that creates this node
* @param id the unique identifier for this AST node
*/
public ASTCommand(Grammar p, int id) {
super(p, id);
}

/**
* Sets the command associated with this AST node.
*
* @param command the {@link CommandSymbol} representing the command
*/
public void command(CommandSymbol command) {
this.command = command;
}

/**
* Retrieves the command associated with this AST node.
*
* @return the {@link CommandSymbol} representing the command
*/
public CommandSymbol command() {
return command;
}

/**
* Accepts a visitor to perform an operation on this AST node.
*
* <p>This method is part of the visitor pattern implementation.
*
* @param visitor the {@link GrammarVisitor} to process this node
* @param data additional data passed to the visitor
* @return the result of the visitor's operation
*/
@Override
public Object jjtAccept(GrammarVisitor visitor, Object data) {
return visitor.visit(this, data);
}
}
Loading