[jboss-svn-commits] JBL Code SVN: r20042 - labs/jbossrules/branches/parser-rewrite/drools-compiler/src/main/java/org/drools/lang.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Mon May 19 13:39:55 EDT 2008
Author: porcelli
Date: 2008-05-19 13:39:55 -0400 (Mon, 19 May 2008)
New Revision: 20042
Added:
labs/jbossrules/branches/parser-rewrite/drools-compiler/src/main/java/org/drools/lang/DroolsToken.java
labs/jbossrules/branches/parser-rewrite/drools-compiler/src/main/java/org/drools/lang/DroolsTree.java
labs/jbossrules/branches/parser-rewrite/drools-compiler/src/main/java/org/drools/lang/DroolsTreeAdaptor.java
Log:
ANTLR based classes to adress DLR needs:
- Keep offset info
- Add a type info for each Tree (it will be used by editor)
Added: labs/jbossrules/branches/parser-rewrite/drools-compiler/src/main/java/org/drools/lang/DroolsToken.java
===================================================================
--- labs/jbossrules/branches/parser-rewrite/drools-compiler/src/main/java/org/drools/lang/DroolsToken.java (rev 0)
+++ labs/jbossrules/branches/parser-rewrite/drools-compiler/src/main/java/org/drools/lang/DroolsToken.java 2008-05-19 17:39:55 UTC (rev 20042)
@@ -0,0 +1,33 @@
+package org.drools.lang;
+
+import org.antlr.runtime.CharStream;
+import org.antlr.runtime.CommonToken;
+import org.antlr.runtime.Token;
+
+public class DroolsToken extends CommonToken {
+
+ private static final long serialVersionUID = 3635806195731072579L;
+
+ public DroolsToken(int type) {
+ super(type);
+ }
+
+ public DroolsToken(CharStream input, int type, int channel, int start,
+ int stop) {
+ super(input, type, channel, start, stop);
+ }
+
+ public DroolsToken(int type, String text) {
+ super(type, text);
+ }
+
+ public DroolsToken(Token oldToken) {
+ super(oldToken);
+ if (null != oldToken
+ && (oldToken.getClass().equals(CommonToken.class) || oldToken
+ .getClass().equals(DroolsToken.class))) {
+ start = ((CommonToken) oldToken).getStartIndex();
+ stop = ((CommonToken) oldToken).getStopIndex();
+ }
+ }
+}
\ No newline at end of file
Property changes on: labs/jbossrules/branches/parser-rewrite/drools-compiler/src/main/java/org/drools/lang/DroolsToken.java
___________________________________________________________________
Name: svn:eol-style
+ native
Added: labs/jbossrules/branches/parser-rewrite/drools-compiler/src/main/java/org/drools/lang/DroolsTree.java
===================================================================
--- labs/jbossrules/branches/parser-rewrite/drools-compiler/src/main/java/org/drools/lang/DroolsTree.java (rev 0)
+++ labs/jbossrules/branches/parser-rewrite/drools-compiler/src/main/java/org/drools/lang/DroolsTree.java 2008-05-19 17:39:55 UTC (rev 20042)
@@ -0,0 +1,48 @@
+package org.drools.lang;
+
+import org.antlr.runtime.Token;
+import org.antlr.runtime.tree.CommonTree;
+import org.antlr.runtime.tree.Tree;
+
+public class DroolsTree extends CommonTree {
+ int startCharOffset = -1;
+ int endCharOffset = -1;
+ int editorElementType = -1;
+
+ public DroolsTree(DroolsTree node) {
+ super(node);
+ this.token = node.token;
+ }
+
+ public DroolsTree(Token token) {
+ super(token);
+ }
+
+ public Tree dupNode() {
+ return new DroolsTree(this);
+ }
+
+ public int getStartCharOffset() {
+ return startCharOffset;
+ }
+
+ public void setStartCharOffset(int startCharOffset) {
+ this.startCharOffset = startCharOffset;
+ }
+
+ public int getEndCharOffset() {
+ return endCharOffset;
+ }
+
+ public void setEndCharOffset(int endCharOffset) {
+ this.endCharOffset = endCharOffset;
+ }
+
+ public int getEditorElementType() {
+ return editorElementType;
+ }
+
+ public void setEditorElementType(int editorElementType) {
+ this.editorElementType = editorElementType;
+ }
+}
\ No newline at end of file
Property changes on: labs/jbossrules/branches/parser-rewrite/drools-compiler/src/main/java/org/drools/lang/DroolsTree.java
___________________________________________________________________
Name: svn:eol-style
+ native
Added: labs/jbossrules/branches/parser-rewrite/drools-compiler/src/main/java/org/drools/lang/DroolsTreeAdaptor.java
===================================================================
--- labs/jbossrules/branches/parser-rewrite/drools-compiler/src/main/java/org/drools/lang/DroolsTreeAdaptor.java (rev 0)
+++ labs/jbossrules/branches/parser-rewrite/drools-compiler/src/main/java/org/drools/lang/DroolsTreeAdaptor.java 2008-05-19 17:39:55 UTC (rev 20042)
@@ -0,0 +1,64 @@
+package org.drools.lang;
+
+import org.antlr.runtime.CommonToken;
+import org.antlr.runtime.Token;
+import org.antlr.runtime.tree.CommonTreeAdaptor;
+import org.antlr.runtime.tree.Tree;
+
+public class DroolsTreeAdaptor extends CommonTreeAdaptor {
+
+ public Object create(Token token) {
+ DroolsTree tree = new DroolsTree(token);
+ if (null != token
+ && (token.getClass().equals(CommonToken.class) || token
+ .getClass().equals(DroolsToken.class))) {
+ tree.setStartCharOffset(((CommonToken) token).getStartIndex());
+ tree.setEndCharOffset(((CommonToken) token).getStopIndex());
+ }
+ return tree;
+ }
+
+ /**
+ * Add a child to the tree t. If child is a flat tree (a list), make all in
+ * list children of t. Warning: if t has no children, but child does and
+ * child isNil then you can decide it is ok to move children to t via
+ * t.children = child.children; i.e., without copying the array. Just make
+ * sure that this is consistent with have the user will build ASTs.
+ */
+ public void addChild(Object t, Object child) {
+ if (t != null && child != null) {
+ DroolsTree tParent = (DroolsTree) t;
+ DroolsTree tChild = (DroolsTree) child;
+
+ if (0 >= tParent.getStartCharOffset()) {
+ tParent.setStartCharOffset(tChild.getStartCharOffset());
+ tParent.setEndCharOffset(tChild.getEndCharOffset());
+ }
+ if (0 < tParent.getChildCount()) {
+ tParent.setEndCharOffset(tChild.getEndCharOffset());
+ }
+
+ if (DRLLexer.RIGHT_PAREN != tChild.getType()) {
+ ((Tree) t).addChild((Tree) child);
+ }
+ }
+ }
+
+ public Object create(int tokenType, Token fromToken, String text) {
+ if (fromToken instanceof DroolsToken){
+ DroolsTree result = (DroolsTree) super.create(tokenType, fromToken, text);
+ result.setStartCharOffset(((DroolsToken) fromToken).getStartIndex());
+ result.setEndCharOffset(result.getStartCharOffset() + text.length());
+ return result;
+ }
+ return super.create(tokenType, fromToken, text);
+ }
+
+ public Token createToken(int tokenType, String text) {
+ return new DroolsToken(tokenType, text);
+ }
+
+ public Token createToken(Token fromToken) {
+ return new DroolsToken(fromToken);
+ }
+}
\ No newline at end of file
Property changes on: labs/jbossrules/branches/parser-rewrite/drools-compiler/src/main/java/org/drools/lang/DroolsTreeAdaptor.java
___________________________________________________________________
Name: svn:eol-style
+ native
More information about the jboss-svn-commits
mailing list