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.factor
modern-harvey2
Doug Coleman 2017-11-24 19:12:04 -06:00
parent 43628c8340
commit bc285f7072
16 changed files with 116 additions and 52 deletions

View File

@ -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 ;

View File

@ -473,7 +473,7 @@ ERROR: bad-effect quot effect ;
! so we don't pollute the manifest qualified-vocabs
! and also so restarts don't add multiple times
qualified-vocabs length
"locals" { "let[" ":>" } add-words-from
"syntax" { "let[" ":>" } add-words-from
"kernel" { "dup" "nip" "over" } add-words-from
"sequences" { "nth" } add-words-from
[ string-lines parse-lines ] dip

View File

@ -109,6 +109,34 @@ IN: bootstrap.syntax
"'["
"@"
"_"
"[["
"[=["
"[==["
"[===["
"[====["
"[=====["
"[======["
"![["
"![=["
"![==["
"![===["
"![====["
"![=====["
"![======["
"I[["
"I[=["
"I[==["
"I[===["
"I[====["
"I[=====["
"I[======["
":>"
"|["
"let["
"'let["
} [ "syntax" create-word drop ] each
"t" "syntax" lookup-word define-symbol

View File

@ -89,6 +89,6 @@ MACRO: interpolate-locals ( str -- quot )
parse-multiline-string
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 ;

View File

@ -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 ;

View File

@ -8,7 +8,8 @@ classes.tuple.parser classes.union combinators compiler.units
definitions delegate delegate.private effects effects.parser fry
generic generic.hook generic.math generic.parser
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
splitting stack-checker strings strings.parser typed vectors
vocabs.parser words words.alias words.constant words.symbol ;
@ -347,4 +348,40 @@ IN: bootstrap.syntax
] define-core-syntax
{ "_" "@" } 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