pretty printer
il manque \t
This commit is contained in:
@@ -12,6 +12,11 @@ options {
|
||||
|
||||
}
|
||||
|
||||
entite: '<' ID '>';
|
||||
|
||||
|
||||
|
||||
// Whitespaces are ignored.
|
||||
fragment WS: (' ' | '\n' | '\t' | '\r' | '\u000C');
|
||||
WSS: WS+ { skip(); };
|
||||
WSS: WS+ { skip(); };
|
||||
ID: ('a'..'z'|'A'..'Z')('a'..'z'|'A'..'Z'|'0'..'9'|'_')*;
|
||||
55
src/main/java/TP1/ASD_Turtle.java
Normal file
55
src/main/java/TP1/ASD_Turtle.java
Normal file
@@ -0,0 +1,55 @@
|
||||
package TP1;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class ASD_Turtle implements TurtleASD {
|
||||
sealed interface Turtle{}
|
||||
sealed interface Phrase{}
|
||||
sealed interface Affectation{}
|
||||
sealed interface Complement{}
|
||||
sealed interface Entity{}
|
||||
|
||||
record TurtleImp(List<PhraseImp> phrases) implements Turtle{}
|
||||
record PhraseImp(EntityImp entity, List<AffectationImp> affs) implements Phrase{}
|
||||
record AffectationImp(EntityImp entity, List<Complement> complements) implements Affectation{}
|
||||
record Complement_EntityImp(EntityImp entity) implements Complement{}
|
||||
record Complement_TextImp(String string) implements Complement{}
|
||||
record EntityImp(String string) implements Entity{}
|
||||
|
||||
public void prettyPrinter(TurtleImp t){
|
||||
for (PhraseImp phrase : t.phrases) {
|
||||
prettyPrinter(phrase);
|
||||
}
|
||||
}
|
||||
|
||||
public void prettyPrinter(PhraseImp phrase){
|
||||
System.out.println("< " + phrase.entity + " >");
|
||||
for (AffectationImp affectation : phrase.affs) {
|
||||
prettyPrinter(affectation);
|
||||
}
|
||||
System.out.println(".");
|
||||
}
|
||||
public void prettyPrinter(AffectationImp affectation){
|
||||
System.out.println("< " + affectation.entity + " >");
|
||||
for (int i =0; i < affectation.complements.size(); i++) {
|
||||
prettyPrinter(affectation.complements.get(i));
|
||||
if (i < affectation.complements.size() - 1) {
|
||||
System.out.print(", ");
|
||||
}
|
||||
}
|
||||
System.out.println(";");
|
||||
}
|
||||
public void prettyPrinter(Complement complement){
|
||||
if( complement instanceof Complement_EntityImp ce){
|
||||
System.out.println(" < " + ce.entity + " >");
|
||||
} else if ( complement instanceof Complement_TextImp ct){
|
||||
System.out.println(" \" " + ct.string + " \"");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
public void prettyPrint(EntityImp entity) {
|
||||
System.out.print(entity.string);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package TP1;
|
||||
|
||||
interface TurtleAST {
|
||||
interface TurtleASD {
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user