[plt-scheme] match-lambda and syntax objects

From: Sridhar Ratna (sridhar.ratna at gmail.com)
Date: Tue May 29 13:06:59 EDT 2007


I am reading sexps from a file and parsing them using `match.ss'..
something like this:

  (define @> 'a-macro-that-constructs-Python-AST)

  (define T
      ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
      ;; MATH operators

      (('+ left right)
       (@> Add (list (T left) (T right))))

  (T (read in-port))

(Note: complete code is here <http://srid.nfshost.com/code/boalisp/compile.ss>)

Now that instead of READ I will have to use READ-SYNTAX which returns
a SYNTAX object. The goal is to make use of the `lineno' information
in the syntax object and construct the Python AST along with line
number information. Thus, the ADD example above, I envision, would

     (('+ left right)
      (@> %lineno% Add (T left) (T right)))

Here we could presume `left' and `right' as SYNTAX objects as opposed
to sexps. To add to the complexity, I might have to lookup up the
%lineno% for `left' and `right' forms too, rather than just the `+'

My question is how to hack `lineno' support, in a code that uses
match-lambda, this way (or the other)?


Posted on the users mailing list.