Skip to content

Commit 56bbf23

Browse files
committed
update golang_highlight_rules
1 parent 518d650 commit 56bbf23

File tree

4 files changed

+42
-28
lines changed

4 files changed

+42
-28
lines changed

lib/ace/mode/_test/highlight_rules_test.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ function modeList() {
2121
}
2222

2323
function checkModes() {
24-
modeList().forEach(function(modeName) {
24+
modeList().forEach(function(modeName, i) {
25+
console.log(padNumber(i+1, 3) + ") check: \u001b[33m" + modeName + "\u001b[0m");
2526
try {
2627
var Mode = require("../" + modeName).Mode;
2728
} catch(e) {

lib/ace/mode/_test/tokens_golang.json

+7-7
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
"start",
4646
["keyword","func"],
4747
["text"," "],
48-
["identifier","main"],
48+
["entity.name.function","main"],
4949
["paren.lparen","("],
5050
["paren.rparen",")"],
5151
["text"," "],
@@ -55,9 +55,9 @@
5555
["text"," "],
5656
["identifier","fmt"],
5757
["punctuation.operator","."],
58-
["identifier","Println"],
58+
["support.function","Println"],
5959
["paren.lparen","("],
60-
["identifier","pi"],
60+
["support.function","pi"],
6161
["paren.lparen","("],
6262
["constant.numeric","5000"],
6363
["paren.rparen","))"]
@@ -76,7 +76,7 @@
7676
"start",
7777
["keyword","func"],
7878
["text"," "],
79-
["identifier","pi"],
79+
["entity.name.function","pi"],
8080
["paren.lparen","("],
8181
["identifier","n"],
8282
["text"," "],
@@ -129,7 +129,7 @@
129129
["text"," "],
130130
["keyword","go"],
131131
["text"," "],
132-
["identifier","term"],
132+
["support.function","term"],
133133
["paren.lparen","("],
134134
["identifier","ch"],
135135
["punctuation.operator",","],
@@ -203,7 +203,7 @@
203203
"start",
204204
["keyword","func"],
205205
["text"," "],
206-
["identifier","term"],
206+
["entity.name.function","term"],
207207
["paren.lparen","("],
208208
["identifier","ch"],
209209
["text"," "],
@@ -231,7 +231,7 @@
231231
["text"," "],
232232
["identifier","math"],
233233
["punctuation.operator","."],
234-
["identifier","Pow"],
234+
["support.function","Pow"],
235235
["paren.lparen","("],
236236
["constant.numeric","-1"],
237237
["punctuation.operator",","],

lib/ace/mode/golang_highlight_rules.js

+31-20
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ define(function(require, exports, module) {
1515
"float64|complex64|complex128|byte|rune|uint|int|uintptr|bool|error"
1616
);
1717
var builtinFunctions = (
18-
"make|close|new|panic|recover"
18+
"new|close|cap|copy|panic|panicln|print|println|len|make|delete|real|recover|imag|append"
1919
);
2020
var builtinConstants = ("nil|true|false|iota");
2121

@@ -24,7 +24,9 @@ define(function(require, exports, module) {
2424
"constant.language": builtinConstants,
2525
"support.function": builtinFunctions,
2626
"support.type": builtinTypes
27-
}, "identifier");
27+
}, "");
28+
29+
var stringEscapeRe = "\\\\(?:[0-7]{3}|x\\h{2}|u{4}|U\\h{6}|[abfnrtv'\"\\\\])".replace(/\\h/g, "[a-fA-F\\d]");
2830

2931
this.$rules = {
3032
"start" : [
@@ -34,32 +36,43 @@ define(function(require, exports, module) {
3436
},
3537
DocCommentHighlightRules.getStartRule("doc-start"),
3638
{
37-
token : "comment", // multi line comment
39+
token : "comment.start", // multi line comment
3840
regex : "\\/\\*",
3941
next : "comment"
4042
}, {
4143
token : "string", // single line
42-
regex : '["](?:(?:\\\\.)|(?:[^"\\\\]))*?["]'
44+
regex : /"(?:[^"\\]|\\.)*?"/
4345
}, {
44-
token : "string", // single line
45-
regex : '[`](?:[^`]*)[`]'
46-
}, {
47-
token : "string", // multi line string start
48-
merge : true,
46+
token : "string", // raw
4947
regex : '[`](?:[^`]*)$',
5048
next : "bqstring"
5149
}, {
5250
token : "constant.numeric", // rune
53-
regex : "['](?:(?:\\\\.)|(?:[^'\\\\]))[']"
51+
regex : "'(?:[^\\'\uD800-\uDBFF]|[\uD800-\uDBFF][\uDC00-\uDFFF]|" + stringEscapeRe.replace('"', '') + ")'"
5452
}, {
5553
token : "constant.numeric", // hex
56-
regex : "0[xX][0-9a-fA-F]+\\b"
54+
regex : "0[xX][0-9a-fA-F]+\\b"
5755
}, {
5856
token : "constant.numeric", // float
5957
regex : "[+-]?\\d+(?:(?:\\.\\d*)?(?:[eE][+-]?\\d+)?)?\\b"
6058
}, {
61-
token : keywordMapper,
62-
regex : "[a-zA-Z_$][a-zA-Z0-9_$]*\\b"
59+
token : ["keyword", "text", "entity.name.function"],
60+
regex : "(func)(\\s+)([a-zA-Z_$][a-zA-Z0-9_$]*)\\b"
61+
}, {
62+
token : function(val) {
63+
if (val[val.length - 1] == "(") {
64+
return [{
65+
type: keywordMapper(val.slice(0, -1)) || "support.function",
66+
value: val.slice(0, -1)
67+
}, {
68+
type: "paren.lparen",
69+
value: val.slice(-1)
70+
}];
71+
}
72+
73+
return keywordMapper(val) || "identifier";
74+
},
75+
regex : "[a-zA-Z_$][a-zA-Z0-9_$]*\\b\\(?"
6376
}, {
6477
token : "keyword.operator",
6578
regex : "!|\\$|%|&|\\*|\\-\\-|\\-|\\+\\+|\\+|~|==|=|!=|<=|>=|<<=|>>=|>>>=|<>|<|>|!|&&|\\|\\||\\?\\:|\\*=|%=|\\+=|\\-=|&=|\\^="
@@ -79,22 +92,20 @@ define(function(require, exports, module) {
7992
],
8093
"comment" : [
8194
{
82-
token : "comment", // closing comment
83-
regex : ".*?\\*\\/",
95+
token : "comment.end",
96+
regex : "\\*\\/",
8497
next : "start"
8598
}, {
86-
token : "comment", // comment spanning whole line
87-
regex : ".+"
99+
defaultToken : "comment",
88100
}
89101
],
90102
"bqstring" : [
91103
{
92104
token : "string",
93-
regex : '(?:[^`]*)`',
105+
regex : '`',
94106
next : "start"
95107
}, {
96-
token : "string",
97-
regex : '.+'
108+
defaultToken : "string"
98109
}
99110
]
100111
};

static.js

+2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ if (!fs.exists)
1313
fs.exists = path.exists;
1414

1515
var allowSave = process.argv.indexOf("--allow-save") != -1;
16+
if (allowSave)
17+
console.warn("writing files from browser is enabled");
1618

1719
http.createServer(function(req, res) {
1820
var uri = unescape(url.parse(req.url).pathname)

0 commit comments

Comments
 (0)