make ids hideable
This commit is contained in:
parent
f072c9f808
commit
2026c603de
|
@ -216,29 +216,29 @@
|
||||||
(for/list ([translated-pattern (in-list translated-patterns)]
|
(for/list ([translated-pattern (in-list translated-patterns)]
|
||||||
[primitive-pattern (syntax->list a-clause)]
|
[primitive-pattern (syntax->list a-clause)]
|
||||||
[pos (in-naturals 1)])
|
[pos (in-naturals 1)])
|
||||||
(with-syntax ([$X
|
(if (syntax-property primitive-pattern 'hide)
|
||||||
(format-id translated-pattern "$~a" pos)]
|
#'null
|
||||||
[$X-start-pos
|
(with-syntax ([$X
|
||||||
(format-id translated-pattern "$~a-start-pos" pos)]
|
(format-id translated-pattern "$~a" pos)]
|
||||||
[$X-end-pos
|
[$X-start-pos
|
||||||
(format-id translated-pattern "$~a-end-pos" pos)])
|
(format-id translated-pattern "$~a-start-pos" pos)]
|
||||||
(syntax-case primitive-pattern (id lit token inferred-id)
|
[$X-end-pos
|
||||||
|
(format-id translated-pattern "$~a-end-pos" pos)])
|
||||||
|
(syntax-case primitive-pattern (id lit token inferred-id)
|
||||||
|
|
||||||
;; When a rule usage is inferred, the value of $X is a syntax object
|
;; When a rule usage is inferred, the value of $X is a syntax object
|
||||||
;; whose head is the name of the inferred rule . We strip that out,
|
;; whose head is the name of the inferred rule . We strip that out,
|
||||||
;; leaving the residue to be absorbed.
|
;; leaving the residue to be absorbed.
|
||||||
[(inferred-id val reason)
|
[(inferred-id val reason)
|
||||||
#'(syntax-case $X ()
|
#'(syntax-case $X ()
|
||||||
[(inferred-rule-name . rest)
|
[(inferred-rule-name . rest)
|
||||||
(syntax->list #'rest)])]
|
(syntax->list #'rest)])]
|
||||||
[(id val)
|
[(id val)
|
||||||
#'(list $X)]
|
#'(list $X)]
|
||||||
;; move the 'hide syntax property into the translated-action
|
[(lit val)
|
||||||
;; because syntax gets datum-ized
|
#'(list (atomic-datum->syntax $X $X-start-pos $X-end-pos))]
|
||||||
[(lit val)
|
[(token val)
|
||||||
#`(list (atomic-datum->syntax $X $X-start-pos $X-end-pos #,(syntax-property primitive-pattern 'hide)))]
|
#'(list (atomic-datum->syntax $X $X-start-pos $X-end-pos))])))))
|
||||||
[(token val)
|
|
||||||
#`(list (atomic-datum->syntax $X $X-start-pos $X-end-pos #,(syntax-property primitive-pattern 'hide)))]))))
|
|
||||||
|
|
||||||
(define whole-rule-loc
|
(define whole-rule-loc
|
||||||
(if (empty? translated-patterns)
|
(if (empty? translated-patterns)
|
||||||
|
|
|
@ -150,15 +150,12 @@ This would be the place to check a syntax property for hiding.
|
||||||
(define stx-with-original?-property
|
(define stx-with-original?-property
|
||||||
(read-syntax #f (open-input-string "meaningless-string")))
|
(read-syntax #f (open-input-string "meaningless-string")))
|
||||||
|
|
||||||
(define elided (gensym))
|
|
||||||
|
|
||||||
;; atomic-datum->syntax: datum position position
|
;; atomic-datum->syntax: datum position position
|
||||||
;; Helper that does the ugly work in wrapping a datum into a syntax
|
;; Helper that does the ugly work in wrapping a datum into a syntax
|
||||||
;; with source location.
|
;; with source location.
|
||||||
(define (atomic-datum->syntax d start-pos end-pos [hide? #f])
|
(define (atomic-datum->syntax d start-pos end-pos)
|
||||||
(if hide?
|
(datum->syntax #f d (positions->srcloc start-pos end-pos) stx-with-original?-property))
|
||||||
elided
|
|
||||||
(datum->syntax #f d (positions->srcloc start-pos end-pos) stx-with-original?-property)))
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -166,10 +163,9 @@ This would be the place to check a syntax property for hiding.
|
||||||
;; 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] . components)
|
||||||
(define flattened-elided-components (filter-not (λ(c) (eq? c elided)) (apply append components)))
|
|
||||||
(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)
|
||||||
flattened-elided-components)
|
(apply append components))
|
||||||
srcloc
|
srcloc
|
||||||
stx-with-original?-property))
|
stx-with-original?-property))
|
|
@ -1,4 +1,4 @@
|
||||||
#lang brag
|
#lang brag
|
||||||
|
|
||||||
;; Simple baby example of JSON structure
|
thing : foo
|
||||||
json: ID <":"> ID
|
foo : <"bar">
|
||||||
|
|
|
@ -14,4 +14,4 @@ array: "[" [json ("," json)*] "]"
|
||||||
|
|
||||||
object: <"{"> [kvpair ("," kvpair)*] <"}">
|
object: <"{"> [kvpair ("," kvpair)*] <"}">
|
||||||
|
|
||||||
kvpair: <ID> <":"> json
|
kvpair: <ID> ":" <json>
|
||||||
|
|
9
brag/brag/elider/test-json-elider-toy.rkt
Normal file
9
brag/brag/elider/test-json-elider-toy.rkt
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
#lang br
|
||||||
|
(require "json-elider-toy.rkt"
|
||||||
|
brag/support
|
||||||
|
rackunit)
|
||||||
|
|
||||||
|
(check-equal?
|
||||||
|
(syntax->datum
|
||||||
|
(parse (list "bar")))
|
||||||
|
'(thing))
|
|
@ -10,10 +10,10 @@
|
||||||
":"
|
":"
|
||||||
(token 'STRING "'hello world'")
|
(token 'STRING "'hello world'")
|
||||||
"}")))
|
"}")))
|
||||||
'(json (object (kvpair (json (string "'hello world'"))))))
|
'(json (object (kvpair "message" (json (string "'hello world'"))))))
|
||||||
|
|
||||||
|
|
||||||
(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 )) #\])) #\])) #\])))
|
||||||
|
|
Loading…
Reference in New Issue
Block a user