How to implement a list in a vipgrammar?
Posted: 5 Aug 2015 15:55
These are my first steps in using the VIPLALR parser.
As a kind of training I started width the following:
This is a very simplified example of a contact
begin:vcard
N:John
end:vcard
A contact must start with begin:vcard and must end with end:vcard.
In between are one or more contentlines. Like:
begin:vcard
VERSION:3.0
N:John
FN: John Neumann
end:vcard
I made a grammar for reading a contact having one contentline, like the first example. Parsing succeeds. The output from the parser is
The grammar goes as follows:
In order to read the second example with more contentlines a list is needed in the grammar.
How to do that?
I could not find any documentation.
Perhaps the lrparserdomains have something to do with it?.
Kind regards
Ben
As a kind of training I started width the following:
This is a very simplified example of a contact
begin:vcard
N:John
end:vcard
A contact must start with begin:vcard and must end with end:vcard.
In between are one or more contentlines. Like:
begin:vcard
VERSION:3.0
N:John
FN: John Neumann
end:vcard
I made a grammar for reading a contact having one contentline, like the first example. Parsing succeeds. The output from the parser is
Code: Select all
vcard("begin",":","vcard",contentline("N",":","John"),"end",":","vcard")
Code: Select all
grammar vCardgrm
open vCard, vCardgrmSem
nonterminals vcrd : vcard.
rules
vcrd {mkVCard(Begin,Colon,VC,CL,End,Colon1,VC1)}==> [t_prop] {Begin}, [t_colon] {Colon}, [t_prop] {VC},cntl {CL},[t_prop] {End}, [t_colon] {Colon1}, [t_prop] {VC1}.
nonterminals cntl : contentline.
rules
cntl {mkCtl(N,Colon,NV)}==> [t_prop] {N},[t_colon] {Colon}, [t_prop] {NV}.
end grammar vCardgrm
How to do that?
I could not find any documentation.
Perhaps the lrparserdomains have something to do with it?.
Kind regards
Ben