Comments (9)
Yes, implementing elseif
is on my high priority list right now. It shouldn't take to much work to implement, but I have to find some time to do it.
from hush.
but I have to find some time to do it.
Fair enough. Thanks for the quick reply!
from hush.
I have two working solutions to this. At this point neither of them make any changes to the ast. They simply wrap nested if
expressions as single statement blocks in the otherwise
field of the outer if
expression. The difference between the two solutions is a classic: One uses elseif
while the other uses else if
(as two separate tokens).
Is there a preference for which direction to go?
The issue with the elseif
approach is that the ast doesn't directly represent the distinction, so the token is not represented in --ast
or --program
, which could potentially be confusing. On the other hand the implementation has a much smaller footprint then an extension to the ast would.
The issue with if
is that I'm relying on source positioning (else
and following if
being on the same line) to identify the else if
branch. I do that specifically to distinguish between the following two examples:
if <cond> then
...
else if <cond> then
...
end
if <cond> then
...
else
if <cond> then
...
end
end
I'm personally a fan of else if
over a single keyword, and I think the same-line compromise is reasonable. It's also more clearly in-line with the ast - since I've left it as-is.
from hush.
The PR looks good! But I still feel like we should stick to not being whitespace sensitive here, so I'd insist on the elseif
approach. Do you feel comfortable adjusting the PR to do so? Once again, thanks for your contribution.
from hush.
There you go: else if
in #30 and elseif
in #31 for comparison - feel free to reject either one.
from hush.
I vouch for the elseif
approach, as Hush currently is not whitespace sensitive, and I'd like to keept it that way. If you're really inclined to else if
, we could consider an implementation that works with the token sequence instead of line number. I.e., if the else
token is immediately followed by an if
token, then it's an else if
construction. Thanks for taking you time into this issue!
from hush.
I generally agree on non-whitespace sensitivity, though I find this to be a reasonable approach. I am more inclined to else if
but beyond that I also just want the feature implemented ;)
we could consider an implementation that works with the token sequence instead of line number. I.e., if the
else
token is immediately followed by anif
token
The token sequence would always be else
followed by if
as whitespace isn't represented - nor should it be. I guess my question is what you mean by "immediately" in this context. I interpret it as "a single space-character between the two". But that would still mean that it's whitespace sensitive, so I'm not sure that's what you meant. I simply took the slightly more laxed approach that the number of spaces shouldn't matter.
When an if
token follows an else
token in the token sequence, the challenge is to detect if the parser should consume it with the else
token as an else
if
sequence, or as a nested if
expression with it's own final end
token.
if <cond> then
...
else if <cond> then
...
end
if <cond> then
...
else
if <cond> then
...
end
end
from hush.
I've created a pull request #30. It's probably simpler to actually look at some code ;)
from hush.
Closed by #31
from hush.
Related Issues (20)
- Shell capture hangs indefinitely HOT 6
- Access to foreign function interface (FFI)? HOT 4
- Will REPL be possible? HOT 1
- Feature request: Add syntax sugar for dictionary access HOT 3
- Exit from script early? HOT 2
- Odd behaviour with overwrite then append in command block HOT 1
- Filesystem queries HOT 6
- Publish vscode extension to open-vsx HOT 2
- Feature: Add print() function with no newline HOT 3
- Parse error when std.import'ed script contains executable statements HOT 3
- Feature: Add symbols for interpreter, program, and script HOT 3
- Feature: Add 'File' support that can cross the curly-block barrier HOT 1
- Feature: Add support for multi-way conditional(s) HOT 1
- Question: std.catch with parameters HOT 4
- Running script has no output unless run inside another program HOT 7
- Test using `capture.hsh` fails HOT 7
- Feature: Potential for bash transpilation? HOT 1
- External: Neovim syntax highlighting and static checks HOT 1
- Regex doesn't work due to UTF-8 HOT 2
- [Suggestion] Add global prelude HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from hush.