File tree Expand file tree Collapse file tree 2 files changed +56
-1
lines changed
Expand file tree Collapse file tree 2 files changed +56
-1
lines changed Original file line number Diff line number Diff line change @@ -19,6 +19,15 @@ var sub = cli.addSubparsers({
1919 dest : 'command'
2020} ) ;
2121
22+
23+ var listCli = sub . addParser ( 'scopes' ) ;
24+
25+ listCli . addArgument ( [ '--syntax' ] , {
26+ help : 'Syntax file in YAML format, ex: "--syntax FooLang.YAML-tmLanguage"' ,
27+ required : true
28+ } ) ;
29+
30+
2231var testCli = sub . addParser ( 'test' ) ;
2332
2433testCli . addArgument ( [ '--tests' ] , {
@@ -89,6 +98,8 @@ function main() {
8998 syntaxdev . buildCson ( options . in , options . out ) ;
9099 } else if ( options . command == 'build-plist' ) {
91100 syntaxdev . buildPList ( options . in , options . out ) ;
101+ } else if ( options . command == 'scopes' ) {
102+ console . log ( syntaxdev . listScopes ( options . syntax ) . join ( '\n' ) ) ;
92103 }
93104}
94105
Original file line number Diff line number Diff line change @@ -303,8 +303,52 @@ function buildPList(inName, outName) {
303303}
304304
305305
306+ function listScopes ( grammarFile ) {
307+ var schema = readGrammarFile ( grammarFile ) ,
308+ scopes = [ ] ;
309+
310+ function addName ( name ) {
311+ scopes . push . apply ( scopes , name . split ( / \s + / g) ) ;
312+ }
313+
314+ function visit ( o ) {
315+ if ( _ . has ( o , 'name' ) ) {
316+ addName ( o . name ) ;
317+ }
318+
319+ if ( _ . has ( o , 'patterns' ) ) {
320+ _ . each ( o . patterns , visit ) ;
321+ }
322+
323+ _ . each (
324+ [ 'beginCaptures' , 'endCaptures' , 'captures' ] ,
325+ function ( prop ) {
326+ if ( ! _ . has ( o , prop ) ) {
327+ return
328+ }
329+
330+ _ . each ( o [ prop ] , function ( v ) {
331+ if ( _ . has ( v , 'name' ) ) {
332+ addName ( v . name ) ;
333+ }
334+ } )
335+ }
336+ ) ;
337+ }
338+
339+ if ( schema . repository ) {
340+ _ . each ( schema . repository , function ( v , k ) {
341+ visit ( v ) ;
342+ } ) ;
343+ }
344+
345+ return _ . chain ( scopes ) . uniq ( ) . sort ( ) . value ( ) ;
346+ }
347+
348+
306349module . exports = {
307350 test : test ,
308351 buildCson : buildCson ,
309- buildPList : buildPList
352+ buildPList : buildPList ,
353+ listScopes : listScopes
310354} ;
You can’t perform that action at this time.
0 commit comments