-
Notifications
You must be signed in to change notification settings - Fork 211
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
Indentation aware readtables implementation #421
Comments
That's probably fit for another repo to propose. |
Could perhaps be done something like this: // this.identationStack = [];
// onIndent function handles indentation, ie.
// - checks if indentation lv is valid with respect to indentation stack
// - call `error` function if bad indentation
// - call `begin` if valid new indentation
// - call `end` if valid end of indentation
this.onIndent(reader, {
// will automatically push to indentation stack
begin: function(reader, continue) {
// reads '{' into token stream as if it was in source :)
this.readPunc('{');
continue(); // continue parsing
},
// will automatically pop from indentation stack and continue
end: function(reader) {
// reads '}' into token stream as if it was in source :)
this.readPunc('}');
},
// called on any indentation error
error: function(err, reader) {
throw Error("Indentation error at:" + reader.index + ' ' + reader.source.slice(20));
}
}) |
Someone needs to keep track of indentation level, and correctly assign multiple dedents for a single new line:
And the generated code needs to know that the first I've played around with the idea at https://github.com/DavidSouther/americano-script, and of course python and Coffee do the same. |
It's tempting to put a lot of stuff into the reader API, but I agree, it should stay a hard-to-use low-level API that other libraries can build on if they want. Readers really shouldn't typically be used, imho. They area hard to work with and easy to introduce bugs. (and don't compose nearly as well as macros) |
@jlongster No arguments there. Is there another way to make an indentation aware parser? EG add Python/Coffee-esque significant whitespace to denote blocking without this? On the one hand, I think not; on the other, if it's provided once and well that should allow anyone else to use a hypothetical |
I'm mass closing issues due to the release of 1.0 obviating lots of bugs. If you feel this issue is something we still need to address feel free to reopen. |
I imagine it could be done using an indentation stack. Would require adding a few extra API methods.
What do you think?
The text was updated successfully, but these errors were encountered: