[DGD] Parse_string question

Noah Lee Gibbs angelbob at monkeyspeak.com
Mon Feb 11 08:56:43 CET 2002


  I have a parse_string grammar I use to parse structured entries in help
files and so forth.  The stuff that's parsed looks like this:

############################################################

~name{~enUS{%clone, clone, clone object}}
~keywords{admin}
~desc{
  ~enUS{

The %clone command clones an object and puts it into your command
history.  Be careful of causing memory leaks!  The cloned object may
be specified by object name or by history number.

See %history.

}}

############################################################

The curly-braces match up and the thing between the tilde (~) and the
open-curly is the label for the stuff in parens, if it's present.  I use
the following parse_string grammar to parse it:

############################################################

regularstring = /[^~{}\\]*/

unq_document: unq_string

substring: regularstring
substring: regularstring '\\' '{' ? concat_string_char
substring: regularstring '\\' '}' ? concat_string_char
substring: regularstring '\\' '~' ? concat_string_char
substring: regularstring '\\' '\\' ? concat_string_char
substring: substring regularstring ? concat_strings

unq_tag: '{' substring '}' ? anon_tag
unq_tag: '~' regularstring '{' substring '}' ? named_tag
unq_tag: '{' unq_string '}' ? anon_tag
unq_tag: '~' regularstring '{' unq_string '}' ? named_tag

unq_string: substring ? simple_anon_tag
unq_string: unq_tag
unq_string: unq_string substring ? concat_ustring_string
unq_string: unq_string unq_tag

############################################################

The problem is if I have an entry that looks like this:

############################################################

~name{~enUS{%code, code}}
~keywords{admin}
~desc{
  ~enUS{

This command will run a bit of DGD LPC code that you specify and return
a result.  Simple examples include:

%code 3 + 7
%code destruct_object($3)
%code (\{ "bob", "sam" \})

This code will be run from your directory, and thus with your
permissions.  The object itself will be called /usr/you/_code where
"you" is replaced by your username.

}}

############################################################

The problem is in that third example line, the one that says:

%code (\{ "bob", "sam" \})

I have all those ugly backslash-escaping rules.  I carefully use them.  My
grammar cheerfully ignores them and sees the pair of braces as a
subexpression - an "unq_tag" token rather than "substring."  That means 
I've got an ambiguous grammar (sigh).  Anybody know a good way to make it
unambiguous, or convince it that the backslash-escaping rule is higher
priority than the curly-brace-matching?

Come to think of it, I guess I could have two grammars -- one to convert
the forbidden characters somehow and another to parse afterwards.  But is
there an easier way that comes to mind?

-- 
angelbob at monkeyspeak.com
See my page of DGD documentation at
"http://www.angelbob.com/projects/DGD_Page.html"
If you post to the DGD list, you may see yourself there!

_________________________________________________________________
List config page:  http://list.imaginary.com/mailman/listinfo/dgd



More information about the DGD mailing list