Skip to content

Commit 48789ca

Browse files
committed
1 parent 088b8b3 commit 48789ca

File tree

7 files changed

+251
-208
lines changed

7 files changed

+251
-208
lines changed

lib/coffee-script/grammar.js

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/coffee-script/lexer.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/coffee-script/parser.js

Lines changed: 230 additions & 201 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/grammar.coffee

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,11 @@ grammar =
7272
# The **Root** is the top-level node in the syntax tree. Since we parse bottom-up,
7373
# all parsing must end here.
7474
Root: [
75+
o 'RootContent EOF'
76+
]
77+
78+
# Top-level block of code.
79+
RootContent: [
7580
o '', -> new Block
7681
o 'Body'
7782
o 'Block TERMINATOR'

src/lexer.coffee

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ exports.Lexer = class Lexer
7373

7474
@closeIndentation()
7575
@error "missing #{tag}" if tag = @ends.pop()
76+
@token 'EOF', 'EOF'
7677
return @tokens if opts.rewrite is off
7778
(new Rewriter).rewrite @tokens
7879

test/literate.litcoffee

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,5 +53,5 @@ and unordered lists, are fine:
5353
5454
Tabs work too:
5555

56-
test "tabbed code", ->
57-
ok yes
56+
test "tabbed code", ->
57+
ok yes

test/location.coffee

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ x = () ->
1818
test "Verify location of generated tokens", ->
1919
tokens = CoffeeScript.tokens "a = 79"
2020

21-
eq tokens.length, 4
21+
eq tokens.length, 5
2222

2323
aToken = tokens[0]
2424
eq aToken[2].first_line, 0
@@ -39,10 +39,11 @@ test "Verify location of generated tokens", ->
3939
eq numberToken[2].last_column, 5
4040

4141
test "Verify location of generated tokens (with indented first line)", ->
42-
tokens = CoffeeScript.tokens " a = 83"
42+
tokens = CoffeeScript.tokens " a = 83\nb"
4343

44-
eq tokens.length, 6
45-
[IndentToken, aToken, equalsToken, numberToken] = tokens
44+
eq tokens.length, 9
45+
[indent, aToken, equalsToken, numberToken, outdent,
46+
terminator1, bToken, terminator2, EOF] = tokens
4647

4748
eq aToken[2].first_line, 0
4849
eq aToken[2].first_column, 2
@@ -59,6 +60,11 @@ test "Verify location of generated tokens (with indented first line)", ->
5960
eq numberToken[2].last_line, 0
6061
eq numberToken[2].last_column, 7
6162

63+
eq bToken[2].first_line, 1
64+
eq bToken[2].first_column, 0
65+
eq bToken[2].last_line, 1
66+
eq bToken[2].last_column, 0
67+
6268
test "Verify all tokens get a location", ->
6369
doesNotThrow ->
6470
tokens = CoffeeScript.tokens testScript

0 commit comments

Comments
 (0)