@@ -23,14 +23,10 @@ public class GCODEHandler {
2323 public static final int LAST_SYNTAX_ERROR = 10 ;
2424 public static final int MISSING_CHAR = 7 ;
2525 //codici di errore semantici aggiunti
26- public static final int ALL_SLOT_LENGTH = 11 ;
27- public static final int TITLE_LENGTH = 12 ;
28- public static final int ARTIST_LENGTH = 13 ;
29- public static final int ALBUM_LENGTH = 14 ;
30- public static final int YEAR_LENGTH = 15 ;
31- public static final int COMMENT_LENGTH = 16 ;
32- //serve per lo stampa slot nel caso leggiamo la grammatica senza header
33- public int conta = 0 ;
26+ public static final int LAST_SEMANTIC_ERROR = 20 ;
27+ //codici di warning
28+ public static final int CIRCLE_NOT_CONNECTING = 21 ;
29+ public static final int LAST_WARNING = 30 ;
3430
3531 List <String > errorList ;
3632 TokenStream lexerStream ;
@@ -64,45 +60,46 @@ void handleError(String[] tokenNames, RecognitionException e, String h, String m
6460 st = st + m ;
6561 else /*if(e.token.getType() == MISSING_CHAR)*/
6662 st += " ('" + e .token .getText () + "')" + m ;
67- errorList .add (st );
63+ errorList .add (st );
64+
65+ }
66+
67+ public void myErrorHandler (int code , String tk ) {
68+ this .myErrorHandler (code , null , tk );
6869 }
70+
6971
7072 // Gestione errori semantici
71- void myErrorHandler (int code , Token tk ) {
73+ private void myErrorHandler (int code , Token tk , String warning ) {
7274 String st ;
7375 if (code == TOKEN_ERROR )
7476 st = "Lexical Error " + code ;
7577 else if (code < LAST_SYNTAX_ERROR ) //è 10
7678 st = "Syntax Error " + code ;
77- else
78- st = "Errore semantico " + code ;
79+ else if (code < LAST_SEMANTIC_ERROR )
80+ st = "Errore semantico " + code ;
81+ else
82+ st = "Warning " + code ;
7983
80- //output in base al'errore semantico
81- switch (code )
82- {
83- case 11 : st =st +" (Data length error)" ; break ;
84- case 12 : st =st +" (TITLE length > 30 char)" ; break ;
85- case 13 : st =st +" (TITLE length < 30 char)" ; break ;
86- case 14 : st =st +" (ARTIST length > 30 char)" ; break ;
87- case 15 : st =st +" (ARTIST length < 30 char)" ; break ;
88- case 16 : st =st +" (ALBUM length > 30 char)" ; break ;
89- case 17 : st =st +" (ALBUM length < 30 char)" ; break ;
90- case 18 : st =st +" (YEAR number of digits > 4)" ; break ;
91- case 19 : st =st +" (YEAR number of digits < 4)" ; break ;
92- case 20 : st =st +" (Wrong YEAR format 1900-CURRENT YEAR)" ; break ;
93- case 21 : st =st +" (COMMENT length > 30 char)" ; break ;
94- case 22 : st =st +" (COMMENT length < 30 char)" ; break ;
84+ //output in base al codice
85+ switch (code ){
86+ case 21 :
87+ if (warning !=null ) st +=": " +warning ;
88+ st +="\n Il disegno potrebbe non essere visualizzato correttamente" ;
89+ default :
90+ break ;
9591 }
9692
9793
9894 if (tk != null )
9995 st += " avvenuto qui: " +tk .getText ()+" @" +tk .getTokenIndex ()+" [" + tk .getLine () + ", " + (tk .getCharPositionInLine ()+1 ) + "]" ;
100- st += ". " ;
96+ st += ".\n " ;
10197
10298 if (code == TOKEN_ERROR )
10399 st += "Unrecognized token '" + tk .getText () + "'" ;
104100
105101 errorList .add (st );
102+ System .out .println (st );
106103 }
107104
108105//utilizzato per creare movimenti e tagli G00 G01
@@ -123,20 +120,23 @@ public String createMovement(Token g, Token x, Token y, Token i, Token j) {
123120 return null ;
124121 }
125122
126-
127- public void addExit (List <String > list , String pd ) {
128- //System.out.println("Movimento-> "+pd);
129- list .add (pd );
130- }
131123
132124 public void addMovement (List <String > list , String pd ) {
133125 //System.out.println("Movimento-> "+pd);
134- list .add (pd );
126+ if ( pd != null ) list .add (pd );
135127 }
136128
137129 public void addMCode (List <String > list , Token temp ) {
138130 //System.out.println("MConfig-> "+temp.getText());
139- list .add (temp .getText ());
131+ if (temp !=null ) list .add (temp .getText ());
132+ }
133+
134+ public void addTokenToStringList (List <String > list , Token temp ) {
135+ if (temp !=null ) list .add (temp .getText ());
136+ }
137+
138+ public void addListToStringList (List <String > list , List <String > list2 ) {
139+ if (list2 !=null ) list .addAll (list2 );
140140 }
141141
142142 public void printConfig (List <String > c )
0 commit comments