Skip to content

Commit

Permalink
FIX: comment-like lines inside a string-block
Browse files Browse the repository at this point in the history
CHANGE: going back to picky-comments, since my preprocessor was pretty wrong sometimes. Now things are all correct, just over picky.
HOWEVER - I did fix the biggest problem previously with pick comments. An indented comment after a statement no longer converts it into a funciton invocation.
ALL TESTS PASS
  • Loading branch information
shanebdavis committed Sep 6, 2018
1 parent a0d2aca commit 16db9e0
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 20 deletions.
4 changes: 3 additions & 1 deletion cafInCaf/CaffeineScript/Preprocessors.caf
Expand Up @@ -106,4 +106,6 @@ class Preprocessors
source source


@preprocess: (source) => @preprocess: (source) =>
@normalizeComments @normalizeIndentation source # DISABLED - this needs to be applied at the block level
# @normalizeComments
@normalizeIndentation source
18 changes: 14 additions & 4 deletions cafInCaf/CaffeineScript/Rules/Comments.caf
Expand Up @@ -9,18 +9,28 @@ import &StandardImport
{} pattern: "/##[^\n]*/ unparsedBlock*" {} pattern: "/##[^\n]*/ unparsedBlock*"
{} pattern: /\ *#([^\n$\w\u007f-\uffff]+[^\n]*|(?=\n|$))/ {} pattern: /\ *#([^\n$\w\u007f-\uffff]+[^\n]*|(?=\n|$))/


##
Statement-ends are:
new-line "\n"
end-of-buffer ($)
semi-column ";"
close-parenthesis ")"

NOTE: A close-parenthesis can be considered an 'end'
WHY? It's needed to make this parse: (-> 1)
Without it, the "1" wouldn't be a statement.
NOTE: The close-paren is not 'consumed' by this regexp.

_end: _end:
/// ///
(\ * (\n | ;\ * | $) )+ (\ * (\n | ;\ * | $) )+
| |
(\ * (?=\))) (\ * (?=\)))
# A close-parenthesis can be considered an 'end'
# This is makes this parse: (-> 1).
# Without it, the "1" wouldn't be a statement.
# NOTE: the close-paren is not 'consumed' by this regexp.


lineStartComment: "comment _end" "_end" lineStartComment: "comment _end" "_end"
lineEndComment: "_? comment? _end lineStartComment*" lineEndComment: "_? comment? _end lineStartComment*"


# commenting this out breacks compiling: LiteralStrings.caf # commenting this out breacks compiling: LiteralStrings.caf
{} getPresent: ~> false {} getPresent: ~> false

onlyCommentsRemain: "lineEndComment /$/"
4 changes: 2 additions & 2 deletions cafInCaf/CaffeineScript/Rules/RegExp.caf
Expand Up @@ -60,8 +60,8 @@ multilineRegExpEscape:


multilineRegExpComment: multilineRegExpComment:
pattern: "/^|\\n|\\s/ comment" #/(^|\n|\s)+#(?!\{)[^\n]+[\s\n]*/ pattern: "/^|\\n|\\s/ comment" #/(^|\n|\s)+#(?!\{)[^\n]+[\s\n]*/
stnFactory: :StringStn # stnFactory: :StringStn
stnProps: ~> value: "" # stnProps: ~> value: ""


multilineRegExpInterpolation: multilineRegExpInterpolation:
pattern: "/ */ interpolationStart expression interpolationEnd" pattern: "/ */ interpolationStart expression interpolationEnd"
Expand Down
2 changes: 1 addition & 1 deletion cafInCaf/CaffeineScript/Rules/ValueLists.caf
Expand Up @@ -6,7 +6,7 @@ import &StandardImport, &CaffeineEight


@rule @rule
valueListBlock: Extensions.IndentBlocks.getPropsToSubparseBlock rule: "valueListBlockSubParse" valueListBlock: Extensions.IndentBlocks.getPropsToSubparseBlock rule: "valueListBlockSubParse"
valueListBlockSubParse: "end* listItemStatement*" valueListBlockSubParse: "end* listItemStatement+"


@rule @rule
simpleValueList: simpleValueList:
Expand Down
3 changes: 1 addition & 2 deletions source/CaffeineScript/Preprocessors.js
Expand Up @@ -149,8 +149,7 @@ Caf.defMod(module, () => {
lines.join("\n")) lines.join("\n"))
: source; : source;
}; };
this.preprocess = source => this.preprocess = source => this.normalizeIndentation(source);
this.normalizeComments(this.normalizeIndentation(source));
} }
)); ));
} }
Expand Down
3 changes: 2 additions & 1 deletion source/CaffeineScript/Rules/Comments.js
Expand Up @@ -19,7 +19,8 @@ Caf.defMod(module, () => {
getPresent: function() { getPresent: function() {
return false; return false;
} }
} },
{ onlyCommentsRemain: "lineEndComment /$/" }
); );
}; };
})(); })();
Expand Down
8 changes: 1 addition & 7 deletions source/CaffeineScript/Rules/RegExp.js
Expand Up @@ -65,13 +65,7 @@ Caf.defMod(module, () => {
return { value: this.text === "\\ " ? " " : this.text }; return { value: this.text === "\\ " ? " " : this.text };
} }
}, },
multilineRegExpComment: { multilineRegExpComment: { pattern: "/^|\\n|\\s/ comment" },
pattern: "/^|\\n|\\s/ comment",
stnFactory: "StringStn",
stnProps: function() {
return { value: "" };
}
},
multilineRegExpInterpolation: { multilineRegExpInterpolation: {
pattern: "/ */ interpolationStart expression interpolationEnd" pattern: "/ */ interpolationStart expression interpolationEnd"
}, },
Expand Down
2 changes: 1 addition & 1 deletion source/CaffeineScript/Rules/ValueLists.js
Expand Up @@ -11,7 +11,7 @@ Caf.defMod(module, () => {
valueListBlock: Extensions.IndentBlocks.getPropsToSubparseBlock({ valueListBlock: Extensions.IndentBlocks.getPropsToSubparseBlock({
rule: "valueListBlockSubParse" rule: "valueListBlockSubParse"
}), }),
valueListBlockSubParse: "end* listItemStatement*" valueListBlockSubParse: "end* listItemStatement+"
}); });
this.rule({ this.rule({
simpleValueList: [ simpleValueList: [
Expand Down
Expand Up @@ -392,6 +392,11 @@ module.exports = suite: parseTestSuite
thing. thing.
''': '`This\\nthat and the ${Caf.toString(b)}\\nthing.`;' ''': '`This\\nthat and the ${Caf.toString(b)}\\nthing.`;'


regressions:
"""
""
# looks like a comment but its not
""": '"# looks like a comment but its not";'
interpolated: interpolated:
basic: basic:
'"${#{foo}}"': '`\\${${Caf.toString(foo)}}`;' '"${#{foo}}"': '`\\${${Caf.toString(foo)}}`;'
Expand All @@ -413,4 +418,5 @@ module.exports = suite: parseTestSuite
1 1
2 2
}there" }there"
""": "`hi${Caf.toString([1, 2])}there`;" """: "`hi${Caf.toString([1, 2])}there`;"

0 comments on commit 16db9e0

Please sign in to comment.