This commit is contained in:
hneemann 2017-04-19 17:09:57 +02:00
parent 31d8ee0912
commit 871187305c
3 changed files with 10 additions and 12 deletions

View File

@ -10,9 +10,9 @@ public interface LineEmitter {
* Is called to imit the described line to the listener * Is called to imit the described line to the listener
* *
* @param listener the listener to emit the lines * @param listener the listener to emit the lines
* @param conext the context * @param context the context
* @throws ParserException ParserException * @throws ParserException ParserException
*/ */
void emitLines(LineListener listener, Context conext) throws ParserException; void emitLines(LineListener listener, Context context) throws ParserException;
} }

View File

@ -43,7 +43,7 @@ public class Parser {
*/ */
public Parser parse() throws IOException, ParserException { public Parser parse() throws IOException, ParserException {
parseHeader(); parseHeader();
emitter = parseRows(false); emitter = parseRows(null);
expect(Tokenizer.Token.EOF); expect(Tokenizer.Token.EOF);
return this; return this;
} }
@ -69,7 +69,7 @@ public class Parser {
return new ParserException(Lang.get("err_unexpectedToken_N0_inLine_N1", name, tok.getLine())); return new ParserException(Lang.get("err_unexpectedToken_N0_inLine_N1", name, tok.getLine()));
} }
private LineEmitter parseRows(boolean loop) throws IOException, ParserException { private LineEmitter parseRows(Tokenizer.Token endToken) throws IOException, ParserException {
LineEmitterList list = new LineEmitterList(); LineEmitterList list = new LineEmitterList();
while (true) { while (true) {
Tokenizer.Token t = tok.peek(); Tokenizer.Token t = tok.peek();
@ -77,7 +77,7 @@ public class Parser {
case EOL: case EOL:
break; break;
case EOF: case EOF:
if (loop) if (endToken != null)
throw newUnexpectedToken(t); throw newUnexpectedToken(t);
return list.minimize(); return list.minimize();
case BITS: case BITS:
@ -88,9 +88,7 @@ public class Parser {
break; break;
case END: case END:
tok.consume(); tok.consume();
expect(Tokenizer.Token.LOOP); expect(endToken);
if (!loop)
throw newUnexpectedToken(t);
return list.minimize(); return list.minimize();
case REPEAT: case REPEAT:
tok.consume(); tok.consume();
@ -111,7 +109,7 @@ public class Parser {
if (count > 1 << 16) if (count > 1 << 16)
throw new ParserException(Lang.get("err_toManyTestEntries")); throw new ParserException(Lang.get("err_toManyTestEntries"));
expect(Tokenizer.Token.CLOSE); expect(Tokenizer.Token.CLOSE);
list.add(new LineEmitterRepeat(var, count, parseRows(true))); list.add(new LineEmitterRepeat(var, count, parseRows(Tokenizer.Token.LOOP)));
break; break;
default: default:
throw newUnexpectedToken(t); throw newUnexpectedToken(t);
@ -128,7 +126,7 @@ public class Parser {
switch (token) { switch (token) {
case NUMBER: case NUMBER:
Value num = new Value(tok.getIdent()); Value num = new Value(tok.getIdent());
line.add((vals, conext) -> vals.add(num)); line.add((vals, context) -> vals.add(num));
break; break;
case BITS: case BITS:
expect(Tokenizer.Token.OPEN); expect(Tokenizer.Token.OPEN);

View File

@ -24,8 +24,8 @@ public class ValueAppenderBits implements ValueAppender {
} }
@Override @Override
public void appendValues(ArrayList<Value> values, Context conext) throws ParserException { public void appendValues(ArrayList<Value> values, Context context) throws ParserException {
long value = expression.value(conext); long value = expression.value(context);
long mask = 1L << (bitCount - 1); long mask = 1L << (bitCount - 1);
for (int i = 0; i < bitCount; i++) { for (int i = 0; i < bitCount; i++) {
boolean v = (value & mask) != 0; boolean v = (value & mask) != 0;