3 ms·
The essential difference between Javascript and Go is that in Go, the semicolons are inserted by the lexer[0], while in JS, they're inserted by the parser. I do
by nvader 11y ago
The essential difference between Javascript and Go is that in Go, the semicolons are inserted by the lexer[0], while in JS, they're inserted by the parser. I don't know how Rust does it.
This means that Go's semicolon insertion rules are really simple: to judge if a statement will end in a semicolon, you only need to examine that line (actually, the last token of that line).
In Javascript, on the other hand, the start of the next line needs to be considered as well. If the two lines could possibly be interpreted as one statement together, then they are (except for restricted productions). [ and ( are common offenders that cause lines to "pick up" other lines, but unary + and - can also be candidates when they get promoted to binary operators.
[0] https://golang.org/doc/effective_go.html#semicolons https://golang.org/doc/effective_go.html#semicolons
- steveklabnik 11y agoRust doesn't do any special insertion/deletion, but take an expression and add a ; and it becomes a statement.