Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Implement toString() for SGrammar.

Signed-off-by: Jerome Dassonville <dassonville.jerome@gmail.com>
  • Loading branch information...
commit 158132519dadf344b4b9a0f720ee520a0ecb7253 1 parent c035e6d
Jerome authored
12 src/org/sablecc/sablecc/grammar/Alternative.java
View
@@ -197,4 +197,16 @@ private void buildInlinedAlternative(
}
}
+ @Override
+ public String toString() {
+
+ String alternativeText = "";
+
+ for (Element element : this.elements) {
+ alternativeText += element.toString() + " ";
+ }
+
+ return alternativeText;
+ }
+
}
28 src/org/sablecc/sablecc/grammar/Element.java
View
@@ -112,6 +112,20 @@ public Element clone() {
return new TokenElement(this.name, this.typeName);
}
+
+ @Override
+ public String toString() {
+
+ String text = "";
+
+ if (this.name != null && this.name != "") {
+ text += "[" + this.name + ":]";
+ }
+
+ text += this.typeName;
+
+ return text;
+ }
}
public static class ProductionElement
@@ -185,6 +199,20 @@ public Element clone() {
return new ProductionElement(this.typeName, this.reference);
}
+
+ @Override
+ public String toString() {
+
+ String text = "";
+
+ if (this.name != null && this.name != "") {
+ text += "[" + this.name + ":]";
+ }
+
+ text += this.typeName;
+
+ return text;
+ }
}
}
18 src/org/sablecc/sablecc/grammar/Production.java
View
@@ -179,7 +179,23 @@ public boolean equals(
@Override
public String toString() {
- return this.name;
+ String productionText = getName() + " = " + "\r\n";
+
+ if (this.alternatives.size() > 1) {
+ for (Alternative alternative : this.alternatives.subList(0,
+ this.alternatives.size() - 1)) {
+
+ productionText += "\t " + alternative.toString() + " | \r\n";
+ }
+ }
+
+ if (this.alternatives.size() > 0) {
+ productionText += this.alternatives.get(
+ this.alternatives.size() - 1).toString()
+ + ";";
+ }
+
+ return productionText;
}
}
21 src/org/sablecc/sablecc/grammar/SGrammar.java
View
@@ -173,4 +173,25 @@ public BigInteger getNextProductionId() {
this.nextProductionId = this.nextProductionId.add(BigInteger.ONE);
return productionId;
}
+
+ @Override
+ public String toString() {
+
+ String parserPart = "Parser \r\n";
+ String productionTransformationPart = "Transformation \r\n Production \r\n ";
+ String alternativeTransformationPart = "Alternatives \r\n";
+
+ for (Production production : this.productions.values()) {
+ parserPart += production.toString() + "\r\n";
+ productionTransformationPart += production.getTransformation()
+ .toString() + "\r\n";
+ for (Alternative alternative : production.getAlternatives()) {
+ alternativeTransformationPart += alternative
+ .getTransformation().toString() + "\r\n";
+ }
+ }
+
+ return parserPart + productionTransformationPart
+ + alternativeTransformationPart;
+ }
}
28 src/org/sablecc/sablecc/grammar/transformation/SAlternativeTransformation.java
View
@@ -25,7 +25,7 @@
public class SAlternativeTransformation {
- private Alternative alternative;
+ private final Alternative alternative;
private List<SAlternativeTransformationElement> elements = new LinkedList<SAlternativeTransformationElement>();
@@ -57,6 +57,8 @@ public SAlternativeTransformation(
throw new InternalException("element shouldn't be null");
}
+ this.alternative = alternative;
+
this.elements
.add(new SAlternativeTransformationElement.ReferenceElement(
element));
@@ -74,6 +76,8 @@ public SAlternativeTransformation(
throw new InternalException("elements shouldn't be null");
}
+ this.alternative = alternative;
+
for (Element element : elements) {
this.elements
.add(new SAlternativeTransformationElement.ReferenceElement(
@@ -93,6 +97,9 @@ public SAlternativeTransformation(
if (elements == null) {
throw new InternalException("elements shouldn't be null");
}
+
+ this.alternative = alternative;
+
this.elements.add(new SAlternativeTransformationElement.ListElement(
elements, type));
@@ -105,6 +112,8 @@ public SAlternativeTransformation(
throw new InternalException("alternative shouldn't be null");
}
+ this.alternative = alternative;
+
this.elements.add(new SAlternativeTransformationElement.NullElement());
}
@@ -132,4 +141,21 @@ public SAlternativeTransformation buildInlinedTransformation(
return new SAlternativeTransformation(inlinedAlternative,
newAlternativeTransformationElements);
}
+
+ @Override
+ public String toString() {
+
+ String transformationText = this.alternative.getProduction().getName()
+ + "."
+ + this.alternative.getProduction().getAlternatives()
+ .indexOf(this.alternative) + " -> ";
+
+ for (SAlternativeTransformationElement element : this.elements) {
+ transformationText += element.toString() + " ";
+ }
+
+ transformationText += ";";
+
+ return transformationText;
+ }
}
52 src/org/sablecc/sablecc/grammar/transformation/SAlternativeTransformationElement.java
View
@@ -68,6 +68,12 @@ public void apply(
}
+ @Override
+ public String toString() {
+
+ return "null";
+ }
+
}
public static class ReferenceElement
@@ -139,6 +145,12 @@ public void apply(
}
+ @Override
+ public String toString() {
+
+ return this.reference.toString();
+ }
+
}
public static class NewElement
@@ -258,6 +270,34 @@ public void apply(
visitor.visitNewElement(this);
}
+
+ @Override
+ public String toString() {
+
+ String newText = "New ";
+
+ if (this.alternative instanceof Tree.TreeAlternative) {
+ newText += ((Tree.TreeAlternative) this.alternative)
+ .getProduction().getName()
+ + ((Tree.TreeAlternative) this.alternative).getName();
+ }
+ else {
+ newText += ((Parser.ParserAlternative) this.alternative)
+ .getProduction().getName()
+ + ((Parser.ParserAlternative) this.alternative)
+ .getName();
+
+ }
+
+ newText += "(";
+ for (SAlternativeTransformationElement element : this.elements) {
+ newText += element.toString();
+ }
+
+ newText += ")";
+
+ return newText;
+ }
}
public static class ListElement
@@ -328,6 +368,18 @@ public void apply(
}
+ @Override
+ public String toString() {
+
+ String listText = "List(";
+
+ for (SAlternativeTransformationListElement element : this.elements) {
+ listText += element.toString() + " ";
+ }
+ listText += ")";
+ return listText;
+ }
+
}
}
53 src/org/sablecc/sablecc/grammar/transformation/SAlternativeTransformationListElement.java
View
@@ -20,6 +20,7 @@
import java.util.*;
import org.sablecc.exception.*;
+import org.sablecc.sablecc.core.*;
import org.sablecc.sablecc.core.interfaces.*;
import org.sablecc.sablecc.grammar.*;
import org.sablecc.sablecc.grammar.interfaces.*;
@@ -125,6 +126,12 @@ public void apply(
}
+ @Override
+ public String toString() {
+
+ return this.reference.toString();
+ }
+
}
public static class NewElement
@@ -201,6 +208,34 @@ public void apply(
}
+ @Override
+ public String toString() {
+
+ String newText = "New ";
+
+ if (this.alternative instanceof Tree.TreeAlternative) {
+ newText += ((Tree.TreeAlternative) this.alternative)
+ .getProduction().getName()
+ + ((Tree.TreeAlternative) this.alternative).getName();
+ }
+ else {
+ newText += ((Parser.ParserAlternative) this.alternative)
+ .getProduction().getName()
+ + ((Parser.ParserAlternative) this.alternative)
+ .getName();
+
+ }
+
+ newText += "(";
+ for (SAlternativeTransformationElement element : this.elements) {
+ newText += element.toString();
+ }
+
+ newText += ")";
+
+ return newText;
+ }
+
}
public static class NormalListElement
@@ -293,6 +328,12 @@ public void apply(
}
+ @Override
+ public String toString() {
+
+ return this.reference.toString() + "...";
+ }
+
}
public static class LeftListElement
@@ -385,6 +426,12 @@ public void apply(
}
+ @Override
+ public String toString() {
+
+ return this.reference.toString() + ".Left";
+ }
+
}
public static class RightListElement
@@ -477,6 +524,12 @@ public void apply(
}
+ @Override
+ public String toString() {
+
+ return this.reference.toString() + ".Right";
+ }
+
}
}
12 src/org/sablecc/sablecc/grammar/transformation/SProductionTransformation.java
View
@@ -161,4 +161,16 @@ private void generateElements(
}
+ @Override
+ public String toString() {
+
+ String transformationText = this.production.getName() + " -> ";
+
+ for (SProductionTransformationElement element : this.elements) {
+ transformationText += element.toString() + " ";
+ }
+
+ return transformationText;
+ }
+
}
18 src/org/sablecc/sablecc/grammar/transformation/SProductionTransformationElement.java
View
@@ -124,6 +124,12 @@ public int getIndex() {
return getProductionTransformation().getElements().indexOf(this);
}
+
+ @Override
+ public String toString() {
+
+ return this.name;
+ }
}
public static class SeparatedElement
@@ -236,6 +242,12 @@ public int getIndex() {
return getProductionTransformation().getElements().indexOf(this);
}
+
+ @Override
+ public String toString() {
+
+ return "(" + this.leftName + " Separated " + this.rightName + ")";
+ }
}
public static class AlternatedElement
@@ -349,6 +361,12 @@ public int getIndex() {
return getProductionTransformation().getElements().indexOf(this);
}
+ @Override
+ public String toString() {
+
+ return "(" + this.leftName + " " + this.rightName + ")";
+ }
+
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.