Merge branch 'master' of git://factorcode.org/git/factor
commit
bf884ebce8
|
@ -1,12 +1,11 @@
|
||||||
! Copyright (C) 2005, 2007 Slava Pestov.
|
! Copyright (C) 2005, 2008 Slava Pestov.
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: arrays definitions generic assocs kernel math
|
USING: arrays definitions generic assocs kernel math
|
||||||
namespaces prettyprint sequences strings vectors words
|
namespaces prettyprint sequences strings vectors words
|
||||||
quotations inspector io.styles io combinators sorting
|
quotations inspector io.styles io combinators sorting
|
||||||
splitting math.parser effects continuations debugger
|
splitting math.parser effects continuations debugger
|
||||||
io.files io.streams.string io.streams.lines vocabs
|
io.files io.streams.string io.streams.lines vocabs
|
||||||
source-files classes hashtables compiler.errors compiler.units
|
source-files classes hashtables compiler.errors compiler.units ;
|
||||||
ascii ;
|
|
||||||
IN: parser
|
IN: parser
|
||||||
|
|
||||||
TUPLE: lexer text line column ;
|
TUPLE: lexer text line column ;
|
||||||
|
@ -55,8 +54,9 @@ t parser-notes set-global
|
||||||
0 over set-lexer-column
|
0 over set-lexer-column
|
||||||
dup lexer-line 1+ swap set-lexer-line ;
|
dup lexer-line 1+ swap set-lexer-line ;
|
||||||
|
|
||||||
: skip ( i seq quot -- n )
|
: skip ( i seq ? -- n )
|
||||||
over >r find* drop
|
over >r
|
||||||
|
[ swap CHAR: \s eq? xor ] curry find* drop
|
||||||
[ r> drop ] [ r> length ] if* ; inline
|
[ r> drop ] [ r> length ] if* ; inline
|
||||||
|
|
||||||
: change-column ( lexer quot -- )
|
: change-column ( lexer quot -- )
|
||||||
|
@ -67,14 +67,13 @@ t parser-notes set-global
|
||||||
GENERIC: skip-blank ( lexer -- )
|
GENERIC: skip-blank ( lexer -- )
|
||||||
|
|
||||||
M: lexer skip-blank ( lexer -- )
|
M: lexer skip-blank ( lexer -- )
|
||||||
[ [ blank? not ] skip ] change-column ;
|
[ t skip ] change-column ;
|
||||||
|
|
||||||
GENERIC: skip-word ( lexer -- )
|
GENERIC: skip-word ( lexer -- )
|
||||||
|
|
||||||
M: lexer skip-word ( lexer -- )
|
M: lexer skip-word ( lexer -- )
|
||||||
[
|
[
|
||||||
2dup nth CHAR: " =
|
2dup nth CHAR: " = [ drop 1+ ] [ f skip ] if
|
||||||
[ drop 1+ ] [ [ blank? ] skip ] if
|
|
||||||
] change-column ;
|
] change-column ;
|
||||||
|
|
||||||
: still-parsing? ( lexer -- ? )
|
: still-parsing? ( lexer -- ? )
|
||||||
|
|
|
@ -4,7 +4,7 @@ USING: arrays byte-arrays byte-vectors bit-arrays bit-vectors
|
||||||
generic hashtables io assocs kernel math namespaces sequences
|
generic hashtables io assocs kernel math namespaces sequences
|
||||||
strings sbufs io.styles vectors words prettyprint.config
|
strings sbufs io.styles vectors words prettyprint.config
|
||||||
prettyprint.sections quotations io io.files math.parser effects
|
prettyprint.sections quotations io io.files math.parser effects
|
||||||
tuples classes float-arrays float-vectors ascii ;
|
tuples classes float-arrays float-vectors ;
|
||||||
IN: prettyprint.backend
|
IN: prettyprint.backend
|
||||||
|
|
||||||
GENERIC: pprint* ( obj -- )
|
GENERIC: pprint* ( obj -- )
|
||||||
|
@ -58,24 +58,17 @@ M: f pprint* drop \ f pprint-word ;
|
||||||
! Strings
|
! Strings
|
||||||
: ch>ascii-escape ( ch -- str )
|
: ch>ascii-escape ( ch -- str )
|
||||||
H{
|
H{
|
||||||
{ CHAR: \e "\\e" }
|
{ CHAR: \e CHAR: \\e }
|
||||||
{ CHAR: \n "\\n" }
|
{ CHAR: \n CHAR: \\n }
|
||||||
{ CHAR: \r "\\r" }
|
{ CHAR: \r CHAR: \\r }
|
||||||
{ CHAR: \t "\\t" }
|
{ CHAR: \t CHAR: \\t }
|
||||||
{ CHAR: \0 "\\0" }
|
{ CHAR: \0 CHAR: \\0 }
|
||||||
{ CHAR: \\ "\\\\" }
|
{ CHAR: \\ CHAR: \\\\ }
|
||||||
{ CHAR: \" "\\\"" }
|
{ CHAR: \" CHAR: \\\" }
|
||||||
} at ;
|
} at ;
|
||||||
|
|
||||||
: ch>unicode-escape ( ch -- str )
|
|
||||||
>hex 6 CHAR: 0 pad-left "\\u" swap append ;
|
|
||||||
|
|
||||||
: unparse-ch ( ch -- )
|
: unparse-ch ( ch -- )
|
||||||
dup quotable? [
|
dup ch>ascii-escape [ ] [ ] ?if , ;
|
||||||
,
|
|
||||||
] [
|
|
||||||
dup ch>ascii-escape [ ] [ ch>unicode-escape ] ?if %
|
|
||||||
] if ;
|
|
||||||
|
|
||||||
: do-string-limit ( str -- trimmed )
|
: do-string-limit ( str -- trimmed )
|
||||||
string-limit get [
|
string-limit get [
|
||||||
|
|
|
@ -24,5 +24,3 @@ IN: ascii
|
||||||
|
|
||||||
: alpha? ( ch -- ? )
|
: alpha? ( ch -- ? )
|
||||||
dup Letter? [ drop t ] [ digit? ] if ; inline
|
dup Letter? [ drop t ] [ digit? ] if ; inline
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue