Starting to switch xmode to regexp; getting rid of <TAGS

db4
Daniel Ehrenberg 2009-02-12 13:18:43 -06:00
parent ccfd9f9c52
commit d0d615fb2b
6 changed files with 37 additions and 59 deletions

View File

@ -1,13 +1,14 @@
USING: xmode.loader xmode.utilities xmode.rules namespaces
strings splitting assocs sequences kernel io.files xml memoize
words globs combinators io.encodings.utf8 sorting accessors xml.data ;
words globs combinators io.encodings.utf8 sorting accessors xml.data
xml.traversal ;
IN: xmode.catalog
TUPLE: mode file file-name-glob first-line-glob ;
<TAGS: parse-mode-tag ( modes tag -- )
TAGS: parse-mode-tag ( modes tag -- )
TAG: MODE
TAG: MODE parse-mode-tag
dup "NAME" attr [
mode new {
{ "FILE" f (>>file) }
@ -17,11 +18,9 @@ TAG: MODE
] dip
rot set-at ;
TAGS>
: parse-modes-tag ( tag -- modes )
H{ } clone [
swap child-tags [ parse-mode-tag ] with each
swap children-tags [ parse-mode-tag ] with each
] keep ;
MEMO: modes ( -- modes )

View File

@ -1,56 +1,54 @@
USING: xmode.loader.syntax xmode.tokens xmode.rules
xmode.keyword-map xml.data xml.traversal xml assocs kernel
combinators sequences math.parser namespaces parser
xmode.utilities parser-combinators.regexp io.files accessors ;
xmode.utilities regexp io.files accessors ;
IN: xmode.loader
! Based on org.gjt.sp.jedit.XModeHandler
! RULES and its children
<TAGS: parse-rule-tag ( rule-set tag -- )
TAGS: parse-rule-tag ( rule-set tag -- )
TAG: PROPS
TAG: PROPS parse-rule-tag
parse-props-tag >>props drop ;
TAG: IMPORT
TAG: IMPORT parse-rule-tag
"DELEGATE" attr swap import-rule-set ;
TAG: TERMINATE
TAG: TERMINATE parse-rule-tag
"AT_CHAR" attr string>number >>terminate-char drop ;
RULE: SEQ seq-rule
RULE: SEQ seq-rule parse-rule-tag
shared-tag-attrs delegate-attr literal-start ;
RULE: SEQ_REGEXP seq-rule
RULE: SEQ_REGEXP seq-rule parse-rule-tag
shared-tag-attrs delegate-attr regexp-attr regexp-start ;
RULE: SPAN span-rule
RULE: SPAN span-rule parse-rule-tag
shared-tag-attrs delegate-attr match-type-attr span-attrs parse-begin/end-tags init-span-tag ;
RULE: SPAN_REGEXP span-rule
RULE: SPAN_REGEXP span-rule parse-rule-tag
shared-tag-attrs delegate-attr match-type-attr span-attrs regexp-attr parse-begin/end-tags init-span-tag ;
RULE: EOL_SPAN eol-span-rule
RULE: EOL_SPAN eol-span-rule parse-rule-tag
shared-tag-attrs delegate-attr match-type-attr literal-start init-eol-span-tag ;
RULE: EOL_SPAN_REGEXP eol-span-rule
RULE: EOL_SPAN_REGEXP eol-span-rule parse-rule-tag
shared-tag-attrs delegate-attr match-type-attr regexp-attr regexp-start init-eol-span-tag ;
RULE: MARK_FOLLOWING mark-following-rule
RULE: MARK_FOLLOWING mark-following-rule parse-rule-tag
shared-tag-attrs match-type-attr literal-start ;
RULE: MARK_PREVIOUS mark-previous-rule
RULE: MARK_PREVIOUS mark-previous-rule parse-rule-tag
shared-tag-attrs match-type-attr literal-start ;
TAG: KEYWORDS ( rule-set tag -- key value )
TAG: KEYWORDS parse-rule-tag
rule-set get ignore-case?>> <keyword-map>
swap child-tags [ over parse-keyword-tag ] each
swap children-tags [ over parse-keyword-tag ] each
swap (>>keywords) ;
TAGS>
: ?<regexp> ( string/f -- regexp/f )
dup [ rule-set get ignore-case?>> <regexp> ] when ;
dup [ rule-set get ignore-case?>> drop <regexp> ] when ;
: (parse-rules-tag) ( tag -- rule-set )
<rule-set> dup rule-set set
@ -66,7 +64,7 @@ TAGS>
: parse-rules-tag ( tag -- rule-set )
[
[ (parse-rules-tag) ] [ child-tags ] bi
[ (parse-rules-tag) ] [ children-tags ] bi
[ parse-rule-tag ] with each
rule-set get
] with-scope ;

View File

@ -3,7 +3,7 @@
USING: accessors xmode.tokens xmode.rules xmode.keyword-map
xml.data xml.traversal xml assocs kernel combinators sequences
math.parser namespaces make parser lexer xmode.utilities
parser-combinators.regexp io.files splitting arrays ;
regexp io.files splitting arrays xml.syntax.private ;
IN: xmode.loader.syntax
! Rule tag parsing utilities
@ -11,9 +11,10 @@ IN: xmode.loader.syntax
new swap init-from-tag swap add-rule ; inline
: RULE:
scan scan-word
scan scan-word scan-word
parse-definition { } make
swap [ (parse-rule-tag) ] 2curry (TAG:) ; parsing
[ swap [ (parse-rule-tag) ] 2curry ] dip
swap define-tag ; parsing
! Attribute utilities
: string>boolean ( string -- ? ) "TRUE" = ;
@ -32,7 +33,7 @@ IN: xmode.loader.syntax
[ "NAME" attr ] [ "VALUE" attr ] bi ;
: parse-props-tag ( tag -- assoc )
child-tags
children-tags
[ parse-prop-tag ] H{ } map>assoc ;
: position-attrs ( tag -- at-line-start? at-whitespace-end? at-word-start? )
@ -46,7 +47,7 @@ IN: xmode.loader.syntax
swap position-attrs <matcher> ;
: parse-regexp-matcher ( tag -- matcher )
dup children>string rule-set get ignore-case?>> <regexp>
dup children>string rule-set get ignore-case?>> drop <regexp>
swap position-attrs <matcher> ;
: shared-tag-attrs ( -- )
@ -79,22 +80,20 @@ IN: xmode.loader.syntax
[ parse-literal-matcher >>end drop ] , ;
! SPAN's children
<TAGS: parse-begin/end-tag ( rule tag -- )
TAGS: parse-begin/end-tag ( rule tag -- )
TAG: BEGIN
TAG: BEGIN parse-begin/end-tag
! XXX
parse-literal-matcher >>start drop ;
TAG: END
TAG: END parse-begin/end-tag
! XXX
parse-literal-matcher >>end drop ;
TAGS>
: parse-begin/end-tags ( -- )
[
! XXX: handle position attrs on span tag itself
child-tags [ parse-begin/end-tag ] with each
children-tags [ parse-begin/end-tag ] with each
] , ;
: init-span-tag ( -- ) [ drop init-span ] , ;

View File

@ -4,8 +4,10 @@ IN: xmode.marker
USING: kernel namespaces make xmode.rules xmode.tokens
xmode.marker.state xmode.marker.context xmode.utilities
xmode.catalog sequences math assocs combinators strings
parser-combinators.regexp splitting parser-combinators ascii
regexp splitting ascii parser-combinators regexp.backend
ascii combinators.short-circuit accessors ;
! parser-combinators is for the string-head? word
! regexp.backend is for the regexp class
! Based on org.gjt.sp.jedit.syntax.TokenMarker
@ -150,7 +152,7 @@ M: escape-rule handle-rule-start
process-escape? get [
escaped? [ not ] change
position [ + ] change
] [ 2drop ] if ;
] [ drop ] if ;
M: seq-rule handle-rule-start
?end-rule

