=================
Modules
=================

module A

module B
end

module C
end

end

---

(source_file
  (module_definition (identifier)
    (module_definition (identifier))
    (module_definition (identifier))))


=================
Structs
=================

# primitive
primitive type T 8 end
primitive type T <: S 16 end
primitive type Ptr{T} 32 end

# abstract
abstract type T end
abstract type T <: S end
abstract type T{S} <: U end

# empty
struct NoFields
end

# mutable
mutable struct Bar
  baz
  qux::Float64
end

# parametric
struct Point{T}
  x::T
  y::T
end

# parametric with constraints, parent type
struct Rational{T<:Integer} <: Real
  num::T
  den::T
end

# parametric fields
mutable struct Foo<:Bar
  asd::Vector{Bar}
end

---

(source_file
  (line_comment)
  (primitive_definition
    (identifier)
    (integer_literal))
  (primitive_definition
    (identifier)
    (subtype_clause (identifier))
    (integer_literal))
  (primitive_definition
    (identifier)
    (type_parameter_list
      (identifier))
    (integer_literal))
  (line_comment)
  (abstract_definition
    (identifier))
  (abstract_definition
    (identifier)
    (subtype_clause (identifier)))
  (abstract_definition
    (identifier)
    (type_parameter_list
      (identifier))
    (subtype_clause (identifier)))
  (line_comment)
  (struct_definition
    (identifier))
  (line_comment)
  (struct_definition
    (identifier)
    (identifier)
    (typed_expression (identifier) (identifier)))
  (line_comment)
  (struct_definition
    (identifier)
    (type_parameter_list (identifier))
    (typed_expression (identifier) (identifier))
    (typed_expression (identifier) (identifier)))
  (line_comment)
  (struct_definition
    (identifier)
    (type_parameter_list (constrained_parameter (identifier) (identifier)))
    (subtype_clause (identifier))
    (typed_expression (identifier) (identifier))
    (typed_expression (identifier) (identifier)))
  (line_comment)
  (struct_definition
    (identifier)
    (subtype_clause (identifier))
    (typed_expression
      (identifier)
      (parameterized_identifier (identifier) (type_argument_list (identifier))))))

===============================
Functions with typed parameters
===============================

function a(b::C)
end

function d{E}(f::E)
end

---

(source_file
  (function_definition
    (identifier)
    (parameter_list (typed_parameter (identifier) (identifier))))
  (function_definition
    (identifier)
    (type_parameter_list (identifier))
    (parameter_list (typed_parameter (identifier) (identifier)))))

===============================================
Functions with optional and keyword parameters
===============================================

function a(b::C = 1; d, e::F = 2)
end

---

(source_file
  (function_definition
    (identifier)
    (parameter_list
      (optional_parameter (typed_parameter (identifier) (identifier)) (integer_literal))
      (keyword_parameters
        (identifier)
        (optional_parameter
          (typed_parameter (identifier) (identifier))
          (integer_literal))))))

============================
Macro definitions
======================

macro treelike(T, fs = nothing)
  fs = [:($(map(QuoteNode, fs.args)...),)]
  :(treelike(@__MODULE__, $(esc(T)), $(fs...)))
end

---

(source_file
  (macro_definition
    (identifier)
    (parameter_list (identifier) (optional_parameter (identifier) (identifier)))
    (assignment_expression
      (identifier)
      (operator)
      (array_expression
        (quote_expression
          (tuple_expression
            (interpolation_expression
              (parenthesized_expression (spread_expression
                (call_expression
                  (identifier)
                  (argument_list
                    (identifier)
                    (field_expression (identifier) (identifier)))))))))))
    (quote_expression
      (parenthesized_expression
        (call_expression
          (identifier)
          (argument_list
            (macro_expression (macro_identifier (identifier)))
            (interpolation_expression (parenthesized_expression
              (call_expression (identifier) (argument_list (identifier)))))
            (interpolation_expression (parenthesized_expression
              (spread_expression (identifier))))))))))
