Merge branch 'master' of git://factorcode.org/git/factor

db4
Eduardo Cavazos 2008-08-30 22:01:02 -05:00
commit 3e2692d836
13 changed files with 140 additions and 137 deletions

View File

@ -3,7 +3,7 @@
! !
! Channels - based on ideas from newsqueak ! Channels - based on ideas from newsqueak
USING: kernel sequences sequences.lib threads continuations USING: kernel sequences sequences.lib threads continuations
random math ; random math accessors ;
IN: channels IN: channels
TUPLE: channel receivers senders ; TUPLE: channel receivers senders ;
@ -17,14 +17,14 @@ GENERIC: from ( channel -- value )
<PRIVATE <PRIVATE
: wait ( channel -- ) : wait ( channel -- )
[ channel-senders push ] curry [ senders>> push ] curry
"channel send" suspend drop ; "channel send" suspend drop ;
: (to) ( value receivers -- ) : (to) ( value receivers -- )
delete-random resume-with yield ; delete-random resume-with yield ;
: notify ( continuation channel -- channel ) : notify ( continuation channel -- channel )
[ channel-receivers push ] keep ; [ receivers>> push ] keep ;
: (from) ( senders -- ) : (from) ( senders -- )
delete-random resume ; delete-random resume ;
@ -32,11 +32,11 @@ GENERIC: from ( channel -- value )
PRIVATE> PRIVATE>
M: channel to ( value channel -- ) M: channel to ( value channel -- )
dup channel-receivers dup receivers>>
dup empty? [ drop dup wait to ] [ nip (to) ] if ; dup empty? [ drop dup wait to ] [ nip (to) ] if ;
M: channel from ( channel -- value ) M: channel from ( channel -- value )
[ [
notify channel-senders notify senders>>
dup empty? [ drop ] [ (from) ] if dup empty? [ drop ] [ (from) ] if
] curry "channel receive" suspend ; ] curry "channel receive" suspend ;

View File

@ -52,17 +52,17 @@ H{ } clone root-cache set-global
SYMBOL: load-help? SYMBOL: load-help?
: load-source ( vocab -- vocab ) : load-source ( vocab -- vocab )
f >>source-loaded? f over set-vocab-source-loaded?
[ vocab-source-path [ parse-file ] [ [ ] ] if* ] keep [ vocab-source-path [ parse-file ] [ [ ] ] if* ] keep
t >>source-loaded? t over set-vocab-source-loaded?
[ [ % ] [ call ] if-bootstrapping ] dip ; [ [ % ] [ call ] if-bootstrapping ] dip ;
: load-docs ( vocab -- vocab ) : load-docs ( vocab -- vocab )
load-help? get [ load-help? get [
f >>docs-loaded? f over set-vocab-docs-loaded?
[ vocab-docs-path [ ?run-file ] when* ] keep [ vocab-docs-path [ ?run-file ] when* ] keep
t >>docs-loaded? t over set-vocab-docs-loaded?
] when ; ] when ;
: reload ( name -- ) : reload ( name -- )

View File

