groupon / cson-parser

Simple & safe CSON parser
BSD 3-Clause "New" or "Revised" License
133 stars 27 forks source link

Odd behaviour with certain property assignments #71

Open Alhadis opened 6 years ago

Alhadis commented 6 years ago

Parsing this:

{foo: 2; @bar: 3} # CSON

... quite literally results in "this":

{a: 2, this: 3} // JS

It's also possible to use equals signs for assignment within curly braces, even though CSON docs state that variable assignments aren't allowed in CSON data:

{foo: 2; bar = 1 } # CSON
{foo: 2, bar: 1} // JS

I know cson-parser uses coffee---------script for lexing/parsing, so it's no surprise that some vestiges of its old class syntax are still hanging around. Even so, these constructs should ideally be considered invalid by the parser.

jkrems commented 6 years ago

Nice find! Thanks for reporting this. Agreed - neither of those should be allowed. I assume it should be possible to exclude them by looking more closely at the AST nodes.

Alhadis commented 6 years ago

Another oddity I've encountered: the following (presumably legal) syntax coughs up an error:

[### aaaa ### a: 2, 
Block: "comment"
]

CSON parser:

[stdin]:1:16: error: unexpected :
[### aaaa ### a: 2,
               ^

However, running the CSON snippet above in a CoffeeScript REPL shows what I expected to see:

[{/* aaaa */ a: 2, Block: "comment"}];

I'm still trying to work out how CoffeeScript handles overly-long # comments like this:

#########
Commented?
### End-of-comment?

The sample above yields puzzling errors from both CoffeeScript and cson-parser:

CoffeeScript REPL:

#########
Commented?
### End-of-comment?

cson-parser:

[stdin]:3:1: error: unexpected #
### End-of-comment?
^
Inve1951 commented 5 years ago

Only an exact amount of 3 # open/close a block comment - everything else is a single-line comment.

Just wanted to drop this heads-up: CS is currently undergoing heavy changes in regards to AST generation: coffeescript/ast