Pārlūkot izejas kodu

Syntaxaddition: Class

Scarlett Schäfer 2 gadi atpakaļ
vecāks
revīzija
0321e0ff0a
1 mainītis faili ar 115 papildinājumiem un 1 dzēšanām
  1. 115 1
      txtcompile.py

+ 115 - 1
txtcompile.py

@@ -29,6 +29,76 @@ outputDir = sys.argv[2]+ '/' + gitBranch
 if not os.path.exists(outputDir):
     os.makedirs(outputDir)
 
+def class2qsp(text):
+	regex = r"\s*!\s*CLASS\s*\((\S+)\){"
+	regex_inner = r"\s*(\S+):([^;]*);"
+
+	match = re.search(regex, text, re.IGNORECASE)	
+
+	
+
+
+	while match is not None:
+		class_name = match.groups()[0]
+		fields_set = []
+		fields_get = []
+
+		field_missing_error = 'ERROR("Missing field '+class_name+'.<<$ARGS[1]>>")'
+
+		nextClose = text.find('}',match.end())
+
+		field_text = text[match.end() : nextClose]
+
+		field_match = re.search(regex_inner, field_text, re.IGNORECASE)	
+
+		while field_match is not None:
+			print(field_match.groups())
+
+			fields_get += [field_match.groups()]
+			fields_set += [field_match.groups()]
+
+			field_text = field_text[field_match.end():]
+			field_match = re.search(regex_inner, field_text, re.IGNORECASE)	
+		
+		text_get = '\nif $ARGS[0] = "get":\n'
+		text_set = '\nif $ARGS[0] = "set":\n'
+
+		for i in range(len(fields_get)):
+			if i >0:
+				text_get += '\telse'
+				text_set += '\telse'		
+			text_get += 'if $ARGS[1] = "'+fields_get[i][0]+'":\n'
+			text_set += 'if $ARGS[1] = "'+fields_get[i][0]+'":\n'
+			if fields_get[i][0][0] == '$':
+				text_get += '\t\t$RESULT = $'+class_name+'_'+fields_get[i][0][1:]+'\n'
+				text_set += '\t\t$'+class_name+'_'+fields_get[i][0][1:]+'=$ARGS[2]\n'
+			else:
+				text_get += '\t\tRESULT = '+class_name+'_'+fields_get[i][0]+'\n'
+				text_set += '\t\t'+class_name+'_'+fields_get[i][0]+'=ARGS[2]\n'
+		
+		if len(fields_get) > 0:
+			text_get += '\telse:\n\t\t!'+field_missing_error+'\n\tend\n'
+			text_set += '\telse:\n\t\t!'+field_missing_error+'\n\tend\n'
+		else:
+			text_get += '\n\t!'+field_missing_error+'\n'
+			text_set += '\n\t!'+field_missing_error+'\n'
+
+		text_get += 'end\n'
+		text_set += 'end\n'
+
+			
+			
+
+		
+		
+
+		text = text[:max(match.start(),0)] +text_get+text_set+ text[(nextClose+1):]
+		match = re.search(regex, text, re.IGNORECASE)	
+
+	return text
+
+
+
 def getProcessingArguments(text):
 	regex = r"\s*!!\s*PROCESS\s*:(.*)"
 	match = re.search(regex, text, re.IGNORECASE)	
@@ -86,14 +156,32 @@ def foreach2while(text):
 		
 	return text
 
+def messages2qsp(text):
+	regex = r"!\s*ERROR\(([^\)]+)\)"
+
+	match = re.search(regex, text, re.IGNORECASE)	
+
+	while match is not None:
+		text = (text[:max(match.start(),0)] + "gs 'util_message','add','Error',"+ match.groups()[0] + text[match.end():])
+		match = re.search(regex, text, re.IGNORECASE)	
+
+	return text
+
 def syntaxAdditions2qsp(text):
 	# Since foreach is translated into while it has to be processed before while is processed
 	
+	# CLASS
+	text = class2qsp(text)
+
 	# FOREACH	
 	text = 	foreach2while(text)
 		
 	# WHILE
 	text = while2qsp(text)
+
+	text = messages2qsp(text)
+
+	text = var2qsp(text)
 	
 	return text
 	
@@ -104,7 +192,33 @@ def commentsPurge(text):
 def trim(text):
 	trimmedText =  "\n".join([line.strip() for line in text.split('\n') if line.strip() != ''])
 	return trimmedText
-	
+
+def var2qsp(text):
+	#SET
+	regex = r"\#([\w\d_$]+)\.([\w\d_$]+)\s*=\s*([^\#\n]+)\#"
+	match = re.search(regex, text, re.IGNORECASE)	
+
+	while match is not None:
+		text = (text[:max(match.start(),0)] + 
+			"gs '"+match.groups()[0]+"','set','"+match.groups()[1]+"'," +match.groups()[2]+
+			text[match.end():])
+		match = re.search(regex, text, re.IGNORECASE)	
+
+
+	#GET
+	regex = r"\#([\w\d_$]+)\.([\w\d_$]+)"
+
+	match = re.search(regex, text, re.IGNORECASE)	
+
+	while match is not None:
+		text = (text[:max(match.start(),0)] + 
+			"FUNC('"+match.groups()[0]+"','get','"+match.groups()[1]+"')"+ 
+			text[match.end():])
+		match = re.search(regex, text, re.IGNORECASE)	
+
+	return text
+
+
 def while2qsp(text):
 	
 	regex = r"\s*!\s*while\s*[(]\s*([^{]+)[)]{"