Skip to content

Commit f8bdfb4

Browse files
committed
Fix docs + minor code details
1 parent 1bc719a commit f8bdfb4

File tree

1 file changed

+23
-27
lines changed

1 file changed

+23
-27
lines changed

larkjs/lark.js

Lines changed: 23 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ function intersection(setA, setB) {
202202
}
203203

204204
function set_subtract(a, b) {
205-
return [...a].filter(e => !b.has(e))
205+
return [...a].filter((e) => !b.has(e));
206206
}
207207

208208
function dict(d) {
@@ -401,6 +401,8 @@ class LexError extends LarkError {
401401
*/
402402

403403
class UnexpectedInput extends LarkError {
404+
pos_in_stream = null;
405+
_terminals_by_name = null;
404406
/**
405407
Returns a pretty string pinpointing the error in the text,
406408
with span amount of context characters around it.
@@ -1895,7 +1897,10 @@ class BasicLexer extends Lexer {
18951897
throw new LexError(
18961898
format(
18971899
"Ignore terminals are not defined: %s",
1898-
new Set(conf.ignore) - new Set(terminals.map((t) => t.name))
1900+
set_subtract(
1901+
new Set(conf.ignore),
1902+
new Set(terminals.map((t) => t.name))
1903+
)
18991904
)
19001905
);
19011906
}
@@ -3006,12 +3011,7 @@ class InteractiveParser {
30063011
*/
30073012

30083013
class ImmutableInteractiveParser extends InteractiveParser {
3009-
static get result() {
3010-
return null;
3011-
}
3012-
get result() {
3013-
return this.constructor.result;
3014-
}
3014+
result = null;
30153015
feed_token(token) {
30163016
let c = copy(this);
30173017
c.result = InteractiveParser.feed_token(c, token);
@@ -3386,6 +3386,7 @@ class PostLex extends ABC {
33863386
return stream;
33873387
}
33883388

3389+
always_accept = [];
33893390
}
33903391

33913392
/**
@@ -3395,38 +3396,37 @@ class PostLex extends ABC {
33953396
*/
33963397

33973398
class LarkOptions extends Serialize {
3398-
static get OPTIONS_DOC() {
3399-
return `
3399+
OPTIONS_DOC = `
34003400
**=== General Options ===**
34013401
34023402
start
34033403
The start symbol. Either a string, or a list of strings for multiple possible starts (Default: "start")
34043404
debug
3405-
Display debug information and extra warnings. Use only when debugging (Default: ````False````)
3405+
Display debug information and extra warnings. Use only when debugging (Default: \`\`False\`\`)
34063406
When used with Earley, it generates a forest graph as "sppf.png", if 'dot' is installed.
34073407
transformer
34083408
Applies the transformer to every parse tree (equivalent to applying it after the parse, but faster)
34093409
propagate_positions
34103410
Propagates (line, column, end_line, end_column) attributes into all tree branches.
3411-
Accepts ````False````, ````True````, or a callable, which will filter which nodes to ignore when propagating.
3411+
Accepts \`\`False\`\`, \`\`True\`\`, or a callable, which will filter which nodes to ignore when propagating.
34123412
maybe_placeholders
3413-
When ````True````, the ````[]```` operator returns ````None```` when not matched.
3414-
When ````False````, ````[]```` behaves like the ````?```` operator, and returns no value at all.
3415-
(default= ````True````)
3413+
When \`\`True\`\`, the \`\`[]\`\` operator returns \`\`None\`\` when not matched.
3414+
When \`\`False\`\`, \`\`[]\`\` behaves like the \`\`?\`\` operator, and returns no value at all.
3415+
(default= \`\`True\`\`)
34163416
cache
34173417
Cache the results of the Lark grammar analysis, for x2 to x3 faster loading. LALR only for now.
34183418
3419-
- When ````False````, does nothing (default)
3420-
- When ````True````, caches to a temporary file in the local directory
3419+
- When \`\`False\`\`, does nothing (default)
3420+
- When \`\`True\`\`, caches to a temporary file in the local directory
34213421
- When given a string, caches to the path pointed by the string
34223422
regex
3423-
When True, uses the ````regex```` module instead of the stdlib ````re````.
3423+
When True, uses the \`\`regex\`\` module instead of the stdlib \`\`re\`\`.
34243424
g_regex_flags
34253425
Flags that are applied to all terminals (both regex and strings)
34263426
keep_all_tokens
3427-
Prevent the tree builder from automagically removing "punctuation" tokens (Default: ````False````)
3427+
Prevent the tree builder from automagically removing "punctuation" tokens (Default: \`\`False\`\`)
34283428
tree_class
3429-
Lark will produce trees comprised of instances of this class instead of the default ````lark.Tree````.
3429+
Lark will produce trees comprised of instances of this class instead of the default \`\`lark.Tree\`\`.
34303430
34313431
**=== Algorithm Options ===**
34323432
@@ -3452,13 +3452,13 @@ class LarkOptions extends Serialize {
34523452
**=== Misc. / Domain Specific Options ===**
34533453
34543454
postlex
3455-
Lexer post-processing (Default: ````None````) Only works with the basic and contextual lexers.
3455+
Lexer post-processing (Default: \`\`None\`\`) Only works with the basic and contextual lexers.
34563456
priority
3457-
How priorities should be evaluated - "auto", ````None````, "normal", "invert" (Default: "auto")
3457+
How priorities should be evaluated - "auto", \`\`None\`\`, "normal", "invert" (Default: "auto")
34583458
lexer_callbacks
34593459
Dictionary of callbacks for the lexer. May alter tokens during lexing. Use with caution.
34603460
use_bytes
3461-
Accept an input of type ````bytes```` instead of ````str````.
3461+
Accept an input of type \`\`bytes\`\` instead of \`\`str\`\`.
34623462
edit_terminals
34633463
A callback for editing the terminals before parse.
34643464
import_paths
@@ -3467,10 +3467,6 @@ class LarkOptions extends Serialize {
34673467
Override the source of from where the grammar was loaded. Useful for relative imports and unconventional grammar loading
34683468
**=== End of Options ===**
34693469
`;
3470-
}
3471-
get OPTIONS_DOC() {
3472-
return this.constructor.OPTIONS_DOC;
3473-
}
34743470
// Adding a new option needs to be done in multiple places:
34753471
// - In the dictionary below. This is the primary truth of which options `Lark.__init__` accepts
34763472
// - In the docstring above. It is used both for the docstring of `LarkOptions` and `Lark`, and in readthedocs

0 commit comments

Comments
 (0)