Jelajahi Sumber

Allow prompt to compile and forward AL code from a file; still some problems with includes though

Yentl Van Tendeloo 9 tahun lalu
induk
melakukan
55cf129010
2 mengubah file dengan 22 tambahan dan 2 penghapusan
  1. 18 0
      integration/code/pn_interface.alc
  2. 4 2
      scripts/prompt.py

+ 18 - 0
integration/code/pn_interface.alc

@@ -126,6 +126,7 @@ Element function model_loaded(model : Element):
 			output("  delete      -- Delete an existing element")
 			output("  attr_add    -- Add an attribute to an element")
 			output("  attr_del    -- Delete an attribute of an element")
+			output("  constrain   -- Add a constraint function to the model")
 			output("  rename      -- Rename an existing element")
 			output("  modify      -- Modify the attributes of an element")
 			output("  list        -- Prints the list of elements in the model")
@@ -182,6 +183,23 @@ Element function model_loaded(model : Element):
 							output("Instantiation error!")
 			else:
 				output("Unknown type specified; aborting")
+		elif (cmd == "constrain"):
+			output("Element to constrain (empty for global)?")
+			String model_name
+			model_name = input()
+
+			if (model_name == ""):
+				// Global constraint
+				output("Give input to function constructors for GLOBAL constraint!")
+				set_model_constraints(model, construct_function())
+			elif (dict_in(model["model"], model_name)):
+				// Local constraint for this model
+				output("Give input to function constructors for LOCAL constraint!")
+				add_constraint(model, model_name, construct_function())
+				output("Added constraint to model!")
+			else:
+				// Local constraint, but model not found
+				output("Unknown model; aborting")
 		elif (cmd == "modify"):
 			String model_name
 			output("Element to modify?")

+ 4 - 2
scripts/prompt.py

@@ -107,7 +107,7 @@ while 1:
             local_print("Sending file through parser!")
 
             try:
-                commands = hutn_compile(tmp_file, grammar_file, "CS")
+                commands = hutn_compile(tmp_file, "interface/HUTN/grammars/actionlanguage.g", "CS")
                 local_print("Compilation succesfully terminated!")
                 local_print("Upload this file? [Y/n]")
                 i = raw_input()
@@ -115,10 +115,12 @@ while 1:
                     continue
                 send_data(commands, address)
             except:
+                import traceback
+                traceback.print_exc()
                 local_print("Error during compilation!")
                 local_print("Do you want to try again? [Y/n]")
                 i = raw_input()
-                if i == "n\n":
+                if i[0] == "n":
                     break
 
             local_print("HUTN input finished, going back to regular prompt!")