static void Scenario7() { ParserInfo parserInfo = GetExample2ParserInfo(); CommandLineParser parser = new CommandLineParser(parserInfo); SettingsExample2 settings = parser.ParseSettings() as SettingsExample2; //The 'settings' object is now populated. }
public While(XmlNode node, DFG <Block> dfg, ParserInfo parserInfo) { string id = ParseTools.ParseID(node); string mode = node.GetNodeWithAttributeValue(WHILE_MODE_FIELD_NAME).InnerText; if (mode != SUPPORTED_MODE) { parserInfo.ParseExceptions.Add(new ParseException(id, "While block only supports while mode.")); } XmlNode conditionalNode = node.GetInnerBlockNode(CONDITIONAL_BLOCK_FIELD_NAME, parserInfo, new MissingBlockException(id, "While block is missing its conditional block.")); VariableBlock decidingBlock = null; if (conditionalNode != null) { decidingBlock = (VariableBlock)XmlParser.ParseAndAddNodeToDFG(conditionalNode, dfg, parserInfo); } XmlNode guardedNode = node.GetInnerBlockNode(DO_BLOCK_FIELD_NAME, parserInfo, new MissingBlockException(id, "While block is missing blocks to execute.")); if (guardedNode != null) { DFG <Block> guardedDFG = XmlParser.ParseDFG(guardedNode, parserInfo); DFG <Block> nextDFG = XmlParser.ParseNextDFG(node, parserInfo); this.Cond = new Conditional(decidingBlock, guardedDFG, nextDFG); } }
public static Block Parse(XmlNode node, ParserInfo parseInfo, bool canBeScheduled) { string id = ParseTools.ParseID(node); float value = ParseTools.ParseFloat(node, parseInfo, id); return(new Constant(value, parseInfo.GetUniqueAnonymousName(), id, canBeScheduled)); }
private void SelectFile() { if (this.cboParser.SelectedIndex < 0) { MessageBox.Show("Please select a parser first."); return; } ParserInfo info = this.GetParserInfo(); if (info == null) { return; } string extension = info.FileExtension; string filter = $"{info.Language} files|*{extension}|all files|*.*"; this.openFileDialog1.FileName = ""; this.openFileDialog1.Filter = filter; if (this.openFileDialog1.ShowDialog() == DialogResult.OK) { this.txtFile.Text = this.openFileDialog1.FileName; this.LoadFromFile(); } }
private void AddOrUpdateFileForChapter(Chapter chapter, ParserInfo info) { chapter.Files ??= new List <MangaFile>(); var existingFile = chapter.Files.SingleOrDefault(f => f.FilePath == info.FullFilePath); if (existingFile != null) { existingFile.Format = info.Format; if (!new FileInfo(existingFile.FilePath).DoesLastWriteMatch(existingFile.LastModified)) { existingFile.Pages = _archiveService.GetNumberOfPagesFromArchive(info.FullFilePath); } } else { if (info.Format == MangaFormat.Archive) { chapter.Files.Add(CreateMangaFile(info)); existingFile = chapter.Files.Last(); } else { _logger.LogDebug("Ignoring {Filename}. Non-archives are not supported", info.Filename); } } if (existingFile != null) { existingFile.LastModified = new FileInfo(existingFile.FilePath).LastWriteTime; } }
public static T FromCommandLine(ParserInfo parserInfo, string[] commandLineArguments) { CommandLineArgs.Set(commandLineArguments); CommandLineParser p = new CommandLineParser(typeof(T), parserInfo); return(p.ParseSettings() as T); }
public static T GetSettings <T>(T settingsObject, ParserInfo parserInfo, params string[] commandLineArguments) where T : class, ISettings { CommandLineArgs.Set(commandLineArguments); var parser = new CommandLineParser(settingsObject, parserInfo); return(parser.ParseSettings() as T); }
public Direct GetProgram(XmlNode currentProgramXml, ParserInfo parserInfo) { string id = ParseTools.ParseID(currentProgramXml); InlineProgramInfo programInfo = GetInlineProgramInfo(currentProgramXml, parserInfo); CDFG newProgram = ProgramCDFG.Copy(); TransformCDFGToFunctionCDFG(newProgram, programInfo); TransformVariableNames(newProgram, programInfo, parserInfo.GetUniquePostFix()); ChangeIDs(newProgram, id); //Add new variables that this program added programInfo.OutputsFromTo.ForEach(x => parserInfo.AddVariable(string.Empty, VariableType.FLUID, x.Value)); DFG <Block> nextDFG = XmlParser.ParseNextDFG(currentProgramXml, parserInfo); DFG <Block> endDFG = newProgram.GetEndDFGInFirstScope(); int i = newProgram.Nodes.FindIndex(x => x.dfg == endDFG); if (newProgram.Nodes[i].control == null) { newProgram.Nodes[i] = (new Direct(nextDFG), endDFG); } else { newProgram.Nodes[i] = (newProgram.Nodes[i].control.GetNewControlWithNewEnd(nextDFG), endDFG); } //merge the programs together nd return the link between then parserInfo.cdfg.AddCDFG(newProgram); return(new Direct(newProgram.StartDFG)); }
public static Block Parse(XmlNode node, DFG <Block> dfg, ParserInfo parserInfo) { string id = ParseTools.ParseID(node); string output = ParseTools.ParseString(node, OUTPUT_FLUID_FIELD_NAME); Validator.CheckVariableName(id, output); parserInfo.AddVariable(id, VariableType.FLUID, output); XmlNode innerNode = node.GetInnerBlockNode(INPUT_FLUID_FIELD_NAME, parserInfo, new MissingBlockException(id, "Fluid is missing fluid definition blocks.")); if (innerNode != null) { switch (innerNode.GetAttributeValue(Block.TYPE_FIELD_NAME)) { case HeaterUsage.XML_TYPE_NAME: return(HeaterUsage.CreateHeater(output, innerNode, dfg, parserInfo)); case Mixer.XmlTypeName: return(Mixer.CreateMixer(output, innerNode, dfg, parserInfo)); case Union.XML_TYPE_NAME: return(Union.CreateUnion(output, innerNode, dfg, parserInfo)); default: return(CreateFluid(output, innerNode, dfg, parserInfo)); } } return(null); }
public void SetUp() { var solutionPath = TestUtility.GetFixturePath(@"ndriven\NDriven.sln"); var info = new ParserInfo(solutionPath); var web = info.GetProjects().First(p => p.Name == "Presentation.Web"); _doc = new ProjectDocument(web, info); }
public static Block Parse(XmlNode node, ParserInfo parserInfo, bool canBeScheduled) { string id = ParseTools.ParseID(node); string arrayName = ParseTools.ParseString(node, ARRAY_NAME_FIELD_NAME); parserInfo.CheckVariable(id, new VariableType[] { VariableType.NUMBER_ARRAY, VariableType.FLUID_ARRAY }, arrayName); return(new GetArrayLength(arrayName, parserInfo.GetUniqueAnonymousName(), id, canBeScheduled)); }
public static Block Parse(XmlNode node, ParserInfo parserInfo, bool canBeScheduled) { string id = ParseTools.ParseID(node); string variableName = ParseTools.ParseString(node, VARIABLE_FIELD_NAME); parserInfo.CheckVariable(id, VariableType.NUMBER, variableName); return(new GetNumberVariable(variableName, parserInfo.GetUniqueAnonymousName(), id, canBeScheduled)); }
public static Block Parse(XmlNode node, ParserInfo parserInfo) { string id = ParseTools.ParseID(node); string moduleName = ParseTools.ParseString(node, MODULE_NAME_FIELD_NAME); parserInfo.AddVariable(id, VariableType.WASTE, moduleName); return(new WasteDeclaration(moduleName, parserInfo.GetUniqueAnonymousName(), id)); }
public static DropletDeclaration Parse(XmlNode node, ParserInfo parserInfo) { string id = ParseTools.ParseID(node); string output = ParseTools.ParseString(node, INPUT_FLUID_FIELD_NAME); parserInfo.AddVariable(id, VariableType.FLUID, output); return(new DropletDeclaration(output, id)); }
private MangaFile CreateMangaFile(ParserInfo info) { return(new MangaFile() { FilePath = info.FullFilePath, Format = info.Format, Pages = _archiveService.GetNumberOfPagesFromArchive(info.FullFilePath) }); }
public static InputDeclaration Parse(XmlNode node, ParserInfo parserInfo) { string id = ParseTools.ParseID(node); float amount = ParseTools.ParseFloat(node, parserInfo, id, INPUT_AMOUNT_FIELD_NAME); string output = ParseTools.ParseString(node, INPUT_FLUID_FIELD_NAME); parserInfo.AddVariable(id, VariableType.FLUID, output); return(new InputDeclaration(output, amount, id)); }
internal static float TextToFloat(this XmlNode xmlNode, string id, ParserInfo parseInfo) { if (float.TryParse(xmlNode.InnerText, NumberStyles.Any, CultureInfo.InvariantCulture, out float value)) { return(value); } parseInfo.ParseExceptions.Add(new NotANumberException(id, xmlNode.InnerText)); return(float.NaN); }
public void SetUp() { var path = TestUtility.GetFixturePath("NDriven.sln"); _info = new ParserInfo(path); _assembler = new SolutionAssembler(_info); var projects = _info.GetProjects(); SetUpFiles(); SetUpProjects(projects); }
public static FluidInput ParseFluidInput(XmlNode node, DFG <Block> dfg, ParserInfo parserInfo, string id, string nodeName, ParseException exception) { XmlNode inputFluidNode = node.GetInnerBlockNode(nodeName, parserInfo, exception); if (inputFluidNode != null) { return(XmlParser.ParseFluidInput(inputFluidNode, dfg, parserInfo)); } return(null); }
public static T ParseBlock <T>(XmlNode node, DFG <Block> dfg, ParserInfo parserInfo, string id, string nodeName, ParseException exception) where T : Block { XmlNode leftNode = node.GetInnerBlockNode(nodeName, parserInfo, exception); if (leftNode != null) { return((T)XmlParser.ParseBlock(leftNode, dfg, parserInfo, false, false)); } return(null); }
public static Block Parse(XmlNode node, DFG <Block> dfg, ParserInfo parserInfo, bool canBeScheduled) { string id = ParseTools.ParseID(node); RoundOPTypes roundType = StringToRoundOPType(id, ParseTools.ParseString(node, OPTypeFieldName)); VariableBlock numberBlock = ParseTools.ParseBlock <VariableBlock>(node, dfg, parserInfo, id, NUMBER_FIELD_NAME, new MissingBlockException(id, "Number defining block is missing.")); dfg.AddNode(numberBlock); return(new RoundOP(numberBlock, parserInfo.GetUniqueAnonymousName(), roundType, id, canBeScheduled)); }
private void LoadTree() { this.ClearValues(); this.txtMessage.Text = ""; this.tvParserNodes.Nodes.Clear(); this.dictTokenInfo.Clear(); if (this.cboParser.SelectedIndex < 0) { return; } if (string.IsNullOrEmpty(this.txtText.Text)) { return; } string parserName = this.cboParser.Text; Type parserType = this.parserTypes.FirstOrDefault(item => item.Name == parserName); Type lexerType = this.GetLexerType(parserType.Name.Replace("Parser", "Lexer")); Lexer lexer = (Lexer)Activator.CreateInstance(lexerType, new object[] { CharStreams.fromstring(this.txtText.Text) }); CommonTokenStream tokens = new CommonTokenStream(lexer); this.parser = (Parser)Activator.CreateInstance(parserType, new object[] { tokens }); ParserInfo info = this.GetParserInfo(); if (info == null) { return; } MethodInfo rootMethod = parserType.GetMethod(info.EntryRuleName); object value = rootMethod.Invoke(parser, new object[] { }); TreeNode rootNode = this.CreateTreeNode(info.EntryRuleName); rootNode.Tag = value; this.tvParserNodes.Nodes.Add(rootNode); this.AddChildNodes(rootNode, false); rootNode.Expand(); rootNode.EnsureVisible(); }
private static ParserInfo GetDefaultParserInfo() { ParserInfo info = new ParserInfo(); info.SwitchIndicators = new string[] { "-", "/" }; info.AllowSwitchCharsInArguments = false; info.PropertySwitchesAreExclusive = true; info.ContinueOnFailedValidation = false; info.SwitchesAreCaseSensitive = false; info.UnconsumedArgumentMode = UnconsumedArgumentMode.Allowed; return(info); }
public static Block Parse(XmlNode node, DFG <Block> dfg, ParserInfo parserInfo, bool canBeScheduled) { string id = ParseTools.ParseID(node); string arrayName = ParseTools.ParseString(node, ARRAY_NAME_FIELD_NAME); parserInfo.CheckVariable(id, VariableType.NUMBER_ARRAY, arrayName); VariableBlock indexBlock = ParseTools.ParseBlock <VariableBlock>(node, dfg, parserInfo, id, INDEX_FIELD_NAME, new MissingBlockException(id, "Missing block which define the index into the array.")); dfg.AddNode(indexBlock); return(new GetArrayNumber(indexBlock, arrayName, parserInfo.GetUniqueAnonymousName(), id, canBeScheduled)); }
public void ParseConstantBlock() { JSProgram program = new JSProgram(); program.AddConstantBlock(210); TestTools.ExecuteJS(program); XmlNode node = TestTools.GetWorkspace(); ParserInfo parserInfo = new ParserInfo(); Constant constant = (Constant)XmlParser.ParseBlock(node, null, parserInfo); Assert.AreEqual(0, parserInfo.ParseExceptions.Count, parserInfo.ParseExceptions.FirstOrDefault()?.Message); Assert.AreEqual(210, constant.Value); }
private ParserInfo GetParserInfo() { string parserName = this.cboParser.Text; ParserInfo info = ParserManager.GetParserInfoByName(parserName); if (info == null) { MessageBox.Show($"Can't get ParserInfo for parser \"{parserName}\"."); return(null); } return(info); }
public static Block Parse(XmlNode node, DFG <Block> dfg, ParserInfo parserInfo) { string id = ParseTools.ParseID(node); string arrayName = ParseTools.ParseString(node, ARRAY_NAME_FIELD_NAME); parserInfo.AddVariable(id, VariableType.NUMBER_ARRAY, arrayName); VariableBlock arrayLengthBlock = ParseTools.ParseBlock <VariableBlock>(node, dfg, parserInfo, id, ARRAY_LENGTH_FIELD_NAME, new MissingBlockException(id, "Missing block which define the length of the array.")); dfg.AddNode(arrayLengthBlock); return(new NumberArray(arrayName, arrayLengthBlock, id)); }
public static Block Parse(XmlNode node, DFG <Block> dfg, ParserInfo parserInfo) { string id = ParseTools.ParseID(node); string output = ParseTools.ParseString(node, VARIABLE_FIELD_NAME); parserInfo.AddVariable(id, VariableType.NUMBER, output); VariableBlock operandBlock = ParseTools.ParseBlock <VariableBlock>(node, dfg, parserInfo, id, INPUT_VARIABLE_FIELD_NAME, new MissingBlockException(id, "Missing block to define the variables value.")); dfg.AddNode(operandBlock); return(new SetNumberVariable(operandBlock, output, id)); }
private InlineProgramInfo GetInlineProgramInfo(XmlNode node, ParserInfo parserInfo) { string id = node.GetAttributeValue(Block.ID_FIELD_NAME); XmlNode mutatorNode = node.TryGetNodeWithName("mutation"); string inputCountString = mutatorNode.TryGetAttributeValue(INPUT_COUNT_ATTRIBUTE_NAME); string outputCountString = mutatorNode.TryGetAttributeValue(OUTPUT_COUNT_ATTRIBUTE_NAME); string variableCountString = mutatorNode.TryGetAttributeValue(VARIABLE_COUNT_ATTRIBUTE_NAME); int inputCount = int.Parse(inputCountString ?? "0"); int outputCunt = int.Parse(outputCountString ?? "0"); int variableCount = int.Parse(variableCountString ?? "0"); if (inputCount != Inputs.Length || outputCunt != Outputs.Length || variableCount != VariableImports.Length) { throw new InternalParseException($"Actual argument count doesn't match expected argument count when loading the program: {ProgramName}"); } DFG <Block> dfg = new DFG <Block>(); InlineProgramInfo info = new InlineProgramInfo(); for (int i = 0; i < Inputs.Length; i++) { XmlNode inputNode = node.GetInnerBlockNode(GetInputFieldName(i), parserInfo, new MissingBlockException(id, $"Input {Inputs[i]} is missing a fluid block.")); if (inputNode != null) { FluidInput input = XmlParser.ParseFluidInput(inputNode, dfg, parserInfo); info.InputsFromTo.Add(Inputs[i], input); } } for (int i = 0; i < Outputs.Length; i++) { string toName = node.GetNodeWithAttributeValue(GetOutputFieldName(i)).InnerText; info.OutputsFromTo.Add(Outputs[i], toName); } for (int i = 0; i < VariableImports.Length; i++) { XmlNode variableNode = node.GetInnerBlockNode(GetVariableFieldName(i), parserInfo, new MissingBlockException(id, "")); if (variableNode != null) { VariableBlock varBlock = (VariableBlock)XmlParser.ParseBlock(variableNode, dfg, parserInfo, false, false); info.VariablesFromTo.Add(VariableImports[i], varBlock); } } return(info); }
public static Block Parse(XmlNode node, DFG <Block> dfg, ParserInfo parserInfo, bool canBeScheduled) { string id = ParseTools.ParseID(node); BoolOPTypes opType = BoolOP.StringToBoolOPType(id, ParseTools.ParseString(node, OPTypeFieldName)); VariableBlock leftBoolBlock = ParseTools.ParseBlock <VariableBlock>(node, dfg, parserInfo, id, LeftBoolFieldName, new MissingBlockException(id, "Left side of boolean operator is missing a block.")); VariableBlock rightBoolBlock = ParseTools.ParseBlock <VariableBlock>(node, dfg, parserInfo, id, RightBoolFieldName, new MissingBlockException(id, "Right side of boolean operator is missing a block.")); dfg.AddNode(leftBoolBlock); dfg.AddNode(rightBoolBlock); return(new BoolOP(leftBoolBlock, rightBoolBlock, parserInfo.GetUniqueAnonymousName(), opType, id, canBeScheduled)); }