Skip to content

tmLanguage file: python considers it invalid xml? #195

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
asottile opened this issue Feb 15, 2020 · 2 comments · Fixed by #196
Closed

tmLanguage file: python considers it invalid xml? #195

asottile opened this issue Feb 15, 2020 · 2 comments · Fixed by #196

Comments

@asottile
Copy link
Contributor

asottile commented Feb 15, 2020

(kinda meta so I deleted the default text here)

A little background, I'm trying to use the textmate grammars here to power a terminal highlighter for a text editor I'm building -- as such I'm using the plist format of various grammars (vs code's json ones strip useful information like the file types, and cson is slow to parse and requires an external dependency)

when trying to use the tmLanguage files provided here, I get an error loading them as the xml comment appears before the declaration:

  File "/home/asottile/workspace/textmate-highlight/demo/../highlight_demo.py", line 306, in parse
    data = plistlib.load(f)
  File "/usr/lib/python3.8/plistlib.py", line 986, in load
    raise InvalidFileException()
plistlib.InvalidFileException: Invalid file

If I run this through an xml validator (I'm using check-xml), it also complains as well:

$ check-xml MagicPython.tmLanguage 
MagicPython.tmLanguage: Failed to xml parse (MagicPython.tmLanguage:2:0: XML or text declaration not at start of entity)

An easy fix for this would be to move the comment below the xml declaration, which passes/parses fine:

$ head -3 MagicPython.tmLanguage 
<?xml version="1.0" encoding="UTF-8"?>
<!-- AUTOGENERATED FROM grammars/src/MagicPython.syntax.yaml -->
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
$ check-xml MagicPython.tmLanguage 
$

any chance that I could fix this by moving the comment down one line? I'd be happy to submit a PR if you point me in the right direction -- thanks!

@elprans
Copy link
Member

elprans commented Feb 15, 2020

The files are actually generated by the syntaxdev tool here, so you'll need to make a PR there and then regen the files in this repo.

@asottile
Copy link
Contributor Author

hmm! looks like this got fixed a while ago: https://github.com/MagicStack/syntaxdev/blob/f668e7dc86a8e3b721d22375259c7f932e213c9f/index.js#L472

MagicStack/syntaxdev@3324100

I'll make a PR to regen then 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants