Skip to content

Commit

Permalink
Merge pull request #1 from peret/fix-condition-block-detection
Browse files Browse the repository at this point in the history
Fix parsing of while-loops
  • Loading branch information
HookyQR committed Mar 5, 2019
2 parents 39d8a38 + 11fad50 commit 5227d71
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
4 changes: 2 additions & 2 deletions lib/parse.js
Expand Up @@ -276,9 +276,9 @@ function ConditionBlock(entry, buffer, os) {
let ros = os - 1;
while ((ch = buffer[ros]) && ~_nb_white.indexOf(ch)) ros--;

// if there is and it's not a ';' then it's not a block at all,
// if there is and it's not a newline or ';' then it's not a block at all,
// just set the exit at the end of the line
if (~_eol.indexOf(ch)) {
if (!~_eol.indexOf(ch)) {
os += entry.length;
while ((ch = buffer[os]) && !~_eol.indexOf(ch) && ch !== '#') os++;
return {
Expand Down
25 changes: 24 additions & 1 deletion test/parse.js
Expand Up @@ -151,7 +151,7 @@ def other!
end`;
check(contextString);
});
it("recognises a while", function() {
it("recognises two whiles", function() {
const contextString = `
def fn
a = 1 while false
Expand All @@ -161,6 +161,29 @@ def fn
end
end
def other!
end`;
check(contextString);
});
it("recognises a single while", function() {
const contextString = `
def fn
while true
a = 1
break
end
end
def other!
end`;
check(contextString);
});
it("recognises a while modifier", function() {
const contextString = `
def fn
a = 1 while false
end
def other!
end`;
check(contextString);
Expand Down

0 comments on commit 5227d71

Please sign in to comment.