steele232

steele232

Hello Ash friends,

I’m working on implementing a relatively simple DSL. Mostly just a fancy formatting for data, since I know the Spark DSL renders out to plain Elixir maps/structs etc.

I’m working on following the Getting Started guide here: Spark — spark v2.7.2

and I’ve worked through the example to the point that I think it makes sense but I’m getting some compiler errors.

First: the code I’m working with – code snippets here should give you an idea of what I’m building.

# lib/legacy_dsl/application/dsl.ex
defmodule LegacyDSL.Application.Dsl do
  use Spark.Dsl,
    default_extensions: [
      extensions: [LegacyDSL.Application.ApplicationExtension]
    ]
end

#lib/legacy_dsl/application/application_extension.ex
defmodule LegacyDSL.Application.ApplicationExtension do
  defmodule Component do
    # The __spark_metadata__ field is required for Spark entities
    # It stores source location information for better error messages and tooling
    defstruct [:name, :description, :__spark_metadata__]
  end

  @component %Spark.Dsl.Entity{
    name: :component,
    args: [:name, :description],
    target: Component,
    describe: "A component that is either reusable or swappable, the user has some intuition around working with it",
    schema: [
      name: [
        type: :atom,
        required: true,
        doc: "The name of the field"
      ],
      type: [
        type: :string,
        required: false,
        doc: "The type of the field"
      ],
    ]
  }

  @overview %Spark.Dsl.Section{
    name: :overview,
    schema: [
      name: [
        type: :string,
        doc: "Name of the software system"
      ],
      system_maintainer: [
        type: {:list, :atom},
        doc: "Name of responsible system owners"
      ],
      prior_system_maintainer: [
        type: {:list, :atom},
        doc: "Name of prior system owners"
      ],
    ],
    entities: [
      @component,
        #--> @negativeBranch,
      #   @stateLocation
      #   @polymorphism / combinatorics of configurations
    ],
    describe: """
    Global System description for the software
    """
  }

  use Spark.Dsl.Extension, sections: [@overview]

  # def dsl_patches do
  #   :ok
  # end
end

#lib/legacy_dsl/application.ex
defmodule LegacyDSL.Application do

  @overview %Spark.Dsl.Section{
    name: :overview,
    describe: """
    Global System description for the software
    """,
    schema: [
      system_maintainer: [
        type: {:list, :atom},
        doc:
          "Name of responsible system owners"
      ],
      prior_system_maintainer: [
        type: {:list, :atom},
        doc:
          "Name of prior system owners"
      ],
    ],
    # entities: [
    #   @negativeBranch,
    #   @component,
    #   @stateLocation
    # ]
  }

  @sections [@overview]
  # TODO userset


  use Spark.Dsl.Extension,
      sections: @sections
      # transformers: [
      # ],
      # verifiers: [
      # ]

end

And… here’s me trying to use the newly created DSL and … getting my errors

defmodule LegacyDSL.ExampleUsage do
  use LegacyDSL.Application.Dsl

  application do
    overview do
      system_maintainer [:me]
      prior_system_maintainer [:jp]

      components do

      end
    end
  end


end

Errors while trying to run with iex -S mix :

== Compilation error in file lib/legacy_dsl/example_usage.ex ==
** (CompileError) lib/legacy_dsl/example_usage.ex: cannot compile module LegacyDSL.ExampleUsage (errors have been logged)

:error
iex(6)> recompile()
Compiling 4 files (.ex)
    error: undefined function application/1 (there is no such import)
    │
  4 │   application do
    │   ^
    │
    └─ lib/legacy_dsl/example_usage.ex:4:3: LegacyDSL.ExampleUsage (module)

I’m sure there could be some user error, especially as the DSL expands, etc. I’m not really sure what to put under components .. but more especially I’m focused on the error which says that application is not recognized.
I’m trying to use it in the same way I’ve defined Ash resources. I’m also trying to reference the DSL extension stuff in the ash_graphql hex pkg.
I also tried doing a overview block instead of the application block and I get basically the same error:

% iex -S mix 
Erlang/OTP 28 [erts-16.3] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] [jit] [dtrace]

Compiling 4 files (.ex)
    error: undefined function components/1 (there is no such import)
    │
 21 │     components do
    │     ^
    │
    └─ lib/legacy_dsl/example_usage.ex:21:5: LegacyDSL.ExampleUsage (module)


== Compilation error in file lib/legacy_dsl/example_usage.ex ==
** (CompileError) lib/legacy_dsl/example_usage.ex: cannot compile module LegacyDSL.ExampleUsage (errors have been logged)
    expanding macro: LegacyDSL.Application.ApplicationExtension.overview/1

Anyway. I feel like I’ve done some pretty good due diligence in trying to get this to work. Any help from the community is very much appreciated. Thank you in advance!

Showing Posts 1 to 2

zachdaniel

zachdaniel

Creator of Ash

Your top is called overview. If you want to use

application do

end

then you’d need to have a section called :application, with a section called :overview inside of it.

steele232

steele232 OP

Ah. That does help orient me to look in the right place.

I ended up finding an error in my entities definition. Also cloning down ash_graphql to take a closer look at that DSL extension and also the Ash DSL (seeing a working example) helped.

So.. yup I got it working in the end :tada: When I get some time, I’ll try and post the working minimal version.

— All posts loaded —

Where Next? Top

Trending in Questions Top

RSP87
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
kszambelanczyk
Hello! Could someone please give me a help/sample code, how to delete a file from s3 using waffle/waffle_ecto from Phoenix app. I creat...
New
RemyXRenard
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
velrest
So my question is quite simple and i have found no conclusive answer on forum, google or AI. Should we use :erlang.float for Integer to ...
New
samoloth
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
FlyingNoodle
If a change or preparation module uses Ash.Changeset.get_argument/2 or Ash.Query.get_argument/2 (or any of the other get_argument functio...
New
psy-q
I’m trying to set up Emacs with elixir-ls via lsp-mode and credo via Flycheck. This should mostly be preconfigured as Flycheck picks up c...
New

Other Trending Topics Top

mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Dmk
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve. They are GUI (Emerge) and State management (S...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews