Skip to content
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

Fix ParserInteractive.accepts #40

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,6 @@ dmypy.json

# Pyre type checker
.pyre/

# Node
node_modules
9 changes: 4 additions & 5 deletions larkjs/lark.js
Original file line number Diff line number Diff line change
Expand Up @@ -2960,7 +2960,9 @@ class InteractiveParser {
accepts() {
let new_cursor;
let accepts = new Set();
for (const t of this.choices()) {
const choices = this.choices();
for (const key in choices) {
const t = choices[key];
if (isupper(t)) {
// is terminal?
new_cursor = copy(this);
Expand Down Expand Up @@ -3757,10 +3759,7 @@ class Lark extends Serialize {

*/
parse_interactive(text = null, start = null) {
return this.parser.parse_interactive({
unknown_param_0: text,
start: start,
});
return this.parser.parse_interactive(text, start);
}

/**
Expand Down
22 changes: 13 additions & 9 deletions test/test.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
const {TestTrees} = require("./test_trees.js");
const {TestInteractive} = require("./test_interactive.js");

function run_test_class(cls) {
describe(cls.constructor.name, function() {
describe(cls.constructor.name, function() {

let test = new cls();
test.setUp();
let test_names = Object.getOwnPropertyNames(cls.prototype).filter((prop) => prop.startsWith("test_"))
for (const name of test_names) {
it(name, () => {test[name]()})
}
});
let test = new cls();
if (test.setUp) {
test.setUp();
}
let test_names = Object.getOwnPropertyNames(cls.prototype).filter((prop) => prop.startsWith("test_"))
for (const name of test_names) {
it(name, () => {test[name]()})
}
});
}

run_test_class(TestTrees);
run_test_class(TestTrees);
run_test_class(TestInteractive);
52 changes: 52 additions & 0 deletions test/test_interactive.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
const _ = require("lodash");
const lark = require("../larkjs/lark.js");
const assert = require('assert');

const {
InteractiveParser,
} = lark;

//
// Test Interactive
//

class TestCase {
assertOk(a) {
assert(!!a); // assert that the value is truthy
}
}

class TestInteractive extends TestCase {
test_it_parses_interactively() {
const mockParser = {};
const mockParserState = {
position: 30,
parse_conf: {
parse_table: {
states: {
30: {

"ESCAPED_STRING": [
{
"name": "Shift"
},
8
],
"string": [
{
"name": "Shift"
},
7
],
},
}
}
}};
const mockLexerThread = {};
const interactiveParser = new InteractiveParser(mockParser, mockParserState, mockLexerThread);
this.assertOk(interactiveParser.accepts());
}
}

module.exports = { TestInteractive };

Loading