Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Exports custom API in the grammar file
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  2 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Giovanni Giacobbi  
View profile  
 More options Jul 7 2012, 5:26 pm
From: Giovanni Giacobbi <giovann...@gmail.com>
Date: Sat, 7 Jul 2012 14:26:50 -0700 (PDT)
Local: Sat, Jul 7 2012 5:26 pm
Subject: Exports custom API in the grammar file

Good morning or good afternoon, depending where you are.

I wrote my first grammar today with PEG and I think it's an awesome tool.
Anyway, I ran into a sort of design limitation. My grammar describe a
simple template parser, the problem is that I would like to isolate
everything in the grammar file, and have a full template engine in that
file.

This translates to a very simple requirement: being able to export a
function to the public interface of the parser, which now contains only
parse().
Basically what my new method would do is something like:

  function templateEngine(tpl, vars, callback) {
    var node = this.parse(tpl);
    if (node == "IfStatement") {
      callback.call("IfStatement", this.resolve(node.condition, vars));
    }
    else if ( .... )
  }

So as you can see it's very simple logic, that would otherwise need to go
into my main application file or yet another file with only this two
functions that wraps the generated parser.
I hope the purpose it's clear, I don't feel very expressive today. What I
want is a way to publish a function to the same level of the "parse:" call.
Any ideas?
Thank you. This tool rocks.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
David Majda  
View profile  
 More options Jul 29 2012, 10:47 am
From: David Majda <da...@majda.cz>
Date: Sun, 29 Jul 2012 16:47:45 +0200
Local: Sun, Jul 29 2012 10:47 am
Subject: Re: Exports custom API in the grammar file
2012/7/7 Giovanni Giacobbi <giovann...@gmail.com>:

> Anyway, I ran into a sort of design limitation. My grammar describe a simple
> template parser, the problem is that I would like to isolate everything in
> the grammar file, and have a full template engine in that file.

> This translates to a very simple requirement: being able to export a
> function to the public interface of the parser, which now contains only
> parse().

Parsers should just parse, period :-) Extending their interface in any
way beyond this is a violation of the single responsibility principle.
I won't add such a feature.

The correct approach is to include your parser into the object
providing the additional functionality (i.e. use composition). If you
target Node.js you can do it easily using modules, if not, there are
other ways.

--
David Majda
Entropy fighter
http://majda.cz/


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »