JuliaSyntax.jl icon indicating copy to clipboard operation
JuliaSyntax.jl copied to clipboard

some errors when parsing `test/syntax.jl`

Open simeonschaub opened this issue 3 years ago • 2 comments

I thought that file might be a good stress test of this package. It seems to do quite well. The first case is probably up to interpretation, since although the flisp parser parses it, it's definitely not valid syntax. There does seem to be a bug in parsing empty multidimensional array literals though:

julia> JuliaSyntax.parseall(JuliaSyntax.SyntaxNode, read("test/syntax.jl"); filename=abspath("test/syntax.jl"))
ERROR: Error: Expected identifier:
@test !@isdefined(y)

@test_throws ErrorException eval(:(import .Mod.x as (a.b)))

import .Mod.maybe_undef as mu

Error: unexpected closing token:
@testset "empty nd arrays" begin
    @test :([])    == Expr(:vect)
    @test :([;])   == Expr(:ncat, 1)
    @test :([;;])  == Expr(:ncat, 2)
    @test :([;;;]) == Expr(:ncat, 3)

Error: unexpected closing token:
    @test :([])    == Expr(:vect)
    @test :([;])   == Expr(:ncat, 1)
    @test :([;;])  == Expr(:ncat, 2)
    @test :([;;;]) == Expr(:ncat, 3)


Error: unexpected closing token:
    @test :([;])   == Expr(:ncat, 1)
    @test :([;;])  == Expr(:ncat, 2)
    @test :([;;;]) == Expr(:ncat, 3)

    @test []    == Array{Any}(undef, 0)

Error: unexpected closing token:

    @test []    == Array{Any}(undef, 0)
    @test [;]   == Array{Any}(undef, 0)
    @test [;;]  == Array{Any}(undef, 0, 0)
    @test [;;;] == Array{Any}(undef, 0, 0, 0)

Error: unexpected closing token:
    @test []    == Array{Any}(undef, 0)
    @test [;]   == Array{Any}(undef, 0)
    @test [;;]  == Array{Any}(undef, 0, 0)
    @test [;;;] == Array{Any}(undef, 0, 0, 0)


Error: unexpected closing token:
    @test [;]   == Array{Any}(undef, 0)
    @test [;;]  == Array{Any}(undef, 0, 0)
    @test [;;;] == Array{Any}(undef, 0, 0, 0)

    @test :(T[])    == Expr(:ref, :T)

Error: unexpected closing token:

    @test :(T[])    == Expr(:ref, :T)
    @test :(T[;])   == Expr(:typed_ncat, :T, 1)
    @test :(T[;;])  == Expr(:typed_ncat, :T, 2)
    @test :(T[;;;]) == Expr(:typed_ncat, :T, 3)

Error: unexpected closing token:
    @test :(T[])    == Expr(:ref, :T)
    @test :(T[;])   == Expr(:typed_ncat, :T, 1)
    @test :(T[;;])  == Expr(:typed_ncat, :T, 2)
    @test :(T[;;;]) == Expr(:typed_ncat, :T, 3)


Error: unexpected closing token:
    @test :(T[;])   == Expr(:typed_ncat, :T, 1)
    @test :(T[;;])  == Expr(:typed_ncat, :T, 2)
    @test :(T[;;;]) == Expr(:typed_ncat, :T, 3)

    @test Int[]    == Array{Int}(undef, 0)

Error: unexpected closing token:

    @test Int[]    == Array{Int}(undef, 0)
    @test Int[;]   == Array{Int}(undef, 0)
    @test Int[;;]  == Array{Int}(undef, 0, 0)
    @test Int[;;;] == Array{Int}(undef, 0, 0, 0)

Error: unexpected closing token:
    @test Int[]    == Array{Int}(undef, 0)
    @test Int[;]   == Array{Int}(undef, 0)
    @test Int[;;]  == Array{Int}(undef, 0, 0)
    @test Int[;;;] == Array{Int}(undef, 0, 0, 0)


Error: unexpected closing token:
    @test Int[;]   == Array{Int}(undef, 0)
    @test Int[;;]  == Array{Int}(undef, 0, 0)
    @test Int[;;;] == Array{Int}(undef, 0, 0, 0)

    @test :([  ]) == Expr(:vect)

Error: unexpected closing token:
    @test :([
            ]) == Expr(:vect)
    @test :([ ;; ]) == Expr(:ncat, 2)
    @test :([
             ;;

Error: unexpected closing token:
    @test :([ ;; ]) == Expr(:ncat, 2)
    @test :([
             ;;
            ]) == Expr(:ncat, 2)

Once those are fixed, I think that would be a good test case for CI.

simeonschaub avatar Feb 05 '22 03:02 simeonschaub

Yes indeed, I noticed you'd just added those cases recently in Base :sweat_smile:

If you look in the JuliaSyntax tests you'll see there's a plan in motion to parse all of Base test and the stdlibs... but we're not there yet:

https://github.com/c42f/JuliaSyntax.jl/blob/e11f4688202debcce3600782f07b505a21ab40ec/test/parse_packages.jl#L17

Once I get individual cases of syntax working, I've been adding them as AST unit tests in two places:

  1. As annotations on (ideally) every branch in the parser. For example https://github.com/c42f/JuliaSyntax.jl/blob/e11f4688202debcce3600782f07b505a21ab40ec/src/parser.jl#L2734
  2. As a corresponding parser unit test at https://github.com/c42f/JuliaSyntax.jl/blob/e11f4688202debcce3600782f07b505a21ab40ec/test/parser.jl#L576

Ideally (2) would be created automatically from (1) (including attributing the correct line in the source!) but this is still to be done.

You can see there's some made up S-Expression syntax for compactly and unambiguously specifying how a given expression parses into an AST.

As AST tests, these leave out trivia handling. So in addition to these, we'll eventually need tests for the green tree of each of these cases as well.

c42f avatar Feb 07 '22 01:02 c42f

Additionally, there's a list of other tests which are currently broken at

https://github.com/c42f/JuliaSyntax.jl/blob/e11f4688202debcce3600782f07b505a21ab40ec/test/parser.jl#L663-L682

c42f avatar Feb 07 '22 01:02 c42f

All these have been fixed for some time, I think :-)

c42f avatar May 07 '23 09:05 c42f