CoffeeScriptRedux icon indicating copy to clipboard operation
CoffeeScriptRedux copied to clipboard

usability with coffee-script repo examples

Open ttilley opened this issue 13 years ago • 5 comments

At this point in time in the development of CoffeeScriptRedux, is it worthwhile to report that it doesn't compile the examples included with coffee-script? (well, some of, but you know what I mean)

└─▪ ./bin/coffee --compile --input ../coffee-script/examples/underscore.coffee > /dev/null
Syntax error on line 476: invalid indentation
473 :   # Compare regular expressions.
474 :   if _.isRegExp(a) and _.isRegExp(b)
475 :     return a.source     is b.source and
476 :            a.global     is b.global and
^^^ :~~~~~~~^
477 :            a.ignoreCase is b.ignoreCase and
478 :            a.multiline  is b.multiline
479 :   # If a is not an object by this point, we can't handle it.
└─▪ ./bin/coffee --compile --input ../coffee-script/examples/potion.coffee > /dev/null
Syntax error on line 17, column 6: unexpected 'p' (\u0070)
14 : 
15 : # loop: 'quaff' print.
16 : 
17 : loop print 'quaff'
^^ :~~~~~~^
18 : 
19 : 
20 : # ('cheese', 'bread', 'mayo') at (1) print

I know that super has yet to be implemented, but for completeness:

└─▪ ./bin/coffee --compile --input ../coffee-script/examples/code.coffee > /dev/null
Syntax error on line 146, column 11: unexpected '5' (\u0035)
143 : class Snake extends Animal
144 :   move: ->
145 :     alert 'Slithering...'
146 :     super 5
^^^ :~~~~~~~~~~~^
147 : 
148 : class Horse extends Animal
149 :   move: ->

Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

ttilley avatar Jan 27 '13 05:01 ttilley

also for completeness sake, a quick scripted run against the documentation examples via:

for doc_coffee in $(find ../coffee-script/documentation -type f -name '*.coffee')
do
  echo "${doc_coffee}"
  ./bin/coffee --compile --input "${doc_coffee}" > /dev/null
done

results in the following (non-super-related) errors:

../coffee-script/documentation/coffee/existence.coffee
Syntax error on line 13, column 2: unexpected end of input
../coffee-script/documentation/coffee/objects_reserved.coffee
Syntax error on line 1, column 25: unexpected ':' (\u003A)
1 : $('.account').attr class: 'active'
^ :~~~~~~~~~~~~~~~~~~~~~~~~~^
2 : 
3 : log object.class
4 : 
../coffee-script/documentation/coffee/parallel_assignment.coffee
Syntax error on line 9, column 2: unexpected end of input
../coffee-script/documentation/coffee/splices.coffee
Syntax error on line 7, column 2: unexpected end of input

...and obviously the one super-related error (again, just for completeness):

../coffee-script/documentation/coffee/classes.coffee
Syntax error on line 10, column 11: unexpected '5' (\u0035)
07 : class Snake extends Animal
08 :   move: ->
09 :     alert "Slithering..."
10 :     super 5
^^ :~~~~~~~~~~~^
11 : 
12 : class Horse extends Animal
13 :   move: ->

ttilley avatar Jan 27 '13 05:01 ttilley

speaking of super, it may be worthwhile to include it within the PEG syntax as an exception case with a more descriptive error message. Perhaps super is currently unimplemented or some such, at least so the debugging makes sense to someone used to vanilla coffee-script.

ttilley avatar Jan 27 '13 05:01 ttilley

https://github.com/jashkenas/coffee-script/blob/master/documentation/coffee/existence.coffee

The error here occurs in the following conditions:

  • The file has at least one line with valid syntax
  • The file doesn't end with a new line
  • The last line in the file has at least one blank

https://github.com/jashkenas/coffee-script/blob/master/documentation/coffee/objects_reserved.coffee

The error here seems to occur only when class is used as the key. Quick testing:

$('.account').attr do: 'active'  # works (sort-of, do is not quoted)
$('.account').attr function: 'active'  # works (sort-of, function is not quoted)
$('.account').attr key: 'active'  # works
$('.account').attr class: 'active'  # error

https://github.com/jashkenas/coffee-script/blob/master/documentation/coffee/parallel_assignment.coffee

Same error as existance.coffee


https://github.com/jashkenas/coffee-script/blob/master/documentation/coffee/splices.coffee

Same error as existance.coffee

mehcode avatar Jan 27 '13 05:01 mehcode

EDIT: when I mentioned syntax error reporting, I was thinking of language.js and not PEG.js. Still, it might be nice to have specific handling for the short-term and a more descriptive error message as a result.

@mehcode - I wasn't kidding earlier about offer of beer, pizza, or... Well, I don't know your life situation. Hiring a babysitter? Heh. :wink:

ttilley avatar Jan 27 '13 05:01 ttilley

https://github.com/jashkenas/coffee-script/blob/master/examples/underscore.coffee
# Works
do ->
  return a.source is b.source and 
  a.global is b.global

# Works
do ->
  a.source is b.source and 
  a.global is b.global

# Doesn't work
do ->
  a.source is b.source and 
    a.global is b.global

# Doesn't work
do ->
  return a.source is b.source and 
    a.global is b.global

# Some more examples of the same problem
# Works
x = a + 
3 + 
5

# Doesn't work
x = a + 
  3 + 
    5

It looks like this problem is caused because of a few reasons. One is that returns are implicit. This causes the return keyword to not introduce any sort of block or statement that would allow for indentation on a successive line. Line statements are strict in that continuations must start on the same indentation. Original coffee-script has allowed for any sort of indentation on successive lines (as long as the operator is the last symbol on the previous line).

Honestly I feel we should extend this to allow for easier continuations. For expressions take the initial indentation and continue the expression until the initial indentation is reached (unless the last symbol on a previous line was an operator then we allow the expression to continue on the same indentation level). Here are some example expressions that would compile with these rules:

# Form that works in original coffee-script but not in redux
x = a +
    4 +
    42

# Form that doesn't work in either but I feel it should
x = a 
  + 4
  + 42

# Only form that works right now
x = a +
4 +
42

Thoughts on the changes, etc. ?


https://github.com/jashkenas/coffee-script/blob/master/examples/potion.coffee
loop then print "a"  # Works
loop
  print "a"    # Works
loop print "a"  # Doesn't work

From some quick testing it looks like loop needs to have an implied then when then is not present. From my 15-minute review of PEG.js this looks like a simple fix for anyone interested. I'll be spending some dedicated time next weekend (or perhaps the one after, we'll see how my time goes) to work on some of this stuff. I'd like to get super up honestly.


@mehcode - I wasn't kidding earlier about offer of beer, pizza, or... Well, I don't know your life situation. Hiring a babysitter? Heh.

@ttilley Heh. I just have a lot of work going on. I'll take a rain check on the beer though. :beers:

mehcode avatar Jan 27 '13 07:01 mehcode