Is there a way to write a rule to identify sentence that have number separated by “,” or “-”
See original GitHub issueHello, I got a couple questions. I read all the doc on the web site and two blogs abut nearley.js and I’m still stuck with, that seem, a simple problem.
I have a rule targeting a sentence with number separated by “,” and a other rule that number are separated by “-”.
But the rule that target “,” take over on the rule that target “-”.
My grammar:
MAIN -> RANGESELECTION
| ACCUMULATIONSELECTION
BUCKET -> [a-zA-Z0-9-]:+ {% function(data) {
return {
value: data.join('').replace(/,/g,"")
};
} %}
ACCUMULATIONSELECTION -> "select " BUCKET:+ "," {%
function(data){
return {type: 'rangeSelection', body: data}
} %}
RANGESELECTION -> "select " (BUCKET "-" BUCKET) {%
function(data){
return {type: 'rangeSelection', body: [data[0],data[2]]}
} %}
The result I would like to have is, when a user enter “select 111-222” the return is a object saying that is a range selection and the 2 values (min, max). And when the sentence is “select a1,a2,a3,a4,a5” the return is a object saying that is a accumulation selection and all the value entered.
thanks in advance for the help
Issue Analytics
- State:
- Created 4 years ago
- Comments:10
Top Results From Across the Web
Rules for Writing Numbers: Know When To Spell Them Out
Spell Numbers That Begin Sentences. Whenever there are numbers at the beginning of a sentence, those numbers should be written out. Sixty children...
Read more >10 Rules for Writing Numbers and Numerals - Daily Writing Tips
5. Don't start a sentence with a numeral. Make it “Fourscore and seven years ago,” not “4 score and 7 years ago.” ...
Read more >Hyphens with Numbers
The number twenty-five is always hyphenated regardless of how it is used in a sentence. You are most likely thinking of the rule...
Read more >Comma Rules | Style and Grammar | Academic Writing
Use commas to separate independent clauses when they are joined by any of these seven coordinating conjunctions: and, but, for, or, nor, so,...
Read more >Run-On Sentences and Sentence Fragments - Grammar
You can correct a run-on sentence by connecting or separating its parts correctly. There are several easy ways to connect independent clauses.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
data
argument for the post-processors is an array. You wantdata[0]
,data[1]
, and so on, as appropriate. Note that since we’re using a lexer, each of them is a lexer object, so you want to calldata[i].value
(ordata[i].text
in some cases, the Moo docs explains the difference) to get the actual value.ACCUMULATION_SELECTION
into an array and return it. Check how the JSON grammar example handles the arrays. The return value should be the gathered array with all the values you’ll need inside them.data[0]
acting as placeholders for every non-terminal that you want to add into the object (keep in mind that within parentheses the object will actually be in something likedata[2][0]
and notdata[2]
). You may want to reorganize the rules to make it easier for you to do this.When you use a lexer, every string you use needs to be declared in the lexer. So if you have a grammar like:
Then in the lexer, you must declare:
It tripped me up the first time too, but if you think about it, it kinda makes sense, since the lexer completely replaces Nearley’s tokenizer, so it has to know them too. This fact is also subtly demonstrated in the JSON grammar example (you’ll notice all the braces and brackets used are declared in the lexer), but can be easy to miss 😃.