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

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; private static Parser instance;
public static Parser parse(List<Token> tokens) { public static Parser parse(List<Token> tokens, SaveInfo save) {
instance = new Parser(tokens); if (save == null) instance = new Parser(tokens);
else instance = new Parser(tokens, save);
return instance; return instance;
} }
@ -42,9 +43,18 @@ public final class Parser {
private boolean hasEndMenu, hasEndIf; private boolean hasEndMenu, hasEndIf;
public Parser(List<Token> tokens) { 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; this.tokens = tokens;
tokensCount = tokens.size(); tokensCount = tokens.size();
position = 0; this.position = position;
labels = new HashMap<String, Integer>(); labels = new HashMap<String, Integer>();
hasEndMenu = false; hasEndMenu = false;
hasEndIf = false; hasEndIf = false;

View File

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