djc / rnc2rng

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

Can't use reserved word as element or attribute name #9

Closed dargueta-work closed 7 years ago

dargueta-work commented 7 years ago

In the specification for Compact RELAX NG it says that:

It is not necessary to quote a keyword that is used as the name of an element or attribute or as datatype parameter.

Unfortunately it doesn't seem to work here. Minimal example:

element string { text } # comment

Running the test suite gets us this stack trace:

Traceback (most recent call last):
  File "test.py", line 23, in runTest
    root = rnc2rng.load(f)
  File "/Users/dargueta/git/rnc2rng/rnc2rng/__init__.py", line 4, in load
    return parser.parse(f=f)
  File "/Users/dargueta/git/rnc2rng/rnc2rng/parser.py", line 529, in parse
    return parser.parse(lex(src), state=State(fn, src))
  File "/Users/dargueta/.pyenv/versions/rnc2rng_35/lib/python3.5/site-packages/rply/parser.py", line 62, in parse
    self.error_handler(state, lookahead)
  File "/Users/dargueta/git/rnc2rng/rnc2rng/parser.py", line 504, in error
    raise ParseError(t, s.fn, ln, col, line)
rnc2rng.parser.ParseError: in tests/simple-escape.rnc [1:9]
element string { text } # comment
        ^

Same thing for attributes:

element test { attribute string { text } }

gives us:

Traceback (most recent call last):
  File "test.py", line 23, in runTest
    root = rnc2rng.load(f)
  File "/Users/dargueta/git/rnc2rng/rnc2rng/__init__.py", line 4, in load
    return parser.parse(f=f)
  File "/Users/dargueta/git/rnc2rng/rnc2rng/parser.py", line 529, in parse
    return parser.parse(lex(src), state=State(fn, src))
  File "/Users/dargueta/.pyenv/versions/rnc2rng_35/lib/python3.5/site-packages/rply/parser.py", line 62, in parse
    self.error_handler(state, lookahead)
  File "/Users/dargueta/git/rnc2rng/rnc2rng/parser.py", line 504, in error
    raise ParseError(t, s.fn, ln, col, line)
rnc2rng.parser.ParseError: in tests/keyword-attribute.rnc [1:26]
element test { attribute string { text } }
                         ^

The crash happens in both Python 3.5 and 2.7.

djc commented 7 years ago

Thanks for your detailed report! It should be fixed in master. Let me know if you've found any other issues; or if not, let me know if you would like a release version with these fixes.

dargueta-work commented 7 years ago

I found one other issue. I have a fix for it but I can't push or create a pull request. I'll create a different issue so we can track it separately, for posterity.

Edit: I filed a new issue.