Knotty Problems (& LDML)

[email protected] ("Philip Coombes")
Newsgroups perl.recdescent
Message-ID <[email protected]>
Hi all,

I've a couple of particularly knotty problems with a particular parsing
exercise I'm trying to do at the moment.

Basically I'm doing a convertor from LDML (Mac style markup) and FileMaker
Pro to php/mysql.

I've run across three particular problems.

1. LDML contructs are (usually) delimited by [] paris except when they are
nested within each other when they become nested by () pairs. Since my rules
specify the delimiters I'd like to be able to reject [] when nested inside
[] and reject () constructs when not nested. Other than that the rest of the
syntax is the same. Currently I'm relying on the source being syntactically
correct and looking for either type of delimeter but I don't want to have to
rely on it. So how can I tell when I'm already within a nested construct and
signal that to subrules whilst also ensuring that it gets reset back again
after. At the moment my rules are all of the form either
    rule: DEL_OPEN 'tag' ':' <stuff> DEL_CLOSE
or for rules that can enclose other stuff and require an equivalent closing
tag
    rule: DEL_OPEN 'tag' ':' <stuff> DEL_CLOSE <other_stuff> DEL_OPEN
"/$item[2]" DEL_CLOSE

2. Additionally some LDML constructs may start with a '-', but I'm having a
problem coming up a generic approach that looks for either the '[]' pair
constructs, or the '-' initiated constructs and parses those whilst
squirting out everything else unchanged. So basically the grammar parses,
syntax checks and converts all valid LDML whilst emitting the remainder
unchanged. I've got a real kludge fix at the moment but it's pretty ugly and
I'd like to get an 'approved' way of doing this. Particularly tricky is when
it swallows the beginning of something starting with '[' or '-' which isn't
LDML and getting it to reject it as an LDML match while still emitting it.
Especially in syntactic elements which require a '[/.+]' closure (see
above).

3. Finally (sighs of relief all round) I've got particularly nasty construct
which is of the form,

rule: DEL_OPEN tag ':' tag1 ',' tag2 ',' ( tag3 ',' )(?) ( tag4 ',' )(?) (
assignment ',' )(s?) tag5 DEL_CLOSE

assignment: value '=' value

It's the part around the optional list of assignments which is the problem,
as all I get back in $item is a list of commas and no values. Is there a way
to tell it to ignore the ','s kind of like in a leftop? I've tried using
<leftop: assignment /,/ assignment>(?) ',' instead but that totally barfs
and fails to match the rule. The assignments may be a list of a=b type
things (though can involve expressions etc) or may not be there at all.

Any and all help appreciated. If I never see another piece of LDMl it will
be too soon, so just me in my quest to rid the world of it! Please!

Cheers,

Phil,
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.