Skip to content

Commit

Permalink
Thread state information into parseError
Browse files Browse the repository at this point in the history
  • Loading branch information
Baltoli committed Oct 11, 2023
1 parent 6181e46 commit b84a314
Showing 1 changed file with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -850,22 +850,22 @@ public Term parse(String input, Source source, int startLine, int startColumn) {
// a parse error after the outer loop finishes also.
if (S.get(k+1).empty() && Q.empty()) {
// no more states to process, so it must be a parse error
parseError(data, k);
parseError(data, S, k);
}
}
if (S.get(data.words.length).empty()) {
parseError(data, data.words.length-1);
parseError(data, S, data.words.length-1);
}
// finished parsing successfully, so return the final parse forest
return Ambiguity.apply(S.get(data.words.length).states.get(0).parseTree().stream().map(list -> list.get(0)).collect(Collectors.toSet()));
}

/**
* @param data The {@link ParserMetadata} about the sentence being parsed
* @param S The set of {@link EarleyState}s for each end-index in the input
* @param k The end-index at which a parse error occurred. In other words, the index just prior to the first token that
* did not parse.
*/
private void parseError(ParserMetadata data, int k) {
private void parseError(ParserMetadata data, EarleySet S, int k) {
int startLine, startColumn, endLine, endColumn;
if (data.words.length == 1) {
startLine = data.lines[0];
Expand Down

0 comments on commit b84a314

Please sign in to comment.