Repository: JuliaLang/julia
File: JuliaSyntax/src/porcelain/syntax_graph.jl (Julia)

Code before:
            @assert(length(p.args) === 1,
                    "use spaces, not commas, in @stm []-patterns")
        elseif Meta.isexpr(p, :hcat)
            @assert(length(p.args) >= 2)
        elseif Meta.isexpr(p, :vcat)
            p = _stm_vcat_to_hcat(p)
            @assert(length(p.args) >= 2)
        else
            @assert(false, "malformed pattern $p")
        end
        @assert(count(x->Meta.isexpr(x, :(...)), p.args[2:end]) <= 1,
                "Multiple `...` in a pattern is ambiguous")

        # This exact `K"kind"` syntax is not necessary since the kind can't be
        # provided by a variable, but requiring [K"kinds"] is consistent with
        # `@ast` and allows us to implement list matching later.
        @assert(Meta.isexpr(p.args[1], :macrocall, 3) &&
            p.args[1].args[1] === Symbol("@K_str") &&
            p.args[1].args[3] isa String, "first pattern elt must be K\"\"")

        for subp in p.args[2:end]
            _stm_check_pattern(subp; syms)
        end
    end

    @assert Meta.isexpr(pats, :block) "Usage: @st_match st begin; ...; end"
    for pcr in filter(e->!isa(e, LineNumberNode), pats.args)
        @assert(Meta.isexpr(pcr, :(->), 2), "Expected pat -> res, got malformed case: $pcr")
        if Meta.isexpr(pcr.args[1], :tuple)
            @assert(length(pcr.args[1].args) === 2,
                    "Expected `pat` or `(pat, when=cond)`, got $(pcr.args[1])")
            p = pcr.args[1].args[1]
            c = pcr.args[1].args[2]
            @assert(Meta.isexpr(c, :(=), 2) && c.args[1] === :when,
                    "Expected `(when=cond)` in tuple pattern, got $(c)")
        else
            p = pcr.args[1]
        end
        _stm_check_pattern(p)
    end
end

#-------------------------------------------------------------------------------
# RawGreenNode->SyntaxTree
# WIP: expr_structure param will be deleted

function build_tree(::Type{SyntaxTree}, stream::ParseStream;
                    filename=nothing, first_line=1,
                    expr_structure=false)
    cursor = RedTreeCursor(stream)
    graph = SyntaxGraph()

Review comment (suggestion):
```suggestion
    @assert Meta.isexpr(pats, :block) "Usage: @stm st begin; ...; end"
```

Code after:
            @assert(length(p.args) === 1,
                    "use spaces, not commas, in @stm []-patterns")
        elseif Meta.isexpr(p, :hcat)
            @assert(length(p.args) >= 2)
        elseif Meta.isexpr(p, :vcat)
            p = _stm_vcat_to_hcat(p)
            @assert(length(p.args) >= 2)
        else
            @assert(false, "malformed pattern $p")
        end
        @assert(count(x->Meta.isexpr(x, :(...)), p.args[2:end]) <= 1,
                "Multiple `...` in a pattern is ambiguous")

        # This exact `K"kind"` syntax is not necessary since the kind can't be
        # provided by a variable, but requiring [K"kinds"] is consistent with
        # `@ast` and allows us to implement list matching later.
        @assert(Meta.isexpr(p.args[1], :macrocall, 3) &&
            p.args[1].args[1] === Symbol("@K_str") &&
            p.args[1].args[3] isa String, "first pattern elt must be K\"\"")

        for subp in p.args[2:end]
            _stm_check_pattern(subp; syms)
        end
    end

    @assert Meta.isexpr(pats, :block) "Usage: @stm st begin; ...; end"
    for pcr in filter(e->!isa(e, LineNumberNode), pats.args)
        @assert(Meta.isexpr(pcr, :(->), 2), "Expected pat -> res, got malformed case: $pcr")
        if Meta.isexpr(pcr.args[1], :tuple)
            @assert(length(pcr.args[1].args) === 2,
                    "Expected `pat` or `(pat, when=cond)`, got $(pcr.args[1])")
            p = pcr.args[1].args[1]
            c = pcr.args[1].args[2]
            @assert(Meta.isexpr(c, :(=), 2) && c.args[1] === :when,
                    "Expected `(when=cond)` in tuple pattern, got $(c)")
        else
            p = pcr.args[1]
        end
        _stm_check_pattern(p)
    end
end

#-------------------------------------------------------------------------------
# RawGreenNode->SyntaxTree
# WIP: expr_structure param will be deleted

function build_tree(::Type{SyntaxTree}, stream::ParseStream;
                    filename=nothing, first_line=1,
                    expr_structure=false)
    cursor = RedTreeCursor(stream)
    graph = SyntaxGraph()