Questions tagged [nearley]

nearley.js is a parser toolkit for JavaScript that uses the Earley algorithm. Often used in conjunction with the moo parser.

nearley.js is a parser toolkit for JavaScript that uses the Earley algorithm.

Often used with the following tags:

30 questions
6
votes
1 answer

Nearley grammar recognizes same non-terminal symbol multiple times under certain conditions

Given the following nearley code: @builtin "whitespace.ne" @{% let numberedParams = { 3: 45 }; const lexer = require("moo").compile({ comment: /\(.*?\)/, expstart: /\[/, expend: /\]/, paramstart:…
Lars Juel Jensen
  • 1,643
  • 1
  • 22
  • 31
3
votes
1 answer

(E)BNF How to match until next non-terminal rule?

I'm trying to write a grammar for content in the RIS format with nearley Example of file: TY - JOUR KW - foo KW - bar ER - A *.ris file always starts with the tag TY and ends with the tag ER. In between there can be many other tags like KW…
customcommander
  • 17,580
  • 5
  • 58
  • 84
3
votes
1 answer

How can I write an unambiguous nearley grammar for boolean search operators

The Context I am climbing the Nearley learning curve and trying to write a grammar for a search query parser. The Goal I would like to write grammar that is able to parse a querystring that contains boolean operators (e.g. AND, OR, NOT). Lets use…
slifty
  • 13,062
  • 13
  • 71
  • 109
3
votes
1 answer

Nearley Tokenizers vs Rules

I'm pretty new to nearly.js, and I would like to know what tokenizers/lexers do compared to rules, according to the website: By default, nearley splits the input into a stream of characters. This is called scannerless parsing. A tokenizer splits…
kepe
  • 282
  • 1
  • 18
2
votes
2 answers

Nearley. How to resolve grammar Nearley use JS syntax

Let's say I have some kind of grammar, but it works by itself, but the JS code does not recognize it. Is there such an option so that you can combine the code of your grammar and syntax in one. Let's say I have this grammar (Nearley +…
Tim
  • 17
  • 5
2
votes
1 answer

[Nearley]: how to parse matching opening and closing tag

I'm trying to parse a very simple language with nearley: you can put a string between matching opening and closing tags, and you can chain some tags. It looks like a kind of XML, but with[ instead of < , with tag always 2 chars long, and without…
Molochdaa
  • 2,158
  • 1
  • 17
  • 23
2
votes
2 answers

Grammar - How to match optional and required whitespaces before and after words?

I am using nearley and moo to come up with a rather complex grammar. It seems to be working fine EXCEPT for my whitespace requirements. I need to require whitespace when needed and allow it when not while keeping the grammar unambiguous. For…
jiveturkey
  • 2,484
  • 1
  • 23
  • 41
2
votes
2 answers

Using nested macros in Nearley nests the data result

The problem At first sight, macros can't be properly nested without getting some serious bugs. The main problem is that retrieving a macro's value from the data object nests this value into a list: a[X] -> $X {% id %} main -> a["test"] {% id…
TheMrZZ
  • 188
  • 1
  • 11
1
vote
1 answer

Nearley parser - how to return indefinite string of matches without ambiguity? (Only four lines)

I am writing software meant to make it easy to publish your choose-your-own-adventure story. However, I wanted to change my parser to the Nearley system from JavaScript I wrote myself. I have a four line nearley parser: main->(excludebrackets…
user1833028
  • 865
  • 1
  • 9
  • 18
1
vote
1 answer

How to improve performance of Nearley-based parser

I'm trying to parse SQL INSERT statements like: INSERT INTO `Album` (`Title`, `ArtistId`) VALUES ('Blue Moods', 89); using the following grammar written for Nearley: main -> statement:* statement -> insert_clause values_clause ";" insert_clause…
Rene Saarsoo
  • 13,580
  • 8
  • 57
  • 85
1
vote
2 answers

Nearley at least one

I have a grammar where I want to have some whitespace (including newlines) in between two terms. There should be some whitespace, i.e. it should fail if the two terms are touching, however there can be as much whitespace as desired. The issue I'm…
shmish111
  • 3,697
  • 5
  • 30
  • 52
1
vote
1 answer

Why is my Nearley grammar causing a loop?

I am playing around with nearley.js and something is confusing me. As a test I am trying to build a parser parsing poker ranks. Now, this grammar is working as expected: @{% function nuller() { return null; } %} main -> _ composition _ …
mspoulsen
  • 1,226
  • 1
  • 11
  • 19
1
vote
2 answers

Nearley Moo - Grammar does not work with Moo lexer used

I'm using the nearley.js grammar (and parser) with the moo.js tokeniser. My grammar.ne file is the following: @{% const moo = require('moo') let lexer = moo.compile({ number: /[0-9]+/ }); %} @lexer lexer trig -> "sin"…
TheMrZZ
  • 188
  • 1
  • 11
1
vote
1 answer

Why is nearley-unparse not including tokens in sample strings generated from a compiled Nearley grammar when using Moo as tokenizer/lexer

I'm not sure whether this a problem with the Nearley.js library, the Moo tokenizer/lexer or with my own code. So I might need to submit this as an issue to the Nearley repo. All the referenced files can be found in this Gist. I am attempting to…
Rob Rose
  • 1,806
  • 22
  • 41
0
votes
0 answers

What in this Nearley grammar is causing an infinite loop?

I'm attempting to write a Nearley grammar that will parse a .pbtxt file (a protobuf in textual format). I'm very close but seem to be encountering an infinite loop when tested in the Nearley playground (https://omrelli.ug/nearley-playground/). Can…
ScoPi
  • 1,193
  • 9
  • 14
1
2