mirror of
https://github.com/jashkenas/coffeescript.git
synced 2026-05-03 03:00:14 -04:00
Merge pull request #3329 from xixixao/issue3325
Fixes #3325: implicit indendation error messages
This commit is contained in:
@@ -202,10 +202,12 @@ parser.yy.parseError = (message, {token}) ->
|
||||
# Disregard the token, we take its value directly from the lexer in case
|
||||
# the error is caused by a generated token which might refer to its origin.
|
||||
{errorToken, tokens} = parser.lexer
|
||||
[ignored, errorText, errorLoc] = errorToken
|
||||
[errorTag, errorText, errorLoc] = errorToken
|
||||
|
||||
errorText = if errorToken is tokens[tokens.length - 1]
|
||||
'end of input'
|
||||
else if errorTag in ['INDENT', 'OUTDENT']
|
||||
'indentation'
|
||||
else
|
||||
helpers.nameWhitespaceCharacter errorText
|
||||
|
||||
|
||||
@@ -396,7 +396,7 @@ class exports.Rewriter
|
||||
if tag in SINGLE_LINERS and @tag(i + 1) isnt 'INDENT' and
|
||||
not (tag is 'ELSE' and @tag(i + 1) is 'IF')
|
||||
starter = tag
|
||||
[indent, outdent] = @indentation yes
|
||||
[indent, outdent] = @indentation tokens[i]
|
||||
indent.fromThen = true if starter is 'THEN'
|
||||
tokens.splice i + 1, 0, indent
|
||||
@detectEnd i + 2, condition, action
|
||||
@@ -426,11 +426,14 @@ class exports.Rewriter
|
||||
return 1
|
||||
|
||||
# Generate the indentation tokens, based on another token on the same line.
|
||||
indentation: (implicit = no) ->
|
||||
indentation: (origin) ->
|
||||
indent = ['INDENT', 2]
|
||||
outdent = ['OUTDENT', 2]
|
||||
indent.generated = outdent.generated = yes if implicit
|
||||
indent.explicit = outdent.explicit = yes if not implicit
|
||||
if origin
|
||||
indent.generated = outdent.generated = yes
|
||||
indent.origin = outdent.origin = origin
|
||||
else
|
||||
indent.explicit = outdent.explicit = yes
|
||||
[indent, outdent]
|
||||
|
||||
generate: generate
|
||||
|
||||
Reference in New Issue
Block a user