Erlang Mailing Lists

Author Message

<  Erlyweb mailing list  ~  Erlang Macros in ErlTL?

Guest
Posted: Sat Aug 11, 2007 2:51 pm Reply with quote
Guest
Has anyone had any luck using Erlang macros in an ErlTL file? I just
tried, and erltl compilation seems to file on the ? at the start.

So, if I have a .et file that looks something like this:

<%~ -include("const_defs.hrl") %>

<%@ index(blah) %>
<% ?MY_CONST %>

Then, erltl:forms_for_file/2 exits with this error:
** exited: {{badmatch,{error,{parse_error,
{4,
erl_parse,
["syntax error before: ",
["'?'"]]}}}},
[{erl_eval,expr,3}]} **

-Bryan


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "erlyweb" group.
To post to this group, send email to erlyweb@googlegroups.com
To unsubscribe from this group, send email to erlyweb-unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.com/group/erlyweb?hl=en
-~----------~----~----~----~------~----~------~--~---

Post recived from mailinglist
khigia
Posted: Sun Aug 12, 2007 2:57 am Reply with quote
User Joined: 27 Mar 2007 Posts: 52
Haven't try it, but not sure it comes from the macro: does it change anything to add some point "." at the end of your "include statement"?

On 8/11/07, Bryan Fink <bryan.fink@gmail.com (bryan.fink@gmail.com)> wrote:[quote]
Has anyone had any luck using Erlang macros in an ErlTL file?
View user's profile Send private message
Guest
Posted: Sun Aug 12, 2007 4:07 am Reply with quote
Guest
I tried it, and it does look like a real bug. I'll fix it.

Thanks,
Yariv

On 8/11/07, Ludovic Coquelle <lcoquelle@gmail.com> wrote:
> Haven't try it, but not sure it comes from the macro: does it change
> anything to add some point "." at the end of your "include statement"?
>
>
> On 8/11/07, Bryan Fink <bryan.fink@gmail.com> wrote:
> >
> > Has anyone had any luck using Erlang macros in an ErlTL file? I just
> > tried, and erltl compilation seems to file on the ? at the start.
> >
> > So, if I have a .et file that looks something like this:
> >
> > <%~ -include("const_defs.hrl") %>
> >
> > <%@ index(blah) %>
> > <% ?MY_CONST %>
> >
> > Then, erltl:forms_for_file/2 exits with this error:
> > ** exited: {{badmatch,{error,{parse_error,
> > {4,
> > erl_parse,
> > ["syntax error before:
> ",
> > ["'?'"]]}}}},
> > [{erl_eval,expr,3}]} **
> >
> > -Bryan
> >
> >
> > > >
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "erlyweb" group.
To post to this group, send email to erlyweb@googlegroups.com
To unsubscribe from this group, send email to erlyweb-unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.com/group/erlyweb?hl=en
-~----------~----~----~----~------~----~------~--~---

Post recived from mailinglist
Guest
Posted: Wed Aug 15, 2007 6:43 am Reply with quote
Guest
So... I did a little more digging and it looks like erl_parse and
erl_scan, which ErlTL uses, don't support macros. Macros are only
handled by epp, the preprocessor. The problems is that epp only works
with complete files, not string snippets. All this means is that
supporting macros in ErlTL is harder than I anticipated.

How critical is this feature? Can you get by without using macros in
ErlTL templates?

BR,
Yariv

On 8/11/07, Yariv Sadan <yarivsadan@gmail.com> wrote:
> I tried it, and it does look like a real bug. I'll fix it.
>
> Thanks,
> Yariv
>
> On 8/11/07, Ludovic Coquelle <lcoquelle@gmail.com> wrote:
> > Haven't try it, but not sure it comes from the macro: does it change
> > anything to add some point "." at the end of your "include statement"?
> >
> >
> > On 8/11/07, Bryan Fink <bryan.fink@gmail.com> wrote:
> > >
> > > Has anyone had any luck using Erlang macros in an ErlTL file? I just
> > > tried, and erltl compilation seems to file on the ? at the start.
> > >
> > > So, if I have a .et file that looks something like this:
> > >
> > > <%~ -include("const_defs.hrl") %>
> > >
> > > <%@ index(blah) %>
> > > <% ?MY_CONST %>
> > >
> > > Then, erltl:forms_for_file/2 exits with this error:
> > > ** exited: {{badmatch,{error,{parse_error,
> > > {4,
> > > erl_parse,
> > > ["syntax error before:
> > ",
> > > ["'?'"]]}}}},
> > > [{erl_eval,expr,3}]} **
> > >
> > > -Bryan
> > >
> > >
> > > > > >
> > >
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "erlyweb" group.
To post to this group, send email to erlyweb@googlegroups.com
To unsubscribe from this group, send email to erlyweb-unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.com/group/erlyweb?hl=en
-~----------~----~----~----~------~----~------~--~---

Post recived from mailinglist
uffe
Posted: Wed Aug 15, 2007 8:09 am Reply with quote
User Joined: 02 Mar 2005 Posts: 365 Location: Sweden
Yariv,

You may recall Mats Cronqvist posting on the subject "compile module
from string, containing macro definitions"?

http://www.erlang.org/pipermail/erlang-questions/2007-March/025507.html

