guile-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

macro fu question


From: Stefan Israelsson Tampe
Subject: macro fu question
Date: Mon, 25 Apr 2011 21:02:57 +0200

Hi,

I'm working on a small environment to verify macros like the syntax-parse framework.

The idea is to use the tools I've already made for guile/scheme. I will explain this a little
more in detail if anyone is interested. Here I just focus here on a question
about how to use the macro system to solve a design issue.


Here is the idea. Consider to use a pattern system like syntax-case and call it
syntax-parse, the prototype looks familiar as

(syntax-parse stx (literalls ...)  (pat code ....) ...)

The difference is that patterns can have elements like

  (:  p  verifier) added to the standard setup

for this case we will (e.g. for the stx reaching this pattern) will call the verifier (a function) with the stx
to verify it and on success we will continue just as with syntax case else we will log an error
message and continue with the next row and associated pattern and verification. If all patterns
have been consumed an error message will be deduced and an error message tree can be consulted.

The tool is a function  get-ver :  stx -> (lambda : stx -> boolean)

e.g. get-ver takes an stx representing an extended pattern and constructs a function that takes a
stx representing the incomming code tpo be verified and outputs the verdicet true or false.

and a get-pat that extracts a pattern that can be feeded into syntax-case

I got a PEG tool and a error database system to be able to smootly design verifiers and the get-ver
system what I find tricky is to design the syntax-parse macro.

I'm working with something like

(define-syntax syntax-parse
  (lambda (x)
    (syntax-case x ()
      ((_ . l)
       (set! *errors* '())
       #'(syntax-parse0 . l)))))

(define-syntax syntax-parse0
  (lambda (x)
    (syntax-case x ()
      ((_ r (p code) . l)              
       (let-syntax ((check-stx (get-ver #'p))
         (with-syntax ((pp (datum->syntax x (get-pat  #'p))))
              #'(lambda (x)             
                  (define-syntax rest
                    (lambda (x)
                      (syntax-case x r
                        (pp code)
                        (_  (print-error)
                            #'(error "MACRO-SYNTAX-ERROR")))))
                  (syntax-case x ()
                    ((x . l)
                     #'(if (check-stx . l)
                           (rest . l)
                           (syntax-parse0 r . l)))))))



/stefan

by the way, One shouled be able to mod the PEG parser going into guile to do all the main job here at
constructing verifiers, also to ote is that I mod car cdr pair? etc to be able to handle syntax objkect
and transfered syntax-object? syntax-object-_expression_ into guile namespace to be able to keep source and syntactic information consistent.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]