11#!/usr/bin/env python3
22
3- import json , re
3+ from json import load , dump
44
5- original = open ("squirrel.json" , "r" )
6- unparsed = original .read ()
7- original .close ()
5+ def main ():
6+ try :
7+ with open ("squirrel.json" , "r" , encoding = "utf-8" ) as vsc_file :
8+ vsc_data = load (vsc_file )
9+ except IOError :
10+ print ("Unable to local \" .json\" file" )
11+ quit ()
812
9- unparsed = re .sub ("\n \t ///// BEGIN TF2 VScript Snippets /////" , "" , unparsed )
10- unparsed = re .sub ("\n \t ///// END TF2 VScript Snippets /////" , "" , unparsed )
13+ snippets = []
1114
12- parsed = json .loads (unparsed )
15+ for annotation in vsc_data :
16+ snippet = {
17+ "trigger" : vsc_data [annotation ]["prefix" ],
18+ "annotation" : annotation ,
19+ "contents" : vsc_data [annotation ]["body" ][0 ],
20+ "kind" : "keyword" ,
21+ "details" : vsc_data [annotation ]["description" ]
22+ }
23+ snippets .append (snippet )
24+
25+ snippets_registry = {
26+ "scope" : "source.nut" ,
27+ "completions" : snippets
28+ }
1329
14- i = 1
15- print ("{\n \t \" scope\" : \" source.nut\" ,\n \t \" completions\" : [" )
16- for annotation in parsed :
17- trigger = parsed [annotation ]["prefix" ]
18- contents = parsed [annotation ]["body" ][0 ]
19- details = parsed [annotation ]["description" ]
20- details = re .sub ("\" " , "\\ \" " , details )
21- print ("\t \t {" )
22- print (f"\t \t \t \" trigger\" : \" { trigger } \" ,\n \t \t \t \" annotation\" : \" { annotation } \" ,\n \t \t \t \" contents\" : \" { contents } \" ,\n \t \t \t \" kind\" : \" keyword\" ,\n \t \t \t \" details\" : \" { details } \" " )
23- print ("\t \t }" , end = "" )
24- if (i < len (parsed )):
25- print ("," )
26- i += 1
27- print ("\n \t ]\n }" , end = "" )
30+ with open ("tf2-snippets.sublime-completions" , "w" , encoding = "utf-8" ) as sublime_json :
31+ dump (snippets_registry , sublime_json , indent = 2 )
32+
33+ if __name__ == "__main__" :
34+ main ()
0 commit comments