djc / rnc2rng

RELAX NG Compact to regular syntax conversion library
MIT License
16 stars 13 forks source link

rnc2rng failure #3

Open mildred opened 8 years ago

mildred commented 8 years ago

I have the following rnc schema:

namespace xsd = "http://www.w3.org/2001/XMLSchema"

grammar {
    start = element svn {
        # Path to the svn dump file
        attribute dump-file { xsd:string }?,

        # Content of the .SVNAccessFile inline in the XML
        element access-file { xsd:string }?

        # E-mail subscriptions
        & element notification {
            attribute path { xsd:string },
            attribute emails { xsd:string }
        }*
    }
}

Running rnc2rng version 2.0 yields:

Traceback (most recent call last):
  File "/bin/rnc2rng", line 9, in <module>
    load_entry_point('rnc2rng==2.0', 'console_scripts', 'rnc2rng')()
  File "/usr/lib/python3.5/site-packages/rnc2rng/__main__.py", line 9, in main
    xml = serializer.XMLSerializer().toxml(parser.parse(input))
  File "/usr/lib/python3.5/site-packages/rnc2rng/parser.py", line 390, in parse
    return parser.parse(lex(src), state=State())
  File "/usr/lib/python3.5/site-packages/rply/parser.py", line 62, in parse
    self.error_handler(state, lookahead)
  File "/usr/lib/python3.5/site-packages/rnc2rng/parser.py", line 375, in error
    raise Exception(s, t)
Exception: (<rnc2rng.parser.State object at 0x7f78692afa20>, Token('LBRACE', '{'))

I believe my rnc file is correct (but I can't be so sure because I cannot find a converter that would work). If the rnc file is incorrect, I would at least expect a better error message.

djc commented 8 years ago

According to my reading of the spec, this is not a valid grammar. You should probably get rid of the top-level grammar { } wrapper.

Yeah, error messages aren't that great yet.

djc commented 8 years ago

Error messages have been improved in 6682abb3bbc93480d0e1f895bb45be171a8f0f50. Closing.

mthuurne commented 6 years ago

I think the top-level grammar { } is valid: there is a rule that produces it via the pattern nonterminal in section 2 of the spec (second to last entry).

Also "grammar" is in the list of keywords in the spec, but not in rnc2rng's parser.py. Other missing keywords are "external", "inherit" and "token".

I ran into this problem when trying to convert the schemas from the Nu Html Checker, for example this one.

djc commented 6 years ago

Hmm, okay. So I interpreted the "single element" constraint for pattern in topLevelBody as, it should be an element primary, but that interpretation appears to be too narrow.

I've started to extend the grammar to allow it to eventually deal with the SVG spec (that's certainly the largest schema I've thrown at rnc2rng so far!), but it looks like it might take some further work.

djc commented 6 years ago

@mthuurne so current rnc2rng master can parse a lot more of the SVG spec from the validator repo you pointed to (and also the original schema that started this issue). However, it's currently failing when trying to parse svg-extensibility.rnc. As far as I can tell, the use of annotation elements here is invalid per the spec. The spec says that a top-level annotation must always be surrounded by square brackets, and so an annotation element like a:documentation cannot appear at the start of an RNC file like it does here.

Do you disagree with my interpretation of the spec?