[honu] return the current expression when a semicolon is parsed

This commit is contained in:
Jon Rafkind 2012-03-15 17:06:09 -06:00
parent 47ae2b387a
commit 918c87e96b
8 changed files with 47 additions and 10 deletions

View File

@ -19,6 +19,7 @@
[parse:honu-identifier identifier] [parse:honu-identifier identifier]
[racket:else else] [racket:else else]
[racket:void void] [racket:void void]
[parse:honu-number number]
[honu-function function] [honu-function function]
[honu-function fun] [honu-function fun]
[honu-var var] [honu-var var]

View File

@ -481,6 +481,7 @@ Then, in the pattern above for 'if', 'then' would be bound to the following synt
(honu->racket parsed))] (honu->racket parsed))]
[(unparsed ...) unparsed]) [(unparsed ...) unparsed])
(debug "Final parsed syntax\n~a\n" (pretty-format (syntax->datum #'parsed))) (debug "Final parsed syntax\n~a\n" (pretty-format (syntax->datum #'parsed)))
(debug "Unparsed syntax ~a\n" #'(unparsed ...))
(if (null? (syntax->datum #'(unparsed ...))) (if (null? (syntax->datum #'(unparsed ...)))
(if (parsed-syntax? #'parsed) (if (parsed-syntax? #'parsed)
#'parsed #'parsed

View File

@ -229,10 +229,12 @@
(define-honu-syntax honu-provide (define-honu-syntax honu-provide
(lambda (code context) (lambda (code context)
(syntax-parse code #:literal-sets (cruft) (syntax-parse code #:literal-sets (cruft)
[(_ name:id ... (~optional semicolon) . rest) [(_ name:honu-identifier ... (~optional semicolon) . rest)
(define out (racket-syntax (provide name ...))) (debug "Provide matched names ~a\n" (syntax->datum #'(name.result ...)))
(define out (racket-syntax (provide name.result ...)))
(debug "Provide properties ~a\n" (syntax-property-symbol-keys out)) (debug "Provide properties ~a\n" (syntax-property-symbol-keys out))
(values out #'() #'rest)]))) (debug "Rest ~a\n" #'rest)
(values out #'rest #f)])))
(provide honu-with-input-from-file) (provide honu-with-input-from-file)
(define-honu-syntax honu-with-input-from-file (define-honu-syntax honu-with-input-from-file

View File

@ -181,6 +181,7 @@
;; instead of x_result. x_result is still there, too ;; instead of x_result. x_result is still there, too
(with-syntax ([pattern-variable.name #'pattern-variable.result] (with-syntax ([pattern-variable.name #'pattern-variable.result]
...) ...)
(debug "~a = ~a\n" 'pattern-variable.name #'pattern-variable.name) ...
(parse-stuff action ...)) (parse-stuff action ...))
#'more #t)] #'more #t)]
[else (raise-syntax-error #f "Could not match macro" stx)] [else (raise-syntax-error #f "Could not match macro" stx)]

View File

@ -416,6 +416,7 @@
(lambda (x) x) (lambda (x) x)
(left final)))] (left final)))]
#;
[(stopper? #'head) [(stopper? #'head)
(debug "Parse a stopper ~a\n" #'head) (debug "Parse a stopper ~a\n" #'head)
(values (left final) (values (left final)
@ -424,6 +425,10 @@
(define-splicing-syntax-class no-left (define-splicing-syntax-class no-left
[pattern (~seq) #:when (and (= precedence 0) (not current))]) [pattern (~seq) #:when (and (= precedence 0) (not current))])
(syntax-parse #'(head rest ...) #:literal-sets (cruft) (syntax-parse #'(head rest ...) #:literal-sets (cruft)
[(semicolon . rest)
(debug "Parsed a semicolon, finishing up with ~a\n" current)
(values (left current) #'rest)]
#;
[((semicolon more ...) . rest) [((semicolon more ...) . rest)
#; #;
(define-values (parsed unparsed) (define-values (parsed unparsed)
@ -589,13 +594,19 @@
#:attributes (result) #:attributes (result)
#:description "expression" #:description "expression"
(lambda (stx fail) (lambda (stx fail)
(debug "honu expression syntax class\n") (define context (gensym))
(if (stx-null? stx) (debug "[~a] honu expression syntax class on ~a\n" context stx)
(fail) (if (or (stx-null? stx)
#;
(stopper? (stx-car stx)))
(begin
(debug "[~a] failed\n" context)
(fail))
(let () (let ()
(define-values (parsed unparsed) (define-values (parsed unparsed)
(parse stx)) (parse stx))
(debug "parsed ~a\n" (if parsed (syntax->datum parsed) parsed)) (debug "[~a] expression parsed ~a\n" context (if parsed (syntax->datum parsed) parsed))
(debug "[~a] Parsed things ~a\n" context (parsed-things stx unparsed))
(list (parsed-things stx unparsed) (list (parsed-things stx unparsed)
(parsed-syntax parsed) (parsed-syntax parsed)
#; #;
@ -615,7 +626,15 @@
(provide honu-identifier) (provide honu-identifier)
(define-splicing-syntax-class honu-identifier (define-splicing-syntax-class honu-identifier
[pattern x:id #:with result #'x]) #:literal-sets (cruft)
[pattern (~and (~not semicolon)
x:id) #:with result #'x])
(provide honu-number)
(define-splicing-syntax-class honu-number
#:literal-sets (cruft)
[pattern x:number #:with result #'x])
(provide identifier-comma-list) (provide identifier-comma-list)
(define-splicing-syntax-class identifier-comma-list (define-splicing-syntax-class identifier-comma-list

View File

@ -333,7 +333,7 @@
;; ((%semicolon 3 + 4) (%semicolon 1 + 2)) ;; ((%semicolon 3 + 4) (%semicolon 1 + 2))
;; ;;
;; The entire list will be reversed at the end of parsing. ;; The entire list will be reversed at the end of parsing.
(define (do-semicolon current tokens table) (define (do-semicolon2 current tokens table)
;; (debug "Do semicolon on ~a\n" current) ;; (debug "Do semicolon on ~a\n" current)
(define-values (wrap ok) (define-values (wrap ok)
(let loop ([found '()] (let loop ([found '()]
@ -350,10 +350,16 @@
(car tokens) (car tokens)
source)) source))
(do-parse (cons semicolon ok) (do-parse (cons semicolon ok)
(cdr tokens) (cdr tokens)
table)) table))
(define (do-semicolon current tokens table)
(do-parse (cons (make-syntax '%semicolon (car tokens) source) current)
(cdr tokens)
table))
(define (semicolon? tokens) (define (semicolon? tokens)
(is-first-token token-semicolon? tokens)) (is-first-token token-semicolon? tokens))
@ -423,6 +429,7 @@
(action current tokens table)] (action current tokens table)]
[else (loop (cdr use))]))) [else (loop (cdr use))])))
(debug 3 "Parsing tokens ~a\n" (map position-token-token tokens))
(if (null? tokens) (if (null? tokens)
(datum->syntax #f '() #f) (datum->syntax #f '() #f)
(datum->syntax #f (do-parse '() tokens dispatch-table) (datum->syntax #f (do-parse '() tokens dispatch-table)

View File

@ -92,7 +92,7 @@
(test (test
"cond" "cond"
@input{ @input{
var n = 5; var n = 5
cond cond
n < 10: 'x1, n < 10: 'x1,
n > 10: 'x2 n > 10: 'x2

View File

@ -27,3 +27,9 @@ mymatch [1, 2, 3] with
| [1, 2, 3] => 8, | [1, 2, 3] => 8,
// mymatch [1] with | [2] => 5 // mymatch [1] with | [2] => 5
mymatch [true, false] with
| [true] => 1,
| [false] => 2,
| [false, true] => 3,
| [true, false] => 4,