Skip to content

Conversation

@mmiller-max
Copy link
Contributor

Adds macros to define StructTypes, see #64

Example use:

help?> StructTypes.@Struct
  @StructTypes.Struct(expr::Expr)
  @StructTypes.Struct(expr::Symbol)

  If expr is a struct definition, sets the StructType of the defined struct to StructTypes.Struct(). If expr is the name of a Type,
  sets the StructType of that type to StructTypes.Struct().

  Examples
  ≡≡≡≡≡≡≡≡≡≡

  @StructTypes.Struct MyStruct

  is equivalent to

  StructTypes.StructType(::Type{MyStruct}) = StructType.Struct()

  and

  @StructTypes.Struct struct MyStruct
      val::Int
  end

  is equivalent to

  struct MyStruct
      val::Int
  end
  StructTypes.StructType(::Type{MyStruct}) = StructType.Struct()

Ideally they would be exported as well, to minimise how much typing was required.

If this seems something we would want I'll add tests and docs.

Copy link
Member

@quinnj quinnj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I like this idea. Would you mind adding some tests in the test/runtests.jl file to ensure the codepaths are exercised? Probably don't need to test each type, but at least the various symbol/expr forms.

src/macros.jl Outdated
for struct_type in (:Struct, :Mutable, :CustomStruct, :OrderedStruct, :AbstractType, :DictType, :ArrayType, :StringType, :NumberType, :BoolType, :NullType)
@eval begin
@doc """
@$($struct_type)(expr::Expr)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From the tests, it seems like we're over-interpolating here; maybe change to @$(Meta.quot($struct_type))

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's possibly to do with the macros being evaluated before the struct types exist - moving the include statement to the end of StructTypes.jl seems to work.

@$(Meta.quot($struct_type)) made the docs look a bit funny:

help?> StructTypes.@DictType
  @:(StructTypes.DictType)(expr::Expr)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, that makes sense. do you want to push your change then?

@mmiller-max
Copy link
Contributor Author

Changed the docs (it had @StructTypes.Struct before) and improved the wording in the error messages. Do you want me add something to the docs, and is it worth exporting the macros too?

@codecov
Copy link

codecov bot commented Sep 23, 2021

Codecov Report

Merging #65 (7e62529) into main (cc49757) will increase coverage by 0.70%.
The diff coverage is 90.90%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main      #65      +/-   ##
==========================================
+ Coverage   72.83%   73.53%   +0.70%     
==========================================
  Files           1        2       +1     
  Lines         346      359      +13     
==========================================
+ Hits          252      264      +12     
- Misses         94       95       +1     
Impacted Files Coverage Δ
src/StructTypes.jl 72.98% <ø> (+0.15%) ⬆️
src/macros.jl 90.90% <90.90%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update cc49757...7e62529. Read the comment docs.

@quinnj quinnj merged commit 8e8aa4a into JuliaData:main Oct 2, 2021
@mmiller-max mmiller-max mentioned this pull request Nov 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants