Skip to content

Commit

Permalink
syntax highlight keywords and quad names
Browse files Browse the repository at this point in the history
  • Loading branch information
ngn committed Feb 20, 2015
1 parent c65c4b0 commit c1081cb
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 15 deletions.
27 changes: 25 additions & 2 deletions client/codemirror-apl-mode.coffee
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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'
Expand Down
28 changes: 15 additions & 13 deletions style/style.sass
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit c1081cb

Please sign in to comment.