Chris Newcombe followed up with some improvements in
http://www.erlang.org/pipermail/erlang-questions/2007-July/028023.html

That might be a good starting point.

Another way to support macros is to use epp_dodger (in syntax_tools),
It only supports syntactically well-formed macros, but IMHO, this limitation
is shared by most programmers as well. Wink

BR,
Ulf W

2007/8/15, Yariv Sadan <yarivsadan@gmail.com>:
>
> So... I did a little more digging and it looks like erl_parse and
> erl_scan, which ErlTL uses, don't support macros. Macros are only
> handled by epp, the preprocessor. The problems is that epp only works
> with complete files, not string snippets. All this means is that
> supporting macros in ErlTL is harder than I anticipated.
>
> How critical is this feature? Can you get by without using macros in
> ErlTL templates?
>
> BR,
> Yariv
>
> On 8/11/07, Yariv Sadan <yarivsadan@gmail.com> wrote:
> > I tried it, and it does look like a real bug. I'll fix it.
> >
> > Thanks,
> > Yariv
> >
> > On 8/11/07, Ludovic Coquelle <lcoquelle@gmail.com> wrote:
> > > Haven't try it, but not sure it comes from the macro: does it change
> > > anything to add some point "." at the end of your "include statement"?
> > >
> > >
> > > On 8/11/07, Bryan Fink <bryan.fink@gmail.com> wrote:
> > > >
> > > > Has anyone had any luck using Erlang macros in an ErlTL file? I just
> > > > tried, and erltl compilation seems to file on the ? at the start.
> > > >
> > > > So, if I have a .et file that looks something like this:
> > > >
> > > > <%~ -include("const_defs.hrl") %>
> > > >
> > > > <%@ index(blah) %>
> > > > <% ?MY_CONST %>
> > > >
> > > > Then, erltl:forms_for_file/2 exits with this error:
> > > > ** exited: {{badmatch,{error,{parse_error,
> > > > {4,
> > > > erl_parse,
> > > > ["syntax error before:
> > > ",
> > > > ["'?'"]]}}}},
> > > > [{erl_eval,expr,3}]} **
> > > >
> > > > -Bryan
> > > >
> > > >
> > > > > > >
> > > >
> > >
> >
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "erlyweb" group.
To post to this group, send email to erlyweb@googlegroups.com
To unsubscribe from this group, send email to erlyweb-unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.com/group/erlyweb?hl=en
-~----------~----~----~----~------~----~------~--~---

Post recived from mailinglist
View user's profile Send private message Visit poster's website
Guest
Posted: Wed Aug 15, 2007 12:31 pm Reply with quote
Guest
Hi Yariv. Thanks for looking into it.

It's not a huge deal, though. I've worked around it by exporting a
function from another module, which just returns the value of the
[constant] macro. The call isn't in a time-critical spot or anything
(only called once each time a certain page is loaded), so I wouldn't
gain much from compile-time replacement.

So, don't worry about it. Toss it at the end of the list of things
you'd like to design in if a complete rewrite were ever to happen. Wink

-Bryan

On Aug 15, 2:42 am, "Yariv Sadan" <yarivsa...@gmail.com> wrote:
> So... I did a little more digging and it looks like erl_parse and
> erl_scan, which ErlTL uses, don't support macros. Macros are only
> handled by epp, the preprocessor. The problems is that epp only works
> with complete files, not string snippets. All this means is that
> supporting macros in ErlTL is harder than I anticipated.
>
> How critical is this feature? Can you get by without using macros in
> ErlTL templates?
>
> BR,
> Yariv
>
> On 8/11/07, Yariv Sadan <yarivsa...@gmail.com> wrote:
>
> > I tried it, and it does look like a real bug. I'll fix it.
>
> > Thanks,
> > Yariv
>
> > On 8/11/07, Ludovic Coquelle <lcoque...@gmail.com> wrote:
> > > Haven't try it, but not sure it comes from the macro: does it change
> > > anything to add some point "." at the end of your "include statement"?
>
> > > On 8/11/07, Bryan Fink <bryan.f...@gmail.com> wrote:
>
> > > > Has anyone had any luck using Erlang macros in an ErlTL file? I just
> > > > tried, and erltl compilation seems to file on the ? at the start.
>
> > > > So, if I have a .et file that looks something like this:
>
> > > > <%~ -include("const_defs.hrl") %>
>
> > > > <%@ index(blah) %>
> > > > <% ?MY_CONST %>
>
> > > > Then, erltl:forms_for_file/2 exits with this error:
> > > > ** exited: {{badmatch,{error,{parse_error,
> > > > {4,
> > > > erl_parse,
> > > > ["syntax error before:
> > > ",
> > > > ["'?'"]]}}}},
> > > > [{erl_eval,expr,3}]} **
>
> > > > -Bryan


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "erlyweb" group.
To post to this group, send email to erlyweb@googlegroups.com
To unsubscribe from this group, send email to erlyweb-unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.com/group/erlyweb?hl=en
-~----------~----~----~----~------~----~------~--~---

Post recived from mailinglist

Display posts from previous:  

All times are GMT
Page 1 of 1
This forum is locked: you cannot post, reply to, or edit topics.

Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum