unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
From: Jan Nieuwenhuizen <janneke@gnu.org>
To: guile-devel <guile-devel@gnu.org>
Subject: [PATCH 2/2] LALR-parser: transparent source locations using source-proprerties.
Date: Sat,  2 Aug 2014 09:58:31 +0200	[thread overview]
Message-ID: <1406966311-19014-3-git-send-email-janneke@gnu.org> (raw)
In-Reply-To: <1406966311-19014-1-git-send-email-janneke@gnu.org>

	* module/system/base/lalr.upstream.scm (lalr-parser): Add
	token argument to push.
	(lr-driver): (___push): Transparently set source location from
	token using source-properties.
---
 module/system/base/lalr.upstream.scm | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/module/system/base/lalr.upstream.scm b/module/system/base/lalr.upstream.scm
index b250c23..871c931 100755
--- a/module/system/base/lalr.upstream.scm
+++ b/module/system/base/lalr.upstream.scm
@@ -1609,7 +1609,10 @@
 				   '()))
 			,(if (= nt 0)
 			     '$1
-			     `(___push ,n ,nt ,(cdr p) ,@(if (eq? driver-name 'lr-driver) '() '(___sp)))))))))
+			     `(___push ,n ,nt ,(cdr p) ,@(if (eq? driver-name 'lr-driver) '() '(___sp)) 
+                                       ,(if (eq? driver-name 'lr-driver)
+                                                       `(vector-ref ___stack (1+ ___sp))
+                                                       `(list-ref ___sp (1+ ___sp))))))))))
 
 	   gram/actions))))
 
@@ -1825,7 +1828,11 @@
     (if (>= ___sp (vector-length ___stack))
         (___growstack)))
   
-  (define (___push delta new-category lvalue)
+  (define (___push delta new-category lvalue tok)
+    (if (and (supports-source-properties? lvalue)
+             (not (source-property lvalue 'loc))
+             (lexical-token? tok))
+        (set-source-property! lvalue 'loc (lexical-token-source tok)))
     (set! ___sp (- ___sp (* delta 2)))
     (let* ((state     (vector-ref ___stack ___sp))
            (new-state (cdr (assoc new-category (vector-ref ___gtable state)))))
@@ -2000,7 +2007,7 @@
     (set! *parses* (cons parse *parses*)))
     
 
-  (define (push delta new-category lvalue stack)
+  (define (push delta new-category lvalue stack tok)
     (let* ((stack     (drop stack (* delta 2)))
            (state     (car stack))
            (new-state (cdr (assv new-category (vector-ref ___gtable state)))))
-- 
Jan Nieuwenhuizen <janneke@gnu.org> | GNU LilyPond http://lilypond.org
Freelance IT http://JoyofSource.com | Avatar®  http://AvatarAcademy.nl  




  parent reply	other threads:[~2014-08-02  7:58 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-08-02  7:58 Bison-like source locations in LALR-parser Jan Nieuwenhuizen
2014-08-02  7:58 ` [PATCH 1/2] LALR-parser: provide bison-like location constructs @1 ... @n Jan Nieuwenhuizen
2014-08-02  7:58 ` Jan Nieuwenhuizen [this message]
2014-08-11 18:21 ` Bison-like source locations in LALR-parser Ludovic Courtès
2014-08-13 19:53   ` Jan Nieuwenhuizen
2014-08-13 21:01     ` Ludovic Courtès
2014-10-05 10:27       ` Bison-like source locations in LALR-parser -- upstream update Jan Nieuwenhuizen
2014-12-02 20:27         ` Ludovic Courtès

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/guile/

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

  git send-email \
    --in-reply-to=1406966311-19014-3-git-send-email-janneke@gnu.org \
    --to=janneke@gnu.org \
    --cc=guile-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.
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).