kach / nearley

📜🔜🌲 Simple, fast, powerful parser toolkit for JavaScript.
https://nearley.js.org
MIT License
3.57k stars 232 forks source link

Number with commas #547

Open jnbbender opened 3 years ago

jnbbender commented 3 years ago

I am using the standard Nearley definition of a Number (see below) but I don't know how Nearley supports ranges. i.e. digits{1,3}

Here's what I'm using for number

number -> 
           digits "." digits {% (data) => Number(data[0] + "." + data[2]) %}
// Trying to figure out digits{1,3} "," digits
       | digits {% (data) => Number(data.join("")) %}

digits ->
         digit {% id %}
       | digit digits {% (data) => data.join("") %}

digit -> [0-9] {% id %}

Thanks