~sjm/notesviz_parse

e8310113534ab369034d3be9a4f783ca9ae1cf91 — Sam Marshall 3 years ago 3d3d203
initial commit
A .formatter.exs => .formatter.exs +4 -0
@@ 0,0 1,4 @@
# Used by "mix format"
[
  inputs: ["{mix,.formatter}.exs", "{config,lib,test}/**/*.{ex,exs}"]
]

A .gitignore => .gitignore +27 -0
@@ 0,0 1,27 @@
# The directory Mix will write compiled artifacts to.
/_build/

# If you run "mix test --cover", coverage assets end up here.
/cover/

# The directory Mix downloads your dependencies sources to.
/deps/

# Where third-party dependencies like ExDoc output generated docs.
/doc/

# Ignore .fetch files in case you like to edit your project deps locally.
/.fetch

# If the VM crashes, it generates a dump, let's ignore it too.
erl_crash.dump

# Also ignore archive artifacts (built via "mix archive.build").
*.ez

# Ignore package tarball (built via "mix hex.build").
notesviz_parse-*.tar


# Temporary files for e.g. tests
/tmp

A README.md => README.md +21 -0
@@ 0,0 1,21 @@
# NotesvizParse

**TODO: Add description**

## Installation

If [available in Hex](https://hex.pm/docs/publish), the package can be installed
by adding `notesviz_parse` to your list of dependencies in `mix.exs`:

```elixir
def deps do
  [
    {:notesviz_parse, "~> 0.1.0"}
  ]
end
```

Documentation can be generated with [ExDoc](https://github.com/elixir-lang/ex_doc)
and published on [HexDocs](https://hexdocs.pm). Once published, the docs can
be found at [https://hexdocs.pm/notesviz_parse](https://hexdocs.pm/notesviz_parse).


A lib/notesviz_parse.ex => lib/notesviz_parse.ex +18 -0
@@ 0,0 1,18 @@
defmodule NotesvizParse do
  @moduledoc """
  Documentation for `NotesvizParse`.
  """

  @doc """
  Hello world.

  ## Examples

      iex> NotesvizParse.hello()
      :world

  """
  def hello do
    :world
  end
end

A lib/notesviz_parse/application.ex => lib/notesviz_parse/application.ex +20 -0
@@ 0,0 1,20 @@
defmodule NotesvizParse.Application do
  # See https://hexdocs.pm/elixir/Application.html
  # for more information on OTP Applications
  @moduledoc false

  use Application

  @impl true
  def start(_type, _args) do
    children = [
      # Starts a worker by calling: NotesvizParse.Worker.start_link(arg)
      # {NotesvizParse.Worker, arg}
    ]

    # See https://hexdocs.pm/elixir/Supervisor.html
    # for other strategies and supported options
    opts = [strategy: :one_for_one, name: NotesvizParse.Supervisor]
    Supervisor.start_link(children, opts)
  end
end

A mix.exs => mix.exs +25 -0
@@ 0,0 1,25 @@
defmodule NotesvizParse.MixProject do
  use Mix.Project
    def project do
      [
        app: :notesviz_parse,
        version: "0.1.0",
        elixir: "~> 1.11",
        start_permanent: Mix.env() == :prod,
        deps: deps()
      ]
    end
  # Run "mix help compile.app" to learn about applications.
    def application do
      [
        extra_applications: [:logger],
        mod: {NotesvizParse.Application, []}
      ]
    end
    # Run "mix help deps" to learn about dependencies.
    defp deps do
      [
        {:nimble_parsec, "~> 1.0"}
      ]
    end
end

A notesviz_parse.org => notesviz_parse.org +72 -0
@@ 0,0 1,72 @@
* Notesviz Parse

This elixir application will at first be responsible for extracting the links out of org files. Eventually, it may parse more types of links, or more parts of org files. Or both.

The information gained is intended to be used throughout notesviz.

** A note on literate programming

I'm new to Elixir, so a lot of this will be exploration. As a result, I thought that the literate programming approach would make a lot of sense.

I've generated a basic Elixir project, and I'll be "importing" the pre-existing files into the literate environment only when it makes sense to - namely, when I need to edit them in some way. I'll try and avoid deconstructing these files for its own sake, but will do so when it improves clarity for me.

I'm fairly new to literate programming, too - especially within org-mode. But I'm familiar enough with org-mode that I'm fairly comfortable. I think we can only see how this goes.

** Config

A standard mix file, slightly deconstructed for neatness

#+begin_src elixir :noweb-ref defproject
  def project do
    [
      app: :notesviz_parse,
      version: "0.1.0",
      elixir: "~> 1.11",
      start_permanent: Mix.env() == :prod,
      deps: deps()
    ]
  end
#+end_src

"Run "mix help compile.app" to learn about applications."
#+begin_src elixir :noweb-ref defapplication
  def application do
    [
      extra_applications: [:logger],
      mod: {NotesvizParse.Application, []}
    ]
  end
#+end_src

"Run "mix help deps" to learn about dependencies."
#+begin_src elixir :noweb-ref defdeps :noweb yes
  defp deps do
    [
      <<deps>>
    ]
  end
#+end_src

#+begin_src elixir :tangle ./mix.exs :noweb yes
defmodule NotesvizParse.MixProject do
  use Mix.Project
  <<defproject>>
  <<defapplication>>
  <<defdeps>>
end

#+end_src

** Parsing a link

While I've barely touched Elixir before, I'm a little familiar with parser combinators in other languages. So I had a google to see what was out there and the first library to pop up for Elixir was [[https://github.com/dashbitco/nimble_parsec][nimble parsec]]. This seems like as good a start as any, so I'll begin by adding this as a dependency to the library.

#+begin_src elixir :noweb-ref deps
{:nimble_parsec, "~> 1.0"}
#+end_src

I've never used this library before, though - so might need a little bit of play. I think the first goal is to parse just an org-mode link by itself. This looks like as follows

: [[target][name]]

where target refers to the file or place the link will lead to, and the name is the part generally displayed to the user.

A test/notesviz_parse_test.exs => test/notesviz_parse_test.exs +8 -0
@@ 0,0 1,8 @@
defmodule NotesvizParseTest do
  use ExUnit.Case
  doctest NotesvizParse

  test "greets the world" do
    assert NotesvizParse.hello() == :world
  end
end

A test/test_helper.exs => test/test_helper.exs +1 -0
@@ 0,0 1,1 @@
ExUnit.start()