Skip to content

Commit db88a35

Browse files
authored
Merge pull request #89 from JuliaLang/cjf/README-ast
Add notes about AST differences + minor recovery fix
2 parents 660ed65 + d00a04a commit db88a35

File tree

3 files changed

+23
-13
lines changed

3 files changed

+23
-13
lines changed

README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,22 @@ julia> text = "x = \"\"\"\n \$a\n b\"\"\""
435435
21:23 │ """ "\"\"\""
436436
```
437437

438+
### Less redundant `block`s
439+
440+
Sometimes `Expr` needs to contain redundant block constructs in order to have a
441+
place to store `LineNumberNode`s, but we don't need these and avoid adding them
442+
in several cases:
443+
* The right hand side of short form function syntax
444+
* The conditional in `elseif`
445+
* The body of anonymous functions after the `->`
446+
447+
### Distinct conditional ternary expression
448+
449+
The syntax `a ? b : c` is the same as `if a b else c` in `Expr` so macros can't
450+
distinguish these cases. Instead, we use a distinct expression head `K"?"` and
451+
lower to `Expr(:if)` during `Expr` conversion.
452+
453+
438454
## More about syntax kinds
439455

440456
We generally track the type of syntax nodes with a syntax "kind", stored

src/parser.jl

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3244,7 +3244,6 @@ function parse_atom(ps::ParseState, check_identifiers=true)
32443244
if leading_kind == K":"
32453245
# symbol/expression quote
32463246
# :foo ==> (quote foo)
3247-
# : foo ==> (quote (error-t) foo)
32483247
t = peek_token(ps, 2)
32493248
k = kind(t)
32503249
if is_closing_token(ps, k) && (!is_keyword(k) || preceding_whitespace(t))
@@ -3256,19 +3255,12 @@ function parse_atom(ps::ParseState, check_identifiers=true)
32563255
end
32573256
bump(ps, TRIVIA_FLAG) # K":"
32583257
if preceding_whitespace(t)
3259-
# : a ==> (quote (error-t) a))
3260-
# ===
3261-
# :
3262-
# a
3263-
# ==> (quote (error))
3264-
bump_trivia(ps, TRIVIA_FLAG,
3258+
# : foo ==> (quote (error-t) foo)
3259+
# :\nfoo ==> (quote (error-t) foo)
3260+
bump_trivia(ps, TRIVIA_FLAG, skip_newlines=true,
32653261
error="whitespace not allowed after `:` used for quoting")
32663262
# Heuristic recovery
3267-
if kind(t) == K"NewlineWs"
3268-
bump_invisible(ps, K"error")
3269-
else
3270-
bump(ps)
3271-
end
3263+
bump(ps)
32723264
else
32733265
# Being inside quote makes keywords into identifiers at at the
32743266
# first level of nesting

test/parser.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -568,10 +568,12 @@ tests = [
568568
],
569569
JuliaSyntax.parse_atom => [
570570
":foo" => "(quote foo)"
571-
": foo" => "(quote (error-t) foo)"
572571
# Literal colons
573572
":)" => ":"
574573
": end" => ":"
574+
# Whitespace after quoting colon
575+
": foo" => "(quote (error-t) foo)"
576+
":\nfoo" => "(quote (error-t) foo)"
575577
# plain equals
576578
"=" => "(error =)"
577579
# Identifiers

0 commit comments

Comments
 (0)