core: Move multiline and interpolate to core.
caveats: peg.ebnf needs to find :> and let[ in "syntax" not locals anymore. - You have to define a word ``IN: syntax`` before Factor picks up syntax changes - You have to add a syntax word to core/bootstrap/syntax.factormodern-harvey2
parent
43628c8340
commit
bc285f7072
|
|
@ -1,47 +0,0 @@
|
||||||
! Copyright (C) 2007 Daniel Ehrenberg
|
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
|
||||||
USING: accessors kernel lexer locals make math namespaces
|
|
||||||
sequences ;
|
|
||||||
IN: multiline
|
|
||||||
|
|
||||||
<PRIVATE
|
|
||||||
|
|
||||||
:: (scan-multiline-string) ( i end lexer -- j )
|
|
||||||
lexer line-text>> :> text
|
|
||||||
lexer still-parsing? [
|
|
||||||
end text i subseq-start-from |[ j |
|
|
||||||
i j text subseq % j end length +
|
|
||||||
] [
|
|
||||||
text i short tail % char: \n ,
|
|
||||||
lexer next-line
|
|
||||||
0 end lexer (scan-multiline-string)
|
|
||||||
] if*
|
|
||||||
] [ end throw-unexpected-eof ] if ;
|
|
||||||
|
|
||||||
:: (parse-multiline-string) ( end-text lexer skip-n-chars -- str )
|
|
||||||
[
|
|
||||||
lexer
|
|
||||||
[ skip-n-chars + end-text lexer (scan-multiline-string) ]
|
|
||||||
change-column drop
|
|
||||||
] "" make ;
|
|
||||||
|
|
||||||
PRIVATE>
|
|
||||||
|
|
||||||
: parse-multiline-string ( end-text -- str )
|
|
||||||
lexer get 1 (parse-multiline-string) ;
|
|
||||||
|
|
||||||
SYNTAX: \[[ "]]" parse-multiline-string suffix! ;
|
|
||||||
SYNTAX: \[=[ "]=]" parse-multiline-string suffix! ;
|
|
||||||
SYNTAX: \[==[ "]==]" parse-multiline-string suffix! ;
|
|
||||||
SYNTAX: \[===[ "]===]" parse-multiline-string suffix! ;
|
|
||||||
SYNTAX: \[====[ "]====]" parse-multiline-string suffix! ;
|
|
||||||
SYNTAX: \[=====[ "]=====]" parse-multiline-string suffix! ;
|
|
||||||
SYNTAX: \[======[ "]======]" parse-multiline-string suffix! ;
|
|
||||||
|
|
||||||
SYNTAX: \![[ "]]" parse-multiline-string drop ;
|
|
||||||
SYNTAX: \![=[ "]=]" parse-multiline-string drop ;
|
|
||||||
SYNTAX: \![==[ "]==]" parse-multiline-string drop ;
|
|
||||||
SYNTAX: \![===[ "]===]" parse-multiline-string drop ;
|
|
||||||
SYNTAX: \![====[ "]====]" parse-multiline-string drop ;
|
|
||||||
SYNTAX: \![=====[ "]=====]" parse-multiline-string drop ;
|
|
||||||
SYNTAX: \![======[ "]======]" parse-multiline-string drop ;
|
|
||||||
|
|
@ -473,7 +473,7 @@ ERROR: bad-effect quot effect ;
|
||||||
! so we don't pollute the manifest qualified-vocabs
|
! so we don't pollute the manifest qualified-vocabs
|
||||||
! and also so restarts don't add multiple times
|
! and also so restarts don't add multiple times
|
||||||
qualified-vocabs length
|
qualified-vocabs length
|
||||||
"locals" { "let[" ":>" } add-words-from
|
"syntax" { "let[" ":>" } add-words-from
|
||||||
"kernel" { "dup" "nip" "over" } add-words-from
|
"kernel" { "dup" "nip" "over" } add-words-from
|
||||||
"sequences" { "nth" } add-words-from
|
"sequences" { "nth" } add-words-from
|
||||||
[ string-lines parse-lines ] dip
|
[ string-lines parse-lines ] dip
|
||||||
|
|
|
||||||
|
|
@ -109,6 +109,34 @@ IN: bootstrap.syntax
|
||||||
"'["
|
"'["
|
||||||
"@"
|
"@"
|
||||||
"_"
|
"_"
|
||||||
|
"[["
|
||||||
|
"[=["
|
||||||
|
"[==["
|
||||||
|
"[===["
|
||||||
|
"[====["
|
||||||
|
"[=====["
|
||||||
|
"[======["
|
||||||
|
|
||||||
|
"![["
|
||||||
|
"![=["
|
||||||
|
"![==["
|
||||||
|
"![===["
|
||||||
|
"![====["
|
||||||
|
"![=====["
|
||||||
|
"![======["
|
||||||
|
|
||||||
|
"I[["
|
||||||
|
"I[=["
|
||||||
|
"I[==["
|
||||||
|
"I[===["
|
||||||
|
"I[====["
|
||||||
|
"I[=====["
|
||||||
|
"I[======["
|
||||||
|
|
||||||
|
":>"
|
||||||
|
"|["
|
||||||
|
"let["
|
||||||
|
"'let["
|
||||||
} [ "syntax" create-word drop ] each
|
} [ "syntax" create-word drop ] each
|
||||||
|
|
||||||
"t" "syntax" lookup-word define-symbol
|
"t" "syntax" lookup-word define-symbol
|
||||||
|
|
|
||||||
|
|
@ -89,6 +89,6 @@ MACRO: interpolate-locals ( str -- quot )
|
||||||
parse-multiline-string
|
parse-multiline-string
|
||||||
interpolate-locals-quot append! ;
|
interpolate-locals-quot append! ;
|
||||||
|
|
||||||
SYNTAX: \I[[ "]]" define-interpolate-syntax ;
|
! SYNTAX: \I[[ "]]" define-interpolate-syntax ;
|
||||||
SYNTAX: \I[=[ "]=]" define-interpolate-syntax ;
|
! SYNTAX: \I[=[ "]=]" define-interpolate-syntax ;
|
||||||
SYNTAX: \I[==[ "]==]" define-interpolate-syntax ;
|
! SYNTAX: \I[==[ "]==]" define-interpolate-syntax ;
|
||||||
|
|
@ -0,0 +1,46 @@
|
||||||
|
! Copyright (C) 2007 Daniel Ehrenberg
|
||||||
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
|
USING: accessors kernel lexer make math namespaces sequences ;
|
||||||
|
IN: multiline
|
||||||
|
|
||||||
|
<PRIVATE
|
||||||
|
|
||||||
|
:: (scan-multiline-string) ( i end lexer -- j )
|
||||||
|
lexer line-text>> :> text
|
||||||
|
lexer still-parsing? [
|
||||||
|
end text i subseq-start-from |[ j |
|
||||||
|
i j text subseq % j end length +
|
||||||
|
] [
|
||||||
|
text i short tail % char: \n ,
|
||||||
|
lexer next-line
|
||||||
|
0 end lexer (scan-multiline-string)
|
||||||
|
] if*
|
||||||
|
] [ end throw-unexpected-eof ] if ;
|
||||||
|
|
||||||
|
:: (parse-multiline-string) ( end-text lexer skip-n-chars -- str )
|
||||||
|
[
|
||||||
|
lexer
|
||||||
|
[ skip-n-chars + end-text lexer (scan-multiline-string) ]
|
||||||
|
change-column drop
|
||||||
|
] "" make ;
|
||||||
|
|
||||||
|
PRIVATE>
|
||||||
|
|
||||||
|
: parse-multiline-string ( end-text -- str )
|
||||||
|
lexer get 1 (parse-multiline-string) ;
|
||||||
|
|
||||||
|
! SYNTAX: \[[ "]]" parse-multiline-string suffix! ;
|
||||||
|
! SYNTAX: \[=[ "]=]" parse-multiline-string suffix! ;
|
||||||
|
! SYNTAX: \[==[ "]==]" parse-multiline-string suffix! ;
|
||||||
|
! SYNTAX: \[===[ "]===]" parse-multiline-string suffix! ;
|
||||||
|
! SYNTAX: \[====[ "]====]" parse-multiline-string suffix! ;
|
||||||
|
! SYNTAX: \[=====[ "]=====]" parse-multiline-string suffix! ;
|
||||||
|
! SYNTAX: \[======[ "]======]" parse-multiline-string suffix! ;
|
||||||
|
|
||||||
|
! SYNTAX: \![[ "]]" parse-multiline-string drop ;
|
||||||
|
! SYNTAX: \![=[ "]=]" parse-multiline-string drop ;
|
||||||
|
! SYNTAX: \![==[ "]==]" parse-multiline-string drop ;
|
||||||
|
! SYNTAX: \![===[ "]===]" parse-multiline-string drop ;
|
||||||
|
! SYNTAX: \![====[ "]====]" parse-multiline-string drop ;
|
||||||
|
! SYNTAX: \![=====[ "]=====]" parse-multiline-string drop ;
|
||||||
|
! SYNTAX: \![======[ "]======]" parse-multiline-string drop ;
|
||||||
|
|
@ -8,7 +8,8 @@ classes.tuple.parser classes.union combinators compiler.units
|
||||||
definitions delegate delegate.private effects effects.parser fry
|
definitions delegate delegate.private effects effects.parser fry
|
||||||
generic generic.hook generic.math generic.parser
|
generic generic.hook generic.math generic.parser
|
||||||
generic.standard hash-sets hashtables hashtables.identity hints
|
generic.standard hash-sets hashtables hashtables.identity hints
|
||||||
io.pathnames kernel lexer locals.parser macros math memoize
|
interpolate io.pathnames kernel lexer locals.errors
|
||||||
|
locals.parser locals.types macros math memoize multiline
|
||||||
namespaces parser quotations sbufs sequences slots source-files
|
namespaces parser quotations sbufs sequences slots source-files
|
||||||
splitting stack-checker strings strings.parser typed vectors
|
splitting stack-checker strings strings.parser typed vectors
|
||||||
vocabs.parser words words.alias words.constant words.symbol ;
|
vocabs.parser words words.alias words.constant words.symbol ;
|
||||||
|
|
@ -347,4 +348,40 @@ IN: bootstrap.syntax
|
||||||
] define-core-syntax
|
] define-core-syntax
|
||||||
|
|
||||||
{ "_" "@" } define-fry-specifiers
|
{ "_" "@" } define-fry-specifiers
|
||||||
|
|
||||||
|
"[[" [ "]]" parse-multiline-string suffix! ] define-core-syntax
|
||||||
|
"[=[" [ "]=]" parse-multiline-string suffix! ] define-core-syntax
|
||||||
|
"[==[" [ "]==]" parse-multiline-string suffix! ] define-core-syntax
|
||||||
|
"[===[" [ "]===]" parse-multiline-string suffix! ] define-core-syntax
|
||||||
|
"[====[" [ "]====]" parse-multiline-string suffix! ] define-core-syntax
|
||||||
|
"[=====[" [ "]=====]" parse-multiline-string suffix! ] define-core-syntax
|
||||||
|
"[======[" [ "]======]" parse-multiline-string suffix! ] define-core-syntax
|
||||||
|
|
||||||
|
"![[" [ "]]" parse-multiline-string drop ] define-core-syntax
|
||||||
|
"![=[" [ "]=]" parse-multiline-string drop ] define-core-syntax
|
||||||
|
"![==[" [ "]==]" parse-multiline-string drop ] define-core-syntax
|
||||||
|
"![===[" [ "]===]" parse-multiline-string drop ] define-core-syntax
|
||||||
|
"![====[" [ "]====]" parse-multiline-string drop ] define-core-syntax
|
||||||
|
"![=====[" [ "]=====]" parse-multiline-string drop ] define-core-syntax
|
||||||
|
"![======[" [ "]======]" parse-multiline-string drop ] define-core-syntax
|
||||||
|
|
||||||
|
"I[[" [ "]]" define-interpolate-syntax ] define-core-syntax
|
||||||
|
"I[=[" [ "]=]" define-interpolate-syntax ] define-core-syntax
|
||||||
|
"I[==[" [ "]==]" define-interpolate-syntax ] define-core-syntax
|
||||||
|
"I[===[" [ "]===]" define-interpolate-syntax ] define-core-syntax
|
||||||
|
"I[====[" [ "]====]" define-interpolate-syntax ] define-core-syntax
|
||||||
|
"I[=====[" [ "]=====]" define-interpolate-syntax ] define-core-syntax
|
||||||
|
"I[======[" [ "]======]" define-interpolate-syntax ] define-core-syntax
|
||||||
|
|
||||||
|
":>" [
|
||||||
|
in-lambda? get [ :>-outside-lambda-error ] unless
|
||||||
|
scan-token parse-def suffix!
|
||||||
|
] define-core-syntax
|
||||||
|
|
||||||
|
"|[" [ parse-lambda append! ] define-core-syntax
|
||||||
|
|
||||||
|
"let[" [ parse-let append! ] define-core-syntax
|
||||||
|
"'let[" [
|
||||||
|
H{ } clone (parse-lambda) [ fry call <let> ?rewrite-closures call ] curry append!
|
||||||
|
] define-core-syntax
|
||||||
] with-compilation-unit
|
] with-compilation-unit
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue