-
Notifications
You must be signed in to change notification settings - Fork 0
/
Syntax.py
137 lines (107 loc) · 3.87 KB
/
Syntax.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# import sublime
# import sublime_plugin
# import os
# import threading
# import re
# from User.ruamel import yaml
# import json
# dir = 'w:\\cpp\\code\\'
# syntax_file = "C:\\Users\\AgentOfChaos\\AppData\\Roaming\\Sublime Text 3\\Packages\\User\\CMine.sublime-syntax"
# defaults = ['true', 'false', 'for']
# parameters = []
# variables = []
# macros = []
# structs = []
# types = []
# struct_str = ''
# type_str = ''
# def GetTypeData(filename):
# with open(filename) as f:
# content = f.readlines()
# for line in content:
# if ("#define" in line):
# try:
# macro = re.search("^(#define)\\s+(\\w+)", line)
# if macro.group(2) not in macros:
# macros.append(macro.group(2))
# except:
# pass
# if (re.match("struct", line)):
# try:
# struct = re.search("^(struct)\\s+(\\w+)", line)
# if struct.group(2) not in structs:
# structs.append(struct.group(2))
# except:
# pass
# if (re.match("typedef", line)):
# try:
# typedef = re.search("^typedef\\s*\\w+\\s+(\\w+)|^typedef\\s*\\w+\\((\\w+)\\)", line)
# if (typedef.groups()[0]):
# if typedef.groups()[0] not in types:
# types.append(typedef.groups()[0])
# else:
# if typedef.groups()[1] not in types:
# types.append(typedef.groups()[1])
# except:
# pass
# def GetAllTypeData():
# files = os.listdir(dir)
# for file in files:
# GetTypeData(dir+file)
# def AddVarsAndParametes(self, view):
# if view.syntax().name != "C++" and view.syntax().name != "C":
# return
# filename = str(view.file_name())
# GetTypeData(filename)
# param_re = re.compile(r"(?<=\()(.*)(?=\n{)", re.S)
# varab_re = re.compile(r"(?<=\{)(.*)", re.S)
# regions = view.find_by_selector('meta.function')
# for region in regions:
# text = view.substr(region)
# params = []
# varabs = []
# try:
# param_text = str(param_re.search(text).groups()[0])
# # print("paramText: ", param_text)
# varab_text = str(varab_re.search(text).groups()[0])
# # print("varabText: ", varab_text)
# params = re.findall(r"(?<!\.|\d)(\w+)(?:,|\)|\s=)", param_text)
# # print("params: ", params)
# varabs = re.findall(r"(?:"+'|'.join(structs)+'|'.join(types)+r")\s*\*?\s*(\w+)(?!\,)(?!\))(?:(?:\s+=)|(?:;))", varab_text)
# # print("varabs: ", varabs)
# except:
# # print("!!!Exception: ", text[0:20])
# pass
# if params:
# for param in params:
# if param:
# if param not in parameters and param not in defaults:
# parameters.append(param)
# if varabs:
# for varab in varabs:
# if varab:
# if varab not in variables and varab not in defaults:
# variables.append(varab)
# # print(parameters)
# # print(variables)
# with open(syntax_file) as file:
# data = yaml.round_trip_load(file, preserve_quotes=True)
# data['variables']['my_structs'] = "|".join(structs)
# data['variables']['my_types'] = "|".join(types)
# data['variables']['my_macros'] = "|".join(macros)
# data['variables']['my_parameters'] = "|".join(parameters)
# data['variables']['my_vars'] = "|".join(variables)
# with open(syntax_file, 'w') as file:
# file.write('%YAML 1.2\n---\n')
# yaml.dump(data,file, Dumper=yaml.RoundTripDumper)
# class SyntaxListener(sublime_plugin.EventListener):
# def on_init(self, views):
# r1 = threading.Thread(target=GetAllTypeData, args=())
# r1.start()
# def on_post_save_async(self, view):
# AddVarsAndParametes(self, view)
# def on_activated_async(self, view):
# AddVarsAndParametes(self, view)
# def on_modified_async(self, view):
# r1 = threading.Thread(target=lsp_semantic, args=(self, view))
# r1.start()