public TES5CodeChunkCollection createCodeChunk(ITES4CodeChunk chunk, TES5CodeScope codeScope, TES5GlobalScope globalScope, TES5MultipleScriptsScope multipleScriptsScope) { TES4Branch branch = chunk as TES4Branch; if (branch != null) { return(TES5BranchFactory.CreateCodeChunk(branch, codeScope, globalScope, multipleScriptsScope, this, valueFactory)); } TES4Return returnChunk = chunk as TES4Return; if (returnChunk != null) { return(this.returnFactory.CreateCodeChunkCollection(codeScope.LocalScope.FunctionScope, globalScope, multipleScriptsScope)); } ITES4Callable callable = chunk as ITES4Callable; if (callable != null) { return(this.valueFactory.CreateCodeChunks(callable, codeScope, globalScope, multipleScriptsScope)); } TES4VariableAssignation assignation = chunk as TES4VariableAssignation; if (assignation != null) { return(this.variableAssignationConversionFactory.CreateCodeChunk(assignation, codeScope, globalScope, multipleScriptsScope)); } TES4VariableDeclarationList declarationList = chunk as TES4VariableDeclarationList; if (declarationList != null) { TES5LocalVariableListFactory.createCodeChunk(declarationList, codeScope); return(null); } throw new ConversionException("Cannot convert a chunk: " + chunk.GetType().FullName); }
public static void createCodeChunk(TES4VariableDeclarationList chunk, TES5CodeScope codeScope) { foreach (TES4VariableDeclaration variable in chunk.getVariableList()) { TES4Type variableType = variable.VariableType; TES5LocalVariable property; if (variableType == TES4Type.T_FLOAT) { property = new TES5LocalVariable(variable.VariableName, TES5BasicType.T_FLOAT); } else if (variableType == TES4Type.T_INT || variableType == TES4Type.T_SHORT || variableType == TES4Type.T_LONG) { property = new TES5LocalVariable(variable.VariableName, TES5BasicType.T_INT); } else if (variableType == TES4Type.T_REF) { //most basic one, if something from inherited class is used, we will set to the inheriting class property = new TES5LocalVariable(variable.VariableName, TES5BasicType.T_FORM); } else { throw new ConversionException("Unknown local variable declaration type."); } codeScope.LocalScope.AddVariable(property); } }
public TES5GlobalScope Build(string scriptPath, TES5GlobalVariables globalVariables) { TES4Script parsedScript = this.standaloneParsingService.ParseOrGetFromCache(scriptPath); TES5ScriptHeader scriptHeader = this.CreateHeader(parsedScript); TES4VariableDeclarationList variableList = parsedScript.VariableDeclarationList; TES5GlobalScope globalScope = new TES5GlobalScope(scriptHeader); if (variableList != null) { TES5PropertiesFactory.CreateProperties(variableList, globalScope, globalVariables); } return(globalScope); }
public TES5GlobalScope Build(string sourcePath, TES5GlobalVariables globalVariables) { string scriptName = Path.GetFileNameWithoutExtension(sourcePath); TES4VariableDeclarationList variableList = fragmentsReferencesBuilder.BuildVariableDeclarationList(sourcePath, scriptName, fragmentType); //Create the header. TES5ScriptHeader scriptHeader = TES5ScriptHeaderFactory.GetFromCacheOrConstructByBasicType(scriptName, scriptType, scriptNamePrefix, true); TES5GlobalScope globalScope = new TES5GlobalScope(scriptHeader); if (variableList != null) { propertyFactory.CreateAndAddProperties(variableList, globalScope, globalVariables); } return(globalScope); }
public TES5GlobalScope Build(string sourcePath, TES5GlobalVariables globalVariables) { string scriptName = Path.GetFileNameWithoutExtension(sourcePath); string referencesPath = Path.Combine(Path.GetDirectoryName(sourcePath), scriptName + ".references"); //Create the header. TES5ScriptHeader scriptHeader = new TES5ScriptHeader(scriptName, TES5BasicType.T_QUEST, "", true); TES5GlobalScope globalScope = new TES5GlobalScope(scriptHeader); TES4VariableDeclarationList variableList = FragmentsReferencesBuilder.buildVariableDeclarationList(referencesPath); if (variableList != null) { TES5PropertiesFactory.CreateProperties(variableList, globalScope, globalVariables); } return(globalScope); }
/* * @throws ConversionException */ public static void CreateProperties(TES4VariableDeclarationList variableList, TES5GlobalScope globalScope, TES5GlobalVariables globalVariables) { Dictionary <string, TES4VariableDeclaration> alreadyDefinedVariables = new Dictionary <string, TES4VariableDeclaration>(); foreach (TES4VariableDeclaration variable in variableList.getVariableList()) { string variableName = variable.VariableName; string variableNameLower = variableName.ToLower(); TES4Type variableType = variable.VariableType; TES4VariableDeclaration alreadyDefinedVariable; if (alreadyDefinedVariables.TryGetValue(variableNameLower, out alreadyDefinedVariable)) { if (variableType == alreadyDefinedVariable.VariableType) { continue; //Same variable defined twice, smack the original script developer and fallthrough silently. } throw new ConversionException("Double definition of variable named " + variableName + " with different types ( " + alreadyDefinedVariables[variableNameLower].VariableType.Name + " and " + variable.VariableType.Name + " )"); } TES5Property property; if (variableType == TES4Type.T_FLOAT) { property = new TES5Property(variable.VariableName, TES5BasicType.T_FLOAT, null); } else if (variableType == TES4Type.T_INT || variableType == TES4Type.T_SHORT || variableType == TES4Type.T_LONG) { property = new TES5Property(variable.VariableName, TES5BasicType.T_INT, null); } else if (variableType == TES4Type.T_REF) { property = CreatePropertyFromReference(variable, globalVariables); } else { throw new ConversionException("Unknown variable declaration type."); } globalScope.AddProperty(property); alreadyDefinedVariables.Add(variableNameLower, variable); } }
public TES4VariableDeclarationList BuildVariableDeclarationList(string sourcePath, string scriptName, TES5FragmentType fragmentType) { TES4VariableDeclarationList list = new TES4VariableDeclarationList(); var scroRecords = TES5ReferenceFactory.GetTypesFromSCRO(esmAnalyzer, scriptName, fragmentType); string[] references = #if USEFILESINSTEADOFESM GetReferences(sourcePath, scriptName) #else scroRecords #if !NEWBT .Where(r => r.Value.Key != TES5PlayerReference.FormID) #endif .Select(r => r.Key) #endif .ToArray(); foreach (var reference in references) { var scroReference = scroRecords[reference]; list.Add(new TES4VariableDeclaration(reference, TES4Type.T_REF, formID: scroReference.Key, tes5Type: scroReference.Value)); } return(list); }
/* * @throws ConversionException */ public void CreateAndAddProperties(TES4VariableDeclarationList variableList, TES5GlobalScope globalScope, TES5GlobalVariables globalVariables) { Dictionary <string, TES4VariableDeclaration> alreadyDefinedVariables = new Dictionary <string, TES4VariableDeclaration>(); foreach (TES4VariableDeclaration variable in variableList.VariableList) { string variableName = variable.VariableName; string variableNameLower = variableName.ToLower(); TES4Type variableType = variable.VariableType; TES4VariableDeclaration?alreadyDefinedVariable; if (alreadyDefinedVariables.TryGetValue(variableNameLower, out alreadyDefinedVariable)) { if (variableType == alreadyDefinedVariable.VariableType) { continue; //Same variable defined twice, smack the original script developer and fallthrough silently. } throw GetDuplicatePropertyException(variableName, alreadyDefinedVariable.VariableType.Name, variable.VariableType.Name); } CreateAndAddProperty(variable, globalScope, globalVariables); alreadyDefinedVariables.Add(variableNameLower, variable); } }
public static TES4VariableDeclarationList buildVariableDeclarationList(string path) { TES4VariableDeclarationList list = new TES4VariableDeclarationList(); if (!File.Exists(path)) { return(list); } string[] references = File.ReadAllLines(path); foreach (var reference in references) { string trimmedReference = reference.Trim(); if (trimmedReference == "") { continue; } list.add(new TES4VariableDeclaration(trimmedReference, TES4Type.T_REF)); } return(list); }
public void execute(string buildPath = Build.DEFAULT_BUILD_PATH, bool skipParsing = false, string mode = "strict") { set_time_limit(10800); // 3 hours is the maximum for this command. Need more? You really screwed something, full suite for all Oblivion vanilla data takes 20 minutes. :) float threshold; switch (mode) { case "sloppy": { threshold = 0.5f; break; } case "normal": { threshold = 0.85f; break; } case "strict": default: { threshold = 0.95f; break; } case "perfect": { threshold = 1; break; } } if (!skipParsing) { SyntaxErrorCleanParser parser = new SyntaxErrorCleanParser(new TES4ObscriptCodeGrammar()); //parser = new Parser(new TES4OBScriptGrammar()); TES4ToTES5ASTTIFFragmentConverter converter = TES4ToTES5ASTTIFFragmentConverterFactory.GetConverter(new Build(buildPath)); string inputFolder = "./Fragments/TIF/fragments/"; string outputFolder = "./Fragments/TIF/PapyrusFragments/"; string[] scandir = Directory.GetFiles(inputFolder); int success = 0, total = 0; Dictionary <string, TES5MultipleScriptsScope> ASTTable = new Dictionary <string, TES5MultipleScriptsScope>(); Console.WriteLine("Lexing and parsing.."); int totalNumber = scandir.Length; foreach (var scriptPath in scandir) { if (!scriptPath.EndsWith(".txt")) { continue; } if ((total % 10) == 0) { Console.WriteLine(total + "/" + totalNumber + "..."); } string scriptFileName = scriptPath.Substring(0, scriptPath.Length - 4); string outputScriptPath = scriptFileName + ".psc"; total++; try { Console.WriteLine(scriptFileName + "..."); FragmentLexer lexer = new FragmentLexer(); ArrayTokenStream tokens = lexer.lex(File.ReadAllText(path)); TES4VariableDeclarationList variableList = this.fragmentsReferencesBuilder.buildVariableDeclarationList(inputFolder + scriptFileName + ".references"); TES5MultipleScriptsScope AST = (TES5MultipleScriptsScope)parser.ParseWithFixLogic(tokens); ASTTable[scriptPath] = AST; TES5Target TES5AST = converter.convert(scriptFileName, variableList, AST); string outputScript = TES5AST.output(); File.WriteAllText(outputFolder + outputScriptPath, outputScript); Process.Start("lua", "\"Utilities/beautifier.lua\" \"" + outputFolder + outputScriptPath + "\""); success++; } catch (Exception e) { Console.WriteLine(scriptPath + "\r\n" + e.GetType().FullName + ": " + e.Message + "\r\n"); continue; } } float successRate = (float)success / total; if (successRate < threshold) { float percent = (float)Math.Round(successRate * 100); Console.WriteLine("ERROR: Build failed on parsing step in " + mode + " mode. The rate is " + success + "/" + total + " (" + percent + " %)"); return; } Console.WriteLine("Parsing in " + mode + " mode succedeed (rate " + success + "/" + total + "). Copying Skyrim scripts and parsed papyrus fragments to build folder..."); } Console.WriteLine("Build in " + mode + " mode succeeded!"); }
protected void createObscriptCodeParsingTree() { __invoke("Code+").Is("Code+", "Code").Call((TES4CodeChunks list, ITES4CodeChunk codeDeclaration) => { list.Add(codeDeclaration); return(list); }). Is("Code").Call((ITES4CodeChunk codeDeclaration) => { TES4CodeChunks list = new TES4CodeChunks(); list.Add(codeDeclaration); return(list); }); __invoke("Code").Is("Branch").Is("SetValue", "NWL").Is("Function", "NWL").Is("ObjectCall", "NWL").Is("LocalVariableDeclaration+").Is("Return"); //todo-THIS should be fixed on lexer level, right now it ignores NWL after the return __invoke("LocalVariableDeclaration+").Is("LocalVariableDeclaration+", "LocalVariableDeclaration").Call((TES4VariableDeclarationList list, TES4VariableDeclaration variableDeclaration) => { list.add(variableDeclaration); return(list); }). Is("LocalVariableDeclaration").Call((TES4VariableDeclaration variableDeclaration) => { TES4VariableDeclarationList list = new TES4VariableDeclarationList(); list.add(variableDeclaration); return(list); }) ; __invoke("LocalVariableDeclaration").Is("LocalVariableDeclarationType", "VariableName").Call((System.Func <CommonToken, CommonToken, TES4VariableDeclaration>)((CommonToken variableDeclarationType, CommonToken variableName) => { return(new TES4VariableDeclaration((string)variableName.Value, TES4Type.GetFirst((string)variableDeclarationType.Value.ToLower()))); })) ; __invoke("Branch").Is("BranchStart", "BranchEndToken") //If a == 2 { doSomeCode(); endIf .Call((TES4SubBranch branchStart, object end) => { return(new TES4Branch(branchStart, null, null)); }). Is("BranchStart", "BranchSubBranch+", "BranchEndToken") //If a == 2 { doSomeCode(); endIf .Call((TES4SubBranch branchStart, TES4SubBranchList subbranches, object end) => { return(new TES4Branch(branchStart, subbranches, null)); }). Is("BranchStart", "BranchElse", "BranchEndToken") //If a == 2 { doSomeCode(); endIf .Call((TES4SubBranch branchStart, TES4ElseSubBranch branchElse, object end) => { return(new TES4Branch(branchStart, null, branchElse)); }). Is("BranchStart", "BranchSubBranch+", "BranchElse", "BranchEndToken").Call((TES4SubBranch branchStart, TES4SubBranchList subbranches, TES4ElseSubBranch branchElse, object end) => { return(new TES4Branch(branchStart, subbranches, branchElse)); }) ; __invoke("BranchElse").Is("BranchElseToken", "Code+").Call((object branchElseToken, TES4CodeChunks code) => { return(new TES4ElseSubBranch(code)); }). Is("BranchElseToken").Call((branchElseToken) => { return(new TES4ElseSubBranch(null)); }) ; __invoke("BranchStart").Is("BranchStartToken", "Value", "NWL", "Code+").Call((object branchStart, ITES4Value expression, object newLine, TES4CodeChunks code) => { return(new TES4SubBranch(expression, code)); }). Is("BranchStartToken", "Value", "NWL").Call((object branchStart, ITES4Value expression, object newLine) => { return(new TES4SubBranch(expression, null)); }) ; __invoke("BranchSubBranch+").Is("BranchSubBranch+", "BranchSubBranch").Call((TES4SubBranchList list, TES4SubBranch branchSubBranchDeclaration) => { list.Add(branchSubBranchDeclaration); return(list); }). Is("BranchSubBranch").Call((TES4SubBranch branchSubBranchDeclaration) => { TES4SubBranchList list = new TES4SubBranchList(); list.Add(branchSubBranchDeclaration); return(list); }) ; __invoke("BranchSubBranch").Is("BranchElseifToken", "Value", "NWL", "Code+").Call((object branchElseif, ITES4Value expression, object nwl, TES4CodeChunks codeChunks) => { return(new TES4SubBranch(expression, codeChunks)); }). Is("BranchElseifToken", "Value", "NWL").Call((object branchElseif, ITES4Value expression, object nwl) => { return(new TES4SubBranch(expression, null)); }) ; __invoke("MathOperator").Is("==").Call((System.Func <CommonToken, TES4ComparisonExpressionOperator>)((CommonToken op) => { return(TES4ComparisonExpressionOperator.GetFirst((string)op.Value)); })). Is("!=").Call((System.Func <CommonToken, TES4ComparisonExpressionOperator>)((CommonToken op) => { return(TES4ComparisonExpressionOperator.GetFirst((string)op.Value)); })). Is(">").Call((System.Func <CommonToken, TES4ComparisonExpressionOperator>)((CommonToken op) => { return(TES4ComparisonExpressionOperator.GetFirst((string)op.Value)); })). Is("<").Call((System.Func <CommonToken, TES4ComparisonExpressionOperator>)((CommonToken op) => { return(TES4ComparisonExpressionOperator.GetFirst((string)op.Value)); })). Is("<=").Call((System.Func <CommonToken, TES4ComparisonExpressionOperator>)((CommonToken op) => { return(TES4ComparisonExpressionOperator.GetFirst((string)op.Value)); })). Is(">=").Call((System.Func <CommonToken, TES4ComparisonExpressionOperator>)((CommonToken op) => { return(TES4ComparisonExpressionOperator.GetFirst((string)op.Value)); })) ; __invoke("LogicalOperator").Is("||").Call((System.Func <CommonToken, TES4LogicalExpressionOperator>)((CommonToken op) => { return(TES4LogicalExpressionOperator.GetFirst((string)op.Value)); })). Is("&&").Call((System.Func <CommonToken, TES4LogicalExpressionOperator>)((CommonToken op) => { return(TES4LogicalExpressionOperator.GetFirst((string)op.Value)); })) ; __invoke("Value").Is("Value", "LogicalOperator", "NotLogicalValue").Call((ITES4Value left, TES4LogicalExpressionOperator op, ITES4Value right) => { return(new TES4LogicalExpression(left, op, right)); }). Is("NotLogicalValue"); __invoke("NotLogicalValue").Is("NotLogicalValue", "MathOperator", "NotLogicalAndBinaryValue").Call((ITES4Value left, TES4ComparisonExpressionOperator op, ITES4Value right) => { return(new TES4ComparisonExpression(left, op, right)); }). Is("NotLogicalAndBinaryValue"); __invoke("NotLogicalAndBinaryValue").Is("NotLogicalAndBinaryValue", "BinaryOperator", "NonExpressionValue").Call((ITES4Value left, TES4ArithmeticExpressionOperator op, ITES4Value right) => { return(new TES4ArithmeticExpression(left, op, right)); }). Is("NonExpressionValue"); __invoke("NonExpressionValue").Is("ObjectAccess").Is("Function").Is("APIToken").Is("Primitive"); __invoke("BinaryOperator").Is("+").Call((System.Func <CommonToken, TES4ArithmeticExpressionOperator>)((CommonToken op) => { return(TES4ArithmeticExpressionOperator.GetFirst((string)op.Value)); })). Is("-").Call((System.Func <CommonToken, TES4ArithmeticExpressionOperator>)((CommonToken op) => { return(TES4ArithmeticExpressionOperator.GetFirst((string)op.Value)); })). Is("*").Call((System.Func <CommonToken, TES4ArithmeticExpressionOperator>)((CommonToken op) => { return(TES4ArithmeticExpressionOperator.GetFirst((string)op.Value)); })). Is("/").Call((System.Func <CommonToken, TES4ArithmeticExpressionOperator>)((CommonToken op) => { return(TES4ArithmeticExpressionOperator.GetFirst((string)op.Value)); })) ; __invoke("ObjectAccess").Is("ObjectCall").Is("ObjectProperty"); __invoke("ObjectCall").Is("APIToken", "TokenDelimiter", "Function").Call((TES4ApiToken apiToken, object delimiter, TES4Function function) => { return(new TES4ObjectCall(apiToken, function)); }) ; __invoke("ObjectProperty").Is("APIToken", "TokenDelimiter", "APIToken").Call((TES4ApiToken apiToken, object delimiter, TES4ApiToken nextApiToken) => { return(new TES4ObjectProperty(apiToken, nextApiToken)); }) ; __invoke("SetValue").Is("SetInitialization", "ObjectProperty", "Value").Call((object setInitialization, TES4ObjectProperty objectProperty, ITES4Value expression) => { return(new TES4VariableAssignation(objectProperty, expression)); }). Is("SetInitialization", "APIToken", "Value").Call((object setInitialization, TES4ApiToken apiToken, ITES4Value expression) => { return(new TES4VariableAssignation(apiToken, expression)); }) ; __invoke("Function").Is("FunctionCall", "FunctionArguments").Call((TES4FunctionCall functionCall, TES4FunctionArguments functionArguments) => { return(new TES4Function(functionCall, functionArguments)); }). Is("FunctionCall").Call((TES4FunctionCall functionCall) => { return(new TES4Function(functionCall, new TES4FunctionArguments())); }) ; __invoke("FunctionCall").Is("FunctionCallToken").Call((System.Func <CommonToken, TES4FunctionCall>)((CommonToken functionCall) => { return(new TES4FunctionCall((string)functionCall.Value)); })) ; __invoke("APIToken").Is("ReferenceToken").Call((System.Func <CommonToken, TES4ApiToken>)((CommonToken token) => { return(new TES4ApiToken((string)token.Value)); })) ; __invoke("FunctionArguments").Is("FunctionArguments", "FunctionParameter").Call((TES4FunctionArguments list, ITES4StringValue value) => { list.Add(value); return(list); }). Is("FunctionParameter").Call((ITES4StringValue value) => { TES4FunctionArguments list = new TES4FunctionArguments(); list.Add(value); return(list); }) ; __invoke("FunctionParameter").Is("ObjectAccess").Is("Function").Is("APIToken").Is("Primitive"); __invoke("Primitive").Is("Float").Call((System.Func <CommonToken, TES4Float>)((CommonToken fl) => { string floatValue = fl.Value; if (floatValue.StartsWith(".")) { floatValue = "0" + floatValue; } return(new TES4Float(float.Parse(floatValue))); })). Is("Integer").Call((System.Func <CommonToken, TES4Integer>)((CommonToken token) => { return(new TES4Integer(int.Parse((string)token.Value))); })). Is("Boolean").Call((System.Func <CommonToken, TES4Integer>)((CommonToken token) => { if (token.Value.ToLower() == "true") { return(new TES4Integer(1)); } return(new TES4Integer(0)); })). Is("String").Call((System.Func <CommonToken, TES4String>)((CommonToken str) => { return(new TES4String((string)str.Value)); })) ; __invoke("Return").Is("ReturnToken", "NWL").Call((object returnToken, object nwl) => { return(new TES4Return()); }). Is("ReturnToken").Call((returnToken) => { return(new TES4Return()); }) ; }
public TES4OBScriptGrammar() : base(false) { __invoke("Script").Is("ScriptHeader", "Block+").Call((TES4ScriptHeader header, TES4BlockList blockList) => { return(new TES4Script(header, null, blockList)); }). Is("ScriptHeader", "VariableDeclaration+").Call((TES4ScriptHeader header, TES4VariableDeclarationList variableList) => { return(new TES4Script(header, variableList, null)); }). Is("ScriptHeader", "VariableDeclaration+", "Block+").Call((TES4ScriptHeader header, TES4VariableDeclarationList variableList, TES4BlockList blockList) => { return(new TES4Script(header, variableList, blockList)); }) ; __invoke("ScriptHeader").Is("ScriptHeaderToken", "ScriptName").Call((System.Func <object, CommonToken, TES4ScriptHeader>)((object headerToken, CommonToken scriptName) => { return(new TES4ScriptHeader((string)scriptName.Value)); })) ; __invoke("VariableDeclaration+").Is("VariableDeclaration+", "VariableDeclaration").Call((TES4VariableDeclarationList list, TES4VariableDeclaration variableDeclaration) => { list.add(variableDeclaration); return(list); }). Is("VariableDeclaration").Call((TES4VariableDeclaration variableDeclaration) => { TES4VariableDeclarationList list = new TES4VariableDeclarationList(); list.add(variableDeclaration); return(list); }) ; __invoke("VariableDeclaration").Is("VariableDeclarationType", "VariableName").Call((System.Func <CommonToken, CommonToken, TES4VariableDeclaration>)((CommonToken variableDeclarationType, CommonToken variableName) => { return(new TES4VariableDeclaration((string)variableName.Value, TES4Type.GetFirst((string)variableDeclarationType.Value.ToLower()))); })) ; __invoke("Block+").Is("Block+", "Block").Call((TES4BlockList list, TES4CodeBlock blockDeclaration) => { list.Add(blockDeclaration); return(list); }). Is("Block").Call((TES4CodeBlock blockDeclaration) => { TES4BlockList list = new TES4BlockList(); list.Add(blockDeclaration); return(list); }) ; __invoke("Block").Is("BlockStart", "BlockType", "BlockParameter+", "Code+", "BlockEnd").Call((System.Func <object, CommonToken, TES4BlockParameterList, TES4CodeChunks, object, TES4CodeBlock>)((object blockStart, CommonToken blockType, TES4BlockParameterList blockParameters, TES4CodeChunks codeChunks, object blockEnd) => { return(new TES4CodeBlock((string)blockType.Value, blockParameters, codeChunks)); })). Is("BlockStart", "BlockType", "BlockParameter+", "BlockEnd").Call((System.Func <object, CommonToken, TES4BlockParameterList, object, TES4CodeBlock>)((object blockStart, CommonToken blockType, TES4BlockParameterList blockParameters, object blockEnd) => { return(new TES4CodeBlock((string)blockType.Value, blockParameters, null)); })) //rare empty block . Is("BlockStart", "BlockType", "Code+", "BlockEnd").Call((System.Func <object, CommonToken, TES4CodeChunks, object, TES4CodeBlock>)((object blockStart, CommonToken blockType, TES4CodeChunks codeChunks, object blockEnd) => { return(new TES4CodeBlock((string)blockType.Value, null, codeChunks)); })). Is("BlockStart", "BlockType", "BlockEnd").Call((System.Func <object, CommonToken, object, TES4CodeBlock>)((object blockStart, CommonToken blockType, object blockEnd) => { return(new TES4CodeBlock((string)blockType.Value, null, null)); })) ; //rare empty block __invoke("BlockParameter+").Is("BlockParameter+", "BlockParameter").Call((TES4BlockParameterList list, TES4BlockParameter blockParameter) => { list.Add(blockParameter); return(list); }). Is("BlockParameter").Call((TES4BlockParameter blockParameter) => { TES4BlockParameterList block = new TES4BlockParameterList(); block.Add(blockParameter); return(block); }) ; __invoke("BlockParameter").Is("BlockParameterToken").Call((System.Func <CommonToken, TES4BlockParameter>)((CommonToken token) => { return(new TES4BlockParameter((string)token.Value)); })) ; this.createObscriptCodeParsingTree(); this.Start("Script"); }
public TES4OBScriptGrammar() : base(false) { __invoke("Script").Is("ScriptHeader", "Block+").Call((TES4ScriptHeader header, TES4BlockList blockList) => { return(new TES4Script(header, null, blockList)); }). Is("ScriptHeader", "VariableDeclaration+").Call((TES4ScriptHeader header, TES4VariableDeclarationList variableList) => { return(new TES4Script(header, variableList, null)); }). Is("ScriptHeader", "VariableDeclaration+", "Block+").Call((TES4ScriptHeader header, TES4VariableDeclarationList variableList, TES4BlockList blockList) => { return(new TES4Script(header, variableList, blockList)); }) #if NEWBT . Is("ScriptHeader").Call((TES4ScriptHeader header) =>//WTM: Change: I added this section to allow for a few more scripts to parsed (scripts that are just a header). { return(new TES4Script(header, null, null)); }) #endif ; __invoke("ScriptHeader").Is("ScriptHeaderToken", "ScriptName").Call((object headerToken, CommonToken scriptName) => { return(new TES4ScriptHeader(scriptName.Value)); }) ; __invoke("VariableDeclaration+").Is("VariableDeclaration+", "VariableDeclaration").Call((TES4VariableDeclarationList list, TES4VariableDeclaration variableDeclaration) => { list.Add(variableDeclaration); return(list); }). Is("VariableDeclaration").Call((TES4VariableDeclaration variableDeclaration) => { TES4VariableDeclarationList list = new TES4VariableDeclarationList(); list.Add(variableDeclaration); return(list); }) ; __invoke("VariableDeclaration").Is("VariableDeclarationType", "VariableName").Call((CommonToken variableDeclarationType, CommonToken variableName) => { return(new TES4VariableDeclaration(variableName.Value, TES4Type.GetFirst(variableDeclarationType.Value.ToLower()))); }) ; __invoke("Block+").Is("Block+", "Block").Call((TES4BlockList list, TES4CodeBlock blockDeclaration) => { list.Add(blockDeclaration); return(list); }). Is("Block").Call((TES4CodeBlock blockDeclaration) => { TES4BlockList list = new TES4BlockList(); list.Add(blockDeclaration); return(list); }) ; __invoke("Block").Is("BlockStart", "BlockType", "BlockParameter+", "Code+", "BlockEnd").Call((object blockStart, CommonToken blockType, TES4BlockParameterList blockParameters, TES4CodeChunks codeChunks, object blockEnd) => { return(new TES4CodeBlock(blockType.Value, blockParameters, codeChunks)); }). Is("BlockStart", "BlockType", "BlockParameter+", "BlockEnd").Call((object blockStart, CommonToken blockType, TES4BlockParameterList blockParameters, object blockEnd) => { return(new TES4CodeBlock(blockType.Value, blockParameters, null)); }) //rare empty block . Is("BlockStart", "BlockType", "Code+", "BlockEnd").Call((object blockStart, CommonToken blockType, TES4CodeChunks codeChunks, object blockEnd) => { return(new TES4CodeBlock(blockType.Value, null, codeChunks)); }). Is("BlockStart", "BlockType", "BlockEnd").Call((object blockStart, CommonToken blockType, object blockEnd) => { return(new TES4CodeBlock(blockType.Value, null, null)); }) ; //rare empty block __invoke("BlockParameter+").Is("BlockParameter+", "BlockParameter").Call((TES4BlockParameterList list, TES4BlockParameter blockParameter) => { list.Add(blockParameter); return(list); }). Is("BlockParameter").Call((TES4BlockParameter blockParameter) => { TES4BlockParameterList block = new TES4BlockParameterList(); block.Add(blockParameter); return(block); }) ; __invoke("BlockParameter").Is("BlockParameterToken").Call((CommonToken token) => { return(new TES4BlockParameter(token.Value)); }) ; this.CreateObscriptCodeParsingTree(); this.Start("Script"); }
public TES4Script(TES4ScriptHeader scriptHeader, TES4VariableDeclarationList declarationList = null, TES4BlockList blockList = null) { this.ScriptHeader = scriptHeader; this.VariableDeclarationList = declarationList; this.BlockList = blockList; }