From db508c0d0f21d93af291f4c2d97dccd7320acbbf Mon Sep 17 00:00:00 2001 From: Daniel Flanagan Date: Tue, 19 Nov 2019 21:11:28 -0600 Subject: [PATCH] More resources --- README.md | 9 +++++++++ lib/lytlang.ex | 12 ++++++++---- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index da253b0..204cfb1 100644 --- a/README.md +++ b/README.md @@ -72,6 +72,15 @@ probably never even happen. ## Development Resources ++ https://hexdocs.pm/elixir/syntax-reference.html#the-elixir-ast ++ https://medium.com/cirru-project/resources-on-elixir-ast-e045b613f284 ++ https://elixir-lang.org/getting-started/meta/quote-and-unquote.html ++ https://hexdocs.pm/elixir/Kernel.SpecialForms.html ++ http://slides.com/chrismccord/elixir-macros ++ http://zhenwusw.github.io/blog/2014/10/20/metaprogramming ++ https://www.theerlangelist.com/2014/06/understanding-elixir-macros-part-1.html ++ https://www.theerlangelist.com/2014/06/understanding-elixir-macros-part-3.html ++ https://pragprog.com/book/cmelixir/metaprogramming-elixir + https://pl-rants.net/posts/leex-yecc-in-elixir/ + https://notes.eellson.com/2017/01/22/html-parsing-in-elixir-with-leex-and-yecc/ + https://github.com/elixir-lang/elixir/commits/master?after=e2c78e8ba948739768a335999e35a06d5eb5ad4b+15680 diff --git a/lib/lytlang.ex b/lib/lytlang.ex index d3d4c7f..d6b3442 100644 --- a/lib/lytlang.ex +++ b/lib/lytlang.ex @@ -10,13 +10,20 @@ defmodule Lytlang do value end - def from_lytlang(string, binding \\ [], opts \\ []) do + def from_lytlang( + code, + binding \\ [context: @root_module, import: Kernel, import: Elixir], + opts \\ [] + ) + + def from_lytlang(string, binding, opts) do string |> String.to_charlist() |> tokenize() |> parse() |> to_ast_node(binding, opts) |> to_elixir_ast(opts) + |> IO.inspect(label: "EX AST") end def tokenize(string) do @@ -49,12 +56,10 @@ defmodule Lytlang do def to_elixir_ast({{:literal, expr}, {_meta, _binding, _ast_opts}, _leaves}, _opts) do expr - |> IO.inspect(label: "EX AST") end def to_elixir_ast({s, {_meta, binding, _ast_opts}, leaves}, _opts) do {s, binding, to_elixir_ast(leaves)} - |> IO.inspect(label: "EX AST") end @spec to_ast_node(any, keyword, keyword) :: astnode @@ -67,7 +72,6 @@ defmodule Lytlang do {_s, {_meta, binding, opts}, _operands} -> {s, {nmeta, nbinding, nopts}, operands} = to_ast_node(expr, binding, opts) - {s, {nmeta, Keyword.merge(binding, nbinding), Keyword.merge(opts, nopts)}, operands} end) end