1 ! Copyright (C) 2007, 2008 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: xmode.marker.context xmode.rules accessors
4 xmode.tokens namespaces make kernel sequences assocs math ;
7 ! Based on org.gjt.sp.jedit.syntax.TokenMarker
9 SYMBOLS: line last-offset position context
10 whitespace-end seen-whitespace-end?
11 escaped? process-escape? delegate-end-escaped? ;
13 : current-rule ( -- rule )
14 context get in-rule>> ;
16 : current-rule-set ( -- rule )
17 context get in-rule-set>> ;
19 : current-keywords ( -- keyword-map )
20 current-rule-set keywords>> ;
22 : token, ( from to id -- )
23 2over = [ 3drop ] [ [ line get subseq ] dip <token> , ] if ;
25 : prev-token, ( id -- )
26 [ last-offset get position get ] dip token,
27 position get last-offset set ;
29 : next-token, ( len id -- )
30 [ position get 2dup + ] dip token,
31 position get + dup 1- position set last-offset set ;
33 : push-context ( rules -- )
34 context [ <line-context> ] change ;
38 f >>in-rule context set ;
40 : init-token-marker ( main prev-context line -- )
42 [ ] [ f <line-context> ] ?if context set