Skip to content

Commit 3d2db6f

Browse files
committed
Add parsing for export foo as bar
In analogy to `import foo as bar`. However, no lowering is added for this. My intention is to use this in a macro.
1 parent 82de78c commit 3d2db6f

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

src/julia-parser.scm

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,13 @@
123123
(and (pair? ex)
124124
(eq? '$ (car ex)))))
125125

126+
(define (symbol-as-or-interpolate? ex)
127+
(or (symbol-or-interpolate? ex)
128+
(and (pair? ex)
129+
(eq? 'as (car ex))
130+
(symbol-or-interpolate? (cadr ex))
131+
(symbol-or-interpolate? (caddr ex)))))
132+
126133
(define (is-word-operator? op)
127134
(every identifier-start-char? (string->list (symbol->string op))))
128135

@@ -1378,6 +1385,14 @@
13781385
(take-lineendings s))
13791386
s)))
13801387

1388+
(define (parse-export s)
1389+
(let ((ex (parse-atsym s)))
1390+
(if (eq? (peek-token s) 'as)
1391+
(begin
1392+
(take-token s)
1393+
`(as ,ex ,(parse-atsym s)))
1394+
ex)))
1395+
13811396
;; parse expressions or blocks introduced by syntactic reserved words
13821397
(define (parse-resword s word)
13831398
(with-bindings
@@ -1615,8 +1630,8 @@
16151630
(list 'module (if (eq? word 'module) '(true) '(false)) name
16161631
`(block ,loc ,@(cdr body)))))
16171632
((export public)
1618-
(let ((es (parse-comma-separated s parse-atsym)))
1619-
(if (not (every symbol-or-interpolate? es))
1633+
(let ((es (parse-comma-separated s (if (eq? word 'export) parse-export parse-atsym))))
1634+
(if (not (every symbol-as-or-interpolate? es))
16201635
(error (string "invalid \"" word "\" statement")))
16211636
`(,word ,@es)))
16221637
((import using)

0 commit comments

Comments
 (0)