-
Notifications
You must be signed in to change notification settings - Fork 5
if
significant whitespace
#16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
if
significant whitespace
#16
Conversation
- Use stack to track `if` blocks and match alternate blocks correctly - catch out-of-place `elif` keywords - Add fixtures
002b09c
to
bfa1aa8
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, this is looking good!
} | ||
|
||
case tt._else: | ||
case tt._else: case tt._elif: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
src/plugins/lightscript.js
Outdated
}; | ||
|
||
pp.pushBlockState = function (blockType, indentLevel) { | ||
this.state.blockStack = this.state.blockStack || []; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's just initialize in src/tokenizer/state.js
src/plugins/lightscript.js
Outdated
|
||
pp.matchBlockState = function(blockType, indentLevel) { | ||
const stack = this.state.blockStack; | ||
return (stack && stack.find( (x) => x.blockType === blockType && x.indentLevel === indentLevel )) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just return stack.some(x => x.blockType === blockType && x.indentLevel === indentLevel)
should be good
src/plugins/lightscript.js
Outdated
// clause does not match the current `if` -- so unwind the recursive descent. | ||
const alternateIndentLevel = this.state.indentLevel; | ||
if ( | ||
( alternateIndentLevel !== ifIndentLevel ) && |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I try to avoid style nits, but the extra spaces here don't match (though I personally prefer them as well)
@@ -0,0 +1,3 @@ | |||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this test should be changed to:
x =
if false: 1
elif true:
2
and should still pass.
An additional test should be added with the name over-indented-elif
(or similar) that fails with this error message.
@@ -0,0 +1,6 @@ | |||
x = if a: | |||
if(b) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (b) {
@@ -0,0 +1,4 @@ | |||
x = if a: | |||
if b: c |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should also have
x = if a:
if b: c
elif d: e
else:
f
should probably also have
if (a) {
b
if c:
d
elif e:
f
} else {
g
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(as separate tests of course)
|
||
pp.pushBlockState = function (blockType, indentLevel) { | ||
this.state.blockStack = this.state.blockStack || []; | ||
this.state.blockStack.push({ blockType, indentLevel }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
have you played with try/catch at all yet? would rather just track indentLevel in something like this.state.ifBlockStack
instead of an object if we're only using one blockType.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Definitely some issues with try/catch:
try:
a()
try:
b()
catch e:
c()
finally:
d()
unknown: Missing catch or finally clause (1:0)
> 1 | try:
| ^
2 | a()
3 | try:
4 | b()
- Initialize state in tokenizer/state - Misc cleanup
Comments have been addressed |
Fixes lightscript/lightscript#22
if
s: if an alternate clause could close a higher whiteblockif
at the same indent level, it always closes the matching whiteblock rather than any innerif
.elif
as an unexpected else block.