El mar, 24-04-2007 a las 04:31 +0900, Brian C.
escribió:> The cleanest way I suspect would be to define a grammar for your own
language, and write a parser for it. I believe there’s a Ruby parser
generator out there.
Then you are not bound by the rules of Ruby syntax at all.
Perhaps I didn’t explain myself clearly… We do have our own parser
and grammar. The thing is that within our language there are “blocks”
of code that are meant to be processed by the Ruby interpreter. At the
risk of being acused of going off topic, let me offer a little example:
<RuleSet person>
<Structure>
<Descriptor has_given_names>
property swv:hasGivenNames
minCardinality 1
maxCardinality 1
outRequirement fromPropRange
</Descriptor>
<Descriptor has_last_names>
property swv:hasLastNames
minCardinality 1
maxCardinality 1
outRequirement fromPropRange
</Descriptor>
<Descriptor has_parent>
property swv:hasParent
minCardinality 2
maxCardinality 2
outRequirement fromPropRange
</Descriptor>
</Structure>
<KRRelationRules>
<KRRelationRule parent_place_of_birth>
has_parent->place_of_birth
</KRRelationRule>
</KRRelationRules>
<BPVFunctions>
<TextBPVFunction full_name_fl>
orderUsing has_last_names
|{ (ROOT->has_given_names).textBPV + " " +
(ROOT->has_last_names).textBPV }|
<Descriptions>
defaultOrderBy has_last_names
VariableDesc default
ShortDesc default
FullDesc default
</Descriptions>
</RuleSet>
(I know, it’s very ugly… In the next version we’ll replace all the
xml-ish tags with angle brackets and make it all much more succinct.)
Anyway, all of this is processed by our own interpreter, including, for
example, the rule
has_parent->place_of_birth
As you can see it’s mainly declarative. However this part
|{ (ROOT->has_given_names).textBPV + " " +
(ROOT->has_last_names).textBPV }|
is read by our interpreter only as a string between a |{ and a }| .
That string is then passed to the Ruby interpreter and is meant to be
run (from within a specific context that our interpreter determines). In
these bits we don’t want just our language running about, of course, we
want full-blown Ruby code with extensions that allow a programmer to
refer to the graph traversal rules using a syntax similar to that used
in the rule definitions that appear outside the Ruby code blocks.
Thanks again for your advice and apologies if this is considered
off-topic.