use of uk.me.parabola.mkgmap.scan.TokenScanner in project mkgmap by openstreetmap.
the class TypTextReader method read.
public void read(String filename, Reader r) {
TokenScanner scanner = new TokenScanner(filename, r);
// the '#' comment character is not appropriate for this file
scanner.setCommentChar(null);
ProcessSection currentSection = null;
while (!scanner.isEndOfFile()) {
Token tok = scanner.nextToken();
if (tok.getType() == TokType.EOF)
break;
// We deal with whole line comments here
if (tok.isValue(";")) {
scanner.skipLine();
continue;
}
if (tok.getType() == TokType.SYMBOL) {
switch(tok.getValue().charAt(0)) {
case ';':
scanner.skipLine();
break;
case '[':
ProcessSection newSection = readSectionType(scanner);
if (currentSection != null)
currentSection.finish(scanner);
currentSection = newSection;
break;
case '"':
scanner.skipLine();
break;
}
} else {
if (currentSection == null)
throw new SyntaxException(scanner, "Missing section start");
// Line inside a section
String name = tok.getValue();
String sep = scanner.nextValue();
if (!sep.equals("=") && !sep.equals(":"))
throw new SyntaxException(scanner, "Expecting '=' or ':' instead of " + sep);
String value = scanner.readLine();
currentSection.processLine(scanner, name, value);
}
scanner.skipSpace();
}
}
use of uk.me.parabola.mkgmap.scan.TokenScanner in project mkgmap by openstreetmap.
the class Options method readOptionFile.
public void readOptionFile(Reader r, String filename) {
BufferedReader br = new BufferedReader(r);
TokenScanner ts = new TokenScanner(filename, br);
ts.setExtraWordChars("-");
File file = new File(filename);
String parent = file.getParent();
while (!ts.isEndOfFile()) {
Token tok = ts.nextToken();
if (tok.isValue("#")) {
ts.skipLine();
continue;
}
String key = tok.getValue();
ts.skipSpace();
tok = ts.peekToken();
if (tok.getType() == TokType.SYMBOL) {
String punc = ts.nextValue();
String val;
if (punc.equals(":") || punc.equals("=")) {
val = ts.readLine();
} else if (punc.equals("{")) {
ts.skipSpace();
val = ts.readUntil(TokType.SYMBOL, "}");
// discard the closing brace
ts.nextToken();
} else {
ts.skipLine();
continue;
}
// location of the argument file.
if (key.equals("input-file") && !new File(val).isAbsolute())
val = new File(parent, val).getPath();
proc.processOption(new Option(key, val));
} else if (key != null) {
proc.processOption(new Option(key, ""));
} else {
ts.skipLine();
}
}
}
use of uk.me.parabola.mkgmap.scan.TokenScanner in project mkgmap by openstreetmap.
the class ExpressionArrangerTest method createOp.
private Op createOp(String s) {
TokenScanner scanner = new TokenScanner("test.file", new StringReader(s));
ExpressionReader er = new ExpressionReader(scanner, FeatureKind.POLYLINE);
return er.readConditions();
}
use of uk.me.parabola.mkgmap.scan.TokenScanner in project mkgmap by openstreetmap.
the class RulesTest method runArrangeTest.
private boolean runArrangeTest(String rule, int id) {
TokenScanner scanner = new TokenScanner("test.file", new StringReader(rule));
ExpressionReader er = new ExpressionReader(scanner, FeatureKind.POLYLINE);
Op op = er.readConditions();
boolean[] orig = evalWays(op);
Op result = arranger.arrange(op);
if (!isSolved(result))
throw new SyntaxException("Could not solve rule expression: best attempt was " + fmtExpr(result));
boolean[] after = evalWays(result);
boolean ok = Arrays.equals(after, orig);
if (ok) {
if (!onlyErrors)
System.out.println("OK: " + rule);
} else {
System.out.println("ERROR: FAILED test: " + rule);
System.out.println(" new expr: " + op);
for (int i = 0; i < orig.length; i++) {
if (orig[i] != after[i]) {
System.out.println(" way " + testWays.get(i) + ", orig=" + orig[i] + ", arranged=" + after[i]);
}
}
checkStopOnFail();
}
return ok;
}
use of uk.me.parabola.mkgmap.scan.TokenScanner in project mkgmap by openstreetmap.
the class StyleImpl method checkVersion.
private void checkVersion() throws FileNotFoundException {
Reader r = fileLoader.open(FILE_VERSION);
TokenScanner scan = new TokenScanner(FILE_VERSION, r);
int version;
try {
version = scan.nextInt();
log.debug("Got version", version);
} catch (NumberFormatException e) {
// default to 0 if no version can be found.
version = 0;
}
if (version > VERSION) {
System.err.println("Warning: unrecognised style version " + version + ", but only versions up to " + VERSION + " are understood");
}
}
Aggregations