lhs-id splicing works ; tests pass

pull/2/head
Matthew Butterick 9 years ago
parent 6d80193419
commit f6181b90d7

@ -42,7 +42,7 @@
#| #|
MB: `rules` still carries 'hide syntax property MB: `rules` still carries 'hide syntax property
|# |#
#;(report flattened-rules) #;(report rules)
#| #|
@ -54,7 +54,7 @@
(define generated-rule-codes (map flat-rule->yacc-rule flattened-rules)) (define generated-rule-codes (map flat-rule->yacc-rule flattened-rules))
#| #|
MB: `generated-rule-codes` loses the 'hide syntax property MB: `generated-rule-codes` loses the 'hide syntax property (but not for lhs-ids)
|# |#
#;(report generated-rule-codes) #;(report generated-rule-codes)
@ -179,6 +179,7 @@
;; stx :== (name (U tokens rule-stx) ...) ;; stx :== (name (U tokens rule-stx) ...)
;; ;;
(define (flat-rule->yacc-rule a-flat-rule) (define (flat-rule->yacc-rule a-flat-rule)
;; lhs-ids still carry 'hide property on #'name field
#;(report a-flat-rule) #;(report a-flat-rule)
(syntax-case a-flat-rule () (syntax-case a-flat-rule ()
[(rule-type origin name clauses ...) [(rule-type origin name clauses ...)
@ -251,7 +252,8 @@
[(translated-action ...) translated-actions]) [(translated-action ...) translated-actions])
#`[(translated-pattern ...) #`[(translated-pattern ...)
(rule-components->syntax '#,rule-name/false translated-action ... (rule-components->syntax '#,rule-name/false translated-action ...
#:srcloc #,whole-rule-loc)])) #:srcloc #,whole-rule-loc
#:splice? #,(syntax-property rule-name/false 'hide))]))

@ -158,14 +158,20 @@ This would be the place to check a syntax property for hiding.
(datum->syntax #f d (positions->srcloc start-pos end-pos) stx-with-original?-property)) (datum->syntax #f d (positions->srcloc start-pos end-pos) stx-with-original?-property))
(define splice-signal '@)
;; rule-components->syntax: (U symbol false) (listof stx) ... #:srcloc (U #f (list src line column offset span)) -> stx ;; rule-components->syntax: (U symbol false) (listof stx) ... #:srcloc (U #f (list src line column offset span)) -> stx
;; Creates an stx out of the rule name and its components. ;; Creates an stx out of the rule name and its components.
;; The location information of the rule spans that of its components. ;; The location information of the rule spans that of its components.
(define (rule-components->syntax rule-name/false #:srcloc [srcloc #f] . components) (define (rule-components->syntax rule-name/false #:srcloc [srcloc #f] #:splice? [splice #f] . componentss)
(let ([componentss (append-map (λ(cs)
(if (and (pair? cs) (syntax-property (car cs) 'splice))
(list (cdr (syntax->list (car cs))))
(list cs))) componentss)])
(syntax-property
(datum->syntax #f (datum->syntax #f
(cons (cons
(datum->syntax #f rule-name/false srcloc stx-with-original?-property) (datum->syntax #f rule-name/false srcloc stx-with-original?-property)
(apply append components)) (apply append componentss))
srcloc srcloc
stx-with-original?-property)) stx-with-original?-property)
'splice splice)))

@ -14,4 +14,4 @@ array: "[" [json ("," json)*] "]"
object: <"{"> [kvpair ("," kvpair)*] <"}"> object: <"{"> [kvpair ("," kvpair)*] <"}">
kvpair: <ID> ":" <json> <kvpair> : <ID> ":" <json>

@ -10,10 +10,10 @@
":" ":"
(token 'STRING "'hello world'") (token 'STRING "'hello world'")
"}"))) "}")))
'(json (object (kvpair "message" (json (string "'hello world'")))))) '(json (object ":")))
#;(check-equal? (check-equal?
(syntax->datum (syntax->datum
(parse "[[[{}]],[],[[{}]]]")) (parse "[[[{}]],[],[[{}]]]"))
'(json (array #\[ (json (array #\[ (json (array #\[ (json (object)) #\])) #\])) #\, (json (array #\[ #\])) #\, (json (array #\[ (json (array #\[ (json (object )) #\])) #\])) #\]))) '(json (array #\[ (json (array #\[ (json (array #\[ (json (object)) #\])) #\])) #\, (json (array #\[ #\])) #\, (json (array #\[ (json (array #\[ (json (object )) #\])) #\])) #\])))

@ -21,6 +21,7 @@
(define (rule->stx source a-rule) (define (rule->stx source a-rule)
(define id-stx (define id-stx
(syntax-property
(datum->syntax #f (datum->syntax #f
(string->symbol (lhs-id-val (rule-lhs a-rule))) (string->symbol (lhs-id-val (rule-lhs a-rule)))
(list source (list source
@ -31,7 +32,8 @@
(number? (pos-offset (lhs-id-end (rule-lhs a-rule))))) (number? (pos-offset (lhs-id-end (rule-lhs a-rule)))))
(- (pos-offset (lhs-id-end (rule-lhs a-rule))) (- (pos-offset (lhs-id-end (rule-lhs a-rule)))
(pos-offset (lhs-id-start (rule-lhs a-rule)))) (pos-offset (lhs-id-start (rule-lhs a-rule))))
#f)))) #f)))
'hide (lhs-id-hide (rule-lhs a-rule))))
(define pattern-stx (pattern->stx source (rule-pattern a-rule))) (define pattern-stx (pattern->stx source (rule-pattern a-rule)))
(define line (pos-line (rule-start a-rule))) (define line (pos-line (rule-start a-rule)))
(define column (pos-col (rule-start a-rule))) (define column (pos-col (rule-start a-rule)))

Loading…
Cancel
Save