From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Ted Zlatanov Newsgroups: gmane.emacs.devel 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 Organization: =?utf-8?B?0KLQtdC+0LTQvtGAINCX0LvQsNGC0LDQvdC+0LI=?= @ Cienfuegos Message-ID: <874o3hftlb.fsf@lifelogs.com> References: <87mxhgl44t.fsf@lifelogs.com> <87r56oz146.fsf@lifelogs.com> <87fwn3oujj.fsf@lifelogs.com> Reply-To: emacs-devel@gnu.org NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: dough.gmane.org 1308777892 5494 80.91.229.12 (22 Jun 2011 21:24:52 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Wed, 22 Jun 2011 21:24:52 +0000 (UTC) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Wed Jun 22 23:24:47 2011 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([140.186.70.17]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1QZUug-0000I3-OK for ged-emacs-devel@m.gmane.org; Wed, 22 Jun 2011 23:24:42 +0200 Original-Received: from localhost ([::1]:51647 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QZUuf-0001h9-AD for ged-emacs-devel@m.gmane.org; Wed, 22 Jun 2011 17:24:41 -0400 Original-Received: from eggs.gnu.org ([140.186.70.92]:58030) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QZUuM-0001g4-5R for emacs-devel@gnu.org; Wed, 22 Jun 2011 17:24:23 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QZUuJ-0001dJ-Gb for emacs-devel@gnu.org; Wed, 22 Jun 2011 17:24:22 -0400 Original-Received: from lo.gmane.org ([80.91.229.12]:34645) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QZUuI-0001cx-Sp for emacs-devel@gnu.org; Wed, 22 Jun 2011 17:24:19 -0400 Original-Received: from list by lo.gmane.org with local (Exim 4.69) (envelope-from ) id 1QZUuE-0008TC-Re for emacs-devel@gnu.org; Wed, 22 Jun 2011 23:24:14 +0200 Original-Received: from 38.98.147.133 ([38.98.147.133]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Wed, 22 Jun 2011 23:24:14 +0200 Original-Received: from tzz by 38.98.147.133 with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Wed, 22 Jun 2011 23:24:14 +0200 X-Injected-Via-Gmane: http://gmane.org/ Mail-Followup-To: emacs-devel@gnu.org Original-Lines: 103 Original-X-Complaints-To: usenet@dough.gmane.org X-Gmane-NNTP-Posting-Host: 38.98.147.133 X-Face: bd.DQ~'29fIs`T_%O%C\g%6jW)yi[zuz6; d4V0`@y-~$#3P_Ng{@m+e4o<4P'#(_GJQ%TT= D}[Ep*b!\e,fBZ'j_+#"Ps?s2!4H2-Y"sx" Mail-Copies-To: never User-Agent: Gnus/5.110018 (No Gnus v0.18) Emacs/24.0.50 (gnu/linux) Cancel-Lock: sha1:5eTZoymtFnUzGSsgMqTWKZlG+J0= X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-Received-From: 80.91.229.12 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:140884 Archived-At: On Wed, 22 Jun 2011 13:44:02 -0400 Stefan Monnier 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_]+: