diff --git a/JuliaSyntax/AGENTS.md b/JuliaSyntax/AGENTS.md new file mode 100644 index 0000000000000..b5953f2154c32 --- /dev/null +++ b/JuliaSyntax/AGENTS.md @@ -0,0 +1,7 @@ +# JuliaSyntax Agent Instructions + +See [../AGENTS.md](../AGENTS.md) for general instructions. + +## Parser changes + +When modifying the parser, always verify that AST production comments (e.g., `# f.[x] ==> (error f x)`) accurately reflect the actual parser output. diff --git a/JuliaSyntax/CLAUDE.md b/JuliaSyntax/CLAUDE.md new file mode 120000 index 0000000000000..47dc3e3d863cf --- /dev/null +++ b/JuliaSyntax/CLAUDE.md @@ -0,0 +1 @@ +AGENTS.md \ No newline at end of file diff --git a/JuliaSyntax/src/julia/parser.jl b/JuliaSyntax/src/julia/parser.jl index 75c806caaa60a..eedfe03653c41 100644 --- a/JuliaSyntax/src/julia/parser.jl +++ b/JuliaSyntax/src/julia/parser.jl @@ -1738,6 +1738,14 @@ function parse_call_chain(ps::ParseState, mark, is_macrocall=false) emit(ps, emark, K"error", error="the .' operator for transpose is discontinued") emit(ps, mark, K"dotcall", POSTFIX_OP_FLAG) + elseif k == K"[" || k == K"{" + # f.[x] ==> (error f x) + # f.{x} ==> (error f x) + # Parse as broadcasted brackets, then wrap in error + close = k == K"[" ? K"]" : K"}" + bump(ps, TRIVIA_FLAG) + parse_cat(ParseState(ps, end_symbol=true), close, ps.end_symbol) + emit(ps, mark, K"error", error="brackets are not allowed after `.`") else if saw_misplaced_atsym # If we saw a misplaced `@` earlier, this might be the place diff --git a/JuliaSyntax/test/diagnostics.jl b/JuliaSyntax/test/diagnostics.jl index 151aad919c0ed..e258386c1d3d2 100644 --- a/JuliaSyntax/test/diagnostics.jl +++ b/JuliaSyntax/test/diagnostics.jl @@ -48,6 +48,10 @@ end Diagnostic(3, 4, :error, "`@` must appear on first or last macro name component") @test diagnostic("@M.(x)") == Diagnostic(1, 3, :error, "dot call syntax not supported for macros") + @test diagnostic("a.[x]") == + Diagnostic(1, 5, :error, "brackets are not allowed after `.`") + @test diagnostic("a.{x}") == + Diagnostic(1, 5, :error, "brackets are not allowed after `.`") @test diagnostic("try x end") == Diagnostic(1, 9, :error, "try without catch or finally") diff --git a/test/syntax.jl b/test/syntax.jl index 5691ca7135993..851ceec87da49 100644 --- a/test/syntax.jl +++ b/test/syntax.jl @@ -934,8 +934,8 @@ g21054(>:) = >:2 @test g21054(-) == -2 # issue #21168 -@test_broken Meta.lower(Main, :(a.[1])) == Expr(:error, "invalid syntax \"a.[1]\"") -@test_broken Meta.lower(Main, :(a.{1})) == Expr(:error, "invalid syntax \"a.{1}\"") +@test_parseerror "a.[1]" +@test_parseerror "a.{1}" # Issue #21225 let abstr = Meta.parse("abstract type X end")