" ------------------------------------------------------------------ " Language: j " Author: SM Smithfield " Last Change: February 11, 2020 " Filenames: *.ijs " Version: 0.2 " ------------------------------------------------------------------ " if exists('b:current_syntax') | finish | endif let s:save_cpo = &cpo set cpo&vim syn case match syn sync clear syn sync fromstart " syn cluster jStuff contains=jAdverb,jVerb,jConjunction,jNoun,jCopula,jNumeral,jForeign,jComment,jControl,jPreProc,jLocativeBase " " adverbs=: '~ / \ /. \. } b. f. M. t. t:' " syn match jAdverb "\~" syn match jAdverb "/\.\=" syn match jAdverb "\\\.\=" syn match jAdverb "}" syn match jAdverb "\<[bfMt]\." syn match jAdverb "t:" " " arguments=: 'm n u v x y' " syn match jArgument contained "\<[mnuvxy]\{1}\>" " " Verbs: " t=. '= < <. <: > >. >: _: + +. +: * *. *: - -. -: % %. %: ^ ^.' " t=. t,' $ $. $: ~. ~: | |. |: , ,. ,: ; ;: # #. #: ! /: \: [ [: ]' " t=. t,' { {. {: {:: }. }: ". ": ? ?.' " t=. t,' A. c. C. e. E. i. i: I. j. L. o. p. p: q: r. s: u: x:' " t=. t,' _9: _8: _7: _6: _5: _4: _3: _2: _1:' " t=. t,' 0: 1: 2: 3: 4: 5: 6: 7: 8: 9:' " syn match jVerb ";" syn match jVerb "=" syn match jVerb "<[.:]\=" syn match jVerb ">[.:]\=" " precedence issue see byzorkipt "syn match jVerb "\<_[:]\>" syn match jVerb "+[.:]\=" syn match jVerb "\*[.:]\=" syn match jVerb "-[.:]\=" syn match jVerb "%[.:]\=" syn match jVerb "\^[.]\=" syn match jVerb "$[.]\=" syn match jNoun "$:" syn match jVerb "\~[.:]" syn match jVerb "|[.:]\=" syn match jVerb ",[.:]\=" syn match jVerb ";[:]" syn match jVerb "#[.:]\=" syn match jVerb "!" syn match jVerb "/:" syn match jVerb "\\:" syn match jVerb "\[[.:]\=" syn match jVerb "\]" syn match jVerb "{[.:]\=" syn match jVerb "{::" syn match jVerb "}[.:]" syn match jVerb "?[.]\=" syn match jVerb "\<[AcCeEiIjLopr]\." syn match jVerb "\<[ipqsuxL]:" syn match jVerb "\" syn match jLocativeIndirect contained "__\a\+\>" syn match jLocativeZ contained "_z_" " " Control: " t=. 'assert. break. case. catch. catchd. catcht. continue. do.' " t=. t,' else. elseif. end. fcase. for. goto. if. label.' " t=. t,' return. select. throw. trap. try. while. whilst.' " syn match jControl contained "\(\(assert\)\|\(break\)\|\(case\)\|\(catch\)\|\(catchd\)\)\." syn match jControl contained "\(\(catcht\)\|\(continue\)\|\(do\)\|\(else\)\|\(elseif\)\)\." syn match jControl contained "\(\(end\)\|\(fcase\)\|\(if\)\|\(return\)\|\(select\)\)\." syn match jControl contained "\(\(throw\)\|\(trap\)\|\(try\)\|\(while\)\|\(whilst\)\)\." syn match jControl contained "\(\(for\)\|\(goto\)\|\(label\)\)\(_\w\+\)\=\." contains=jControlLabel syn match jControlLabel contained "_\w\+" " Nouns: syn match jNoun "\" syn match jNoun contained "\<__\?\>" " precedence issue. verb must follow jNoun. see byzorkipt syn match jVerb "_[.:]\{1}" syn match jCopula "=[.:]\{1}" syn match jCopula contained "=[.:]\{1}" syn match jForeign %\d\+\s*!:\s*\d\+% contains=jConjunction,jForeignAdverb syn match jForeignAdverb +\d\++ contained syn match jComment "NB\..*$" syn match jCommentError "NB\.[.:].*$" " Trick: contained flag creates a second behavior. syn region jParens extend keepend oneline matchgroup=PreProc start=+(+ end=+)+ contains=@jStuff,jQuotes,jParens,jColon,jColonConj,jQuoteEscape syn region jParens contained extend keepend oneline matchgroup=PreProc start=+(+ end=+)+ contains=@jStuff,jQuotes,jParens,jColon,jColonConj,jQuoteEscape,jArgument syn region jParensJ contained extend keepend oneline matchgroup=PreProc start=+(+ end=+)+ contains=@jStuff,jQuotesJ,jParensJ,jColon,jColonConj,jQuoteEscape,jArgument syn region jQuotes extend keepend oneline matchgroup=PreProc start=+'+ end=+'+ skip=+''+ contains=jQuoteEscape syn region jQuotesJ contained extend keepend oneline matchgroup=PreProc start=+'+ end=+'+ skip=+''+ contains=jQuoteEscape,jArgument,@jStuff,jParens,jColon,jColonConj syn match jQuoteEscape contained +''+ syn keyword jPreProc load require syn keyword jPreProc coclass cocreate cocurrent codestroy coerase cofind cofindv syn keyword jPreProc cofullname coinfo coinsert coname conames conew conl conouns syn keyword jPreProc conounsx copath copathnl copathnlx coreset costate syn keyword jPreProc CR CRLF DEL EAV EMPTY FF LF TAB "------------------------------------ " All About The Colon: two cases.. " single line " syn match jColon "\" skipwhite skipnl skipempty nextgroup=jColonRH syn match jColon "13\s\+:\ze[^.:]" skipwhite skipnl skipempty nextgroup=jColonRH syn match jColon "[1234]\s\+:\ze[^.:]" skipwhite skipnl skipempty nextgroup=jColonRH syn match jColonConj ":\ze[^.:]" skipwhite skipnl skipempty nextgroup=jColonRH syn match jColonConj ":\ze[^.:]" contained " order matters for contains= group lists. first group matches preferentially syn region jColonRH contained keepend start="." end="$" contains=jQuotesJ,jColonExtend,@jStuff,jParensJ " multi line. 'extend' breaks out syn region jColonExtend contained extend matchgroup=Underlined start="0" end="^)" contains=@jStuff,jQuotes,jParens,jArgument,jColon,jColonTP,jNounIs fold " Trick: sort of a trick. because j relies so lightly on nested structures, " this is enough to make the coloring correct. It will however also color " additional parens which could be seen as an error, but the intent of this " file is to facilitate the reading of correct code rather than catching this " particular sort of edge case/error. syn match jColonTP contained ")" " 0 : 0 Nouns: syn match jColonNoun "0\s\+:\s*0" contains=jColonNoun2,@jStuff,jQuotes,jParensNoun skipwhite skipnl skipempty nextgroup=jColonRHNounExtend syn match jColonNoun "0\s\+:\s*0$" contains=jColonNoun2,@jStuff,jQuotes,jParensNoun skipwhite skipnl skipempty nextgroup=jColonNounExtend syn match jColonNoun "^0\s\+:\s*0" contains=jColonNoun2 skipwhite skipnl skipempty nextgroup=jColonNounExtend syn match jColonNoun2 "0\s\+:\s*0" contained syn region jColonRHNounExtend contained start="." end="$" contains=jQuotesJ,@jStuff,jParensJ skipwhite skipnl skipempty nextgroup=jColonNounExtend syn region jColonNounExtend contained extend matchgroup=Underlined start="\ze." end="^)" contains=jColonTP fold syn region jParensNoun contained oneline matchgroup=PreProc start=+(+ end=+)+ contains=@jStuff,jQuotes,jColonNoun2 "------------------------------------ "------------------------------------ " Define: syn region jDefine extend matchgroup=Underlined start="\(\(verb\)\|\(dyad\)\|\(monad\)\|\(adverb\)\|\(conjunction\)\)\s\+define" end="^)" contains=@jStuff,jQuotes,jParens,jArgument fold syn region jDefine extend matchgroup=Underlined start="noun define" end="^)" fold syn region jDefine extend matchgroup=Underlined start="Note" end="^)" fold "------------------------------------ " Numerals: syn match jNumeralBase3 "a[dr]" contained nextgroup=jNumeralBaseValue syn match jNumeralBase2 "[jprxe]" contained nextgroup=jNumeralBaseValue syn match jNumeralBase1 "b" contained nextgroup=jNumeralBaseValue syn match jNumeral "_\?\d\+a[dr]_\?\d\+" contains=jNumeralBase3 syn match jNumeral "_\?\d\+[jpre]_\?\d\+" contains=jNumeralBase2 syn match jNumeral "_\?\d\+x\(_\?\d\+\)\?" contains=jNumeralBase2 syn match jNumeral "\d\+b\x\+" contains=jNumeralBase1 syn match jNumeralBaseValue contained "_\?\x\+" "------------------------------------ syn match jShebang "\%^\s*#!.*$" "------------------------------------ " Term Output: syn match jError "^|.*error.*\n|.*\n" syn match jBoxElms contained "[+|-]" syn match jBox "^+-.*\n\(\(|.*\n\)\++-.*\n\)*" contains=jBoxElms,jNumeral " Note: jBox is an expensive match and it will cause vim to stall momentarily " when parsing files containing extensive boxing. But its functional, this " problem is a very narrow edge case and worth the cost. Most of the time. "------------------------------------ syn match jNounIs "\k\+\(\s*=:\)" contained contains=jCopula,jLocative,jLocativeZ,jLocativeIndirect syn match jNounIs "\k\+\(\s*=:\)" contains=jCopula,jLocative,jLocativeZ,jLocativeIndirect " Trick: catches ONE case -> define=: : 0 in stdlib syn match jNounIs "\k\+\(\s*=:\) : 0" contains=jCopula "------------------------------------ hi def link jCommentError ErrorMsg hi def link jComment Comment hi def link jError Error hi def link jPreProc PreProc hi def link jLocative PreProc hi def link jArgument PreProc hi def link jCopula PreProc hi def link jNumeralBase3 PreProc hi def link jNumeralBase2 PreProc hi def link jNumeralBase1 PreProc hi def link jBoxElms PreProc hi def link jShebang PreProc hi def link jVerb Type hi def link jForeign Type hi def link jAdverb Statement hi def link jForeignAdverb jAdverb hi def link jRankAdverb jAdverb hi def link jCutAdverb jAdverb hi def link jPowerAdverb jAdverb hi def link jColon Underlined hi def link jColonConj Special hi def link jColonNoun2 Underlined hi def link jColonTP PreProc hi def link jNoun Underlined hi def link jNounIs Bleached hi def link jConjunction Special hi def link jControl Identifier hi def link jControlLabel PreProc hi def link jQuotes String hi def link jQuotesJ String hi def link jQuoteEscape String hi def link jLocativeIndirect Statement hi def link jLocativeZ Underlined "------------------------------------ let b:current_syntax = "j" let &cpo = s:save_cpo unlet s:save_cpo "------------------------------------ " TODO: " 1.0x is bad, 1x is good. atm both are colored good "------------------------------------ " Done:? " trailing parens (and code) on the line containing a 0 : 0 definition " locatives out. dodgier than I'd thought. see conew=: in stdlib " double quote '' == escaped quote " numerals need to be 'caught' and then color'd. " catch trailing paren after a colon define " noun define and 0 : 0 defines become comments or plain text " stdlib: define=: : 0 - caught by nounIs Hack "------------------------------------