Skip to content

Commit 6d92ef3

Browse files
authored
Lower @ . to @ __dot__ not in parser but in Expr conversion (#146)
The reason to use `__dot__` is to allow `macro __dot__` to be defined in normal Julia source. But doing this in the parser is an awkward special case - better to do it later during some lowering step. Here done in Expr conversion.
1 parent eb3259f commit 6d92ef3

File tree

5 files changed

+10
-21
lines changed

5 files changed

+10
-21
lines changed

src/expr.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,9 @@ function _to_expr(node::SyntaxNode; iteration_spec=false, need_linenodes=true,
152152
loc = source_location(LineNumberNode, node.source, node.position)
153153
if headsym == :macrocall
154154
insert!(args, 2, loc)
155+
if args[1] == Symbol("@.")
156+
args[1] = Symbol("@__dot__")
157+
end
155158
elseif headsym in (:call, :ref)
156159
# Julia's standard `Expr` ASTs have children stored in a canonical
157160
# order which is often not always source order. We permute the children

src/kinds.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -852,7 +852,6 @@ const _kind_names =
852852
# like CORE_DOC_MACRO_NAME)
853853
"BEGIN_MACRO_NAMES"
854854
"MacroName"
855-
"@."
856855
"StringMacroName"
857856
"CmdMacroName"
858857
"core_@doc"

src/parser.jl

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2238,7 +2238,6 @@ function fix_macro_name_kind!(ps::ParseState, macro_name_position, name_kind=not
22382238
end
22392239
if isnothing(name_kind)
22402240
name_kind = k == K"Identifier" ? K"MacroName" :
2241-
k == K"." ? K"@." :
22422241
internal_error("unrecognized source kind for macro name ", k)
22432242
end
22442243
reset_node!(ps, macro_name_position, kind=name_kind)
@@ -2249,21 +2248,13 @@ end
22492248
#
22502249
# flisp: parse-macro-name
22512250
function parse_macro_name(ps::ParseState)
2251+
# @! x ==> (macrocall @! x)
2252+
# @.. x ==> (macrocall @.. x)
2253+
# @$ x ==> (macrocall @$ x)
2254+
# @var"#" x ==> (macrocall (var #) @$ x)
22522255
bump_disallowed_space(ps)
2253-
mark = position(ps)
2254-
k = peek(ps)
2255-
if k == K"."
2256-
# TODO: deal with __dot__ lowering in Expr conversion?
2257-
# @. y ==> (macrocall @__dot__ y)
2258-
bump(ps)
2259-
else
2260-
# @! x ==> (macrocall @! x)
2261-
# @.. x ==> (macrocall @.. x)
2262-
# @$ x ==> (macrocall @$ x)
2263-
# @var"#" x ==> (macrocall (var #) @$ x)
2264-
let ps = with_space_sensitive(ps)
2265-
parse_atom(ps, false)
2266-
end
2256+
let ps = with_space_sensitive(ps)
2257+
parse_atom(ps, false)
22672258
end
22682259
end
22692260

@@ -3402,7 +3393,6 @@ function parse_atom(ps::ParseState, check_identifiers=true)
34023393
elseif leading_kind == K"@" # macro call
34033394
# Macro names can be keywords
34043395
# @end x ==> (macrocall @end x)
3405-
# @. x y ==> (macrocall @__dot__ x y)
34063396
bump(ps, TRIVIA_FLAG)
34073397
parse_macro_name(ps)
34083398
parse_call_chain(ps, mark, true)

src/syntax_tree.jl

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,6 @@ function SyntaxNode(source::SourceFile, raw::GreenNode{SyntaxHead}, position::In
7474
nothing
7575
elseif k == K"error"
7676
ErrorVal()
77-
elseif k == K"@."
78-
:var"@__dot__"
7977
elseif k == K"MacroName"
8078
Symbol("@$(normalize_identifier(val_str))")
8179
elseif k == K"StringMacroName"

test/parser.jl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,6 @@ tests = [
315315
"A.B.@x" => "(macrocall (. (. A (quote B)) (quote @x)))"
316316
"@A.B.x" => "(macrocall (. (. A (quote B)) (quote @x)))"
317317
"[email protected]" => "(macrocall (. (. A (quote B)) (error-t) (quote @x)))"
318-
"@. y" => "(macrocall @__dot__ y)"
319318
"f.(a,b)" => "(. f (tuple a b))"
320319
"f.(a=1; b=2)" => "(. f (tuple (= a 1) (parameters (= b 2))))" =>
321320
Expr(:., :f, Expr(:tuple, Expr(:parameters, Expr(:kw, :b, 2)), Expr(:kw, :a, 1)))
@@ -710,7 +709,7 @@ tests = [
710709
# Macro names can be keywords
711710
"@end x" => "(macrocall @end x)"
712711
# __dot__ macro
713-
"@. x y" => "(macrocall @__dot__ x y)"
712+
"@. x" => "(macrocall @. x)" => Expr(:macrocall, Symbol("@__dot__"), LineNumberNode(1), :x)
714713
# cmd strings
715714
"``" => "(macrocall :(Core.var\"@cmd\") (cmdstring-r \"\"))"
716715
"`cmd`" => "(macrocall :(Core.var\"@cmd\") (cmdstring-r \"cmd\"))"

0 commit comments

Comments
 (0)