From c1081cb611d3e5d9a1eab27e32cf4c80512d5d01 Mon Sep 17 00:00:00 2001 From: ngn Date: Fri, 20 Feb 2015 14:10:41 +0000 Subject: [PATCH] syntax highlight keywords and quad names --- client/codemirror-apl-mode.coffee | 27 +++++++++++++++++++++++++-- style/style.sass | 28 +++++++++++++++------------- 2 files changed, 40 insertions(+), 15 deletions(-) diff --git a/client/codemirror-apl-mode.coffee b/client/codemirror-apl-mode.coffee index b875fe05..3815e965 100644 --- a/client/codemirror-apl-mode.coffee +++ b/client/codemirror-apl-mode.coffee @@ -1,5 +1,25 @@ rLetter = 'A-Z_a-zÀ-ÖØ-Ýß-öø-üþ∆⍙Ⓐ-Ⓩ'; rName0 = ///[#{rLetter}]///; rName1 = ///[#{rLetter}\d]*/// rNotName = ///[^#{rLetter}\d]+/// +keywords = ''' + andif access case caselist class continue else elseif end endclass endfor + endhold endif endinterface endnamespace endproperty endrepeat endsection + endselect endtrap endwhile endwith field for in goto hold include if + implements interface leave namespace orif property repeat return section + select trap until while with +'''.split /[ \r\n]+/ +quadNames = [''].concat ''' + á a af ai an arbin arbout arg at av avu base class clear cmd cr cs ct cy d + dct df div dl dm dmx dq dr ea ec ed em en env es et ex exception export + fappend favail fc fchk fcopy fcreate fdrop ferase fhold fix flib fmt fnames + fnums fprops fr frdac frdci fread frename freplace fresize fsize fstac fstie + ftie funtie fx inp instances io kl l lc load lock lx map ml monitor na + nappend nc ncreate nerase new nl nlock nnames nnums nq nr nread nrename + nreplace nresize ns nsi nsize ntie null nuntie nxlate off or opt path pfkey + pp pr profile ps pt pw refs r rl rsi rtl s save sd se sh shadow si signal + size sm sr src stack state stop svc sve svo svq svr svs syl tc tcnums tf tget + this tid tkill tname tnums tpool tput treq trace trap ts tsync tz ucs ul + using vfi vr wa wc wg wn ws wsid wx x xml xsi xt +'''.split /[ \r\n]+/ CodeMirror.defineMIME 'text/apl', 'apl' CodeMirror.defineMode 'apl', -> # https://codemirror.net/doc/manual.html#modeapi @@ -33,9 +53,12 @@ CodeMirror.defineMode 'apl', -> # https://codemirror.net/doc/manual.html#modeapi else if c == ';' then 'apl-semicolon' else if /[\/⌿\\⍀¨⌸]/.test c then 'apl-monadic-operator' else if /[\.∘⍤⍣⍠]/.test c then 'apl-dyadic-operator' - else if /[\+\−×÷⌈⌊\|⍳\?\⋆⍟○!⌹<≤=>≥≠≡≢∊⍷∪∩∼∨∧⍱⍲⍴,⍪⌽⊖⍉↑↓⊂⊃⌷⍋⍒⊤⊥⍕⍎⊣⊢]/.test c then 'apl-function' - else if state.dfnDepth && /[⍺⍵∇]/.test c then "apl-dfn apl-dfn#{state.dfnDepth}" + else if /[\+\-×÷⌈⌊\|⍳\?\⋆⍟○!⌹<≤=>≥≠≡≢∊⍷∪∩∼∨∧⍱⍲⍴,⍪⌽⊖⍉↑↓⊂⊃⌷⍋⍒⊤⊥⍕⍎⊣⊢]/.test c then 'apl-function' + else if state.dfnDepth && /[⍺⍵∇:]/.test c then "apl-dfn apl-dfn#{state.dfnDepth}" else if c == '∇' then state.isHeader = 1; 'apl-tradfn' + else if c == ':' then (if stream.match(/\w*/)?[0]?.toLowerCase() in keywords then 'apl-keyword' else 'apl-error') + else if c == '⎕' then (if stream.match(/[áa-z0-9]*/i)?[0].toLowerCase() in quadNames then 'apl-quad-name' else 'apl-error') + else if c == '⍞' then 'apl-quad-name' else if rName0.test c stream.match rName1; x = stream.current() if state.dfnDepth || state.vars && x in state.vars then 'apl-name' else 'apl-global-name' diff --git a/style/style.sass b/style/style.sass index c0af15fb..2d995dc7 100644 --- a/style/style.sass +++ b/style/style.sass @@ -161,25 +161,27 @@ input, textarea -moz-box-sizing: border-box; box-sizing: border-box; opacity: .5 // CodeMirror syntax highlighting -.cm-apl-name { color: #888; } -.cm-apl-global-name { color: #000; } -.cm-apl-number { color: #888; } -.cm-apl-string { color: #088; } -.cm-apl-zilde { color: #008; } +.cm-apl-assignment { color: #00f; } +.cm-apl-bracket { color: #00f; } .cm-apl-comment { color: #080; } -.cm-apl-function { color: #008; } -.cm-apl-monadic-operator { color: #008; } -.cm-apl-dyadic-operator { color: #008; } -.cm-apl-dfn { color: #00f; } .cm-apl-dfn1 { color: #004; } .cm-apl-dfn2 { color: #00a; } .cm-apl-dfn3 { color: #008; } -.cm-apl-tradfn { color: #888; } +.cm-apl-dfn { color: #00f; } +.cm-apl-dyadic-operator { color: #008; } +.cm-apl-error { color: #f00; } +.cm-apl-function { color: #008; } +.cm-apl-global-name { color: #000; } +.cm-apl-keyword { color: #800; } +.cm-apl-monadic-operator { color: #008; } +.cm-apl-name { color: #888; } +.cm-apl-number { color: #888; } .cm-apl-paren { color: #00f; } -.cm-apl-bracket { color: #00f; } .cm-apl-semicolon { color: #00f; } -.cm-apl-assignment { color: #00f; } -.cm-apl-error { color: #f00; } +.cm-apl-string { color: #088; } +.cm-apl-tradfn { color: #888; } +.cm-apl-quad-name { color: #808; } +.cm-apl-zilde { color: #008; } // toolbar: appears on top of an editor or debugger, looks like [┈] ⍝ /⍝ X [_______] etc .toolbar