The Fisrt Updated
This commit is contained in:
56
MathMethod.py
Normal file
56
MathMethod.py
Normal file
@@ -0,0 +1,56 @@
|
||||
import shlex
|
||||
import re
|
||||
|
||||
|
||||
|
||||
def GetFlatDivision(s,split_s,number,reto=lambda x:x.strip(),renter="\n\n"):
|
||||
return "\n".join(list(map(reto,s.split(split_s)[number].replace(renter,"").split("\n"))))
|
||||
|
||||
def GetCarriageSpacesSmooth(s):
|
||||
return '\n'.join([line.strip() for line in s.strip().split('\n')])
|
||||
|
||||
def GetBeforeAfterRuleLookup(s,before,after):
|
||||
return "\n".join(list(map(lambda x:re.search(rf'\{before}(.*?)\{after}',x).group(),s.split("\n"))))
|
||||
|
||||
def GetRulesConvertedToJson(s,before,after):
|
||||
result = {}
|
||||
for match in re.finditer(rf'\{before}(.*?)\s(.*?){after}', s, re.DOTALL):
|
||||
key = match.group(1)
|
||||
values = match.group(2)
|
||||
lexer = shlex.shlex(values, posix=True)
|
||||
lexer.whitespace += ' '
|
||||
lexer.whitespace_split = True
|
||||
values = list(lexer)
|
||||
result[key] = values
|
||||
return result
|
||||
|
||||
def GetRulesConvertedToJson2(s):
|
||||
result = {}
|
||||
key, values = re.match(r'(\w+)\s(.+)', s).groups()
|
||||
lexer = shlex.shlex(values, posix=True)
|
||||
lexer.whitespace += ','
|
||||
lexer.whitespace_split = True
|
||||
lexer.quotes = "'"
|
||||
result[key] = list(lexer)
|
||||
return result
|
||||
|
||||
def AssemblyToJson(s,FunctionKeywordRules=r'.([\w]+):',MakeRules=lambda x:x):
|
||||
output_dict = {}
|
||||
current_key = ""
|
||||
current_value = []
|
||||
lines = s.split('\n')
|
||||
for line in lines:
|
||||
if re.match(FunctionKeywordRules, line):
|
||||
if current_key:
|
||||
output_dict[current_key] = current_value
|
||||
current_value = []
|
||||
current_key = line.strip().split(":")[0]
|
||||
else:
|
||||
if line.strip() != "":
|
||||
current_value.append(MakeRules(line.strip().split(";")[0]))
|
||||
if current_key:
|
||||
output_dict[current_key.split(":")[0]] = current_value
|
||||
return output_dict
|
||||
|
||||
def AssembleTextBreakdowns(s):
|
||||
return []
|
||||
Reference in New Issue
Block a user