@ -3,7 +3,7 @@
USING: arrays asn1.ldap assocs byte-arrays combinators USING: arrays asn1.ldap assocs byte-arrays combinators
continuations io io.binary io.streams.string kernel math continuations io io.binary io.streams.string kernel math
math.parser namespaces pack strings sequences ; math.parser namespaces pack strings sequences accessors ;
IN: asn1 IN: asn1
@ -48,16 +48,12 @@ SYMBOL: elements
TUPLE: element syntax id tag tagclass encoding contentlength newobj objtype ; TUPLE: element syntax id tag tagclass encoding contentlength newobj objtype ;
: <element> ( -- element ) element new ;
: set-id ( -- boolean )
read1 dup elements get set-element-id ;
: get-id ( -- id ) : get-id ( -- id )
elements get element-id ; elements get id>> ;
: (set-tag) ( -- ) : (set-tag) ( -- )
elements get element-id 31 bitand elements get id>> 31 bitand
dup elements get set-element-tag dup elements get set-element-tag
31 < [ 31 < [
[ "unsupported tag encoding: #{" % [ "unsupported tag encoding: #{" %
@ -81,14 +77,14 @@ TUPLE: element syntax id tag tagclass encoding contentlength newobj objtype ;
] unless elements get set-element-contentlength ; ] unless elements get set-element-contentlength ;
: set-newobj ( -- ) : set-newobj ( -- )
elements get element-contentlength read elements get contentlength>> read
elements get set-element-newobj ; elements get set-element-newobj ;
: set-objtype ( syntax -- ) : set-objtype ( syntax -- )
builtin-syntax 2array [ builtin-syntax 2array [
elements get element-tagclass swap at elements get tagclass>> swap at
elements get element-encoding swap at elements get encoding>> swap at
elements get element-tag elements get tag>>
swap at [ swap at [
elements get set-element-objtype elements get set-element-objtype
] when* ] when*
@ -99,7 +95,7 @@ DEFER: read-ber
SYMBOL: end SYMBOL: end
: (read-array) ( -- ) : (read-array) ( -- )
elements get element-id [ elements get id>> [
elements get element-syntax read-ber elements get element-syntax read-ber
dup end = [ drop ] [ , (read-array) ] if dup end = [ drop ] [ , (read-array) ] if
] when ; ] when ;
@ -115,9 +111,13 @@ SYMBOL: end
{ "array" [ "" or [ read-array ] with-string-reader ] } { "array" [ "" or [ read-array ] with-string-reader ] }
} case ; } case ;
: set-id ( -- boolean )
read1 dup elements get set-element-id ;
: read-ber ( syntax -- object ) : read-ber ( syntax -- object )
<element> elements set element new
elements get set-element-syntax swap >>syntax
elements set
set-id [ set-id [
(set-tag) (set-tag)
set-tagclass set-tagclass

View File

@ -1,4 +1,4 @@
USING: math kernel debugger ; USING: accessors math kernel debugger ;
IN: benchmark.fib4 IN: benchmark.fib4
TUPLE: box i ; TUPLE: box i ;
@ -6,15 +6,15 @@ TUPLE: box i ;
C: <box> box C: <box> box
: tuple-fib ( m -- n ) : tuple-fib ( m -- n )
dup box-i 1 <= [ dup i>> 1 <= [
drop 1 <box> drop 1 <box>
] [ ] [
box-i 1- <box> i>> 1- <box>
dup tuple-fib dup tuple-fib
swap swap
box-i 1- <box> i>> 1- <box>
tuple-fib tuple-fib
swap box-i swap box-i + <box> swap i>> swap i>> + <box>
] if ; ] if ;
: fib-main ( -- ) T{ box f 34 } tuple-fib T{ box f 9227465 } assert= ; : fib-main ( -- ) T{ box f 34 } tuple-fib T{ box f 9227465 } assert= ;

View File

@ -1,9 +1,9 @@
USING: math kernel ; USING: math kernel accessors ;
IN: benchmark.typecheck1 IN: benchmark.typecheck1
TUPLE: hello n ; TUPLE: hello n ;
: foo ( obj -- obj n ) 0 100000000 [ over hello-n + ] times ; : foo ( obj -- obj n ) 0 100000000 [ over n>> + ] times ;
: typecheck-main ( -- ) 0 hello boa foo 2drop ; : typecheck-main ( -- ) 0 hello boa foo 2drop ;

View File

@ -2,7 +2,7 @@ USING: arrays combinators kernel lists math math.parser
namespaces parser lexer parser-combinators parser-combinators.simple namespaces parser lexer parser-combinators parser-combinators.simple
promises quotations sequences combinators.lib strings math.order promises quotations sequences combinators.lib strings math.order
assocs prettyprint.backend memoize unicode.case unicode.categories assocs prettyprint.backend memoize unicode.case unicode.categories
combinators.short-circuit ; combinators.short-circuit accessors ;
USE: io USE: io
IN: regexp IN: regexp
@ -277,7 +277,7 @@ TUPLE: regexp source parser ignore-case? ;
: match-head ( string regexp -- end ) : match-head ( string regexp -- end )
do-ignore-case regexp-parser parse dup nil? do-ignore-case regexp-parser parse dup nil?
[ drop f ] [ car parse-result-unparsed slice-from ] if ; [ drop f ] [ car parse-result-unparsed from>> ] if ;
! Literal syntax for regexps ! Literal syntax for regexps
: parse-options ( string -- ? ) : parse-options ( string -- ? )

View File

@ -1,6 +1,6 @@
USING: xmode.loader xmode.utilities xmode.rules namespaces USING: xmode.loader xmode.utilities xmode.rules namespaces
strings splitting assocs sequences kernel io.files xml memoize strings splitting assocs sequences kernel io.files xml memoize
words globs combinators io.encodings.utf8 sorting ; words globs combinators io.encodings.utf8 sorting accessors ;
IN: xmode.catalog IN: xmode.catalog
TUPLE: mode file file-name-glob first-line-glob ; TUPLE: mode file file-name-glob first-line-glob ;
@ -10,9 +10,9 @@ TUPLE: mode file file-name-glob first-line-glob ;
TAG: MODE TAG: MODE
"NAME" over at >r "NAME" over at >r
mode new { mode new {
{ "FILE" f set-mode-file } { "FILE" f (>>file) }
{ "FILE_NAME_GLOB" f set-mode-file-name-glob } { "FILE_NAME_GLOB" f (>>file-name-glob) }
{ "FIRST_LINE_GLOB" f set-mode-first-line-glob } { "FIRST_LINE_GLOB" f (>>first-line-glob) }
} init-from-tag r> } init-from-tag r>
rot set-at ; rot set-at ;
@ -35,7 +35,7 @@ MEMO: mode-names ( -- modes )
MEMO: (load-mode) ( name -- rule-sets ) MEMO: (load-mode) ( name -- rule-sets )
modes at [ modes at [
mode-file file>>
"resource:extra/xmode/modes/" prepend "resource:extra/xmode/modes/" prepend
utf8 <file-reader> parse-mode utf8 <file-reader> parse-mode
] [ ] [
@ -52,11 +52,11 @@ SYMBOL: rule-sets
dup -roll at* [ nip ] [ drop no-such-rule-set ] if ; dup -roll at* [ nip ] [ drop no-such-rule-set ] if ;
: resolve-delegate ( rule -- ) : resolve-delegate ( rule -- )
dup rule-delegate dup string? dup delegate>> dup string?
[ get-rule-set nip swap set-rule-delegate ] [ 2drop ] if ; [ get-rule-set nip swap (>>delegate) ] [ 2drop ] if ;
: each-rule ( rule-set quot -- ) : each-rule ( rule-set quot -- )
>r rule-set-rules values concat r> each ; inline >r rules>> values concat r> each ; inline
: resolve-delegates ( ruleset -- ) : resolve-delegates ( ruleset -- )
[ resolve-delegate ] each-rule ; [ resolve-delegate ] each-rule ;
@ -65,14 +65,14 @@ SYMBOL: rule-sets
over [ dupd update ] [ nip clone ] if ; over [ dupd update ] [ nip clone ] if ;
: import-keywords ( parent child -- ) : import-keywords ( parent child -- )
over >r [ rule-set-keywords ] bi@ ?update over >r [ keywords>> ] bi@ ?update
r> set-rule-set-keywords ; r> (>>keywords) ;
: import-rules ( parent child -- ) : import-rules ( parent child -- )
swap [ add-rule ] curry each-rule ; swap [ add-rule ] curry each-rule ;
: resolve-imports ( ruleset -- ) : resolve-imports ( ruleset -- )
dup rule-set-imports [ dup imports>> [
get-rule-set swap rule-sets [ get-rule-set swap rule-sets [
dup resolve-delegates dup resolve-delegates
2dup import-keywords 2dup import-keywords
@ -80,16 +80,19 @@ SYMBOL: rule-sets
] with-variable ] with-variable
] with each ; ] with each ;
ERROR: mutually-recursive-rulesets ruleset ;
: finalize-rule-set ( ruleset -- ) : finalize-rule-set ( ruleset -- )
dup rule-set-finalized? { dup finalized?>> {
{ f [ { f [
1 over set-rule-set-finalized? {
dup resolve-imports [ 1 >>finalized? drop ]
dup resolve-delegates [ resolve-imports ]
t swap set-rule-set-finalized? [ resolve-delegates ]
[ t >>finalized? drop ]
} cleave
] } ] }
{ t [ drop ] } { t [ drop ] }
{ 1 [ "Mutually recursive rule sets" throw ] } { 1 [ mutually-recursive-rulesets ] }
} case ; } case ;
: finalize-mode ( rulesets -- ) : finalize-mode ( rulesets -- )
@ -107,8 +110,8 @@ SYMBOL: rule-sets
dup [ glob-matches? ] [ 2drop f ] if ; dup [ glob-matches? ] [ 2drop f ] if ;
: suitable-mode? ( file-name first-line mode -- ? ) : suitable-mode? ( file-name first-line mode -- ? )
tuck mode-first-line-glob ?glob-matches tuck first-line-glob>> ?glob-matches
[ 2drop t ] [ mode-file-name-glob ?glob-matches ] if ; [ 2drop t ] [ file-name-glob>> ?glob-matches ] if ;
: find-mode ( file-name first-line -- mode ) : find-mode ( file-name first-line -- mode )
modes modes

View File

@ -1,7 +1,7 @@
USING: xmode.loader.syntax xmode.tokens xmode.rules USING: xmode.loader.syntax xmode.tokens xmode.rules
xmode.keyword-map xml.data xml.utilities xml assocs kernel xmode.keyword-map xml.data xml.utilities xml assocs kernel
combinators sequences math.parser namespaces parser combinators sequences math.parser namespaces parser
xmode.utilities regexp io.files ; xmode.utilities regexp io.files accessors ;
IN: xmode.loader IN: xmode.loader
! Based on org.gjt.sp.jedit.XModeHandler ! Based on org.gjt.sp.jedit.XModeHandler
@ -10,13 +10,13 @@ IN: xmode.loader
<TAGS: parse-rule-tag ( rule-set tag -- ) <TAGS: parse-rule-tag ( rule-set tag -- )
TAG: PROPS TAG: PROPS
parse-props-tag swap set-rule-set-props ; parse-props-tag >>props drop ;
TAG: IMPORT TAG: IMPORT
"DELEGATE" swap at swap import-rule-set ; "DELEGATE" swap at swap import-rule-set ;
TAG: TERMINATE TAG: TERMINATE
"AT_CHAR" swap at string>number swap set-rule-set-terminate-char ; "AT_CHAR" swap at string>number >>terminate-char drop ;
RULE: SEQ seq-rule RULE: SEQ seq-rule
shared-tag-attrs delegate-attr literal-start ; shared-tag-attrs delegate-attr literal-start ;
@ -45,7 +45,7 @@ RULE: MARK_PREVIOUS mark-previous-rule
TAG: KEYWORDS ( rule-set tag -- key value ) TAG: KEYWORDS ( rule-set tag -- key value )
ignore-case? get <keyword-map> ignore-case? get <keyword-map>
swap child-tags [ over parse-keyword-tag ] each swap child-tags [ over parse-keyword-tag ] each
swap set-rule-set-keywords ; swap (>>keywords) ;
TAGS> TAGS>
@ -55,29 +55,29 @@ TAGS>
: (parse-rules-tag) ( tag -- rule-set ) : (parse-rules-tag) ( tag -- rule-set )
<rule-set> <rule-set>
{ {
{ "SET" string>rule-set-name set-rule-set-name } { "SET" string>rule-set-name (>>name) }
{ "IGNORE_CASE" string>boolean set-rule-set-ignore-case? } { "IGNORE_CASE" string>boolean (>>ignore-case?) }
{ "HIGHLIGHT_DIGITS" string>boolean set-rule-set-highlight-digits? } { "HIGHLIGHT_DIGITS" string>boolean (>>highlight-digits?) }
{ "DIGIT_RE" ?<regexp> set-rule-set-digit-re } { "DIGIT_RE" ?<regexp> (>>digit-re) }
{ "ESCAPE" f add-escape-rule } { "ESCAPE" f add-escape-rule }
{ "DEFAULT" string>token set-rule-set-default } { "DEFAULT" string>token (>>default) }
{ "NO_WORD_SEP" f set-rule-set-no-word-sep } { "NO_WORD_SEP" f (>>no-word-sep) }
} init-from-tag ; } init-from-tag ;
: parse-rules-tag ( tag -- rule-set ) : parse-rules-tag ( tag -- rule-set )
dup (parse-rules-tag) [ dup (parse-rules-tag) [
dup rule-set-ignore-case? ignore-case? [ dup ignore-case?>> ignore-case? [
swap child-tags [ parse-rule-tag ] with each swap child-tags [ parse-rule-tag ] with each
] with-variable ] with-variable
] keep ; ] keep ;
: merge-rule-set-props ( props rule-set -- ) : merge-rule-set-props ( props rule-set -- )
[ rule-set-props assoc-union ] keep set-rule-set-props ; [ assoc-union ] change-props drop ;
! Top-level entry points ! Top-level entry points
: parse-mode-tag ( tag -- rule-sets ) : parse-mode-tag ( tag -- rule-sets )
dup "RULES" tags-named [ dup "RULES" tags-named [
parse-rules-tag dup rule-set-name swap parse-rules-tag dup name>> swap
] H{ } map>assoc ] H{ } map>assoc
swap "PROPS" tag-named [ swap "PROPS" tag-named [
parse-props-tag over values parse-props-tag over values

View File

@ -49,41 +49,41 @@ SYMBOL: ignore-case?
swap position-attrs <matcher> ; swap position-attrs <matcher> ;
: shared-tag-attrs ( -- ) : shared-tag-attrs ( -- )
{ "TYPE" string>token set-rule-body-token } , ; inline { "TYPE" string>token (>>body-token) } , ; inline
: delegate-attr ( -- ) : delegate-attr ( -- )
{ "DELEGATE" f set-rule-delegate } , ; { "DELEGATE" f (>>delegate) } , ;
: regexp-attr ( -- ) : regexp-attr ( -- )
{ "HASH_CHAR" f set-rule-chars } , ; { "HASH_CHAR" f (>>chars) } , ;
: match-type-attr ( -- ) : match-type-attr ( -- )
{ "MATCH_TYPE" string>match-type set-rule-match-token } , ; { "MATCH_TYPE" string>match-type (>>match-token) } , ;
: span-attrs ( -- ) : span-attrs ( -- )
{ "NO_LINE_BREAK" string>boolean set-rule-no-line-break? } , { "NO_LINE_BREAK" string>boolean (>>no-line-break?) } ,
{ "NO_WORD_BREAK" string>boolean set-rule-no-word-break? } , { "NO_WORD_BREAK" string>boolean (>>no-word-break?) } ,
{ "NO_ESCAPE" string>boolean set-rule-no-escape? } , ; { "NO_ESCAPE" string>boolean (>>no-escape?) } , ;
: literal-start ( -- ) : literal-start ( -- )
[ parse-literal-matcher swap set-rule-start ] , ; [ parse-literal-matcher >>start drop ] , ;
: regexp-start ( -- ) : regexp-start ( -- )
[ parse-regexp-matcher swap set-rule-start ] , ; [ parse-regexp-matcher >>start drop ] , ;
: literal-end ( -- ) : literal-end ( -- )
[ parse-literal-matcher swap set-rule-end ] , ; [ parse-literal-matcher >>end drop ] , ;
! SPAN's children ! SPAN's children
<TAGS: parse-begin/end-tag ( rule tag -- ) <TAGS: parse-begin/end-tag ( rule tag -- )
TAG: BEGIN TAG: BEGIN
! XXX ! XXX
parse-literal-matcher swap set-rule-start ; parse-literal-matcher >>start drop ;
TAG: END TAG: END
! XXX ! XXX
parse-literal-matcher swap set-rule-end ; parse-literal-matcher >>end drop ;
TAGS> TAGS>

View File

@ -3,7 +3,7 @@ USING: kernel namespaces xmode.rules xmode.tokens
xmode.marker.state xmode.marker.context xmode.utilities xmode.marker.state xmode.marker.context xmode.utilities
xmode.catalog sequences math assocs combinators combinators.lib xmode.catalog sequences math assocs combinators combinators.lib
strings regexp splitting parser-combinators ascii unicode.case strings regexp splitting parser-combinators ascii unicode.case
combinators.short-circuit ; combinators.short-circuit accessors ;
! Based on org.gjt.sp.jedit.syntax.TokenMarker ! Based on org.gjt.sp.jedit.syntax.TokenMarker
@ -12,11 +12,11 @@ combinators.short-circuit ;
: keyword-number? ( keyword -- ? ) : keyword-number? ( keyword -- ? )
{ {
[ current-rule-set rule-set-highlight-digits? ] [ current-rule-set highlight-digits?>> ]
[ dup [ digit? ] contains? ] [ dup [ digit? ] contains? ]
[ [
dup [ digit? ] all? [ dup [ digit? ] all? [
current-rule-set rule-set-digit-re current-rule-set digit-re>>
dup [ dupd matches? ] [ drop f ] if dup [ dupd matches? ] [ drop f ] if
] unless* ] unless*
] ]
@ -26,10 +26,10 @@ combinators.short-circuit ;
keyword-number? DIGIT and ; keyword-number? DIGIT and ;
: mark-keyword ( keyword -- id ) : mark-keyword ( keyword -- id )
current-rule-set rule-set-keywords at ; current-rule-set keywords>> at ;
: add-remaining-token ( -- ) : add-remaining-token ( -- )
current-rule-set rule-set-default prev-token, ; current-rule-set default>> prev-token, ;
: mark-token ( -- ) : mark-token ( -- )
current-keyword current-keyword
@ -48,9 +48,9 @@ M: rule match-position drop position get ;
: can-match-here? ( matcher rule -- ? ) : can-match-here? ( matcher rule -- ? )
match-position { match-position {
[ over ] [ over ]
[ over matcher-at-line-start? over zero? implies ] [ over at-line-start?>> over zero? implies ]
[ over matcher-at-whitespace-end? over whitespace-end get = implies ] [ over at-whitespace-end?>> over whitespace-end get = implies ]
[ over matcher-at-word-start? over last-offset get = implies ] [ over at-word-start?>> over last-offset get = implies ]
} 0&& 2nip ; } 0&& 2nip ;
: rest-of-line ( -- str ) : rest-of-line ( -- str )
@ -72,19 +72,19 @@ M: regexp text-matches?
>r >string r> match-head ; >r >string r> match-head ;
: rule-start-matches? ( rule -- match-count/f ) : rule-start-matches? ( rule -- match-count/f )
dup rule-start tuck swap can-match-here? [ dup start>> tuck swap can-match-here? [
rest-of-line swap matcher-text text-matches? rest-of-line swap text>> text-matches?
] [ ] [
drop f drop f
] if ; ] if ;
: rule-end-matches? ( rule -- match-count/f ) : rule-end-matches? ( rule -- match-count/f )
dup mark-following-rule? [ dup mark-following-rule? [
dup rule-start swap can-match-here? 0 and dup start>> swap can-match-here? 0 and
] [ ] [
dup rule-end tuck swap can-match-here? [ dup end>> tuck swap can-match-here? [
rest-of-line rest-of-line
swap matcher-text context get line-context-end or swap text>> context get end>> or
text-matches? text-matches?
] [ ] [
drop f drop f
@ -94,10 +94,10 @@ M: regexp text-matches?
DEFER: get-rules DEFER: get-rules
: get-always-rules ( vector/f ruleset -- vector/f ) : get-always-rules ( vector/f ruleset -- vector/f )
f swap rule-set-rules at ?push-all ; f swap rules>> at ?push-all ;
: get-char-rules ( vector/f char ruleset -- vector/f ) : get-char-rules ( vector/f char ruleset -- vector/f )
>r ch>upper r> rule-set-rules at ?push-all ; >r ch>upper r> rules>> at ?push-all ;
: get-rules ( char ruleset -- seq ) : get-rules ( char ruleset -- seq )
f -rot [ get-char-rules ] keep get-always-rules ; f -rot [ get-char-rules ] keep get-always-rules ;
@ -108,13 +108,13 @@ GENERIC: handle-rule-end ( match-count rule -- )
: find-escape-rule ( -- rule ) : find-escape-rule ( -- rule )
context get dup context get dup
line-context-in-rule-set rule-set-escape-rule [ ] [ in-rule-set>> escape-rule>> [ ] [
line-context-parent line-context-in-rule-set parent>> in-rule-set>>
dup [ rule-set-escape-rule ] when dup [ escape-rule>> ] when
] ?if ; ] ?if ;
: check-escape-rule ( rule -- ? ) : check-escape-rule ( rule -- ? )
rule-no-escape? [ f ] [ no-escape?>> [ f ] [
find-escape-rule dup [ find-escape-rule dup [
dup rule-start-matches? dup [ dup rule-start-matches? dup [
swap handle-rule-start swap handle-rule-start
@ -138,9 +138,9 @@ GENERIC: handle-rule-end ( match-count rule -- )
] when* ; ] when* ;
: rule-match-token* ( rule -- id ) : rule-match-token* ( rule -- id )
dup rule-match-token { dup match-token>> {
{ f [ dup rule-body-token ] } { f [ dup body-token>> ] }
{ t [ current-rule-set rule-set-default ] } { t [ current-rule-set default>> ] }
[ ] [ ]
} case nip ; } case nip ;
@ -156,8 +156,8 @@ M: seq-rule handle-rule-start
?end-rule ?end-rule
mark-token mark-token
add-remaining-token add-remaining-token
tuck rule-body-token next-token, tuck body-token>> next-token,
rule-delegate [ push-context ] when* ; delegate>> [ push-context ] when* ;
UNION: abstract-span-rule span-rule eol-span-rule ; UNION: abstract-span-rule span-rule eol-span-rule ;
@ -167,8 +167,8 @@ M: abstract-span-rule handle-rule-start
add-remaining-token add-remaining-token
tuck rule-match-token* next-token, tuck rule-match-token* next-token,
! ... end subst ... ! ... end subst ...
dup context get set-line-context-in-rule dup context get (>>in-rule)
rule-delegate push-context ; delegate>> push-context ;
M: span-rule handle-rule-end M: span-rule handle-rule-end
2drop ; 2drop ;
@ -197,15 +197,16 @@ M: mark-previous-rule handle-rule-start
] when ; ] when ;
: check-end-delegate ( -- ? ) : check-end-delegate ( -- ? )
context get line-context-parent [ context get parent>> [
line-context-in-rule [ in-rule>> [
dup rule-end-matches? dup [ dup rule-end-matches? dup [
[ [
swap handle-rule-end swap handle-rule-end
?end-rule ?end-rule
mark-token mark-token
add-remaining-token add-remaining-token
] keep context get line-context-parent line-context-in-rule rule-match-token* next-token, ] keep context get parent>> in-rule>>
rule-match-token* next-token,
pop-context pop-context
seen-whitespace-end? on t seen-whitespace-end? on t
] [ drop check-escape-rule ] if ] [ drop check-escape-rule ] if
@ -213,9 +214,9 @@ M: mark-previous-rule handle-rule-start
] [ f ] if* ; ] [ f ] if* ;
: handle-no-word-break ( -- ) : handle-no-word-break ( -- )
context get line-context-parent [ context get parent>> [
line-context-in-rule [ in-rule>> [
dup rule-no-word-break? [ dup no-word-break?>> [
rule-match-token* prev-token, rule-match-token* prev-token,
pop-context pop-context
] [ drop ] if ] [ drop ] if
@ -231,11 +232,11 @@ M: mark-previous-rule handle-rule-start
: (check-word-break) ( -- ) : (check-word-break) ( -- )
check-rule check-rule
1 current-rule-set rule-set-default next-token, ; 1 current-rule-set default>> next-token, ;
: rule-set-empty? ( ruleset -- ? ) : rule-set-empty? ( ruleset -- ? )
dup rule-set-rules assoc-empty? [ rules>> ] [ keywords>> ] bi
swap rule-set-keywords assoc-empty? and ; [ assoc-empty? ] bi@ and ;
: check-word-break ( -- ? ) : check-word-break ( -- ? )
current-char dup blank? [ current-char dup blank? [
@ -285,9 +286,9 @@ M: mark-previous-rule handle-rule-start
check-rule ; check-rule ;
: unwind-no-line-break ( -- ) : unwind-no-line-break ( -- )
context get line-context-parent [ context get parent>> [
line-context-in-rule [ in-rule>> [
rule-no-line-break? [ no-line-break?>> [
pop-context pop-context
unwind-no-line-break unwind-no-line-break
] when ] when

View File

@ -1,4 +1,4 @@
USING: xmode.marker.context xmode.rules symbols USING: xmode.marker.context xmode.rules symbols accessors
xmode.tokens namespaces kernel sequences assocs math ; xmode.tokens namespaces kernel sequences assocs math ;
IN: xmode.marker.state IN: xmode.marker.state
@ -9,13 +9,13 @@ SYMBOLS: line last-offset position context
escaped? process-escape? delegate-end-escaped? ; escaped? process-escape? delegate-end-escaped? ;
: current-rule ( -- rule ) : current-rule ( -- rule )
context get line-context-in-rule ; context get in-rule>> ;
: current-rule-set ( -- rule ) : current-rule-set ( -- rule )
context get line-context-in-rule-set ; context get in-rule-set>> ;
: current-keywords ( -- keyword-map ) : current-keywords ( -- keyword-map )
current-rule-set rule-set-keywords ; current-rule-set keywords>> ;
: token, ( from to id -- ) : token, ( from to id -- )
2over = [ 3drop ] [ >r line get subseq r> <token> , ] if ; 2over = [ 3drop ] [ >r line get subseq r> <token> , ] if ;
@ -32,9 +32,8 @@ SYMBOLS: line last-offset position context
context [ <line-context> ] change ; context [ <line-context> ] change ;
: pop-context ( -- ) : pop-context ( -- )
context get line-context-parent context get parent>>
dup context set f >>in-rule context set ;
f swap set-line-context-in-rule ;
: init-token-marker ( main prev-context line -- ) : init-token-marker ( main prev-context line -- )
line set line set

View File

@ -30,10 +30,10 @@ finalized?
V{ } clone >>imports ; V{ } clone >>imports ;
MEMO: standard-rule-set ( id -- ruleset ) MEMO: standard-rule-set ( id -- ruleset )
<rule-set> [ set-rule-set-default ] keep ; <rule-set> swap >>default ;
: import-rule-set ( import ruleset -- ) : import-rule-set ( import ruleset -- )
rule-set-imports push ; imports>> push ;
: inverted-index ( hashes key index -- ) : inverted-index ( hashes key index -- )
[ swapd push-at ] 2curry each ; [ swapd push-at ] 2curry each ;
@ -44,8 +44,9 @@ MEMO: standard-rule-set ( id -- ruleset )
] when* ; ] when* ;
: rule-set-no-word-sep* ( ruleset -- str ) : rule-set-no-word-sep* ( ruleset -- str )
dup rule-set-no-word-sep [ no-word-sep>> ]
swap rule-set-keywords dup [ keyword-map-no-word-sep* ] when [ keywords>> ] bi
dup [ keyword-map-no-word-sep* ] when
"_" 3append ; "_" 3append ;
! Match restrictions ! Match restrictions
@ -73,14 +74,14 @@ TUPLE: span-rule < rule ;
TUPLE: eol-span-rule < rule ; TUPLE: eol-span-rule < rule ;
: init-span ( rule -- ) : init-span ( rule -- )
dup rule-delegate [ drop ] [ dup delegate>> [ drop ] [
dup rule-body-token standard-rule-set dup body-token>> standard-rule-set
swap set-rule-delegate swap (>>delegate)
] if ; ] if ;
: init-eol-span ( rule -- ) : init-eol-span ( rule -- )
dup init-span dup init-span
t swap set-rule-no-line-break? ; t >>no-line-break? drop ;
TUPLE: mark-following-rule < rule ; TUPLE: mark-following-rule < rule ;
@ -101,18 +102,17 @@ M: string-matcher text-hash-char string-matcher-string first ;
M: regexp text-hash-char drop f ; M: regexp text-hash-char drop f ;
: rule-chars* ( rule -- string ) : rule-chars* ( rule -- string )
dup rule-chars [ chars>> ] [ start>> ] bi text>>
swap rule-start matcher-text
text-hash-char [ suffix ] when* ; text-hash-char [ suffix ] when* ;
: add-rule ( rule ruleset -- ) : add-rule ( rule ruleset -- )
>r dup rule-chars* >upper swap >r dup rule-chars* >upper swap
r> rule-set-rules inverted-index ; r> rules>> inverted-index ;
: add-escape-rule ( string ruleset -- ) : add-escape-rule ( string ruleset -- )
over [ over [
>r <escape-rule> r> [ <escape-rule> ] dip
2dup set-rule-set-escape-rule 2dup (>>escape-rule)
add-rule add-rule
] [ ] [
2drop 2drop

View File

@ -14,7 +14,7 @@ TUPLE: company employees type ;
: <company> V{ } clone f company boa ; : <company> V{ } clone f company boa ;
: add-employee company-employees push ; : add-employee employees>> push ;
<TAGS: parse-employee-tag <TAGS: parse-employee-tag
@ -22,7 +22,7 @@ TUPLE: employee name description ;
TAG: employee TAG: employee
employee new employee new
{ { "name" f set-employee-name } { f set-employee-description } } { { "name" f (>>name) } { f (>>description) } }
init-from-tag swap add-employee ; init-from-tag swap add-employee ;
TAGS> TAGS>
@ -32,7 +32,7 @@ TAGS>
: parse-company-tag : parse-company-tag
[ [
<company> <company>
{ { "type" >upper set-company-type } } { { "type" >upper (>>type) } }
init-from-tag dup init-from-tag dup
] keep ] keep
children>> [ tag? ] filter children>> [ tag? ] filter