Skip to content

Commit d081a70

Browse files
Nikos MNikos M
Nikos M
authored and
Nikos M
committed
update example grammars with some syntax part
1 parent c50f0b9 commit d081a70

10 files changed

+182
-66
lines changed

test/grammar-css.html

+2-4
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,11 @@ <h3>CodeMirror: Dynamic CSS Grammar</h3>
7474

7575
// use it!
7676
var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
77+
mode: "css",
7778
lineNumbers: true,
7879
matchBrackets: true,
79-
mode: "css",
8080
indentUnit: 4,
81-
indentWithTabs: false,
82-
enterMode: "keep",
83-
tabMode: "shift"
81+
indentWithTabs: false
8482
});
8583
editor.setSize(null, 500);
8684

test/grammar-js.html

+2-4
Original file line numberDiff line numberDiff line change
@@ -328,13 +328,11 @@ <h3>CodeMirror: Dynamic JavaScript Grammar</h3>
328328

329329
// use it!
330330
var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
331+
mode: "js",
331332
lineNumbers: true,
332333
matchBrackets: true,
333-
mode: "js",
334334
indentUnit: 4,
335-
indentWithTabs: false,
336-
enterMode: "keep",
337-
tabMode: "shift"
335+
indentWithTabs: false
338336
});
339337
editor.setSize(null, 500);
340338

test/grammar-php.html

+2-4
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,11 @@ <h3>CodeMirror: Dynamic PHP Grammar</h3>
7070

7171
// use it!
7272
var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
73+
mode: "php",
7374
lineNumbers: true,
7475
matchBrackets: true,
75-
mode: "php",
7676
indentUnit: 4,
77-
indentWithTabs: false,
78-
enterMode: "keep",
79-
tabMode: "shift"
77+
indentWithTabs: false
8078
});
8179
editor.setSize(null, 500);
8280

test/grammar-python.html

+2-4
Original file line numberDiff line numberDiff line change
@@ -128,13 +128,11 @@ <h3>CodeMirror: Dynamic Python Grammar</h3>
128128

129129
// use it!
130130
var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
131+
mode: "python",
131132
lineNumbers: true,
132133
matchBrackets: false,
133-
mode: "python",
134134
indentUnit: 4,
135-
indentWithTabs: false,
136-
enterMode: "keep",
137-
tabMode: "shift"
135+
indentWithTabs: false
138136
});
139137
editor.setSize(null, 500);
140138

test/grammars/contemplate.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ var contemplate_grammar = {
7171
"operator" : {
7272
"type" : "simple",
7373
"tokens" : [
74-
[ "+", "-", "*", "/", "%", "<", ">", "!" ],
75-
[ "=>", "==", "!=", "<=", ">=", "<>", "||", "&&" ]
74+
"+", "-", "*", "/", "%", "<", ">", "!",
75+
"=>", "==", "!=", "<=", ">=", "<>", "||", "&&"
7676
]
7777
},
7878

test/grammars/css.js

+107-28
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ var css_grammar = {
88
// else matched one by one,
99
// this is usefull for speed fine-tuning the parser
1010
"RegExpGroups" : {
11+
"font" : true,
1112
"standard" : true,
12-
"standard2" : true,
1313
"atom" : true,
1414
"meta" : true,
1515
"meta2" : true,
16-
"keyword" : true,
17-
"builtin" : true,
16+
"property" : true,
17+
"element" : true,
1818
"operator" : true,
1919
"delimiter" : true
2020
},
@@ -29,17 +29,19 @@ var css_grammar = {
2929
"meta": "attribute",
3030
"meta2": "def",
3131
"atom": "string-2",
32-
"keyword": "property",
33-
"builtin": "tag",
32+
"property": "property",
33+
"element": "tag",
34+
"url": "tag",
3435
"operator": "operator",
35-
"standard": "variable-2",
36-
"standard2": "keyword",
36+
"font": "variable-2",
37+
"standard": "keyword",
3738
"cssID": "builtin",
3839
"cssClass": "qualifier",
3940
"identifier": "variable-2",
4041
"number": "number",
4142
"number2": "builtin",
42-
"string": "string"
43+
"string": "string",
44+
"unquotedText": "string"
4345
},
4446

4547

@@ -58,20 +60,17 @@ var css_grammar = {
5860
},
5961

6062
// some standard identifiers
61-
"standard" : {
63+
"font" : {
6264
"type" : "simple",
6365
"tokens" : [
64-
"arial",
65-
"tahoma",
66-
"courier"
66+
"arial", "tahoma", "courier"
6767
]
6868
},
6969

70-
"standard2" : {
70+
"standard" : {
7171
"type" : "simple",
7272
"tokens" : [
73-
"!important",
74-
"only"
73+
"!important", "only"
7574
]
7675
},
7776

@@ -108,6 +107,7 @@ var css_grammar = {
108107
"RegExp::0(?![\\dx])(em|px|%|pt)?"
109108
]
110109
},
110+
111111
"number2" : {
112112
"type" : "simple",
113113
"tokens" : [
@@ -126,6 +126,11 @@ var css_grammar = {
126126
]
127127
},
128128

129+
"unquotedText" : {
130+
"type" : "simple",
131+
"tokens" : "RegExp::[^\\(\\)\\[\\]\\{\\}'\"]+"
132+
},
133+
129134
// operators
130135
"operator" : {
131136
"type" : "simple",
@@ -134,11 +139,40 @@ var css_grammar = {
134139
]
135140
},
136141

137-
// delimiters
142+
"leftBracket" : {
143+
"type" : "simple",
144+
"tokens" : "{"
145+
},
146+
147+
"rightBracket" : {
148+
"type" : "simple",
149+
"tokens" : "}"
150+
},
151+
152+
"leftParen" : {
153+
"type" : "simple",
154+
"tokens" : "("
155+
},
156+
157+
"rightParen" : {
158+
"type" : "simple",
159+
"tokens" : ")"
160+
},
161+
162+
"assignment" : {
163+
"type" : "simple",
164+
"tokens" : ":"
165+
},
166+
167+
"endAssignment" : {
168+
"type" : "simple",
169+
"tokens" : ";"
170+
},
171+
138172
"delimiter" : {
139173
"type" : "simple",
140174
"tokens" : [
141-
"(", ")", "[", "]", "{", "}", ",", "=", ";", "."
175+
",", "[", "]", "(", ")"
142176
]
143177
},
144178

@@ -169,8 +203,8 @@ var css_grammar = {
169203
]
170204
},
171205

172-
// keywords
173-
"keyword" : {
206+
// css properties
207+
"property" : {
174208
"type" : "simple",
175209
"tokens" : [
176210
"background-color", "background-image", "background-position", "background-repeat", "background",
@@ -183,7 +217,8 @@ var css_grammar = {
183217
]
184218
},
185219

186-
"builtin" : {
220+
// css html element
221+
"element" : {
187222
"type" : "simple",
188223
"tokens" : [
189224
"a", "p", "i",
@@ -199,26 +234,70 @@ var css_grammar = {
199234
"blockquote",
200235
"before", "after", "url"
201236
]
237+
},
238+
239+
"url" : {
240+
"type" : "simple",
241+
"tokens" : "url"
202242
}
203243
},
204244

245+
//
246+
// Syntax model
247+
"Syntax" : {
248+
249+
"stringOrUnquotedText" : {
250+
"type" : "group",
251+
"match" : "either",
252+
"tokens" : [ "string", "unquotedText" ]
253+
},
254+
255+
// highlight url(...) as string regardless of quotes or not
256+
"urlDeclaration" : {
257+
"type" : "n-gram",
258+
"match" : "either",
259+
"tokens" : [ "url", "leftParen", "stringOrUnquotedText", "rightParen" ]
260+
},
261+
262+
"RHSAssignment" : {
263+
"type" : "group",
264+
"match" : "oneOrMore",
265+
"tokens" : [ "delimiter", "atom", "font", "standard", "string", "number", "number2", "identifier" ]
266+
},
267+
268+
"cssAssignment" : {
269+
"type" : "group",
270+
"match" : "all",
271+
"tokens" : [ "property", "assignment", "RHSAssignment", "endAssignment" ]
272+
},
273+
274+
"cssAssignments" : {
275+
"type" : "group",
276+
"match" : "zeroOrMore",
277+
"tokens" : [ "cssAssignment" ]
278+
},
279+
280+
// syntax grammar (n-gram) for a block of css assignments
281+
"cssBlock" : {
282+
"type" : "n-gram",
283+
"tokens" : [
284+
[ "leftBracket", "cssAssignments", "rightBracket" ]
285+
]
286+
}
287+
},
288+
205289
// what to parse and in what order
206290
"Parser" : [
207291
"comment",
292+
"urlDeclaration",
208293
"number",
209294
"cssID",
210295
"number2",
211296
"string",
212-
"keyword",
213-
"builtin",
214-
"atom",
297+
"element",
215298
"meta",
216299
"meta2",
217-
"operator",
218-
"delimiter",
219-
"standard",
220-
"standard2",
221300
"cssClass",
222-
"identifier"
301+
"cssBlock"
223302
]
224303
};

0 commit comments

Comments
 (0)