- Basic types can now be converted to the "any" type

- Changed OreDict 'contains' to respond to the 'in' operator
This commit is contained in:
Stan Hebben committed 2014-07-20 21:30:40 +02:00
1 parent 52f92dcfd4
commit 1b72abb2b4
59 files changed
+3595 -976

No files matched your search

@@ -20,7 +20,7 @@ public class ParseException extends RuntimeException {
private final String message;
public ParseException(Token token, String error) {
super(token == null ? "Error at end of file - " + error : "Error parsing line " + token.getPosition().getLine() + ":" + token.getPosition().getLineOffset() + " - " + error + " (last token: " + token.getValue() + ")");
super("Error parsing line " + token.getPosition().getLine() + ":" + token.getPosition().getLineOffset() + " - " + error + " (last token: " + token.getValue() + ")");
this.file = token.getPosition().getFile();
this.line = token.getPosition().getLine();
@@ -44,11 +44,11 @@ public class ParseException extends RuntimeException {
}
public int getLine() {
return token == null ? -1 : token.getPosition().getLine();
return line;
}
public int getLineOffset() {
return token == null ? -1 : token.getPosition().getLineOffset();
return lineOffset;
}
public String getExplanation() {
@@ -5,13 +5,17 @@
package stanhebben.zenscript.parser;
import stanhebben.zenscript.ZenParsedFile;
/**
* Thrown when an exception occurs while tokening a character stream.
*
* @author Stan Hebben
*/
public class TokenException extends RuntimeException {
public TokenException(int line, int lineOffset, char value) {
super("Invalid character at " + line + ":" + lineOffset + " - " + value);
public TokenException(ZenParsedFile file, int line, int lineOffset, char value) {
super("Invalid character at " + file + ":" + line + " - " + value);
if (line < 0) throw new IllegalArgumentException("Line cannot be negative");
}
}
@@ -220,15 +220,18 @@ public class TokenStream implements Iterator<Token> {
lineOffset = reader.lineOffset;
nextChar = reader.read();
}
if (line < 0) throw new IllegalStateException("Line cannot be negative");
if (dfa.finals[state] != CompiledDFA.NOFINAL) {
if (state == 0) throw new TokenException(line, lineOffset, (char)nextChar);
if (state == 0) throw new TokenException(file, line, lineOffset, (char)nextChar);
next = process(new Token(value.toString(), dfa.finals[state], new ZenPosition(file, tLine, tLineOffset)));
} else {
if (nextChar < 0 && value.length() == 0) {
return; // happens on comments at the end of files
}
System.out.println("Value: " + value.length() + " characters: " + value);
throw new TokenException(line, lineOffset, (char)nextChar);
//System.out.println("Value: " + value.length() + " characters: " + value);
throw new TokenException(file, line, lineOffset, (char)nextChar);
}
} catch (IOException ex) {
ex.printStackTrace();