Skip to content

Commit

Permalink
-jashkenas#558 beginning of work to support 1-1 line matching
Browse files Browse the repository at this point in the history
  • Loading branch information
hbt committed Dec 25, 2011
1 parent 6a99b26 commit 0069c6d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/coffee-script.coffee
Expand Up @@ -48,8 +48,8 @@ exports.postCompilationMatchLines = (code) ->
continue

# skip line after /*line -- comment
if line is "*/" && newLines[curLine] is ""
continue
if line.indexOf("*/") is 0 && newLines[curLine] is ""
line = line.substring(2)

newLines[curLine] += line

Expand Down
19 changes: 15 additions & 4 deletions src/lexer.coffee
Expand Up @@ -77,31 +77,42 @@ exports.Lexer = class Lexer
blocks = flatten blocks

lastToken = null
lineBlocks = ['INDENT']
tmp = []
lastTokenHadNewLine = false

for t in @tokens
tmp.push t
# TODO: improve to handle "newLine" attribute. Careful with indentation errors

if t[0] == 'TERMINATOR'
lastTokenHadNewLine = true if lastToken and lastToken.newLine and lastToken[0] isnt 'TERMINATOR'

lastTokenLineNumber = lastToken[2] if lastTokenHadNewLine

if t[0] is 'TERMINATOR' or (t[0] in lineBlocks and lastTokenHadNewLine)
lastTokenHadNewLine = false if t[0] is 'TERMINATOR'
line = 'line '
lineNumber = t[2]
if lastToken
lineNumber = lastToken[2]

if lastTokenHadNewLine
lineNumber = lastTokenLineNumber

line += lineNumber+1

# push comment with line number
res.push ['HERECOMMENT', line, lineNumber]

res.push t
res.push ['TERMINATOR', "\n", lineNumber]

# push tokens (actual source code)
res.push tm for tm in tmp

# reset
line = ''
tmp = []
lastTokenHadNewLine = false
lastToken = null


if t[0] not in blocks
lastToken = t
Expand Down

0 comments on commit 0069c6d

Please sign in to comment.