T
Trond Michelsen
Hi.
I'm completely new to Parse::RecDescent and parsing in general (I know
my regexes, though). I'm trying to write a parser to read a config-file,
and I've managed to rules for all the relevant parts of the config-file,
and everything seems to work fine. But, there are several parts of the
config-file where the order doesn't (well, shouldn't) matter, and I was
wondering if there is a simple way to tell Parse::RecDescent that the
order of these rules doesn't matter?
Here's an example:
alphanum: /[A-Za-z0-9_]/
word: alphanum(s)
name: 'NAME' word
rank: 'RANK' word
description: 'DESCRIPTION' word
example: name rank description(?)
So, with this grammar, the following would match:
NAME foo
RANK bar
DESCRIPTION baz
but this wouldn't
RANK bar
NAME foo
DESCRIPTION baz
I know I can just expand the rule to include all combinations, like this:
example: name rank description(?) |
name description rank |
rank name description(?) |
rank description name |
description name rank |
description rank name
but this seems silly. Besides, the real grammar is slightly more complex
too, so I'm not sure it's maintainable in the long run.
So, is it possible to tell Parse::RecDescent that a particular group of
rules are allowed in any order, or is there a better way to solve this?
(or should I simply tell my users that order is important, and they'd
better get used to it
I'm completely new to Parse::RecDescent and parsing in general (I know
my regexes, though). I'm trying to write a parser to read a config-file,
and I've managed to rules for all the relevant parts of the config-file,
and everything seems to work fine. But, there are several parts of the
config-file where the order doesn't (well, shouldn't) matter, and I was
wondering if there is a simple way to tell Parse::RecDescent that the
order of these rules doesn't matter?
Here's an example:
alphanum: /[A-Za-z0-9_]/
word: alphanum(s)
name: 'NAME' word
rank: 'RANK' word
description: 'DESCRIPTION' word
example: name rank description(?)
So, with this grammar, the following would match:
NAME foo
RANK bar
DESCRIPTION baz
but this wouldn't
RANK bar
NAME foo
DESCRIPTION baz
I know I can just expand the rule to include all combinations, like this:
example: name rank description(?) |
name description rank |
rank name description(?) |
rank description name |
description name rank |
description rank name
but this seems silly. Besides, the real grammar is slightly more complex
too, so I'm not sure it's maintainable in the long run.
So, is it possible to tell Parse::RecDescent that a particular group of
rules are allowed in any order, or is there a better way to solve this?
(or should I simply tell my users that order is important, and they'd
better get used to it