Skip to content

Improvement/parser state #131

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,24 @@ public LinkedList<CodeSection> 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();
}

/**
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ public static List<LogEntry> loadScript(Path scriptPath, boolean debug) {
*/
public static List<Statement> loadItems(FileSection section, ParserState parserState, SkriptLogger logger) {
logger.recurse();
parserState.recurseCurrentStatements();
List<Statement> items = new ArrayList<>();
var elements = section.getElements();
for (var element : elements) {
Expand Down Expand Up @@ -120,7 +119,6 @@ public static List<Statement> loadItems(FileSection section, ParserState parserS
items.get(i - 1).setNext(items.get(i));
}
logger.callback();
parserState.callbackCurrentStatements();
return items;
}

Expand Down