From 55e45320397ee1bb0bb29f82c6a0b74a2a8ebe1e Mon Sep 17 00:00:00 2001 From: Mwexim Date: Wed, 5 Jan 2022 15:46:50 +0100 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20ParserState=20(removed=20unnecessar?= =?UTF-8?q?y=20methods)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../skriptparser/parsing/ParserState.java | 25 ++++++------------- .../skriptparser/parsing/ScriptLoader.java | 2 -- 2 files changed, 7 insertions(+), 20 deletions(-) diff --git a/src/main/java/io/github/syst3ms/skriptparser/parsing/ParserState.java b/src/main/java/io/github/syst3ms/skriptparser/parsing/ParserState.java index 474de99c..ce3173f5 100644 --- a/src/main/java/io/github/syst3ms/skriptparser/parsing/ParserState.java +++ b/src/main/java/io/github/syst3ms/skriptparser/parsing/ParserState.java @@ -48,18 +48,24 @@ public LinkedList getCurrentSections() { } /** - * Adds a new enclosing {@link CodeSection} to the hierarchy + * Adds a new enclosing {@link CodeSection} to the hierarchy. + * Uses recursion to allow the addition of the statements of this new section, + * preserving the current statements to be used when the section is + * {@linkplain #removeCurrentSection() removed} again. * @param section the enclosing {@link CodeSection} */ public void addCurrentSection(CodeSection section) { currentSections.addFirst(section); + currentStatements.addLast(new LinkedList<>()); } /** * Removes the current section from the hierarchy, after all parsing inside it has been completed. + * Also clears all stored statements of this enclosing section. */ public void removeCurrentSection() { currentSections.removeFirst(); + currentStatements.removeLast(); } /** @@ -80,23 +86,6 @@ public void addCurrentStatement(Statement statement) { currentStatements.getLast().add(statement); } - /** - * Uses recursion to allow items of a new enclosing section to be added, preserving - * the current items to be used when the {@linkplain #callbackCurrentStatements() callback} - * has been invoked. - */ - public void recurseCurrentStatements() { - currentStatements.addLast(new LinkedList<>()); - } - - /** - * Clears all stored items of this enclosing section, - * after all parsing inside it has been completed. - */ - public void callbackCurrentStatements() { - currentStatements.removeLast(); - } - /** * Define the syntax restrictions enforced by the current section * @param allowedSyntaxes all allowed syntaxes diff --git a/src/main/java/io/github/syst3ms/skriptparser/parsing/ScriptLoader.java b/src/main/java/io/github/syst3ms/skriptparser/parsing/ScriptLoader.java index 52f4d40f..42938fda 100644 --- a/src/main/java/io/github/syst3ms/skriptparser/parsing/ScriptLoader.java +++ b/src/main/java/io/github/syst3ms/skriptparser/parsing/ScriptLoader.java @@ -90,7 +90,6 @@ public static List loadScript(Path scriptPath, boolean debug) { */ public static List loadItems(FileSection section, ParserState parserState, SkriptLogger logger) { logger.recurse(); - parserState.recurseCurrentStatements(); List items = new ArrayList<>(); var elements = section.getElements(); for (var element : elements) { @@ -120,7 +119,6 @@ public static List loadItems(FileSection section, ParserState parserS items.get(i - 1).setNext(items.get(i)); } logger.callback(); - parserState.callbackCurrentStatements(); return items; }