How to write nearley grammar without loop?

236 Views Asked by At

I'm trying to use nearley.js to write a parse for ini-like files, with difference that string value may contain special control symbols. For example ^y mean the text after this symbol must be yellow, ^b - blue, &i - italic.

I use nearley playground (http://omrelli.ug/nearley-playground/) and started with very basic grammar for value:

VALUE -> FONT_MODIFIER | COLOR_MODIFIER | TEXT

TEXT -> [^\n\^\&]:+

FONT_MODIFIER -> "&" [iIbBsS]

COLOR_MODIFIER -> "^" [aAbBcCdDfFgGiIkKmMoOpPrRsSwWyYnN]

But after I add test with random text (just letters, like "asdassad") after few seconds it gives me error Possible infinite loop detected! Check your grammar for infinite recursion.

What am I doing wrong? I just can't see where the loop comes from.

0

There are 0 best solutions below