Change ebnf variables to not use namespaces
parent
27f2992dc5
commit
cc7d945a80
|
@ -237,17 +237,16 @@ GENERIC: (transform) ( ast -- parser )
|
||||||
|
|
||||||
SYMBOL: parser
|
SYMBOL: parser
|
||||||
SYMBOL: main
|
SYMBOL: main
|
||||||
SYMBOL: vars
|
|
||||||
|
|
||||||
: transform ( ast -- object )
|
: transform ( ast -- object )
|
||||||
H{ } clone dup dup [ parser set V{ } vars set swap (transform) main set ] bind ;
|
H{ } clone dup dup [ parser set swap (transform) main set ] bind ;
|
||||||
|
|
||||||
M: ebnf (transform) ( ast -- parser )
|
M: ebnf (transform) ( ast -- parser )
|
||||||
rules>> [ (transform) ] map peek ;
|
rules>> [ (transform) ] map peek ;
|
||||||
|
|
||||||
M: ebnf-rule (transform) ( ast -- parser )
|
M: ebnf-rule (transform) ( ast -- parser )
|
||||||
dup elements>>
|
dup elements>>
|
||||||
vars get clone vars [ (transform) ] with-variable [
|
(transform) [
|
||||||
swap symbol>> set
|
swap symbol>> set
|
||||||
] keep ;
|
] keep ;
|
||||||
|
|
||||||
|
@ -282,30 +281,50 @@ M: ebnf-repeat1 (transform) ( ast -- parser )
|
||||||
M: ebnf-optional (transform) ( ast -- parser )
|
M: ebnf-optional (transform) ( ast -- parser )
|
||||||
transform-group optional ;
|
transform-group optional ;
|
||||||
|
|
||||||
: build-locals ( string vars -- string )
|
GENERIC: build-locals ( code ast -- code )
|
||||||
dup empty? [
|
|
||||||
drop
|
M: ebnf-sequence build-locals ( code ast -- code )
|
||||||
] [
|
elements>> dup [ ebnf-var? ] subset empty? [
|
||||||
|
drop
|
||||||
|
] [
|
||||||
[
|
[
|
||||||
"USING: locals namespaces ; [let* | " %
|
"USING: locals sequences ; [let* | " %
|
||||||
[ dup % " [ \"" % % "\" get ] " % ] each
|
dup length swap [
|
||||||
" | " %
|
dup ebnf-var? [
|
||||||
%
|
name>> %
|
||||||
" ] with-locals" %
|
" [ " % # " over nth ] " %
|
||||||
|
] [
|
||||||
|
2drop
|
||||||
|
] if
|
||||||
|
] 2each
|
||||||
|
" | " %
|
||||||
|
%
|
||||||
|
" ] with-locals" %
|
||||||
] "" make
|
] "" make
|
||||||
] if ;
|
] if ;
|
||||||
|
|
||||||
|
M: ebnf-var build-locals ( code ast -- )
|
||||||
|
[
|
||||||
|
"USING: locals kernel ; [let* | " %
|
||||||
|
name>> % " [ dup ] " %
|
||||||
|
" | " %
|
||||||
|
%
|
||||||
|
" ] with-locals" %
|
||||||
|
] "" make ;
|
||||||
|
|
||||||
|
M: object build-locals ( code ast -- )
|
||||||
|
drop ;
|
||||||
|
|
||||||
M: ebnf-action (transform) ( ast -- parser )
|
M: ebnf-action (transform) ( ast -- parser )
|
||||||
[ parser>> (transform) ] keep
|
[ parser>> (transform) ] [ code>> ] [ parser>> ] tri build-locals
|
||||||
code>> vars get build-locals string-lines [ parse-lines ] with-compilation-unit action ;
|
string-lines [ parse-lines ] with-compilation-unit action ;
|
||||||
|
|
||||||
M: ebnf-semantic (transform) ( ast -- parser )
|
M: ebnf-semantic (transform) ( ast -- parser )
|
||||||
[ parser>> (transform) ] keep
|
[ parser>> (transform) ] [ code>> ] [ parser>> ] tri build-locals
|
||||||
code>> vars get build-locals string-lines [ parse-lines ] with-compilation-unit semantic ;
|
string-lines [ parse-lines ] with-compilation-unit semantic ;
|
||||||
|
|
||||||
M: ebnf-var (transform) ( ast -- parser )
|
M: ebnf-var (transform) ( ast -- parser )
|
||||||
[ parser>> (transform) ] [ name>> ] bi
|
parser>> (transform) ;
|
||||||
dup vars get push [ dupd set ] curry action ;
|
|
||||||
|
|
||||||
M: ebnf-terminal (transform) ( ast -- parser )
|
M: ebnf-terminal (transform) ( ast -- parser )
|
||||||
symbol>> token ;
|
symbol>> token ;
|
||||||
|
|
Loading…
Reference in New Issue