3 ms·
> End of line inference algorithms are incredibly fragile I am working on a language right now with optional semicolons (that is, newlines terminate statements
by saagarjha 7y ago
> End of line inference algorithms are incredibly fragile
I am working on a language right now with optional semicolons (that is, newlines terminate statements unless there is a semicolon, which does the same early) and it’s not really that hard. The only change is that instead of looking for a newline character for statement termination I often also need to look for a semicolon.
- jakear 7y agoI think the issue is more when the new line doesn’t terminate the statement. Like in JS: const a = doThing() (() => throw Error)
- saagarjha 7y agoJavaScript for some reason chose a very strange way to have its newlines work; a number of other languages have it figured out: Swift, for example.
- lioeters 7y ago> newlines terminate statements unless there is a semicolon, which does the same early Since I'm writing a toy language with optional semicolons, I'm curious - how are you solving ambiguities in multi-line expressions? For example: 1 -1 Does your language not allow multi-line expressions, treating the above as two statements? Or, perhaps they must be explicitly an expression, like: (1 -1) I agree with you on another comment, that JavaScript's automatic semicolon insertion is complicated - so I'd like know if there's a sensible solution for languages without semicolons.
- jakear 7y agoPython behaves "sensibly" with regard to this. Semicolons are statement breaks. Endlines are statement breaks, unless theres some reason for them not to be, such as being in a open brace state.
- saagarjha 7y agoIn this language, there's very few multi-line expressions. However, for your specific case: yes, I would consider that two statements. 1 - 1 would be one: putting a binary operator by itself in one line would cause the parser to keep looking.
- lioeters 7y agoAh, I see, so new lines are like invisible operators (with low precedence) that ends a statement unless preceded by another operator. Right, that makes sense.