Возможность восстановления состояния при инициализации парсера

This commit is contained in:
Victor 2015-04-23 14:22:13 +03:00
parent aeb74635f9
commit c112dbea7f
2 changed files with 14 additions and 4 deletions

View File

@ -16,8 +16,9 @@ public final class Parser {
private static Parser instance;
public static Parser parse(List<Token> tokens) {
instance = new Parser(tokens);
public static Parser parse(List<Token> tokens, SaveInfo save) {
if (save == null) instance = new Parser(tokens);
else instance = new Parser(tokens, save);
return instance;
}
@ -42,9 +43,18 @@ public final class Parser {
private boolean hasEndMenu, hasEndIf;
public Parser(List<Token> tokens) {
this(tokens, 0);
}
public Parser(List<Token> tokens, SaveInfo info) {
this(tokens, info.getPosition());
Variables.setVariables(info.getVariables());
}
private Parser(List<Token> tokens, int position) {
this.tokens = tokens;
tokensCount = tokens.size();
position = 0;
this.position = position;
labels = new HashMap<String, Integer>();
hasEndMenu = false;
hasEndIf = false;

View File

@ -94,7 +94,7 @@ public final class ViewActivity extends Activity implements TouchGesture.OnTouch
finish();
}
Parser.parse(Lexer.tokenize( IOUtil.readContents(stream) ));
Parser.parse(Lexer.tokenize( IOUtil.readContents(stream) ), save);
Parser.getInstance().next();
stream = null;
} catch (Exception ex) {