File tree Expand file tree Collapse file tree 2 files changed +28
-0
lines changed Expand file tree Collapse file tree 2 files changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -97,6 +97,21 @@ private Token nextTokenInternal() {
9797 return ret ;
9898 }
9999
100+ // Parsea una string que comienza por ' o "
101+ if (ultimo_caracter == '\'' || ultimo_caracter == '"' ) {
102+ // Come caracteres hasta que encuentres el cerrador
103+ char iniciador = ultimo_caracter ;
104+ String string = "" ;
105+
106+ while (hasNextChar () && (ultimo_caracter = getChar ()) != iniciador )
107+ string += String .valueOf (ultimo_caracter );
108+
109+ // Comete el cerrador
110+ eatNextChar ();
111+
112+ return new Token (Token .Ids .STRING , string , lex_index );
113+ }
114+
100115 // Parsea una palabra vorazmente
101116 if (Character .isLetter (ultimo_caracter ) || ultimo_caracter == '_' ) {
102117 String identificador = "" ;
Original file line number Diff line number Diff line change @@ -155,4 +155,17 @@ public void TestMenos() {
155155 assertEquals (Token .Ids .NUMERO , token .id );
156156 assertEquals ("65" , token .texto );
157157 }
158+
159+ @ Test
160+ public void TestString () {
161+ Lexer lexer = new Lexer ("'He\" llo \" the\" re!' \" OH'AI \" " );
162+
163+ Token token = lexer .nextToken ();
164+ assertEquals (Token .Ids .STRING , token .id );
165+ assertEquals ("He\" llo \" the\" re!" , token .texto );
166+
167+ token = lexer .nextToken ();
168+ assertEquals (Token .Ids .STRING , token .id );
169+ assertEquals (" OH'AI " , token .texto );
170+ }
158171}
You can’t perform that action at this time.
0 commit comments