blob: b19247bc8dfaf6589a24ed393562313c7a133405 [file] [log] [blame]
Bram Moolenaarbaca7f72013-09-22 14:42:24 +02001" Vim syntax file
2" Language: J
3" Maintainer: David Bürgin <676c7473@gmail.com>
Bram Moolenaara6878372014-03-22 21:02:50 +01004" URL: https://github.com/glts/vim-j
5" Last Change: 2014-03-17
Bram Moolenaarbaca7f72013-09-22 14:42:24 +02006
Bram Moolenaara6878372014-03-22 21:02:50 +01007if exists('b:current_syntax')
Bram Moolenaarbaca7f72013-09-22 14:42:24 +02008 finish
9endif
10
11syntax case match
12syntax sync minlines=50
13
Bram Moolenaara6878372014-03-22 21:02:50 +010014syntax match jControl /\<\%(assert\|break\|case\|catch[dt]\=\|continue\|do\|else\%(if\)\=\|end\|fcase\|for\|if\|return\|select\|throw\|try\|whil\%(e\|st\)\)\./
15syntax match jControl /\<\%(for\|goto\|label\)_\a\k*\./
Bram Moolenaarbaca7f72013-09-22 14:42:24 +020016
Bram Moolenaara6878372014-03-22 21:02:50 +010017" 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.
20syntax 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
21syntax keyword jAdverb define each every fapplylines inv inverse items leaf rows table
22syntax keyword jConjunction bind cuts def on
23syntax 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
24syntax match jVerb /\<\%(assert\|break\|do\)\>\.\@!/
Bram Moolenaarbaca7f72013-09-22 14:42:24 +020025
Bram Moolenaara6878372014-03-22 21:02:50 +010026syntax region jString oneline start=/'/ skip=/''/ end=/'/
27
28" Number patterns. Matching J numbers is difficult. The regular expression
29" used for the general case roughly embodies this grammar sketch:
Bram Moolenaarbaca7f72013-09-22 14:42:24 +020030"
Bram Moolenaara6878372014-03-22 21:02:50 +010031" BASE := /_?\d+(\.\d*)?([eE]_?\d+)?/
32" RATIONAL := BASE | BASE r BASE
33" COMPLEX := BASE | BASE (j|a[dr]) BASE
34" JNUMBER := RATIONAL | RATIONAL [px] RATIONAL | COMPLEX | COMPLEX [px] COMPLEX
Bram Moolenaarbaca7f72013-09-22 14:42:24 +020035"
Bram Moolenaara6878372014-03-22 21:02:50 +010036" The grammar is implemented as shown in this pseudo-regexp:
Bram Moolenaarbaca7f72013-09-22 14:42:24 +020037"
Bram Moolenaara6878372014-03-22 21:02:50 +010038" base rational complex remainder
39" /\< B ( [r]B ([px]B([r]B)?)? | (j|a[dr])B ([px]B((j|a[dr])B)?)? | [px]B ((j|a[dr]|r)B)? )?/
40"
41" All in all, a compromise between correctness and practicality had to be
42" made. See http://www.jsoftware.com/help/dictionary/dcons.htm for reference.
43syntax 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\+\)\=\)\=\)\)\=/
44syntax match jNumber /\<_\=\d\+\%([eE]\d\+\)\=b_\=[0-9a-z]\+/
45syntax match jNumber /\<__\=\>/
46syntax match jNumber /\<_\=\d\+x\>/
Bram Moolenaarbaca7f72013-09-22 14:42:24 +020047
Bram Moolenaara6878372014-03-22 21:02:50 +010048syntax keyword jTodo TODO FIXME XXX contained
49syntax match jComment /NB\..*$/ contains=jTodo,@Spell
50syntax match jSharpBang /\%^#!.*$/
Bram Moolenaarbaca7f72013-09-22 14:42:24 +020051
Bram Moolenaara6878372014-03-22 21:02:50 +010052highlight default link jControl Statement
53highlight default link jNoun Identifier
54highlight default link jAdverb Identifier
55highlight default link jConjunction Identifier
56highlight default link jVerb Function
57highlight default link jString String
58highlight default link jNumber Number
59highlight default link jTodo Todo
60highlight default link jComment Comment
61highlight default link jSharpBang PreProc
Bram Moolenaarbaca7f72013-09-22 14:42:24 +020062
Bram Moolenaara6878372014-03-22 21:02:50 +010063let b:current_syntax = 'j'