To your question: I think you must put the token k_matrix before the
token name in your grammar. Also:
Tokens
// copied from
http://sablecc.sourceforge.net/grammars/ISOC.grammar.html
comment = '//' not_eol* eol;
blank = (cr | lf| tab| ' '|eol)+;
k_matrix = 'matrix';
name = (letter_lower|letter_upper) (letter_lower|letter_upper|numerial)*;
I thought it was problem with Lexer, so
I modified your test class to get out which token is the last token.
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PushbackReader;
import java.io.Reader;
import junit.framework.TestCase;
import compiler.minidsl.lexer.Lexer;
import compiler.minidsl.lexer.LexerException;
import compiler.minidsl.node.Start;
import compiler.minidsl.parser.Parser;
import compiler.minidsl.parser.ParserException;
public class MiniDSLTest extends TestCase {
public void test01Time() throws Exception {
try{
final Start parsedResource = parseResource("test01.minidsl");
}catch(ParserException ex)
{
String mes = "last token:" + ex.getToken().getClass().getName() + "
" + ex.toString();
throw new Exception(mes);
}
}
public Start parseResource(String string) throws ParserException,
LexerException, IOException {
return parseInputStream(getClass().getResourceAsStream(string));
}
public Start parseInputStream(InputStream inputStream) throws
ParserException, LexerException, IOException {
final Reader reader = new InputStreamReader(inputStream);
final PushbackReader pushbackReader = new PushbackReader(reader);
final Lexer lexer = new Lexer(pushbackReader);
final Parser parser = new Parser(lexer);
return parser.parse();
}
}