There is an example in Ragel manual 6.5 Semantic conditions, which demonstrates how to write a grammar for variable size structures, using when clause.
action rec_num { i = 0; n = getnumber(); }
action test_len { i++ < n }
data_fields = (
’d’
[0-9]+ %rec_num
’:’
( [a-z] when test_len )*
)**;
It works fine for small structures, however for bigger structures it slows down, because parser tries to evaluate condition on every character.
What I am trying to do is to skip scanning and just copy data into the buffer, for a grammar like this (note any*):
action rec_num { i = 0; n = getnumber(); }
action test_len { i++ < n }
data_fields = (
’d’
[0-9]+ %rec_num
’:’
( any* when test_len )*
)**;
So I want to copy buffer of length n straight away without iteration. How can I do this without leaving parser context?