From 155171b828ff0f39fc46248cfa76015b3f6ad653 Mon Sep 17 00:00:00 2001 From: Doug Coleman Date: Thu, 17 Oct 2019 00:02:12 -0500 Subject: [PATCH] modern: more ws --- extra/modern/lexer/lexer.factor | 14 +++++++++----- extra/modern/modern.factor | 14 +++++++------- extra/modern/slices/slices.factor | 1 + 3 files changed, 17 insertions(+), 12 deletions(-) diff --git a/extra/modern/lexer/lexer.factor b/extra/modern/lexer/lexer.factor index 21199efeb0..5dad4f8b99 100644 --- a/extra/modern/lexer/lexer.factor +++ b/extra/modern/lexer/lexer.factor @@ -1,7 +1,7 @@ ! Copyright (C) 2019 Doug Coleman. ! See http://factorcode.org/license.txt for BSD license. -USING: accessors ascii constructors kernel prettyprint.custom -sequences ; +USING: accessors ascii constructors kernel prettyprint.backend +prettyprint.custom sequences sequences.private ; IN: modern.lexer ERROR: ws-expected string ; @@ -10,10 +10,14 @@ TUPLE: ws string ; CONSTRUCTOR: ws ( string -- ws ) dup string>> [ blank? not ] any? [ ws-expected ] when ; +M: ws nth string>> nth ; +M: ws nth-unsafe string>> nth-unsafe ; +M: ws length string>> length ; + ! Weird experiment -M: ws pprint* - drop ; - ! string>> dup "\"" "\"" pprint-string ; +! M: ws pprint* + ! drop ; +! string>> dup "\"" "\"" pprint-string ; TUPLE: lexed tokens ; diff --git a/extra/modern/modern.factor b/extra/modern/modern.factor index fcc548ed71..d299def08a 100644 --- a/extra/modern/modern.factor +++ b/extra/modern/modern.factor @@ -1,10 +1,10 @@ ! Copyright (C) 2016 Doug Coleman. ! See http://factorcode.org/license.txt for BSD license. USING: arrays assocs combinators combinators.short-circuit -constructors continuations io.encodings.utf8 io.files kernel make math -math.order modern.paths modern.slices sequences sequences.extras -sequences.generalizations sets shuffle splitting strings -syntax.modern unicode vocabs.loader ; +constructors continuations io.encodings.utf8 io.files kernel +make math math.order modern.lexer modern.paths modern.slices +sequences sequences.extras sequences.generalizations sets +shuffle splitting strings syntax.modern unicode vocabs.loader ; IN: modern ERROR: long-opening-mismatch tag open string n ch ; @@ -134,7 +134,7 @@ MACRO:: read-matched ( ch -- quot: ( string n tag -- string n' slice' ) ) 2over ?nth-of char: \[ = [ [ 1 + ] dip 1 modify-to 2over ?nth-of read-double-matched-bracket ] [ - [ slice-til-eol drop ] dip swap 2array + [ slice-til-eol drop ] dip swap 2array ] if ; : terminator? ( slice -- ? ) @@ -364,13 +364,13 @@ DEFER: lex-factor-top* : read-token-or-whitespace-top ( string n slice -- string n' slice/f ) dup length 0 = [ ! [ 1 + ] 2dip drop lex-factor-top - merge-slice-til-not-whitespace + merge-slice-til-not-whitespace ] when ; : read-token-or-whitespace-nested ( string n slice -- string n' slice/f ) dup length 0 = [ ! [ 1 + ] 2dip drop lex-factor-nested - merge-slice-til-not-whitespace + merge-slice-til-not-whitespace ] when ; : lex-factor-fallthrough ( string n/f slice/f ch/f -- string n'/f literal ) diff --git a/extra/modern/slices/slices.factor b/extra/modern/slices/slices.factor index 16bc199074..fb5c5ef256 100644 --- a/extra/modern/slices/slices.factor +++ b/extra/modern/slices/slices.factor @@ -17,6 +17,7 @@ ERROR: unexpected-eof string n expected ; ] if ; inline : >strings ( seq -- str ) + ! [ slice? ] deep-filter [ dup slice? [ >string ] when ] deep-map ; : matching-section-delimiter ( string -- string' )