From 51ed781953bc44bba3c70938aa57b856394cbc88 Mon Sep 17 00:00:00 2001 From: Ananya Sen Date: Mon, 27 Feb 2012 14:41:21 -0800 Subject: updating to codemirror 2.22 Signed-off-by: Ananya Sen --- imports/codemirror/mode/rust/index.html | 6 ++-- imports/codemirror/mode/rust/rust.js | 51 +++++++++++++++++++++++---------- 2 files changed, 39 insertions(+), 18 deletions(-) mode change 100755 => 100644 imports/codemirror/mode/rust/index.html mode change 100755 => 100644 imports/codemirror/mode/rust/rust.js (limited to 'imports/codemirror/mode/rust') diff --git a/imports/codemirror/mode/rust/index.html b/imports/codemirror/mode/rust/index.html old mode 100755 new mode 100644 index a84c61e5..3b811e35 --- a/imports/codemirror/mode/rust/index.html +++ b/imports/codemirror/mode/rust/index.html @@ -15,9 +15,9 @@ // Demo code. type foo = int; -tag bar { - some(int, foo); - none; +enum bar { + some(int, foo), + none } fn check_crate(x: int) { diff --git a/imports/codemirror/mode/rust/rust.js b/imports/codemirror/mode/rust/rust.js old mode 100755 new mode 100644 index 5ab964c1..2a5caac2 --- a/imports/codemirror/mode/rust/rust.js +++ b/imports/codemirror/mode/rust/rust.js @@ -4,12 +4,12 @@ CodeMirror.defineMode("rust", function() { "if": "if-style", "while": "if-style", "else": "else-style", "do": "else-style", "ret": "else-style", "fail": "else-style", "break": "atom", "cont": "atom", "const": "let", "resource": "fn", - "let": "let", "fn": "fn", "for": "for", "alt": "alt", "obj": "fn", - "lambda": "fn", "type": "type", "tag": "tag", "mod": "mod", + "let": "let", "fn": "fn", "for": "for", "alt": "alt", "iface": "iface", + "impl": "impl", "type": "type", "enum": "enum", "mod": "mod", "as": "op", "true": "atom", "false": "atom", "assert": "op", "check": "op", "claim": "op", "native": "ignore", "unsafe": "ignore", "import": "else-style", "export": "else-style", "copy": "op", "log": "op", "log_err": "op", - "use": "op", "bind": "op" + "use": "op", "bind": "op", "self": "atom" }; var typeKeywords = function() { var keywords = {"fn": "fn", "block": "fn", "obj": "obj"}; @@ -169,13 +169,18 @@ CodeMirror.defineMode("rust", function() { }; } + function stat_of(comb, tag) { + return cont(pushlex("stat", tag), comb, poplex, block); + } function block(type) { if (type == "}") return cont(); - if (type == "let") return cont(pushlex("stat", "let"), letdef1, poplex, block); - if (type == "fn") return cont(pushlex("stat"), fndef, poplex, block); + if (type == "let") return stat_of(letdef1, "let"); + if (type == "fn") return stat_of(fndef); if (type == "type") return cont(pushlex("stat"), tydef, endstatement, poplex, block); - if (type == "tag") return cont(pushlex("stat"), tagdef, poplex, block); - if (type == "mod") return cont(pushlex("stat"), mod, poplex, block); + if (type == "enum") return stat_of(enumdef); + if (type == "mod") return stat_of(mod); + if (type == "iface") return stat_of(iface); + if (type == "impl") return stat_of(impl); if (type == "open-attr") return cont(pushlex("]"), commasep(expression, "]"), poplex); if (type == "ignore" || type.match(/[\]\);,]/)) return cont(block); return pass(pushlex("stat"), expression, poplex, endstatement, block); @@ -253,11 +258,13 @@ CodeMirror.defineMode("rust", function() { return pass(); } function fndef(type) { + if (content == "@" || content == "~") {cx.marked = "keyword"; return cont(fndef);} if (type == "name") {cx.marked = "def"; return cont(fndef);} if (content == "<") return cont(typarams, fndef); if (type == "{") return pass(expression); if (type == "(") return cont(pushlex(")"), commasep(argdef, ")"), poplex, fndef); if (type == "->") return cont(typecx, rtype, valcx, fndef); + if (type == ";") return cont(); return cont(fndef); } function tydef(type) { @@ -266,27 +273,41 @@ CodeMirror.defineMode("rust", function() { if (content == "=") return cont(typecx, rtype, valcx); return cont(tydef); } - function tagdef(type) { - if (type == "name") {cx.marked = "def"; return cont(tagdef);} - if (content == "<") return cont(typarams, tagdef); + function enumdef(type) { + if (type == "name") {cx.marked = "def"; return cont(enumdef);} + if (content == "<") return cont(typarams, enumdef); if (content == "=") return cont(typecx, rtype, valcx, endstatement); - if (type == "{") return cont(pushlex("}"), typecx, tagblock, valcx, poplex); - return cont(tagdef); + if (type == "{") return cont(pushlex("}"), typecx, enumblock, valcx, poplex); + return cont(enumdef); } - function tagblock(type) { + function enumblock(type) { if (type == "}") return cont(); - if (type == "(") return cont(pushlex(")"), commasep(rtype, ")"), poplex, tagblock); + if (type == "(") return cont(pushlex(")"), commasep(rtype, ")"), poplex, enumblock); if (content.match(/^\w+$/)) cx.marked = "def"; - return cont(tagblock); + return cont(enumblock); } function mod(type) { if (type == "name") {cx.marked = "def"; return cont(mod);} if (type == "{") return cont(pushlex("}"), block, poplex); return pass(); } + function iface(type) { + if (type == "name") {cx.marked = "def"; return cont(iface);} + if (content == "<") return cont(typarams, iface); + if (type == "{") return cont(pushlex("}"), block, poplex); + return pass(); + } + function impl(type) { + if (content == "<") return cont(typarams, impl); + if (content == "of" || content == "for") {cx.marked = "keyword"; return cont(rtype, impl);} + if (type == "name") {cx.marked = "def"; return cont(impl);} + if (type == "{") return cont(pushlex("}"), block, poplex); + return pass(); + } function typarams(type) { if (content == ">") return cont(); if (content == ",") return cont(typarams); + if (content == ":") return cont(rtype, typarams); return pass(rtype, typarams); } function argdef(type) { -- cgit v1.2.3