-
Notifications
You must be signed in to change notification settings - Fork 51
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Help to create a Macro that use defparsec #27
Comments
Where is |
Hi @meox! As @whatyouhide said, make sure that all variables are unquoted, otherwise you will get undefined function/variable errors. |
Ok, I've moved my code in the same module. defmodule RuleC.Macro do
import NimbleParsec
# some other stuff here
defmacro named_parser(name, parser, tag) do
quote do
defparsec(
unquote(name),
symbol
|> map({:extract, []})
|> ignore(spaces)
|> optional(int_t |> tag(:tag))
|> ignore(spaces)
|> ignore(ascii_char([?:]))
|> ignore(spaces1)
|> concat(unquote(parser))
|> tag(unquote(tag))
|> map({:data_field_prettify, []})
)
end
end
named_parser(
:data_map_type,
parsec(:data_anonymous_map_t),
:tag_data_map_type
)
end I'm getting:
I semplified the problem with this stupid module: defmodule TestMacro do
defmacro my_macro(x) do
quote do
unquote(x) + 1
end
end
def my_fun() do
my_macro(5)
end
end This works (as expected) but not this one: defmodule TestMacro do
defmacro my_macro(x) do
quote do
unquote(x) + 1
end
end
my_macro(5)
end So seems that I have to define the macro in a different module. Is it right? |
Yes, exactly. |
In order to resolve this issue I found now another problem: I'm going to explain it better.
RuleC.BasicDef "import" NimbleParsec Inside RuleC.Parser there are many defparsec that use parser defined in RuleC.BasicDef.
Any suggestion? |
I'm trying to write a super-parser, smthg like this:
but it doesn't works.
So I tried this:
but I get this error:
Any suggestion?
The text was updated successfully, but these errors were encountered: