1 | atom-syntax-tools
|
2 | =================
|
3 |
|
4 | Tools for easier language grammar specification for atom editor.
|
5 |
|
6 | - This tool lets you define grammar in a coffeescript file and takes the input
|
7 | cson, and generates a full grammar cson.
|
8 |
|
9 | - Make use of syntax highlighting of javascript regular expressions, which
|
10 | will be used as Oniguruma Regexes. This way you do not need escape too
|
11 | much.
|
12 |
|
13 | - make use of macros in scopenames and regexes
|
14 |
|
15 | - grammar scopename is autoappended to scopenames
|
16 |
|
17 | - you can shortcut the keys like follows:
|
18 |
|
19 | | shortcut | name |
|
20 | | :------: | ---------------------- |
|
21 | | n | name |
|
22 | | N | contentName |
|
23 | | p | patterns |
|
24 | | i | include |
|
25 | | m | match |
|
26 | | b | begin |
|
27 | | e | end |
|
28 | | c | captures/beginCaptures |
|
29 | | C | endCaptures |
|
30 | | L | applyEndPatternLast |
|
31 |
|
32 |
|
33 | Here a little example, how to produce `json.cson` file:
|
34 |
|
35 | ```coffeescript
|
36 | {makeGrammar} = require('atom-syntax-tools')
|
37 |
|
38 | grammar =
|
39 | name: "JSON"
|
40 | scopeName: "source.json"
|
41 | keyEquivalent: "^~J"
|
42 | fileTypes: [ "json" ]
|
43 |
|
44 | macros:
|
45 | # for demonstartion purpose, how to use regexes as macros
|
46 | hexdigit: /[0-9a-fA-F]/
|
47 | en: "entity.name"
|
48 | pd: "punctuation.definition"
|
49 | ps: "punctuation.separator"
|
50 | ii: "invalid.illegal"
|
51 |
|
52 | patterns: [
|
53 | "#value"
|
54 | ]
|
55 |
|
56 | repository:
|
57 | array:
|
58 | n: "meta.structure.array"
|
59 | b: /\[/
|
60 | c: "{pd}.array.begin"
|
61 | e: /\]/
|
62 | C: "{pd}.array.end"
|
63 | p: [
|
64 | "#value"
|
65 | {
|
66 | m: /,/
|
67 | n: "{ps}.array"
|
68 | }
|
69 | {
|
70 | m: /[^\s\]]/
|
71 | n: "{ii}.expected-array-separator"
|
72 | }
|
73 | ]
|
74 | constant:
|
75 | n: "constant.language"
|
76 | m: /\b(?:true|false|null)\b/
|
77 | number:
|
78 | # this comment is just for demonstration, you will rather use
|
79 | # normal coffee comments
|
80 | comment: "handles integer and decimal numbers"
|
81 | n: "constant.numeric"
|
82 | # This multiline match with be boiled down into a single linen regular
|
83 | # expression. See http://coffeescript.org
|
84 | m: ///
|
85 | -? # an optional minus
|
86 | (?:
|
87 | 0 # a zero
|
88 | | # ...or...
|
89 | [1-9] # a 1-9 character
|
90 | \d* # followed by zero or more digits
|
91 | )
|
92 | (?:
|
93 | (?:
|
94 | \. # a period
|
95 | \d+ # followed by one or more digits
|
96 | )?
|
97 | (?:
|
98 | [eE] # an e character
|
99 | [+-]? # followed by an optional +/-
|
100 | \d+ # followed by one of more digits
|
101 | )? # make exponent optional
|
102 | )? # make decimal portion optional
|
103 | ///
|
104 | object:
|
105 | # "a JSON object"
|
106 | n: "meta.structure.dictionary"
|
107 | b: /\{/
|
108 | c: "{pd}.dictionary.begin"
|
109 | e: /\}/
|
110 | C: "{pd}.dictionary.end"
|
111 | p: [
|
112 | "#string" # JSON object key
|
113 | {
|
114 | b: /:/
|
115 | c: "{ps}.dictionary.key-value"
|
116 | e: /(,)|(?=\})/
|
117 | C:
|
118 | 1: "{ps}.dictionary.pair"
|
119 | n: "meta.structure.dictionary.value"
|
120 | p: [
|
121 | "#value" # JSON object value
|
122 | { m: /[^\s,]/, n: "{ii}.expected-dictionary-separator" }
|
123 | ]
|
124 | }
|
125 | {
|
126 | m: /[^\s\}]/
|
127 | n: "{ii}.expected-dictionary-separator"
|
128 | }
|
129 | ]
|
130 | string:
|
131 | b: /"/
|
132 | c: "{pd}.string.begin"
|
133 | e: /"/
|
134 | C: "{pd}.definition.string.end"
|
135 | n: "string.quoted.double"
|
136 | p: [
|
137 | {
|
138 | n: "constant.character.escape"
|
139 | m: ///
|
140 | \\ # literal backslash
|
141 | (?: # ...followed by...
|
142 | ["\\/bfnrt] # one of these characters
|
143 | | # ...or...
|
144 | u # a u
|
145 | {hexdigit}{4} # and four hex digits
|
146 | )
|
147 | ///
|
148 | }
|
149 | {
|
150 | m: /\\./
|
151 | n: "{ii}.unrecognized-string-escape"
|
152 | }
|
153 | ]
|
154 | value: [ # the 'value' diagram at http://json.org
|
155 | "#constant"
|
156 | "#number"
|
157 | "#string"
|
158 | "#array"
|
159 | "#object"
|
160 | ]
|
161 |
|
162 | makeGrammar grammar, "CSON"
|
163 | ```
|
164 |
|
165 | Then run your script with `coffee grammar-json.coffee > json.cson`
|
166 |
|
167 |
|
168 | Further Infos
|
169 | -------------
|
170 |
|
171 | See spec for examples. More documentation will follow.
|
172 |
|
173 |
|
174 | TODO
|
175 | ----
|
176 |
|
177 | Support grammar injections.
|