You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by bd...@apache.org on 2014/11/14 15:05:03 UTC
svn commit: r1639641 [5/15] - in /sling/trunk/contrib/scripting/sightly: ./
engine/ engine/src/ engine/src/main/ engine/src/main/antlr4/
engine/src/main/antlr4/org/ engine/src/main/antlr4/org/apache/
engine/src/main/antlr4/org/apache/sling/ engine/src/...
Added: sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/compiler/api/expression/ExpressionNode.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/compiler/api/expression/ExpressionNode.java?rev=1639641&view=auto
==============================================================================
--- sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/compiler/api/expression/ExpressionNode.java (added)
+++ sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/compiler/api/expression/ExpressionNode.java Fri Nov 14 14:04:56 2014
@@ -0,0 +1,32 @@
+/*******************************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.sling.scripting.sightly.compiler.api.expression;
+
+/**
+ * ExpressionNode in a Sightly expression tree
+ */
+public interface ExpressionNode {
+
+ /**
+ * Accept a visitor to process this node.
+ * @param visitor The visitor
+ */
+ <T> T accept(NodeVisitor<T> visitor);
+
+}
Added: sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/compiler/api/expression/NodeVisitor.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/compiler/api/expression/NodeVisitor.java?rev=1639641&view=auto
==============================================================================
--- sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/compiler/api/expression/NodeVisitor.java (added)
+++ sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/compiler/api/expression/NodeVisitor.java Fri Nov 14 14:04:56 2014
@@ -0,0 +1,65 @@
+/*******************************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.sling.scripting.sightly.compiler.api.expression;
+
+import org.apache.sling.scripting.sightly.compiler.api.expression.node.ArrayLiteral;
+import org.apache.sling.scripting.sightly.compiler.api.expression.node.BinaryOperation;
+import org.apache.sling.scripting.sightly.compiler.api.expression.node.BooleanConstant;
+import org.apache.sling.scripting.sightly.compiler.api.expression.node.Identifier;
+import org.apache.sling.scripting.sightly.compiler.api.expression.node.MapLiteral;
+import org.apache.sling.scripting.sightly.compiler.api.expression.node.NullLiteral;
+import org.apache.sling.scripting.sightly.compiler.api.expression.node.NumericConstant;
+import org.apache.sling.scripting.sightly.compiler.api.expression.node.PropertyAccess;
+import org.apache.sling.scripting.sightly.compiler.api.expression.node.RuntimeCall;
+import org.apache.sling.scripting.sightly.compiler.api.expression.node.StringConstant;
+import org.apache.sling.scripting.sightly.compiler.api.expression.node.TernaryOperator;
+import org.apache.sling.scripting.sightly.compiler.api.expression.node.UnaryOperation;
+import org.apache.sling.scripting.sightly.compiler.api.expression.node.*;
+
+/**
+ * Visitor for all expression nodes
+ */
+public interface NodeVisitor<T> {
+
+ T evaluate(PropertyAccess propertyAccess);
+
+ T evaluate(Identifier identifier);
+
+ T evaluate(StringConstant text);
+
+ T evaluate(BinaryOperation binaryOperation);
+
+ T evaluate(BooleanConstant booleanConstant);
+
+ T evaluate(NumericConstant numericConstant);
+
+ T evaluate(UnaryOperation unaryOperation);
+
+ T evaluate(TernaryOperator ternaryOperator);
+
+ T evaluate(RuntimeCall runtimeCall);
+
+ T evaluate(MapLiteral mapLiteral);
+
+ T evaluate(ArrayLiteral arrayLiteral);
+
+ T evaluate(NullLiteral nullLiteral);
+
+}
Added: sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/compiler/api/expression/node/ArrayLiteral.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/compiler/api/expression/node/ArrayLiteral.java?rev=1639641&view=auto
==============================================================================
--- sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/compiler/api/expression/node/ArrayLiteral.java (added)
+++ sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/compiler/api/expression/node/ArrayLiteral.java Fri Nov 14 14:04:56 2014
@@ -0,0 +1,47 @@
+/*******************************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.sling.scripting.sightly.compiler.api.expression.node;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import org.apache.sling.scripting.sightly.compiler.api.expression.ExpressionNode;
+import org.apache.sling.scripting.sightly.compiler.api.expression.NodeVisitor;
+
+/**
+ * Syntactical structure for an array of items
+ */
+public class ArrayLiteral implements ExpressionNode {
+
+ private final List<ExpressionNode> items;
+
+ public ArrayLiteral(List<ExpressionNode> items) {
+ this.items = new ArrayList<ExpressionNode>(items);
+ }
+
+ public List<ExpressionNode> getItems() {
+ return Collections.unmodifiableList(items);
+ }
+
+ @Override
+ public <T> T accept(NodeVisitor<T> visitor) {
+ return visitor.evaluate(this);
+ }
+}
Added: sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/compiler/api/expression/node/Atom.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/compiler/api/expression/node/Atom.java?rev=1639641&view=auto
==============================================================================
--- sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/compiler/api/expression/node/Atom.java (added)
+++ sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/compiler/api/expression/node/Atom.java Fri Nov 14 14:04:56 2014
@@ -0,0 +1,36 @@
+/*******************************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.sling.scripting.sightly.compiler.api.expression.node;
+
+import org.apache.sling.scripting.sightly.compiler.api.expression.ExpressionNode;
+
+/**
+ * Nodes that can be translated to simple text, like identifiers
+ * or string constants.
+ */
+public interface Atom extends ExpressionNode {
+
+ /**
+ * Get the text content for this node
+ * @return The text content
+ */
+ String getText();
+
+}
+
Added: sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/compiler/api/expression/node/BinaryOperation.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/compiler/api/expression/node/BinaryOperation.java?rev=1639641&view=auto
==============================================================================
--- sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/compiler/api/expression/node/BinaryOperation.java (added)
+++ sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/compiler/api/expression/node/BinaryOperation.java Fri Nov 14 14:04:56 2014
@@ -0,0 +1,66 @@
+/*******************************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.sling.scripting.sightly.compiler.api.expression.node;
+
+import org.apache.sling.scripting.sightly.compiler.api.expression.ExpressionNode;
+import org.apache.sling.scripting.sightly.compiler.api.expression.NodeVisitor;
+
+/**
+ * An expression where a binary operator is applied.
+ * Ex.: "a AND b"
+ */
+public class BinaryOperation implements ExpressionNode {
+
+ private BinaryOperator operator;
+ private ExpressionNode leftOperand;
+ private ExpressionNode rightOperand;
+
+ public BinaryOperation(BinaryOperator operator, ExpressionNode leftOperand, ExpressionNode rightOperand) {
+ this.operator = operator;
+ this.leftOperand = leftOperand;
+ this.rightOperand = rightOperand;
+ }
+
+ public BinaryOperator getOperator() {
+ return operator;
+ }
+
+ public ExpressionNode getLeftOperand() {
+ return leftOperand;
+ }
+
+ public ExpressionNode getRightOperand() {
+ return rightOperand;
+ }
+
+ @Override
+ public <T> T accept(NodeVisitor<T> visitor) {
+ return visitor.evaluate(this);
+ }
+
+ @Override
+ public String toString() {
+ return "BinaryOperation{" +
+ "operator=" + operator +
+ ", leftOperand=" + leftOperand +
+ ", rightOperand=" + rightOperand +
+ '}';
+ }
+
+}
Added: sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/compiler/api/expression/node/BinaryOperator.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/compiler/api/expression/node/BinaryOperator.java?rev=1639641&view=auto
==============================================================================
--- sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/compiler/api/expression/node/BinaryOperator.java (added)
+++ sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/compiler/api/expression/node/BinaryOperator.java Fri Nov 14 14:04:56 2014
@@ -0,0 +1,46 @@
+/*******************************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.sling.scripting.sightly.compiler.api.expression.node;
+
+/**
+ * Binary operators used in expressions
+ */
+public enum BinaryOperator {
+ AND, //logical conjunction
+ OR, //logical disjunction
+ CONCATENATE, //string concatenation
+
+ LT, //less-than
+ LEQ, //less or equal
+ GT, // greater than
+ GEQ, // greater or equal
+ EQ, //equal
+ NEQ, //not equal
+ STRICT_EQ, //strict version of equality, restricted to just some types
+ STRICT_NEQ, //strict version of the not-equal operator
+
+ ADD, //addition
+ SUB, //difference
+ MUL, //multiplication
+ I_DIV, //integer division
+ REM, //reminder
+
+ DIV //floating point division
+
+}
Added: sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/compiler/api/expression/node/BooleanConstant.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/compiler/api/expression/node/BooleanConstant.java?rev=1639641&view=auto
==============================================================================
--- sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/compiler/api/expression/node/BooleanConstant.java (added)
+++ sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/compiler/api/expression/node/BooleanConstant.java Fri Nov 14 14:04:56 2014
@@ -0,0 +1,66 @@
+/*******************************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.sling.scripting.sightly.compiler.api.expression.node;
+
+import org.apache.sling.scripting.sightly.compiler.api.expression.NodeVisitor;
+import org.apache.sling.scripting.sightly.compiler.api.expression.NodeVisitor;
+
+/**
+ * Boolean constant.
+ * Ex: "true" or "false"
+ */
+public class BooleanConstant implements Atom {
+
+ private String rawText;
+
+ public static final BooleanConstant FALSE = new BooleanConstant(Boolean.toString(false));
+ public static final BooleanConstant TRUE = new BooleanConstant(Boolean.toString(true));
+
+ public BooleanConstant(String text) {
+ this.rawText = text;
+ }
+
+ public BooleanConstant(boolean value) {
+ this(Boolean.toString(value));
+ }
+
+ public boolean getValue() {
+ return Boolean.parseBoolean(rawText);
+ }
+
+
+ @Override
+ public String getText() {
+ return rawText;
+ }
+
+
+ @Override
+ public <T> T accept(NodeVisitor<T> visitor) {
+ return visitor.evaluate(this);
+ }
+
+ @Override
+ public String toString() {
+ return "BooleanConstant{" +
+ "rawText='" + rawText + '\'' +
+ '}';
+ }
+
+}
Added: sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/compiler/api/expression/node/Identifier.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/compiler/api/expression/node/Identifier.java?rev=1639641&view=auto
==============================================================================
--- sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/compiler/api/expression/node/Identifier.java (added)
+++ sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/compiler/api/expression/node/Identifier.java Fri Nov 14 14:04:56 2014
@@ -0,0 +1,64 @@
+/*******************************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.sling.scripting.sightly.compiler.api.expression.node;
+
+import org.apache.sling.scripting.sightly.compiler.api.expression.NodeVisitor;
+
+/**
+ * A single variable. Ex: "myVar"
+ */
+public class Identifier implements Atom {
+
+ private final String name;
+
+ /**
+ * Create an identifier
+ * @param name the name of the identifier
+ */
+ public Identifier(String name) {
+ this.name = name;
+ }
+
+ @Override
+ public <T> T accept(NodeVisitor<T> visitor) {
+ return visitor.evaluate(this);
+ }
+
+ /**
+ * Retrieve the name of the identifier
+ * @return the name string
+ */
+ public String getName() {
+ return name;
+ }
+
+
+ @Override
+ public String getText() {
+ return getName();
+ }
+
+ @Override
+ public String toString() {
+ return "Identifier{" +
+ "name='" + name + '\'' +
+ '}';
+ }
+
+}
Added: sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/compiler/api/expression/node/MapLiteral.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/compiler/api/expression/node/MapLiteral.java?rev=1639641&view=auto
==============================================================================
--- sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/compiler/api/expression/node/MapLiteral.java (added)
+++ sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/compiler/api/expression/node/MapLiteral.java Fri Nov 14 14:04:56 2014
@@ -0,0 +1,65 @@
+/*******************************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.sling.scripting.sightly.compiler.api.expression.node;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.sling.scripting.sightly.compiler.api.expression.ExpressionNode;
+import org.apache.sling.scripting.sightly.compiler.api.expression.NodeVisitor;
+
+/**
+ * A syntactical construction representing a map
+ */
+public class MapLiteral implements ExpressionNode {
+
+ private Map<String, ExpressionNode> map;
+
+ public static final MapLiteral EMPTY = new MapLiteral(new HashMap<String, ExpressionNode>());
+
+ public MapLiteral(Map<String, ExpressionNode> map) {
+ this.map = new HashMap<String, ExpressionNode>();
+ this.map.putAll(map);
+ }
+
+ public Map<String, ExpressionNode> getMap() {
+ return Collections.unmodifiableMap(map);
+ }
+
+ public ExpressionNode getValue(String property) {
+ return map.get(property);
+ }
+
+ public boolean containsKey(String name) {
+ return map.containsKey(name);
+ }
+
+ @Override
+ public <T> T accept(NodeVisitor<T> visitor) {
+ return visitor.evaluate(this);
+ }
+
+ @Override
+ public String toString() {
+ return "MapLiteral{" +
+ "map=" + map +
+ '}';
+ }
+}
Added: sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/compiler/api/expression/node/NullLiteral.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/compiler/api/expression/node/NullLiteral.java?rev=1639641&view=auto
==============================================================================
--- sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/compiler/api/expression/node/NullLiteral.java (added)
+++ sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/compiler/api/expression/node/NullLiteral.java Fri Nov 14 14:04:56 2014
@@ -0,0 +1,38 @@
+/*******************************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.sling.scripting.sightly.compiler.api.expression.node;
+
+import org.apache.sling.scripting.sightly.compiler.api.expression.ExpressionNode;
+import org.apache.sling.scripting.sightly.compiler.api.expression.NodeVisitor;
+
+/**
+ * The null literal
+ */
+public final class NullLiteral implements ExpressionNode {
+
+ public static final NullLiteral INSTANCE = new NullLiteral();
+
+ private NullLiteral() {
+ }
+
+ @Override
+ public <T> T accept(NodeVisitor<T> visitor) {
+ return visitor.evaluate(this);
+ }
+}
Added: sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/compiler/api/expression/node/NumericConstant.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/compiler/api/expression/node/NumericConstant.java?rev=1639641&view=auto
==============================================================================
--- sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/compiler/api/expression/node/NumericConstant.java (added)
+++ sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/compiler/api/expression/node/NumericConstant.java Fri Nov 14 14:04:56 2014
@@ -0,0 +1,80 @@
+/*******************************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.sling.scripting.sightly.compiler.api.expression.node;
+
+import org.apache.sling.scripting.sightly.compiler.api.expression.NodeVisitor;
+
+/**
+ * Numeric constant expression.
+ * Ex: "42.1"
+ */
+public class NumericConstant implements Atom {
+
+ public static final NumericConstant ZERO = new NumericConstant(0);
+ public static final NumericConstant ONE = new NumericConstant(1);
+ public static final NumericConstant TWO = new NumericConstant(2);
+
+ private final String text;
+ private final Number value;
+
+ /**
+ * Create a numeric constant
+ * @param text - the text representation
+ * @throws java.lang.NumberFormatException - if the text is not in a numeric format
+ */
+ public NumericConstant(String text) {
+ this.text = text;
+ this.value = parseNumber(text);
+ }
+
+ public NumericConstant(Number value) {
+ this.value = value.longValue();
+ this.text = value.toString();
+ }
+
+ public Number getValue() {
+ return value;
+ }
+
+ @Override
+ public String getText() {
+ return text;
+ }
+
+ @Override
+ public <T> T accept(NodeVisitor<T> visitor) {
+ return visitor.evaluate(this);
+ }
+
+ @Override
+ public String toString() {
+ return "NumericConstant{" +
+ "text='" + text + '\'' +
+ '}';
+ }
+
+ private Number parseNumber(String s) {
+ try {
+ return Long.parseLong(s);
+ } catch (NumberFormatException e) {
+ return Double.parseDouble(s);
+ }
+ }
+
+}
Added: sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/compiler/api/expression/node/PropertyAccess.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/compiler/api/expression/node/PropertyAccess.java?rev=1639641&view=auto
==============================================================================
--- sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/compiler/api/expression/node/PropertyAccess.java (added)
+++ sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/compiler/api/expression/node/PropertyAccess.java Fri Nov 14 14:04:56 2014
@@ -0,0 +1,99 @@
+/*******************************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.sling.scripting.sightly.compiler.api.expression.node;
+
+import org.apache.sling.scripting.sightly.compiler.api.expression.ExpressionNode;
+import org.apache.sling.scripting.sightly.compiler.api.expression.NodeVisitor;
+
+/**
+ * Expressions in which a property is queried for an object.
+ * Ex.: "E.prop"
+ */
+public class PropertyAccess implements ExpressionNode {
+
+ private final ExpressionNode target;
+ private final ExpressionNode property;
+
+ /**
+ * Create a property access node
+ * @param target The expression for the object being accessed
+ * @param property The name of the property
+ */
+ public PropertyAccess(ExpressionNode target, ExpressionNode property) {
+ this.target = target;
+ this.property = property;
+ }
+
+ public PropertyAccess(ExpressionNode target, String property) {
+ this.target = target;
+ this.property = new StringConstant(property);
+ }
+
+ /**
+ * Build a chained property access node with the given target and the specified properties
+ * @param target The target node
+ * @param properties A non-empty list of property names
+ * @throws IllegalArgumentException if the list of properties is empty
+ */
+ public PropertyAccess(ExpressionNode target, Iterable<String> properties) {
+ String lastProp = null;
+ ExpressionNode result = target;
+ for (String property : properties) {
+ if (lastProp != null) {
+ result = new PropertyAccess(result, new StringConstant(lastProp));
+ }
+ lastProp = property;
+ }
+ if (lastProp == null) {
+ throw new IllegalArgumentException("The list of properties must be non-empty");
+ }
+ this.target = result;
+ this.property = new StringConstant(lastProp);
+ }
+
+ @Override
+ public <T> T accept(NodeVisitor<T> visitor) {
+ return visitor.evaluate(this);
+ }
+
+ /**
+ * The object being accessed
+ * @return a node representing the object being accessed
+ */
+ public ExpressionNode getTarget() {
+ return target;
+ }
+
+ /**
+ * Return the property name
+ * @return the property name
+ */
+ public ExpressionNode getProperty() {
+ return property;
+ }
+
+ @Override
+ public String toString() {
+ return "PropertyAccess{" +
+ "target=" + target +
+ ", property='" + property + '\'' +
+ '}';
+ }
+
+}
Added: sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/compiler/api/expression/node/RuntimeCall.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/compiler/api/expression/node/RuntimeCall.java?rev=1639641&view=auto
==============================================================================
--- sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/compiler/api/expression/node/RuntimeCall.java (added)
+++ sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/compiler/api/expression/node/RuntimeCall.java Fri Nov 14 14:04:56 2014
@@ -0,0 +1,67 @@
+/*******************************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.sling.scripting.sightly.compiler.api.expression.node;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+
+import org.apache.sling.scripting.sightly.compiler.api.expression.ExpressionNode;
+import org.apache.sling.scripting.sightly.compiler.api.expression.NodeVisitor;
+
+/**
+ * Special expression which provides access to utility functions from
+ * the runtime. This mechanism should not be abused!
+ */
+public class RuntimeCall implements ExpressionNode {
+
+ private final String functionName;
+ private final List<ExpressionNode> arguments;
+
+ public RuntimeCall(String functionName, ExpressionNode... arguments) {
+ this(functionName, Arrays.asList(arguments));
+ }
+
+ public RuntimeCall(String functionName, List<ExpressionNode> arguments) {
+ this.functionName = functionName;
+ this.arguments = new ArrayList<ExpressionNode>(arguments);
+ }
+
+ /**
+ * Get the name of the function
+ * @return - the name of the function
+ */
+ public String getFunctionName() {
+ return functionName;
+ }
+
+ /**
+ * Get the nodes of the argument calls
+ * @return - an array of nodes
+ */
+ public List<ExpressionNode> getArguments() {
+ return Collections.unmodifiableList(arguments);
+ }
+
+ @Override
+ public <T> T accept(NodeVisitor<T> visitor) {
+ return visitor.evaluate(this);
+ }
+}
Added: sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/compiler/api/expression/node/StringConstant.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/compiler/api/expression/node/StringConstant.java?rev=1639641&view=auto
==============================================================================
--- sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/compiler/api/expression/node/StringConstant.java (added)
+++ sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/compiler/api/expression/node/StringConstant.java Fri Nov 14 14:04:56 2014
@@ -0,0 +1,61 @@
+/*******************************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.sling.scripting.sightly.compiler.api.expression.node;
+
+import org.apache.sling.scripting.sightly.compiler.api.expression.NodeVisitor;
+
+/**
+ * Simple string constant. Ex: "'hello'"
+ */
+public class StringConstant implements Atom {
+
+ private String text;
+
+ public static final StringConstant EMPTY = new StringConstant("");
+
+ /**
+ * Create a string constant node
+ * @param text the string content (without it's original quotes).
+ */
+ public StringConstant(String text) {
+ this.text = text;
+ }
+
+ @Override
+ public <T> T accept(NodeVisitor<T> visitor) {
+ return visitor.evaluate(this);
+ }
+
+ /**
+ * Get the string content - it strips the quotes from the string
+ * @return a string inner content
+ */
+ @Override
+ public String getText() {
+ return text;
+ }
+
+ @Override
+ public String toString() {
+ return "StringConstant{" +
+ "text='" + text + '\'' +
+ '}';
+ }
+
+}
Added: sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/compiler/api/expression/node/TernaryOperator.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/compiler/api/expression/node/TernaryOperator.java?rev=1639641&view=auto
==============================================================================
--- sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/compiler/api/expression/node/TernaryOperator.java (added)
+++ sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/compiler/api/expression/node/TernaryOperator.java Fri Nov 14 14:04:56 2014
@@ -0,0 +1,65 @@
+/*******************************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.sling.scripting.sightly.compiler.api.expression.node;
+
+import org.apache.sling.scripting.sightly.compiler.api.expression.ExpressionNode;
+import org.apache.sling.scripting.sightly.compiler.api.expression.NodeVisitor;
+
+/**
+ * Defines the Sightly ternary operator: {@code condition ? then : else}.
+ */
+public class TernaryOperator implements ExpressionNode {
+
+ private ExpressionNode condition;
+ private ExpressionNode thenBranch;
+ private ExpressionNode elseBranch;
+
+ public TernaryOperator(ExpressionNode condition, ExpressionNode thenBranch, ExpressionNode elseBranch) {
+ this.condition = condition;
+ this.thenBranch = thenBranch;
+ this.elseBranch = elseBranch;
+ }
+
+ public ExpressionNode getCondition() {
+ return condition;
+ }
+
+ public ExpressionNode getThenBranch() {
+ return thenBranch;
+ }
+
+ public ExpressionNode getElseBranch() {
+ return elseBranch;
+ }
+
+ @Override
+ public <T> T accept(NodeVisitor<T> visitor) {
+ return visitor.evaluate(this);
+ }
+
+ @Override
+ public String toString() {
+ return "TernaryOperator{" +
+ "condition=" + condition +
+ ", thenBranch=" + thenBranch +
+ ", elseBranch=" + elseBranch +
+ '}';
+ }
+}
Added: sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/compiler/api/expression/node/UnaryOperation.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/compiler/api/expression/node/UnaryOperation.java?rev=1639641&view=auto
==============================================================================
--- sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/compiler/api/expression/node/UnaryOperation.java (added)
+++ sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/compiler/api/expression/node/UnaryOperation.java Fri Nov 14 14:04:56 2014
@@ -0,0 +1,58 @@
+/*******************************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.sling.scripting.sightly.compiler.api.expression.node;
+
+import org.apache.sling.scripting.sightly.compiler.api.expression.ExpressionNode;
+import org.apache.sling.scripting.sightly.compiler.api.expression.NodeVisitor;
+
+/**
+ * Defines a unary operation (e.g. !variableName).
+ */
+public class UnaryOperation implements ExpressionNode {
+
+ private UnaryOperator operator;
+ private ExpressionNode target;
+
+ public UnaryOperation(UnaryOperator operator, ExpressionNode target) {
+ this.operator = operator;
+ this.target = target;
+ }
+
+ @Override
+ public <T> T accept(NodeVisitor<T> visitor) {
+ return visitor.evaluate(this);
+ }
+
+ public UnaryOperator getOperator() {
+ return operator;
+ }
+
+ public ExpressionNode getTarget() {
+ return target;
+ }
+
+ @Override
+ public String toString() {
+ return "UnaryOperation{" +
+ "operator=" + operator +
+ ", operand=" + target +
+ '}';
+ }
+
+}
Added: sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/compiler/api/expression/node/UnaryOperator.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/compiler/api/expression/node/UnaryOperator.java?rev=1639641&view=auto
==============================================================================
--- sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/compiler/api/expression/node/UnaryOperator.java (added)
+++ sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/compiler/api/expression/node/UnaryOperator.java Fri Nov 14 14:04:56 2014
@@ -0,0 +1,28 @@
+/*******************************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.sling.scripting.sightly.compiler.api.expression.node;
+
+/**
+ * Unary operators used in expressions
+ */
+public enum UnaryOperator {
+ NOT, //logical negation
+ IS_WHITESPACE, //true if the operand is a string that contains only whitespace
+ LENGTH //the length of a collection
+}
Added: sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/compiler/api/plugin/CompilerContext.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/compiler/api/plugin/CompilerContext.java?rev=1639641&view=auto
==============================================================================
--- sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/compiler/api/plugin/CompilerContext.java (added)
+++ sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/compiler/api/plugin/CompilerContext.java Fri Nov 14 14:04:56 2014
@@ -0,0 +1,44 @@
+/*******************************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.sling.scripting.sightly.compiler.api.plugin;
+
+import org.apache.sling.scripting.sightly.compiler.api.expression.Expression;
+import org.apache.sling.scripting.sightly.compiler.api.expression.Expression;
+
+/**
+ * Compiler context for plugins
+ */
+public interface CompilerContext {
+
+ /**
+ * Generate a unique variable name
+ * @param hint - a hint to be added to the variable name. Leave null
+ * for no hint
+ * @return the variable name
+ */
+ String generateVariable(String hint);
+
+ /**
+ * Adjust the expression node to the specifics of the given context
+ * @param expression - the expression to be changed
+ * @param context - the render context
+ * @return - the adjusted expression
+ */
+ Expression adjustToContext(Expression expression, MarkupContext context);
+}
Added: sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/compiler/api/plugin/MarkupContext.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/compiler/api/plugin/MarkupContext.java?rev=1639641&view=auto
==============================================================================
--- sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/compiler/api/plugin/MarkupContext.java (added)
+++ sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/compiler/api/plugin/MarkupContext.java Fri Nov 14 14:04:56 2014
@@ -0,0 +1,71 @@
+/*******************************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.sling.scripting.sightly.compiler.api.plugin;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Indicates what type of content is being rendered
+ */
+public enum MarkupContext {
+
+ HTML("html"),
+ TEXT("text"),
+ ELEMENT_NAME("elementName"),
+ ATTRIBUTE_NAME("attributeName"),
+ ATTRIBUTE("attribute"),
+ URI("uri"),
+ SCRIPT_TOKEN("scriptToken"),
+ SCRIPT_STRING("scriptString"),
+ SCRIPT_COMMENT("scriptComment"),
+ SCRIPT_REGEXP("scriptRegExp"),
+ STYLE_TOKEN("styleToken"),
+ STYLE_STRING("styleString"),
+ COMMENT("comment"),
+ NUMBER("number"),
+ UNSAFE("unsafe");
+
+ private final String name;
+
+ MarkupContext(String name) {
+ this.name = name;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ /**
+ * Return the render context with the given name
+ * @param name - the name of the render context
+ * @return - the rendering context value or null if the name matches no value
+ */
+ public static MarkupContext lookup(String name) {
+ return reverseMap.get(name);
+ }
+
+ private static final Map<String, MarkupContext> reverseMap = new HashMap<String, MarkupContext>();
+
+ static {
+ for (MarkupContext markupContext : MarkupContext.values()) {
+ reverseMap.put(markupContext.getName(), markupContext);
+ }
+ }
+}
Added: sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/compiler/api/plugin/Plugin.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/compiler/api/plugin/Plugin.java?rev=1639641&view=auto
==============================================================================
--- sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/compiler/api/plugin/Plugin.java (added)
+++ sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/compiler/api/plugin/Plugin.java Fri Nov 14 14:04:56 2014
@@ -0,0 +1,54 @@
+/*******************************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.sling.scripting.sightly.compiler.api.plugin;
+
+import org.apache.sling.scripting.sightly.compiler.api.expression.Expression;
+
+/**
+ * Common interface for plugins
+ */
+public interface Plugin extends Comparable<Plugin> {
+
+ String SCR_PROP_NAME_BLOCK_NAME = "org.apache.sling.scripting.sightly.plugin.name";
+ String SCR_PROP_NAME_PRIORITY = "org.apache.sling.scripting.sightly.plugin.priority";
+
+ /**
+ * Given the plugin invocation provide an invoke object which will influence the rendering command
+ * stream
+ * @param expression the expression used at plugin invocation
+ * @param callInfo the parameters given to the plugin
+ * @param compilerContext a compiler context providing utility methods to plugins
+ * @return an invocation
+ * @see PluginInvoke
+ */
+ PluginInvoke invoke(Expression expression, PluginCallInfo callInfo, CompilerContext compilerContext);
+
+ /**
+ * The priority of the plugin
+ * @return a numeric value which controls when, relative to other plugins, should
+ * this plugin be applied
+ */
+ int priority();
+
+ /**
+ * The name of the plugin
+ * @return the plugin name
+ */
+ String name();
+}
Added: sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/compiler/api/plugin/PluginCallInfo.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/compiler/api/plugin/PluginCallInfo.java?rev=1639641&view=auto
==============================================================================
--- sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/compiler/api/plugin/PluginCallInfo.java (added)
+++ sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/compiler/api/plugin/PluginCallInfo.java Fri Nov 14 14:04:56 2014
@@ -0,0 +1,49 @@
+/*******************************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.sling.scripting.sightly.compiler.api.plugin;
+
+/**
+ * Data related to a plugin call
+ */
+public class PluginCallInfo {
+
+ private final String name;
+ private final String[] arguments;
+
+ public PluginCallInfo(String name, String[] arguments) {
+ this.name = name;
+ this.arguments = arguments;
+ }
+
+ /**
+ * Get the name of the called plugin
+ * @return a string with the name of the called plugin
+ */
+ public String getName() {
+ return name;
+ }
+
+ /**
+ * Get the plugin arguments
+ * @return a possibly empty array of args
+ */
+ public String[] getArguments() {
+ return arguments;
+ }
+}
Added: sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/compiler/api/plugin/PluginException.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/compiler/api/plugin/PluginException.java?rev=1639641&view=auto
==============================================================================
--- sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/compiler/api/plugin/PluginException.java (added)
+++ sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/compiler/api/plugin/PluginException.java Fri Nov 14 14:04:56 2014
@@ -0,0 +1,36 @@
+/*******************************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.sling.scripting.sightly.compiler.api.plugin;
+
+/**
+ * Plugin runtime exception caused by a plugin
+ */
+public class PluginException extends RuntimeException {
+
+ private Plugin plugin;
+
+ public PluginException(Plugin plugin, String message) {
+ super(message);
+ this.plugin = plugin;
+ }
+
+ public Plugin getPlugin() {
+ return plugin;
+ }
+}
Added: sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/compiler/api/plugin/PluginInvoke.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/compiler/api/plugin/PluginInvoke.java?rev=1639641&view=auto
==============================================================================
--- sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/compiler/api/plugin/PluginInvoke.java (added)
+++ sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/compiler/api/plugin/PluginInvoke.java Fri Nov 14 14:04:56 2014
@@ -0,0 +1,62 @@
+/*******************************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.sling.scripting.sightly.compiler.api.plugin;
+
+import org.apache.sling.scripting.sightly.compiler.api.expression.Expression;
+import org.apache.sling.scripting.sightly.compiler.api.expression.ExpressionNode;
+import org.apache.sling.scripting.sightly.compiler.util.stream.PushStream;
+import org.apache.sling.scripting.sightly.compiler.api.expression.Expression;
+import org.apache.sling.scripting.sightly.compiler.util.stream.PushStream;
+
+/**
+ * General interface for plugins
+ */
+public interface PluginInvoke {
+
+ void beforeElement(PushStream stream, String tagName);
+
+ void beforeTagOpen(PushStream stream);
+
+ void beforeAttributes(PushStream stream);
+
+ void beforeAttribute(PushStream stream, String attributeName);
+
+ void beforeAttributeValue(PushStream stream, String attributeName, ExpressionNode attributeValue);
+
+ void afterAttributeValue(PushStream stream, String attributeName);
+
+ void afterAttribute(PushStream stream, String attributeName);
+
+ void onPluginCall(PushStream stream, PluginCallInfo callInfo, Expression expression);
+
+ void afterAttributes(PushStream stream);
+
+ void afterTagOpen(PushStream stream);
+
+ void beforeChildren(PushStream stream);
+
+ void afterChildren(PushStream stream);
+
+ void beforeTagClose(PushStream stream, boolean isSelfClosing);
+
+ void afterTagClose(PushStream stream, boolean isSelfClosing);
+
+ void afterElement(PushStream stream);
+
+}
Added: sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/compiler/api/ris/Command.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/compiler/api/ris/Command.java?rev=1639641&view=auto
==============================================================================
--- sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/compiler/api/ris/Command.java (added)
+++ sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/compiler/api/ris/Command.java Fri Nov 14 14:04:56 2014
@@ -0,0 +1,32 @@
+/*******************************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.sling.scripting.sightly.compiler.api.ris;
+
+/**
+ * A text rendering command
+ */
+public interface Command {
+
+ /**
+ * Accept a visitor
+ * @param visitor - the visitor that will process this command
+ */
+ void accept(CommandVisitor visitor);
+
+}
Added: sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/compiler/api/ris/CommandHandler.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/compiler/api/ris/CommandHandler.java?rev=1639641&view=auto
==============================================================================
--- sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/compiler/api/ris/CommandHandler.java (added)
+++ sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/compiler/api/ris/CommandHandler.java Fri Nov 14 14:04:56 2014
@@ -0,0 +1,44 @@
+/*******************************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.sling.scripting.sightly.compiler.api.ris;
+
+/**
+ * Handles commands from streams
+ */
+public interface CommandHandler {
+
+ /**
+ * Handle the incoming command
+ * @param command - the received command
+ */
+ void onEmit(Command command);
+
+ /**
+ * Called when an error occurs.
+ * @param errorMessage - the message of the error
+ */
+ void onError(String errorMessage);
+
+ /**
+ * Called when the stream has finished. The contract is that after this call, no other
+ * commands or errors will be emitted.
+ */
+ void onDone();
+
+}
Added: sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/compiler/api/ris/CommandStream.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/compiler/api/ris/CommandStream.java?rev=1639641&view=auto
==============================================================================
--- sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/compiler/api/ris/CommandStream.java (added)
+++ sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/compiler/api/ris/CommandStream.java Fri Nov 14 14:04:56 2014
@@ -0,0 +1,32 @@
+/*******************************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.sling.scripting.sightly.compiler.api.ris;
+
+/**
+ * A push-stream of commands
+ */
+public interface CommandStream {
+
+ /**
+ * Add a listening handler
+ * @param handler - a command handler
+ */
+ void addHandler(CommandHandler handler);
+
+}
Added: sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/compiler/api/ris/CommandVisitor.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/compiler/api/ris/CommandVisitor.java?rev=1639641&view=auto
==============================================================================
--- sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/compiler/api/ris/CommandVisitor.java (added)
+++ sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/compiler/api/ris/CommandVisitor.java Fri Nov 14 14:04:56 2014
@@ -0,0 +1,61 @@
+/*******************************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.sling.scripting.sightly.compiler.api.ris;
+
+import org.apache.sling.scripting.sightly.compiler.api.ris.command.BufferControl;
+import org.apache.sling.scripting.sightly.compiler.api.ris.command.Conditional;
+import org.apache.sling.scripting.sightly.compiler.api.ris.command.Loop;
+import org.apache.sling.scripting.sightly.compiler.api.ris.command.OutText;
+import org.apache.sling.scripting.sightly.compiler.api.ris.command.OutVariable;
+import org.apache.sling.scripting.sightly.compiler.api.ris.command.Procedure;
+import org.apache.sling.scripting.sightly.compiler.api.ris.command.VariableBinding;
+
+/**
+ * Processor of rendering commands
+ */
+public interface CommandVisitor {
+
+ void visit(Conditional.Start conditionalStart);
+
+ void visit(Conditional.End conditionalEnd);
+
+ void visit(VariableBinding.Start variableBindingStart);
+
+ void visit(VariableBinding.End variableBindingEnd);
+
+ void visit(VariableBinding.Global globalAssignment);
+
+ void visit(OutVariable outVariable);
+
+ void visit(OutText outText);
+
+ void visit(Loop.Start loopStart);
+
+ void visit(Loop.End loopEnd);
+
+ void visit(BufferControl.Push bufferPush);
+
+ void visit(BufferControl.Pop bufferPop);
+
+ void visit(Procedure.Start startProcedure);
+
+ void visit(Procedure.End endProcedure);
+
+ void visit(Procedure.Call procedureCall);
+}
Added: sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/compiler/api/ris/command/BufferControl.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/compiler/api/ris/command/BufferControl.java?rev=1639641&view=auto
==============================================================================
--- sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/compiler/api/ris/command/BufferControl.java (added)
+++ sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/compiler/api/ris/command/BufferControl.java Fri Nov 14 14:04:56 2014
@@ -0,0 +1,69 @@
+/*******************************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.sling.scripting.sightly.compiler.api.ris.command;
+
+import org.apache.sling.scripting.sightly.compiler.api.ris.Command;
+import org.apache.sling.scripting.sightly.compiler.api.ris.CommandVisitor;
+import org.apache.sling.scripting.sightly.compiler.api.ris.Command;
+import org.apache.sling.scripting.sightly.compiler.api.ris.CommandVisitor;
+
+/**
+ * Commands to control the write buffer
+ */
+public class BufferControl {
+
+ public static final Push PUSH = new Push();
+
+ public static final class Push implements Command {
+ private Push() {
+
+ }
+
+ @Override
+ public void accept(CommandVisitor visitor) {
+ visitor.visit(this);
+ }
+ }
+
+ /**
+ * Pop the current stored buffer into a variable. This command
+ * must effectively be matched by a VariableBinding.End command
+ */
+ public static final class Pop implements Command {
+
+ private String variableName;
+
+ public Pop(String variableName) {
+ this.variableName = variableName;
+ }
+
+ /**
+ * Get the variable that will store the output
+ * @return - a variable name
+ */
+ public String getVariableName() {
+ return variableName;
+ }
+
+ @Override
+ public void accept(CommandVisitor visitor) {
+ visitor.visit(this);
+ }
+ }
+}
Added: sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/compiler/api/ris/command/Conditional.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/compiler/api/ris/command/Conditional.java?rev=1639641&view=auto
==============================================================================
--- sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/compiler/api/ris/command/Conditional.java (added)
+++ sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/compiler/api/ris/command/Conditional.java Fri Nov 14 14:04:56 2014
@@ -0,0 +1,79 @@
+/*******************************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.sling.scripting.sightly.compiler.api.ris.command;
+
+import org.apache.sling.scripting.sightly.compiler.api.ris.Command;
+import org.apache.sling.scripting.sightly.compiler.api.ris.CommandVisitor;
+import org.apache.sling.scripting.sightly.compiler.api.ris.Command;
+import org.apache.sling.scripting.sightly.compiler.api.ris.CommandVisitor;
+
+/**
+ * Imposes a condition on the next rendering commands
+ */
+public class Conditional {
+
+ public static class Start implements Command {
+ private String variable;
+ private boolean expectedTruthValue;
+
+ public Start(String variable, boolean expectedTruthValue) {
+ this.variable = variable;
+ this.expectedTruthValue = expectedTruthValue;
+ }
+
+ @Override
+ public void accept(CommandVisitor visitor) {
+ visitor.visit(this);
+ }
+
+ public String getVariable() {
+ return variable;
+ }
+
+ public boolean getExpectedTruthValue() {
+ return expectedTruthValue;
+ }
+
+ @Override
+ public String toString() {
+ return "Conditional.Start{" +
+ "variable='" + variable + '\'' +
+ ", expectedTruthValue=" + expectedTruthValue +
+ '}';
+ }
+ }
+
+ public static final End END = new End();
+
+ public static final class End implements Command {
+
+ private End() {
+ }
+
+ @Override
+ public void accept(CommandVisitor visitor) {
+ visitor.visit(this);
+ }
+
+ @Override
+ public String toString() {
+ return "Conditional.End{}";
+ }
+ }
+}
Added: sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/compiler/api/ris/command/Loop.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/compiler/api/ris/command/Loop.java?rev=1639641&view=auto
==============================================================================
--- sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/compiler/api/ris/command/Loop.java (added)
+++ sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/compiler/api/ris/command/Loop.java Fri Nov 14 14:04:56 2014
@@ -0,0 +1,88 @@
+/*******************************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.sling.scripting.sightly.compiler.api.ris.command;
+
+import org.apache.sling.scripting.sightly.compiler.api.ris.Command;
+import org.apache.sling.scripting.sightly.compiler.api.ris.CommandVisitor;
+import org.apache.sling.scripting.sightly.compiler.api.ris.Command;
+import org.apache.sling.scripting.sightly.compiler.api.ris.CommandVisitor;
+
+/**
+ * Render a sequence of commands repeatedly. Must have a corresponding end loop later
+ * in the stream
+ */
+public class Loop {
+
+ public static class Start implements Command {
+
+ private String listVariable;
+ private String itemVariable;
+ private String indexVariable;
+
+ public Start(String listVariable, String itemVariable, String indexVariable) {
+ this.listVariable = listVariable;
+ this.itemVariable = itemVariable;
+ this.indexVariable = indexVariable;
+ }
+
+ public String getListVariable() {
+ return listVariable;
+ }
+
+ public String getItemVariable() {
+ return itemVariable;
+ }
+
+ public String getIndexVariable() {
+ return indexVariable;
+ }
+
+ @Override
+ public void accept(CommandVisitor visitor) {
+ visitor.visit(this);
+ }
+
+ @Override
+ public String toString() {
+ return "Loop.Start{" +
+ "listVariable='" + listVariable + '\'' +
+ ", itemVariable='" + itemVariable + '\'' +
+ ", indexVariable='" + indexVariable + '\'' +
+ '}';
+ }
+ }
+
+ public static final End END = new End();
+
+ public static final class End implements Command {
+ private End() {
+ }
+
+ @Override
+ public void accept(CommandVisitor visitor) {
+ visitor.visit(this);
+ }
+
+ @Override
+ public String toString() {
+ return "Loop.End{}";
+ }
+ }
+
+}
Added: sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/compiler/api/ris/command/OutText.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/compiler/api/ris/command/OutText.java?rev=1639641&view=auto
==============================================================================
--- sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/compiler/api/ris/command/OutText.java (added)
+++ sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/compiler/api/ris/command/OutText.java Fri Nov 14 14:04:56 2014
@@ -0,0 +1,52 @@
+/*******************************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.sling.scripting.sightly.compiler.api.ris.command;
+
+import org.apache.sling.scripting.sightly.compiler.api.ris.Command;
+import org.apache.sling.scripting.sightly.compiler.api.ris.CommandVisitor;
+import org.apache.sling.scripting.sightly.compiler.api.ris.Command;
+import org.apache.sling.scripting.sightly.compiler.api.ris.CommandVisitor;
+
+/**
+ * Render a text fragment
+ */
+public class OutText implements Command {
+
+ private String text;
+
+ public OutText(String text) {
+ this.text = text;
+ }
+
+ @Override
+ public void accept(CommandVisitor visitor) {
+ visitor.visit(this);
+ }
+
+ public String getText() {
+ return text;
+ }
+
+ @Override
+ public String toString() {
+ return "OutText{" +
+ "text='" + text + '\'' +
+ '}';
+ }
+}
Added: sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/compiler/api/ris/command/OutVariable.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/compiler/api/ris/command/OutVariable.java?rev=1639641&view=auto
==============================================================================
--- sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/compiler/api/ris/command/OutVariable.java (added)
+++ sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/compiler/api/ris/command/OutVariable.java Fri Nov 14 14:04:56 2014
@@ -0,0 +1,52 @@
+/*******************************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.sling.scripting.sightly.compiler.api.ris.command;
+
+import org.apache.sling.scripting.sightly.compiler.api.ris.Command;
+import org.apache.sling.scripting.sightly.compiler.api.ris.CommandVisitor;
+import org.apache.sling.scripting.sightly.compiler.api.ris.Command;
+import org.apache.sling.scripting.sightly.compiler.api.ris.CommandVisitor;
+
+/**
+ * Render the content of a variable
+ */
+public class OutVariable implements Command {
+
+ private final String variableName;
+
+ public OutVariable(String variableName) {
+ this.variableName = variableName;
+ }
+
+ @Override
+ public void accept(CommandVisitor visitor) {
+ visitor.visit(this);
+ }
+
+ public String getVariableName() {
+ return variableName;
+ }
+
+ @Override
+ public String toString() {
+ return "OutVariable{" +
+ "variableName='" + variableName + '\'' +
+ '}';
+ }
+}