2011/1/21 jmillan <doct...@gmail.com>:
> I have not found a way to specify a 'repetition count' for a parsing
> expression. Is it possible?
currently it is not supported directly, you need to repeat expressions
in the grammar manually. I didn't add a special syntax for expressing
repetition since in most grammars it is used very rarely. Do you have
a specific use case in mind?
--
David Majda
Entropy fighter
http://majda.cz/
First of all, thanks for building this tool.
On Sun, Jan 23, 2011 at 11:37 AM, David Majda <da...@majda.cz> wrote:
> Hi,
>
> 2011/1/21 jmillan <doct...@gmail.com>:
>> I have not found a way to specify a 'repetition count' for a parsing
>> expression. Is it possible?
>
> currently it is not supported directly, you need to repeat expressions
> in the grammar manually. I didn't add a special syntax for expressing
> repetition since in most grammars it is used very rarely. Do you have
> a specific use case in mind?
>
This could be a representative example. A case where the grammar
accepts a number of a maximum of 5 digits for a specific rule:
_________
number = number: (DIGIT DIGIT? DIGIT? DIGIT? DIGIT?) { return
number.join("") }
DIGIT = DIGIT: [0-9]
_________
The specific use cases are network port ranges and IPv4 and and IPv6
network addresses.
Anyway, for this cases, expression repetition does the work.
2011/1/23 jose luis millan <doct...@gmail.com>:
> This could be a representative example. A case where the grammar
> accepts a number of a maximum of 5 digits for a specific rule:
> _________
> number = number: (DIGIT DIGIT? DIGIT? DIGIT? DIGIT?) { return
> number.join("") }
>
> DIGIT = DIGIT: [0-9]
> _________
>
> The specific use cases are network port ranges and IPv4 and and IPv6
> network addresses.
Thanks for the use-case.
I still think adding repetition to the grammar syntax is not really
necessary, but if some nice syntax gets invented, I'd probably add it
for convenience.
sorry for a late reply, I am crawling through a big e-mail backlog.
I reconsidered my negative position towards specifying arbitrary
repetition count. I am now trying to decide the syntax. See the
following issue on GitHub where I tried to summarize my thinking:
https://github.com/dmajda/pegjs/issues/30
David
2011/9/25 Jiangbin Zhao <zhaoji...@gmail.com>:
--