>From my quick glance at this, I'm impressed -- I didn't think it was even
possible to get close to using a xBNF based parser for ABC given the various
ambiguities and weirdnesses in the different versions of the specs.
Resolving most of these in the preprocessor is a nice way to avoid many of
those problems...

A couple of specific comments of things you should watch out for, based on
areas I had specific problems with when doing my own parser:

- The H: field is basically a way to associate an arbitrary text block with
a tune -- I'd treat comments and even %% fields as part of it, along with
any : fields which follow a continuation.

- I'm not sure if the \% sequence to get a percent sign in the text is
valid, since that would also be a valid way to continue a line.  (See the
example in section 2.2 of the 2.0 spec -- a comment may follow a
continuation.  And there's no place which says that the space in that
example needs to be there...)

You can accomplish the same thing by using "\d37" (See section 8.2),
although it would be nice to extend the spec to have something more visually
obvious.

- The Key field in the current 2.0 spec (section 3.1.14) also allows for a
key of "none", which I don't think you covered in your .def file.  And the
clef allows for a clef of "none" as well.  Since a Key field can contain
just a clef (and no key signature), this is a conflict, and I've suggested
changing the spec to require "clef=none" to specify no clef, and "none" by
itself will mean no key signature.

- Clef and Voice specifications in the 2.0 spec (end of section 6) allow for
space delimited program-specific specifiers in the form:
<specifiername>=<specifiervalue>  I don't think that's covered in your .def.

- Also, the spec allows for additional arbitrary clef names in addition to
the ones mentioned in the spec itself.  And thus by extension there may be
other single-word specifiers in voice fields as well.  You got all of those
I'm aware of, but missed some clefs used by abctab2ps.

-->Steve Bennett


Tom Satter wrote:

> Atwood, Robert C said:
> ... (snobal text removed) ...
>> 
>> Any thoughts on using a tool like lex/yacc / flex/bison for parser
>> generation?
> 
> 
> For the parser that I am working on, I am using Python.  I
> have the complete parser working now, using simpleparse, which
> uses an EBNF description as its input.  I am currently working
> on the API and filling in the data structures from the
> callbacks.  The basic structure of my parser is this:
> 
> A) Run a preprocessor that does the following:
>  1) Determine if I am looking at pre-2.0 ABC or not.
>  2) Remove line continuations (doing it correctly depending
>     on the ABC version)
>  3) Remove all % style comments (not %% directives) and store
>     them for later use (if needed).
>  4) In pre-2.0 ABC files, if ! is used as a decoration marker
>     (!ff!), then change it to 2.0 syntax: +ff+.
>  5) If an H: field is found in the header, then any lines that
>     follow it that do not start with '%%' or have ':' as the
>     second character will be changed to have 'H: ' before them.
>     (I believe that this is a problem in the 2.0 specification,
>     which says that the H: is a multiline header - it is
>     a royal pain to do this nicely in the BNF, do I handle
>     it here).
>   6) The %% syntax is irrelevant with the new I: format.  As
>      such, the %% syntax is removed and replaced with I: format.
> B) Use an EBNF description to completely parse the file.  I am
>  using an EBNF that I wrote that is based on the ABC 2.0 ABNF
>  written by Henrik Norbeck.  I added a couple of things to the
>  EBNF to allow parsing older ABC files and corrected a number
>  of mistakes and places where the grammar was ambiguous.
> C) The parser calls callbacks in python which I use to populate
>  the data structures.  I am still working on the data structures
>  that I use.
> 
> So far, I have been able to parse all of the ABC files in my
> small test suite (about 10 ABC files, including a couple of
> very large files).
> 
> You can find the code as it stands right now at:
> 
> http://www.purecode.com/~tsatter/python/
> 
> tom

To subscribe/unsubscribe, point your browser to: http://www.tullochgorm.com/lists.html

Reply via email to