diff --git a/extra/peg/peg.factor b/extra/peg/peg.factor index 00271a9ad3..dd0b11fce3 100755 --- a/extra/peg/peg.factor +++ b/extra/peg/peg.factor @@ -3,7 +3,8 @@ USING: kernel sequences strings namespaces math assocs shuffle vectors arrays combinators.lib math.parser match unicode.categories sequences.lib compiler.units parser - words quotations effects memoize accessors combinators.cleave ; + words quotations effects memoize accessors + combinators.cleave locals ; IN: peg TUPLE: parse-result remaining ast ; @@ -14,9 +15,23 @@ SYMBOL: ignore parse-result construct-boa ; SYMBOL: compiled-parsers +SYMBOL: packrat +SYMBOL: failed GENERIC: (compile) ( parser -- quot ) +:: run-packrat-parser ( input quot c -- result ) + input slice? [ input slice-from ] [ 0 ] if + quot c [ drop H{ } clone ] cache + [ + drop input quot call + ] cache ; inline + +: run-parser ( input quot -- result ) + #! If a packrat cache is available, use memoization for + #! packrat parsing, otherwise do a standard peg call. + packrat get [ run-packrat-parser ] [ call ] if* ; inline + : compiled-parser ( parser -- word ) #! Look to see if the given parser has been compiled. #! If not, compile it to a temporary word, cache it, @@ -24,11 +39,11 @@ GENERIC: (compile) ( parser -- quot ) dup compiled-parsers get at [ nip ] [ - dup (compile) define-temp + dup (compile) [ run-parser ] curry define-temp [ swap compiled-parsers get set-at ] keep ] if* ; -MEMO: compile ( parser -- word ) +: compile ( parser -- word ) H{ } clone compiled-parsers [ [ compiled-parser ] with-compilation-unit ] with-variable ; diff --git a/extra/ui/gadgets/scrollers/scrollers.factor b/extra/ui/gadgets/scrollers/scrollers.factor index 98951b74e3..7966f4e206 100755 --- a/extra/ui/gadgets/scrollers/scrollers.factor +++ b/extra/ui/gadgets/scrollers/scrollers.factor @@ -3,13 +3,14 @@ USING: arrays ui.gadgets ui.gadgets.viewports ui.gadgets.frames ui.gadgets.grids ui.gadgets.theme ui.gadgets.sliders ui.gestures kernel math -namespaces sequences models combinators math.vectors ; +namespaces sequences models combinators math.vectors +tuples ; IN: ui.gadgets.scrollers TUPLE: scroller viewport x y follows ; : find-scroller ( gadget -- scroller/f ) - [ scroller? ] find-parent ; + [ [ scroller? ] is? ] find-parent ; : scroll-up-page scroller-y -1 swap slide-by-page ; diff --git a/extra/ui/tools/listener/listener.factor b/extra/ui/tools/listener/listener.factor index 75401b3861..7db0d63f45 100755 --- a/extra/ui/tools/listener/listener.factor +++ b/extra/ui/tools/listener/listener.factor @@ -6,7 +6,8 @@ kernel models namespaces parser quotations sequences ui.commands ui.gadgets ui.gadgets.editors ui.gadgets.labelled ui.gadgets.panes ui.gadgets.buttons ui.gadgets.scrollers ui.gadgets.tracks ui.gestures ui.operations vocabs words -prettyprint listener debugger threads boxes concurrency.flags ; +prettyprint listener debugger threads boxes concurrency.flags +math arrays ; IN: ui.tools.listener TUPLE: listener-gadget input output stack ; @@ -23,9 +24,19 @@ TUPLE: listener-gadget input output stack ; : ( listener -- gadget ) listener-gadget-output ; +TUPLE: input-scroller ; + +: ( interactor -- scroller ) + + input-scroller construct-empty + [ set-gadget-delegate ] keep ; + +M: input-scroller pref-dim* + drop { 0 100 } ; + : listener-input, ( -- ) g g-> set-listener-gadget-input - "Input" f track, ; + "Input" f track, ; : welcome. ( -- ) "If this is your first time with Factor, please read the " print