View File

@ -1,6 +1,6 @@
USING: accessors xmode.tokens xmode.keyword-map kernel
sequences vectors assocs strings memoize unicode.case
parser-combinators.regexp ;
regexp regexp.backend ; ! regexp.backend has the regexp class
IN: xmode.rules
TUPLE: string-matcher string ignore-case? ;

View File

@ -4,8 +4,6 @@ IN: xmode.utilities
: implies ( x y -- z ) [ not ] dip or ; inline
: child-tags ( tag -- seq ) children>> [ tag? ] filter ;
: map-find ( seq quot -- result elt )
[ f ] 2dip
'[ nip @ dup ] find
@ -37,21 +35,3 @@ MACRO: (init-from-tag) ( specs -- )
: init-from-tag ( tag tuple specs -- tuple )
over [ (init-from-tag) ] dip ; inline
SYMBOL: tag-handlers
SYMBOL: tag-handler-word
: <TAGS:
CREATE tag-handler-word set
H{ } clone tag-handlers set ; parsing
: (TAG:) ( name quot -- ) swap tag-handlers get set-at ;
: TAG:
scan parse-definition
(TAG:) ; parsing
: TAGS>
tag-handler-word get
tag-handlers get >alist [ [ dup main>> ] dip case ] curry
define ; parsing