swaroopch / edn_format

EDN reader and writer implementation in Python, using PLY (lex, yacc)
https://www.swaroopch.com/Wrote-an-EDN-format-reader-and-writer-in-Python-11e0924249b181e3af8bdb9af1456373
Other
134 stars 31 forks source link

SyntaxError: Illegal character '^' when parsing files with metadata #41

Closed p-himik closed 6 years ago

p-himik commented 6 years ago

Example:

>>> edn_format.loads('^:test []')
Traceback (most recent call last):

  File "/home/p-himik/.local/share/virtualenvs/strayhorn-test-HPuom5qM/lib/python3.6/site-packages/IPython/core/interactiveshell.py", line 2963, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)

  File "<ipython-input-4-f8dc7704d4e7>", line 1, in <module>
    edn.loads('^:test []')

  File "/home/p-himik/.local/share/virtualenvs/strayhorn-test-HPuom5qM/lib/python3.6/site-packages/edn_format/edn_parse.py", line 160, in parse
    return p.parse(text, lexer=lex())

  File "/home/p-himik/.local/share/virtualenvs/strayhorn-test-HPuom5qM/lib/python3.6/site-packages/ply/yacc.py", line 333, in parse
    return self.parseopt_notrack(input, lexer, debug, tracking, tokenfunc)

  File "/home/p-himik/.local/share/virtualenvs/strayhorn-test-HPuom5qM/lib/python3.6/site-packages/ply/yacc.py", line 1063, in parseopt_notrack
    lookahead = get_token()     # Get the next token

  File "/home/p-himik/.local/share/virtualenvs/strayhorn-test-HPuom5qM/lib/python3.6/site-packages/ply/lex.py", line 386, in token
    newtok = self.lexerrorf(tok)

  File "/home/p-himik/.local/share/virtualenvs/strayhorn-test-HPuom5qM/lib/python3.6/site-packages/edn_format/edn_lex.py", line 254, in t_error
    c=t.value[0], p=t.lexpos, a=t.value[0:100]))

  File "<string>", line unknown
SyntaxError: Illegal character '^' with lexpos 0 in the area of ...^:test []...
p-himik commented 6 years ago

Ah, apparently metadata is not supposed to be in EDN at all.

bfontaine commented 6 years ago

Yeah, the ^ notation is a a Clojure metadata reader macro.