diff options
Diffstat (limited to 'codemirror_ui/lib/CodeMirror-2.3/mode/erlang')
-rw-r--r-- | codemirror_ui/lib/CodeMirror-2.3/mode/erlang/erlang.js | 251 | ||||
-rw-r--r-- | codemirror_ui/lib/CodeMirror-2.3/mode/erlang/index.html | 61 |
2 files changed, 312 insertions, 0 deletions
diff --git a/codemirror_ui/lib/CodeMirror-2.3/mode/erlang/erlang.js b/codemirror_ui/lib/CodeMirror-2.3/mode/erlang/erlang.js new file mode 100644 index 0000000..5c094f8 --- /dev/null +++ b/codemirror_ui/lib/CodeMirror-2.3/mode/erlang/erlang.js @@ -0,0 +1,251 @@ +// erlang -> CodeMirror tag +// +// atom -> atom +// attribute -> attribute +// builtin -> builtin +// comment -> comment +// error -> error +// fun -> meta +// function -> tag +// guard -> property +// keyword -> keyword +// macro -> variable-2 +// number -> number +// operator -> operator +// record -> bracket +// string -> string +// type -> def +// variable -> variable + +CodeMirror.defineMIME("text/x-erlang", "erlang"); + +CodeMirror.defineMode("erlang", function(cmCfg, modeCfg) { + + var typeWords = [ + "-type", "-spec", "-export_type", "-opaque"]; + + var keywordWords = [ + "after","begin","catch","case","cond","end","fun","if", + "let","of","query","receive","try","when"]; + + var operatorWords = [ + "and","andalso","band","bnot","bor","bsl","bsr","bxor", + "div","not","or","orelse","rem","xor"]; + + var operatorSymbols = [ + "+","-","*","/",">",">=","<","=<","=:=","==","=/=","/=","||","<-"]; + + var guardWords = [ + "is_atom","is_binary","is_bitstring","is_boolean","is_float", + "is_function","is_integer","is_list","is_number","is_pid", + "is_port","is_record","is_reference","is_tuple", + "atom","binary","bitstring","boolean","function","integer","list", + "number","pid","port","record","reference","tuple"]; + + var bifWords = [ + "abs","adler32","adler32_combine","alive","apply","atom_to_binary", + "atom_to_list","binary_to_atom","binary_to_existing_atom", + "binary_to_list","binary_to_term","bit_size","bitstring_to_list", + "byte_size","check_process_code","contact_binary","crc32", + "crc32_combine","date","decode_packet","delete_module", + "disconnect_node","element","erase","exit","float","float_to_list", + "garbage_collect","get","get_keys","group_leader","halt","hd", + "integer_to_list","internal_bif","iolist_size","iolist_to_binary", + "is_alive","is_atom","is_binary","is_bitstring","is_boolean", + "is_float","is_function","is_integer","is_list","is_number","is_pid", + "is_port","is_process_alive","is_record","is_reference","is_tuple", + "length","link","list_to_atom","list_to_binary","list_to_bitstring", + "list_to_existing_atom","list_to_float","list_to_integer", + "list_to_pid","list_to_tuple","load_module","make_ref","module_loaded", + "monitor_node","node","node_link","node_unlink","nodes","notalive", + "now","open_port","pid_to_list","port_close","port_command", + "port_connect","port_control","pre_loaded","process_flag", + "process_info","processes","purge_module","put","register", + "registered","round","self","setelement","size","spawn","spawn_link", + "spawn_monitor","spawn_opt","split_binary","statistics", + "term_to_binary","time","throw","tl","trunc","tuple_size", + "tuple_to_list","unlink","unregister","whereis"]; + + function isMember(element,list) { + return (-1 < list.indexOf(element)); + } + + function isPrev(stream,string) { + var start = stream.start; + var len = string.length; + if (len <= start) { + var word = stream.string.slice(start-len,start); + return word == string; + }else{ + return false; + } + } + + var smallRE = /[a-z_]/; + var largeRE = /[A-Z_]/; + var digitRE = /[0-9]/; + var octitRE = /[0-7]/; + var idRE = /[a-z_A-Z0-9]/; + + function tokenize(stream, state) { + if (stream.eatSpace()) { + return null; + } + + // attributes and type specs + if (stream.sol() && stream.peek() == '-') { + stream.next(); + if (stream.eat(smallRE) && stream.eatWhile(idRE)) { + if (stream.peek() == "(") { + return "attribute"; + }else if (isMember(stream.current(),typeWords)) { + return "def"; + }else{ + return null; + } + } + stream.backUp(1); + } + + var ch = stream.next(); + + // comment + if (ch == '%') { + stream.skipToEnd(); + return "comment"; + } + + // macro + if (ch == '?') { + stream.eatWhile(idRE); + return "variable-2"; + } + + // record + if ( ch == "#") { + stream.eatWhile(idRE); + return "bracket"; + } + + // char + if ( ch == "$") { + if (stream.next() == "\\") { + if (!stream.eatWhile(octitRE)) { + stream.next(); + } + } + return "string"; + } + + // quoted atom + if (ch == '\'') { + return singleQuote(stream); + } + + // string + if (ch == '"') { + return doubleQuote(stream); + } + + // variable + if (largeRE.test(ch)) { + stream.eatWhile(idRE); + return "variable"; + } + + // atom/keyword/BIF/function + if (smallRE.test(ch)) { + stream.eatWhile(idRE); + + if (stream.peek() == "/") { + stream.next(); + if (stream.eatWhile(digitRE)) { + return "meta"; // f/0 style fun + }else{ + stream.backUp(1); + return "atom"; + } + } + + var w = stream.current(); + + if (isMember(w,keywordWords)) { + return "keyword"; // keyword + } + if (stream.peek() == "(") { + if (isMember(w,bifWords) && + (!isPrev(stream,":") || isPrev(stream,"erlang:"))) { + return "builtin"; // BIF + }else{ + return "tag"; // function + } + } + if (isMember(w,guardWords)) { + return "property"; // guard + } + if (isMember(w,operatorWords)) { + return "operator"; // operator + } + + + if (stream.peek() == ":") { + if (w == "erlang") { // f:now() is highlighted incorrectly + return "builtin"; + } else { + return "tag"; // function application + } + } + + return "atom"; + } + + // number + if (digitRE.test(ch)) { + stream.eatWhile(digitRE); + if (stream.eat('#')) { + stream.eatWhile(digitRE); // 16#10 style integer + } else { + if (stream.eat('.')) { // float + stream.eatWhile(digitRE); + } + if (stream.eat(/[eE]/)) { + stream.eat(/[-+]/); // float with exponent + stream.eatWhile(digitRE); + } + } + return "number"; // normal integer + } + + return null; + } + + function doubleQuote(stream) { + return Quote(stream, '"', '\\', "string"); + } + + function singleQuote(stream) { + return Quote(stream,'\'','\\',"atom"); + } + + function Quote(stream,quoteChar,escapeChar,tag) { + while (!stream.eol()) { + var ch = stream.next(); + if (ch == quoteChar) { + return tag; + }else if (ch == escapeChar) { + stream.next(); + } + } + return "error"; + } + + return { + startState: function() { + return {}; + }, + + token: function(stream, state) { + return tokenize(stream, state); + } + }; +}); diff --git a/codemirror_ui/lib/CodeMirror-2.3/mode/erlang/index.html b/codemirror_ui/lib/CodeMirror-2.3/mode/erlang/index.html new file mode 100644 index 0000000..625491f --- /dev/null +++ b/codemirror_ui/lib/CodeMirror-2.3/mode/erlang/index.html @@ -0,0 +1,61 @@ +<!doctype html> +<html> + <head> + <title>CodeMirror: Erlang mode</title> + <link rel="stylesheet" href="../../lib/codemirror.css"> + <script src="../../lib/codemirror.js"></script> + <script src="erlang.js"></script> + <link rel="stylesheet" href="../../theme/erlang-dark.css"> + <style type="text/css">.CodeMirror {border-top: 1px solid black; border-bottom: 1px solid black;}</style> + <link rel="stylesheet" href="../../doc/docs.css"> + </head> + <body> + <h1>CodeMirror: Erlang mode</h1> + +<form><textarea id="code" name="code"> +%% -*- mode: erlang; erlang-indent-level: 2 -*- +%%% Created : 7 May 2012 by mats cronqvist <masse@klarna.com> + +%% @doc +%% Demonstrates how to print a record. +%% @end + +-module('ex'). +-author('mats cronqvist'). +-export([demo/0, + rec_info/1]). + +-record(demo,{a="One",b="Two",c="Three",d="Four"}). + +rec_info(demo) -> record_info(fields,demo). + +demo() -> expand_recs(?MODULE,#demo{a="A",b="BB"}). + +expand_recs(M,List) when is_list(List) -> + [expand_recs(M,L)||L<-List]; +expand_recs(M,Tup) when is_tuple(Tup) -> + case tuple_size(Tup) of + L when L < 1 -> Tup; + L -> + try Fields = M:rec_info(element(1,Tup)), + L = length(Fields)+1, + lists:zip(Fields,expand_recs(M,tl(tuple_to_list(Tup)))) + catch _:_ -> + list_to_tuple(expand_recs(M,tuple_to_list(Tup))) + end + end; +expand_recs(_,Term) -> + Term. +</textarea></form> + + <script> + var editor = CodeMirror.fromTextArea(document.getElementById("code"), { + lineNumbers: true, + matchBrackets: true, + theme: "erlang-dark" + }); + </script> + + <p><strong>MIME types defined:</strong> <code>text/x-erlang</code>.</p> + </body> +</html> |