[ragel-users] Parsing of names with spaces in them

Gerald Gutierrez gerald.gutierrez at gmail.com
Mon Jan 23 07:36:57 UTC 2012


To elaborate a bit on this problem:

I've defined the name as containing only alnum's and spaces, and must
start and end with an alnum.

I've also defined the separator as having a colon (:), possibly
surrounded by spaces.

If I parse "aa bb cc : dd ee ff", the only correct way to parse this
must be for the first name to be "aa bb cc" and the second to be "dd
ee ff". There is no other way to interpret this as the two names must
start and end with a letter.

In other words, the leaving action should be called only once for each
name. But it's not.

Instead, I get this output instead:

Name = aa
Name = aa bb
Name = aa bb cc
Name = dd ee ff

Very confused. Is this a bug or intended behavior?


Gerald.


On Sun, Jan 22, 2012 at 23:11, Gerald Gutierrez
<gerald.gutierrez at gmail.com> wrote:
> Hello folks,
>
> I recently found Ragel and have discovered that it is a very pleasant
> piece of software. That said, I've run into a problem that I was
> hoping is common and a solution available.
>
> Please see the example code at https://gist.github.com/1661150.
>
> Basically, I'd like to parse the following:
>
> name:name
>
> where the names start and end with an alnum, and can contain any
> combination of alnum and spaces inside. They could also be blank. My
> rules for this are:
>
> identifier = alnum (space* alnum)*;
> name       = (identifier | zlen) >sName $pName %fName;
>
> The names can be separated by a colon and optionally spaces inbetween
> the names and the colon. My rules for this are:
>
> sep = space* ":" space*;
> main := name sep name;
>
> This doesn't work because apparently the space* in identifier and the
> space* in sep confuse the parser. I end up getting the action fName
> executed in every space of the name.
>
> If I change sep to:
>
> sep = ":";
>
> then everything is fine. How do I modify these rules so that the
> parser does what I intend?

_______________________________________________
ragel-users mailing list
ragel-users at complang.org
http://www.complang.org/mailman/listinfo/ragel-users


More information about the ragel-users mailing list