Skip to content
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

JSON 2 CSON conversion fails to escape '#{' pattern #81

Open
msftrncs opened this issue Jul 20, 2019 · 1 comment
Open

JSON 2 CSON conversion fails to escape '#{' pattern #81

msftrncs opened this issue Jul 20, 2019 · 1 comment

Comments

@msftrncs
Copy link

Originally posted as bevry/cson#91. Please excuse my unfamiliarity with CSON/Coffee at the time I posted this there. Since then, I have written my own crude CSON generator in PowerShell, https://github.com/msftrncs/PwshOutCSON, where as I had started with the JSON2CSON converter from https://github.com/bevry/cson.

Trying to convert a JSON tmLanguage file to a CSON format, I ran in to a issue where the tmLanguage parser in Atom didn't like the file. Turns out there must be some kind of construct using a #{…} (or maybe its #{(…)}) notation (subexpression?) and my tmLanguage file happens to have 5 such patterns in it. I'm showing the entire section below, but the issue is towards the middle of the begin property.

{
    beginCaptures:
        "1":
            name: "constant.numeric.hex.powershell"
        "2":
            name: "constant.language.powershell"
    begin: "(?>([+\\x{2013}-\\x{2015}-]?0(?i:x[0-9a-f_]+l?))((?i:[kmgtp]b)?))(?![^\\s#{(,;|)}<>.!+%*/=\\x{2013}-\\x{2015}-])"
    end: "$|(?![\\s#.+\\x{2013}-\\x{2015}-]|<#)"
    patterns: [
        {
            begin: "\\G(?=\\.(?!\\.)|::|\\[)"
            end: "(?=[^\\s\\p{L}]|\\n)"
            applyEndPatternLast: true
            patterns: [
                {
                    include: "#accessors"
                }
                {
                    match: "[^\\s\\W]+"
                }
            ]
        }
        {
            include: "#operators"
        }
        {
            include: "#commentBlock"
        }
        {
            include: "#commentLine"
        }
    ]
}

The value of the property is perfectly fine in JSON, but it needs the # (or the { following it) escaped in CSON in order to be acceptable to Atom.

I suspect its the CSON serializer that needs to catch the #{ pattern in strings and escape it with \#{.

@jkrems
Copy link
Contributor

jkrems commented Jul 22, 2019

Another alternative would be to force ' as the delimiter whenever there's a # (or #{) in the string.

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

No branches or pull requests

2 participants