public static Script GetScriptFromContext(HS_Gen1Parser.ScriptDeclarationContext context, DatumIndex rootExpressionIndex, OpcodeLookup opcodes) { // Create a new Script. Script script = new Script { Name = context.scriptID().GetTextSanitized(), ExecutionType = (short)opcodes.GetScriptTypeOpcode(context.SCRIPTTYPE().GetTextSanitized()), ReturnType = (short)opcodes.GetTypeInfo(context.VALUETYPE().GetTextSanitized()).Opcode, RootExpressionIndex = rootExpressionIndex }; // Handle scripts with parameters. var parameterContext = context.scriptParameters(); if (parameterContext != null) { var parameters = parameterContext.parameter(); for (ushort i = 0; i < parameters.Length; i++) { string name = parameters[i].ID().GetTextSanitized(); var valueTypeNode = parameters[i].VALUETYPE(); string valueType = valueTypeNode is null ? "script" : valueTypeNode.GetTextSanitized(); // Add the parameter to the script object. ScriptParameter parameter = new ScriptParameter { Name = name, Type = opcodes.GetTypeInfo(valueType).Opcode }; script.Parameters.Add(parameter); } } return(script); }
public ScriptInfo(HS_Gen1Parser.ScriptDeclarationContext context, ushort index) { Name = context.scriptID().GetTextSanitized(); ScriptType = context.SCRIPTTYPE().GetTextSanitized(); ReturnType = context.VALUETYPE().GetTextSanitized(); Parameters = new List <ParameterInfo>(); Opcode = index; var parameterContext = context.scriptParameters(); if (parameterContext != null) { var parameters = parameterContext.parameter(); // Create parameters from the extracted strings for (ushort i = 0; i < parameters.Length; i++) { string name = parameters[i].ID().GetTextSanitized(); var valueTypeNode = parameters[i].VALUETYPE(); string valueType = valueTypeNode is null ? "script" : valueTypeNode.GetTextSanitized(); var param = new ParameterInfo(name, valueType, i); Parameters.Add(param); } } }
public void Script(HS_Gen1Parser.ScriptDeclarationContext context, CompilerContextAction action) { string name = context.scriptID().GetTextSanitized(); WriteContextIndent("SCRIPT", context, action, name); }