> In gr_test.wy, this line:
> ;; Generate a block analyzer for paren-like blocks
> %type <block> syntax "\\(\\s(\\|\\s)\\)" matchdatatype block
> Is it necessary to wrap the contents in \\( type delimiters?
You're right it isn't necessary. I will remove the \\( and \\)
> An earlier match looked like this:
> ;; Generate a string compare analyzer for punctuations
> %type <punctuation> syntax "\\(\\s.\\|\\s$\\|\\s'\\)+" matchdatatype string
> where (string-match 1) may not be what you expect.
I am afraid, is there any problem with that regexp? The buffer
substring that matches a `syntax' regexp is always obtained using
> I'm converting my dot language (in cedet/cogre/wisent-dot.wy) and got
> this compilation warning:
> Compiling file /home/zappo/cedet/cogre/wisent-dot-wy.el at Wed Jan 14 20:18:04 2004
> In toplevel form:
> wisent-dot-wy.el:253:34:Warning: reference to free variable elt
> which looks like it might be here on line 1265 in semantic-lex.el:
> ,val (substring ,val 0 ,len)))
> (when elt ;; Adjust token end position.
> (setq ,elt (car ,elt)
> Note other refs are to ,elt.
Thanks! I will fix the missing comma.
> Once I fixed that, I could byte compile, load, and run my wisent
> parser against my test dot file with success!
> I tried out %type with both punctuation and blocks. I also used the
> new %keyword keyword. I didn't need anything fancy for other aspects of
> the dot language.
> It worked well. The new syntax is very nice. The block analyzers in
> particular are much clearer in the .wy format than in the Emacs Lisp
> format. This is good stuff!
I am very happy that it works and you like it ;-)
I also plan to add a generic compare analyzer that can use a user's
defined predicate to match tokens. Something like this:
(defun my-predicate (elt1 el2)
;; my code to see if elt1 match elt2
%type <my-type> syntax "some-syntax-regexp"
matchdatatype (predicate my-predicate)
The analyzer could be defined like this:
(defun semantic-lex-predicate-rassoc (key list &optional predicate)
"Find the first item whose cdr matches KEY in LIST.
Optional argument PREDICATE is a function used to compare each LIST
element to KEY. It default to `equal'."
((or (null predicate) (eq predicate 'equal))
(rassoc key list))
((eq predicate 'eq)
(rassq key list))
(while (and (not found) list)
(if (funcall predicate (cdar list) key)
(setq found (car list))
(setq list (cdr list))))
(defmacro define-lex-predicate-type-analyzer (name doc syntax matches default
"Define a predicate based type analyzer NAME with DOC string.
SYNTAX is the regexp that matches a syntactic expression.
MATCHES is an alist of lexical elements used to refine the syntactic
DEFAULT is the default lexical token returned when no MATCHES.
Optional PREDICATE is the function used to compare the string matched
by SYNTAX with values in MATCHES. It defaults to `equal'."
(let* ((elt (make-symbol "elt"))
(pos (make-symbol "pos"))
(end (make-symbol "end")))
(and (looking-at ,syntax)
(let* ((,pos (match-beginning 0))
(,end (match-end 0))
(if ,elt (car ,elt) ,default) ,pos ,end)))))
What do you think?