Skip to content

Commit 5769755

Browse files
authored
Fix bug parsing unary subtypes with newlines (#393)
In expressions like `"a +\n\n<:"` the presence of `peek(ps, skip_newlines=true)` was inconsistent with the use of `bump()` without `skip_newlines`. It seems that we didn't need skip_newlines at all in parse_unary_subtype, so do this to be consistent with parsing of other operators.
1 parent a6b94d2 commit 5769755

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

src/parser.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,7 @@ function parse_toplevel(ps::ParseState)
442442
# a \n \n ==> (toplevel a)
443443
# Empty files
444444
# ==> (toplevel)
445-
bump_trivia(ps, skip_newlines=true)
445+
bump_trivia(ps)
446446
break
447447
else
448448
parse_stmts(ps)
@@ -1027,7 +1027,7 @@ end
10271027
#
10281028
# flisp: parse-unary-subtype
10291029
function parse_unary_subtype(ps::ParseState)
1030-
t = peek_token(ps, skip_newlines=true)
1030+
t = peek_token(ps)
10311031
if is_type_operator(t)
10321032
k2 = peek(ps, 2)
10331033
if is_closing_token(ps, k2) || k2 in KSet"NewlineWs ="
@@ -1060,7 +1060,7 @@ function parse_where_chain(ps0::ParseState, mark)
10601060
ps = ParseState(ps0, where_enabled=false)
10611061
while peek(ps) == K"where"
10621062
bump(ps, TRIVIA_FLAG) # where
1063-
bump_trivia(ps, skip_newlines=true)
1063+
bump_trivia(ps)
10641064
k = peek(ps)
10651065
if k == K"{"
10661066
# x where \n {T} ==> (where x (braces T))
@@ -3457,7 +3457,7 @@ function parse_atom(ps::ParseState, check_identifiers=true)
34573457
if preceding_whitespace(t)
34583458
# : foo ==> (quote-: (error-t) foo)
34593459
# :\nfoo ==> (quote-: (error-t) foo)
3460-
bump_trivia(ps, TRIVIA_FLAG, skip_newlines=true,
3460+
bump_trivia(ps, TRIVIA_FLAG,
34613461
error="whitespace not allowed after `:` used for quoting")
34623462
end
34633463
# Being inside quote makes keywords into identifiers at the

test/parser.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -993,6 +993,9 @@ parsestmt_test_specs = [
993993
"x in'c'" => "(call-i x in (char 'c'))"
994994
"1where'c'" => "(where 1 (char 'c'))"
995995
":+'y'" => "(juxtapose (call-post (quote-: +) ') (call-post y '))"
996+
# unary subtype ops and newlines
997+
"a +\n\n<:" => "(call-i a + <:)"
998+
"for\n\n<:" => "(for (= <: (error (error-t))) (block (error)) (error-t))"
996999
# Empty character consumes trailing ' delimiter (ideally this could be
9971000
# tested above but we don't require the input stream to be consumed in the
9981001
# unit tests there.

0 commit comments

Comments
 (0)