22" Language: J
33" Maintainer: David Bürgin <[email protected] >44" URL: https://github.com/glts/vim-j
5- " Last Change: 2014-03-17
5+ " Last Change: 2014-04-05
66
77if exists (' b:current_syntax' )
88 finish
99endif
1010
11+ let s: save_cpo = &cpo
12+ set cpo &vim
13+
1114syntax case match
1215syntax sync minlines =50
1316
17+ syntax cluster jStdlibItems contains =jStdlibNoun,jStdlibAdverb,jStdlibConjunction,jStdlibVerb
18+ syntax cluster jPrimitiveItems contains =jNoun,jAdverb,jConjunction,jVerb,jCopula
19+
1420syntax match jControl / \<\% (assert\| break\| case\| catch[dt]\=\| continue\| do\| else\% (if\)\=\| end\| fcase\| for\| if\| return\| select\| throw\| try\| whil\% (e\| st\)\)\. /
1521syntax match jControl / \<\% (for\| goto\| label\) _\a\k *\. /
1622
17- " Standard library names defined in the z locale. A few verbs need to be
18- " defined with ":syntax match" because they would otherwise take precedence
19- " over the corresponding jControl items.
20- syntax keyword jNoun ARGV BINPATH CR CRLF DEL Debug EAV EMPTY FF FHS IF64 IFIOS IFJCDROID IFJHS IFQT IFRASPI IFUNIX IFWIN IFWINCE IFWINE IFWOW64 JB01 JBOXED JCHAR JCMPX JFL JINT JPTR JSIZES JSTR JTYPES JVERSION LF LF2 TAB UNAME UNXLIB adverb andurl conjunction dbhelp dyad libjqt monad noun verb
21- syntax keyword jAdverb define each every fapplylines inv inverse items leaf rows table
22- syntax keyword jConjunction bind cuts def on
23- syntax keyword jVerb AND Endian IFDEF Note OR XOR alpha17 alpha27 anddf android_exec_host andunzip apply boxopen boxxopen bx calendar cd cdcb cder cderx cdf charsub chopstring clear coclass cocreate cocurrent codestroy coerase cofind cofindv cofullname coinfo coinsert coname conames conew conl conouns conounsx copath copathnl copathnlx coreset costate cut cutLF cutopen cutpara datatype dbctx dberm dberr dbg dbjmp dblocals dblxq dblxs dbnxt dbq dbr dbret dbrr dbrrx dbrun dbs dbsig dbsq dbss dbst dbstack dbstk dbstop dbstopme dbstopnext dbstops dbtrace dbview deb debc delstring detab dfh dir dircompare dircompares dirfind dirpath dirss dirssrplc dirtree dirused dlb dltb dltbs dquote drop dropafter dropto dtb dtbs echo empty endian erase evtloop exit expand f2utf8 fappend fappends fboxname fc fcopynew fdir ferase fetch fexist fexists fgets file2url fixdotdot fliprgb fmakex foldpara foldtext fpathcreate fpathname fputs fread freadblock freadr freads frename freplace fsize fss fssrplc fstamp fstringreplace ftype fview fwrite fwritenew fwrites getargs getdate getenv getqtbin hfd hostpathsep ic install iospath isatty isotimestamp isutf8 jcwdpath joinstring jpathsep jsystemdefs list ljust load loadd mema memf memr memw nameclass namelist names nc nl pick quote require rjust rplc script scriptd setbreak show sign sminfo smoutput sort split splitnostring splitstring ss startupandroid startupconsole startupide stderr stdin stdout stringreplace symdat symget symset take takeafter taketo timespacex timestamp timex tmoutput toCRLF toHOST toJ todate todayno tolower topara toupper tsdiff tsrep tstamp type ucp ucpcount unxlib usleep utf8 uucp valdate wcsize weekday weeknumber weeksinyear winpathsep
24- syntax match jVerb / \<\% (assert\| break\| do\)\>\.\@ !/
25-
26- syntax region jString oneline start =/ '/ skip =/ ''/ end =/ '/
23+ " Standard library names. A few names need to be defined with ":syntax match"
24+ " because they would otherwise take precedence over the corresponding jControl
25+ " and jDefineExpression items.
26+ syntax keyword jStdlibNoun ARGV BINPATH CR CRLF DEL Debug EAV EMPTY FF FHS IF64 IFIOS IFJCDROID IFJHS IFQT IFRASPI IFUNIX IFWIN IFWINCE IFWINE IFWOW64 JB01 JBOXED JCHAR JCMPX JFL JINT JPTR JSIZES JSTR JTYPES JVERSION LF LF2 TAB UNAME UNXLIB andurl dbhelp libjqt
27+ syntax keyword jStdlibAdverb define each every fapplylines inv inverse items leaf rows table
28+ syntax keyword jStdlibConjunction bind cuts def on
29+ syntax keyword jStdlibVerb AND Endian IFDEF Note OR XOR alpha17 alpha27 anddf android_exec_host andunzip apply boxopen boxxopen bx calendar cd cdcb cder cderx cdf charsub chopstring clear coclass cocreate cocurrent codestroy coerase cofind cofindv cofullname coinfo coinsert coname conames conew conl conouns conounsx copath copathnl copathnlx coreset costate cut cutLF cutopen cutpara datatype dbctx dberm dberr dbg dbjmp dblocals dblxq dblxs dbnxt dbq dbr dbret dbrr dbrrx dbrun dbs dbsig dbsq dbss dbst dbstack dbstk dbstop dbstopme dbstopnext dbstops dbtrace dbview deb debc delstring detab dfh dir dircompare dircompares dirfind dirpath dirss dirssrplc dirtree dirused dlb dltb dltbs dquote drop dropafter dropto dtb dtbs echo empty endian erase evtloop exit expand f2utf8 fappend fappends fboxname fc fcopynew fdir ferase fetch fexist fexists fgets file2url fixdotdot fliprgb fmakex foldpara foldtext fpathcreate fpathname fputs fread freadblock freadr freads frename freplace fsize fss fssrplc fstamp fstringreplace ftype fview fwrite fwritenew fwrites getargs getdate getenv getqtbin hfd hostpathsep ic install iospath isatty isotimestamp isutf8 jcwdpath joinstring jpathsep jsystemdefs list ljust load loadd mema memf memr memw nameclass namelist names nc nl pick quote require rjust rplc script scriptd setbreak show sign sminfo smoutput sort split splitnostring splitstring ss startupandroid startupconsole startupide stderr stdin stdout stringreplace symdat symget symset take takeafter taketo timespacex timestamp timex tmoutput toCRLF toHOST toJ todate todayno tolower topara toupper tsdiff tsrep tstamp type ucp ucpcount unxlib usleep utf8 uucp valdate wcsize weekday weeknumber weeksinyear winpathsep
30+ syntax match jStdlibNoun / \<\% (adverb\| conjunction\| dyad\| monad\| noun\| verb\)\> /
31+ syntax match jStdlibVerb / \<\% (assert\| break\| do\)\>\.\@ !/
2732
28- " Number patterns . Matching J numbers is difficult. The regular expression
29- " used for the general case roughly embodies this grammar sketch:
33+ " Numbers . Matching J numbers is difficult. The regular expression used for
34+ " the general case roughly embodies this grammar sketch:
3035"
3136" BASE := /_?\d+(\.\d*)?([eE]_?\d+)?/
3237" RATIONAL := BASE | BASE r BASE
@@ -43,21 +48,87 @@ syntax region jString oneline start=/'/ skip=/''/ end=/'/
4348syntax match jNumber / \< _\=\d\+\% (\.\d *\)\=\% ([eE]_\=\d\+\)\=\% (\% (r_\=\d\+\% (\.\d *\)\=\% ([eE]_\=\d\+\)\=\% ([px]_\=\d\+\% (\.\d *\)\=\% ([eE]_\=\d\+\)\=\% (r_\=\d\+\% (\.\d *\)\=\% ([eE]_\=\d\+\)\=\)\=\)\=\)\|\% (\% (j\| a[dr]\) _\=\d\+\% (\.\d *\)\=\% ([eE]_\=\d\+\)\=\% ([px]_\=\d\+\% (\.\d *\)\=\% ([eE]_\=\d\+\)\=\% (\% (j\| a[dr]\) _\=\d\+\% (\.\d *\)\=\% ([eE]_\=\d\+\)\=\)\=\)\=\)\|\% ([px]_\=\d\+\% (\.\d *\)\=\% ([eE]_\=\d\+\)\=\% (\% (j\| a[dr]\| r\) _\=\d\+\% (\.\d *\)\=\% ([eE]_\=\d\+\)\=\)\=\)\)\= /
4449syntax match jNumber / \< _\=\d\+\% ([eE]\d\+\)\= b_\= [0-9a-z]\+ /
4550syntax match jNumber / \< __\=\> /
51+ syntax match jNumber / \< _\. /
4652syntax match jNumber / \< _\=\d\+ x\> /
4753
48- syntax keyword jTodo TODO FIXME XXX contained
54+ syntax region jString oneline start =/ '/ skip =/ ''/ end =/ '/
55+
56+ syntax keyword jArgument contained x y u v m n
57+
58+ " Primitives. Order is significant both within the patterns and among
59+ " ":syntax match" statements. Refer to "Parts of speech" in the J dictionary.
60+ syntax match jNoun / \< a[.:]/
61+ syntax match jAdverb / [}~]\| [/\\ ]\.\=\|\<\% ([Mbft]\.\| t:\) /
62+ syntax match jConjunction / "\| `:\=\| [.:@&][.:]\=\| &\. :\|\<\% ([dDHT]\.\| [DLS]:\) /
63+ syntax match jVerb / [=!\] ]\| [\^ ?]\.\=\| [;[]:\=\| {\.\| [_/\\ ]:\| [<>+*\- %$|,#][.:]\=\| [~}"][.:]\| {\% [::]\|\<\% ([ACeEiIjLor]\.\| p\.\.\=\| [ipqsux]:\| 0:\| _\= [1-9]:\) /
64+ syntax match jCopula / =[.:]/
65+ syntax match jConjunction / ;\.\|\^ :\| ![.:]/
66+
67+ " Explicit noun definition. The difficulty is that the define expression
68+ " "0 : 0" can occur in the middle of a line but the jNounDefine region must
69+ " only start on the next line. The trick is to split the problem into two
70+ " regions and link them with "nextgroup=".
71+ syntax region jNounDefineStart
72+ \ matchgroup= jDefineExpression start = /\<\%(0\|noun\)\s\+\%(\:\s*0\|def\s\+0\|define\)\>/
73+ \ keepend matchgroup= NONE end = /$/
74+ \ contains= @j StdlibItems,@j PrimitiveItems,jNumber,jString,jParenGroup,jParen,jComment
75+ \ oneline skipempty nextgroup= jDefineEnd,jNounDefine
76+ " These two items must have "contained", which allows them to match only after
77+ " jNounDefineStart thanks to the "nextgroup=" above.
78+ syntax region jNounDefine
79+ \ matchgroup= NONE start = /^/
80+ \ matchgroup= jDefineEnd end = /^\s*)\s*$/
81+ \ contained
82+ " This match is necessary in case of an empty noun definition
83+ syntax match jDefineEnd contained / ^\s *)\s *$/
84+
85+ " Explicit verb, adverb, and conjunction definition
86+ syntax region jDefine
87+ \ matchgroup= jDefineExpression start = /\<\%([1-4]\|13\|adverb\|conjunction\|verb\|monad\|dyad\)\s\+\%(:\s*0\|def\s\+0\|define\)\>/
88+ \ matchgroup= jDefineEnd end = /^\s*)\s*$/
89+ \ contains= jControl,@j StdlibItems,@j PrimitiveItems,jNumber,jString,jArgument,jParenGroup,jParen,jComment,jDefineMonadDyad
90+ syntax match jDefineMonadDyad contained / ^\s *:\s *$/
91+
92+ " Paired parentheses. When a jDefineExpression such as "3 : 0" is
93+ " parenthesised it will erroneously extend jParenGroup to span over the whole
94+ " definition body. This situation receives a special treatment here.
95+ syntax match jParen / (\% (\s *\% ([0-4]\| 13\| noun\| adverb\| conjunction\| verb\| monad\| dyad\)\s\+\% (:\s *0\| def\s\+ 0\| define\)\s *)\)\@ =/
96+ syntax match jParen contained / \% ((\s *\% ([0-4]\| 13\| noun\| adverb\| conjunction\| verb\| monad\| dyad\)\s\+\% (:\s *0\| def\s\+ 0\| define\)\s *\)\@ <=)/
97+ syntax region jParenGroup
98+ \ matchgroup= jParen start = /(\%(\s*\%([0-4]\|13\|noun\|adverb\|conjunction\|verb\|monad\|dyad\)\s\+\%(:\s*0\|def\s\+0\|define\)\>\)\@!/
99+ \ matchgroup= jParen end = /)/
100+ \ oneline transparent
101+
102+ syntax keyword jTodo contained TODO FIXME XXX
49103syntax match jComment / NB\. .*$/ contains =jTodo,@Spell
104+
50105syntax match jSharpBang / \% ^#!.*$/
51106
52- highlight default link jControl Statement
53- highlight default link jNoun Identifier
54- highlight default link jAdverb Identifier
55- highlight default link jConjunction Identifier
56- highlight default link jVerb Function
57- highlight default link jString String
58- highlight default link jNumber Number
59- highlight default link jTodo Todo
60- highlight default link jComment Comment
61- highlight default link jSharpBang PreProc
107+ highlight default link jControl Statement
108+ highlight default link jStdlibNoun Identifier
109+ highlight default link jStdlibAdverb Function
110+ highlight default link jStdlibConjunction Function
111+ highlight default link jStdlibVerb Function
112+ highlight default link jString String
113+ highlight default link jNumber Number
114+ highlight default link jNoun Constant
115+ highlight default link jAdverb Normal
116+ highlight default link jConjunction Normal
117+ highlight default link jVerb Normal
118+ highlight default link jCopula Normal
119+ highlight default link jArgument Identifier
120+ highlight default link jParen Delimiter
121+
122+ highlight default link jDefineExpression Define
123+ highlight default link jDefineMonadDyad Delimiter
124+ highlight default link jDefineEnd Delimiter
125+ highlight default link jNounDefine Normal
126+
127+ highlight default link jTodo Todo
128+ highlight default link jComment Comment
129+ highlight default link jSharpBang PreProc
62130
63131let b: current_syntax = ' j'
132+
133+ let &cpo = s: save_cpo
134+ unlet s: save_cpo
0 commit comments