use of uk.me.parabola.mkgmap.scan.Token in project mkgmap by openstreetmap.
the class RuleFileReader method readFinalize.
private boolean readFinalize(TokenScanner scanner) {
Token token = scanner.nextToken();
if (scanner.checkToken("finalize")) {
Token finalizeToken = scanner.nextToken();
if (scanner.checkToken(">")) {
if (inFinalizeSection) {
// there are two finalize sections which is not allowed
throw new SyntaxException(scanner, "There is only one finalize section allowed");
} else {
// consume the > token
scanner.nextToken();
// mark start of the finalize block
inFinalizeSection = true;
finalizeRules = new RuleSet();
return true;
}
} else {
scanner.pushToken(finalizeToken);
scanner.pushToken(token);
}
} else {
scanner.pushToken(token);
}
return false;
}
use of uk.me.parabola.mkgmap.scan.Token in project mkgmap by openstreetmap.
the class RuleFileReader method readElse.
private boolean readElse(TokenScanner scanner) {
Token tok = scanner.nextToken();
scanner.skipSpace();
Token next = scanner.peekToken();
if (next.getType() == TokType.SYMBOL && !next.isValue("(") && !next.isValue("!")) {
scanner.pushToken(tok);
return false;
}
Op[] ifExpressions = ifStack.removeLast();
for (int i = 0; i < ifExpressions.length; i++) {
Op op = ifExpressions[i];
NotOp not = new NotOp();
not.setFirst(op);
ifExpressions[i] = not;
}
ifStack.addLast(ifExpressions);
return true;
}
use of uk.me.parabola.mkgmap.scan.Token in project mkgmap by openstreetmap.
the class SrtTextReader method read.
/**
* Read in a file and save the information in a form that can be used
* to compare strings.
* @param filename The name of the file, used for display purposes. It need
* not refer to a file that actually exists.
* @param r The opened file or other readable source.
* @throws SyntaxException If the format of the file is incorrect.
*/
public void read(String filename, Reader r) {
TokenScanner scanner = new TokenScanner(filename, r);
resetPos();
state = IN_INITIAL;
while (!scanner.isEndOfFile()) {
Token tok = scanner.nextToken();
// We deal with whole line comments here
if (tok.isValue("#")) {
scanner.skipLine();
continue;
}
switch(state) {
case IN_INITIAL:
initialState(scanner, tok);
break;
case IN_CHARACTER:
characterState(scanner, tok);
break;
case IN_EXPAND:
expandState(scanner, tok);
break;
}
}
sort.setExpansions(expansions);
sort.finish();
}
use of uk.me.parabola.mkgmap.scan.Token in project mkgmap by openstreetmap.
the class CommonSection method readExtraColourInfo.
/**
* Get any keywords that are on the end of the colour line. Must not step
* over the new line boundary.
*/
private void readExtraColourInfo(TokenScanner scanner, AlphaAdder colour) {
while (!scanner.isEndOfFile()) {
Token tok = scanner.nextRawToken();
if (tok.isEol())
break;
String word = tok.getValue();
// TypWiz uses alpha, TypViewer uses "canalalpha"
if (word.endsWith("alpha")) {
scanner.validateNext("=");
String aval = scanner.nextValue();
try {
// Convert to rgba format
int alpha = Integer.decode(aval);
alpha = 255 - ((alpha << 4) + alpha);
colour.addAlpha(alpha);
} catch (NumberFormatException e) {
throw new SyntaxException(scanner, "Bad number for alpha value " + aval);
}
}
// ignore everything we don't recognise.
}
}
use of uk.me.parabola.mkgmap.scan.Token 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();
}
}
Aggregations