Skip to content

Commit

Permalink
fixed #192; trailing block comments in backcalls
Browse files Browse the repository at this point in the history
  • Loading branch information
satyr committed Nov 20, 2012
1 parent e31e877 commit 0804bc3
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 11 deletions.
3 changes: 2 additions & 1 deletion lib/ast.js
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,7 @@ exports.Block = Block = (function(superclass){
};
prototype.makeReturn = function(it){
var that, ref$, key$, ref1$;
this.chomp();
if (that = (ref1$ = ref$ = this.lines)[key$ = ref1$.length - 1] != null ? ref$[key$] = ref$[key$].makeReturn(it) : void 8) {
if (that instanceof Return && !that.it) {
--this.lines.length;
Expand Down Expand Up @@ -409,7 +410,7 @@ exports.Block = Block = (function(superclass){
};
prototype.compileExpressions = function(o, level){
var lines, i, that, code, last, i$, len$, node;
lines = this.lines;
lines = this.chomp().lines;
i = -1;
while (that = lines[++i]) {
if (that.comment) {
Expand Down
2 changes: 1 addition & 1 deletion lib/grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ bnf = {
})
],
Block: [o('INDENT Lines DEDENT', function(){
return $2.chomp();
return $2;
})],
Expression: [
o('Chain', function(){
Expand Down
2 changes: 1 addition & 1 deletion lib/parser.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion src/ast.co
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ class exports.Block extends Node
# **Block** does not return its entire body, rather it
# ensures that the final line is returned.
makeReturn: ->
@chomp!
if @lines[*-1]?=makeReturn it
[email protected] if that instanceof Return and not that.it
this
Expand Down Expand Up @@ -278,7 +279,7 @@ class exports.Block extends Node

# Compile to a comma-separated list of expressions.
compileExpressions: (o, level) ->
{lines} = this; i = -1
{lines} = @chomp!; i = -1
lines.splice i-- 1 if that.comment while lines[++i]
lines.push Literal \void unless lines.length
lines.0 <<< {@front}; lines[*-1] <<< {@void}
Expand Down
2 changes: 1 addition & 1 deletion src/grammar.co
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ bnf =
# An indented block of expressions.
# Note that [Lexer](#lexer) rewrites some single-line forms into blocks.
Block:
o 'INDENT Lines DEDENT' -> $2.chomp!
o 'INDENT Lines DEDENT' -> $2
...

# All the different types of expressions in our language.
Expand Down
14 changes: 8 additions & 6 deletions test/comment.co
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,11 @@ obj = {
* ^
*/
};
if (1) {
(function(){
/* no semicolon at end -> */
2;
}
1;
return 2;
});
/* trailing top level comment */
''', Coco.compile '''
/* leading block comments */
Expand All @@ -148,11 +149,12 @@ obj = {
* ^
*/
}
if 1
->
/* no semicolon at end -> */
1
2
/* trailing comments in a block */
/* are removed */
/* trailing block comments are */
/* removed when returning value */
/* trailing top level comment */
''', {+bare}

Expand Down
7 changes: 7 additions & 0 deletions test/function.co
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,13 @@ eq 3 do

eq 6 (a <- g 6; a)

# [#192](https://github.com/satyr/coco/issues/192)
eq '192' do
<- '081'replace /./g
-~it
/* ignore trailing */
/* block comments */


### `function`
new
Expand Down

0 comments on commit 0804bc3

Please sign in to comment.