unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Ted Zlatanov <tzz@lifelogs.com>
To: emacs-devel@gnu.org
Subject: Re: asking for advice for changing the cfengine.el progmode to support CFEngine 3.x
Date: Wed, 22 Jun 2011 16:24:00 -0500	[thread overview]
Message-ID: <874o3hftlb.fsf@lifelogs.com> (raw)
In-Reply-To: jwvk4cddghq.fsf-monnier+emacs@gnu.org

On Wed, 22 Jun 2011 13:44:02 -0400 Stefan Monnier <monnier@iro.umontreal.ca> wrote: 

>> I tried, but I can't examine the parser state at a buffer point or do
>> anything else to debug the SMIE grammar.  How do you do it?

SM> I use C-M-f and C-M-b (SMIE hooks into these commands so that it jumps
SM> not only over (..) but also pays attention to the defined grammar), as
SM> well as looking at smie-grammar.

Yeesh...  I'm reading the "Parsing Techniques" book you referenced, but
understanding the SMIE grammar table will take me a while.

>> I'm also surprised that Emacs doesn't have a decent LALR parser outside
>> Semantic, and Semantic itself is poorly documented as far as writing new
>> language support.

SM> LALR only works forward, so it requires parsing from the beginning of
SM> the file, which basically forces you to use a cache or something
SM> like that.  OPG on the other hand are bidirectional.

...so you are saying OPG are the way you'd like to go in general?  I
thought syntax tables took care of most of the parsing and state
caching, but honestly I just don't know that area of Emacs well at all.

...
SM>   I don't understand enough of cfengine's grammar to know how best to
SM>   handle this problem (what makes "$(init) restart" into something
SM>   special, is it because it's a string, is it the \n that follows it,
SM>   ...?).

Rather than try to explain the grammar, I'll write it out.  That way the
terminology is clearer; I should have started there instead of giving
you ad-hoc examples.  Sorry about that.  I hope the explanation is
sufficient to clear things up.

There's a lexer and a parser for cfengine3 here:

http://source.cfengine.com/svn/core/trunk/src/cf3parse.y
http://source.cfengine.com/svn/core/trunk/src/cf3lex.l.in

I don't see a formal BNF grammar but the parser is pretty
understandable, standard top-down.  I rewrote it in a condensed form
from the .y file, hoping to make it easier to understand.  I think it's
pretty hard to parse with an OPG, since it's very context-sensitive.

Ted

specification: blocks
blocks: block | blocks block;
block:                 bundle typeid blockid bundlebody
                     | bundle typeid blockid usearglist bundlebody
                     | body typeid blockid bodybody
                     | body typeid blockid usearglist bodybody;

typeid: id
blockid: id
usearglist: '(' aitems ')';
aitems: aitem | aitem ',' aitems |;
aitem: id

bundlebody: '{' statements '}'
statements: statement | statements statement;
statement: category | classpromises;

bodybody: '{' bodyattribs '}'
bodyattribs: bodyattrib | bodyattribs bodyattrib;
bodyattrib: class | selections;
selections: selection | selections selection;
selection: id ASSIGN rval ';' ;

classpromises: classpromise | classpromises classpromise;
classpromise: class | promises;
promises: promise | promises promise;
category: CATEGORY
promise: promiser ARROW rval constraints ';' | promiser constraints ';';
constraints: constraint | constraints ',' constraint |;
constraint: id ASSIGN rval;
class: CLASS
id: ID
rval: ID | QSTRING | NAKEDVAR | list | usefunction
list: '{' litems '}' ;
litems: litem | litem ',' litems |;
litem: ID | QSTRING | NAKEDVAR | list | usefunction

functionid: ID | NAKEDVAR
promiser: QSTRING
usefunction: functionid givearglist
givearglist: '(' gaitems ')'
gaitems: gaitem | gaitems ',' gaitem |;
gaitem: ID | QSTRING | NAKEDVAR | list | usefunction

# from lexer:

bundle: "bundle"
body: "body"
COMMENT    #[^\n]*
NAKEDVAR   [$@][(][a-zA-Z0-9_\200-\377.]+[)]|[$@][{][a-zA-Z0-9_\200-\377.]+[}]
ID: [a-zA-Z0-9_\200-\377]+
ASSIGN: "=>"
ARROW: "->"
QSTRING: \"((\\\")|[^"])*\"|\'((\\\')|[^'])*\'|`[^`]*`
CLASS: [.|&!()a-zA-Z0-9_\200-\377]+::
CATEGORY: [a-zA-Z_]+:




  reply	other threads:[~2011-06-22 21:24 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-06-17 18:11 asking for advice for changing the cfengine.el progmode to support CFEngine 3.x Ted Zlatanov
2011-06-17 22:02 ` Stefan Monnier
2011-06-20 20:42   ` Ted Zlatanov
2011-06-21 14:59     ` Stefan Monnier
2011-06-21 19:26       ` Ted Zlatanov
2011-06-22 17:44         ` Stefan Monnier
2011-06-22 21:24           ` Ted Zlatanov [this message]
2011-06-23 21:31             ` Ted Zlatanov
2011-06-27 15:44               ` Ted Zlatanov
2011-06-30 12:47                 ` Ted Zlatanov
2011-06-30 16:03                   ` Stefan Monnier
2011-06-30 18:25                     ` Ted Zlatanov
2011-06-30 21:10                       ` Stefan Monnier
2011-06-30 21:29                         ` Ted Zlatanov
2011-07-01  8:19                       ` Eli Zaretskii
2011-07-01 10:15                         ` Ted Zlatanov
2011-07-01 11:22                           ` Eli Zaretskii
2011-07-01 13:03                             ` Ted Zlatanov
2011-06-30 16:11               ` Stefan Monnier
2011-06-30 18:28                 ` Ted Zlatanov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=874o3hftlb.fsf@lifelogs.com \
    --to=tzz@lifelogs.com \
    --cc=emacs-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).