Run-length encoded input?

8 views
Skip to first unread message

maaku

unread,
Apr 6, 2012, 8:36:28 PM4/6/12
to le...@googlegroups.com
Hi, I hope someone can help me with this somewhat newb-ish question. I'm trying to write a parser for a binary syntax that uses run-length encoding. In essence, it looks like the following:

lepl.UnsignedInteger & ~lepl.Literal(':') & lepl.Any()[LENGTH]

Where LENGTH is the result of the matching UnsignedInteger. However I can think of no way to make this value available at that position in the code. Is this possible within LEPL?

Kind regards,
Mark

andrew cooke

unread,
Apr 6, 2012, 8:52:57 PM4/6/12
to le...@googlegroups.com

hmmm.  that's a good question.  unfortunately, i think the answer is no, it's not possible.

it might be possible to hack something up.  i'll have a think and get back to you sometime this weekend.  but there is no simple, direct way of doing this that i can think of (i think there should be - this kind of thing is expected in a python library - but the way that lepl is implemented makes it difficult).

sorry,
andrew

andrew cooke

unread,
Apr 7, 2012, 9:53:04 AM4/7/12
to le...@googlegroups.com

I have a solution for this. It only works in a small number of cases (ie it
works for repetition, but it's not a general fix that makes Lepl more dynamic
everywhere), and I need to release a new minor version of Lepl to support it.
I probably won't have time to do that today (hosting a birthday party!), but
expect to do so tomorrow (Sunday).

Cheers,
Andrew

> --
> You received this message because you are subscribed to the Google Groups "lepl" group.
> To view this discussion on the web visit https://groups.google.com/d/msg/lepl/-/ZOf41mgr9kgJ.
> To post to this group, send email to le...@googlegroups.com.
> To unsubscribe from this group, send email to lepl+uns...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/lepl?hl=en.
>

andrew cooke

unread,
Apr 7, 2012, 2:52:33 PM4/7/12
to le...@googlegroups.com

OK, release 5.1.1 has some minimal support for dynamic values. This won't
work in all cases (in a lot of places Lepl assumes value are fixed and does
optimsations based on that), but it will work in your case - please see the
simple example at
http://code.google.com/p/lepl/source/browse/src/lepl/core/_test/dynamic.py

In particular, note that:

- You need 5.1.1 (or later, I guess).
- You create an IntVar which "picks" up a value returned from a
matcher via Transform(matcher, intVar.setter()).
- You can pass that to Repeat() and it should control the size of the
data.
- You must call .config.no_compile_to_regexp() as part of configuring
the matcher.

This is all very preliminary - let me know how it works.

Cheers,
Andrew

maaku

unread,
Apr 8, 2012, 5:32:20 PM4/8/12
to le...@googlegroups.com
Awesome, thank you Andrew. I'll have to wait until tomorrow to give it a whirl, but from the example it looks like exactly what I need. I'll let you know how it goes.

Cheers,
Mark

> > To unsubscribe from this group, send email to lepl+unsubscribe@googlegroups.com.

maaku

unread,
Apr 9, 2012, 5:34:34 PM4/9/12
to le...@googlegroups.com
Works like a charm, thanks!

In [4]: p.loads('3:abc[7:integer1:\x01]')
Out[4]: ['abc', {0L: 'integer', 1L: '\x01'}]

Mark

andrew cooke

unread,
Apr 9, 2012, 6:39:15 PM4/9/12
to le...@googlegroups.com

Great! (+ thanks for the confirmation). Andrew

> --
> You received this message because you are subscribed to the Google Groups "lepl" group.

> To view this discussion on the web visit https://groups.google.com/d/msg/lepl/-/6gBE3pd5oboJ.


> To post to this group, send email to le...@googlegroups.com.

> To unsubscribe from this group, send email to lepl+uns...@googlegroups.com.

Reply all
Reply to author
Forward
0 new messages