object ISerializerInternal.DeserializeInternal(string data, DeserializationContext context) { if (data.Equals(EmptySymbol)) { return(EmptyValue); } MainParser parser = new MainParser(); IList <INodeData> list; parser.ExtractNodeData(data, out list); Type instanceType; Metadata metadata; if (!CanDeserialize(list, out instanceType, out metadata, context)) { return(EmptyValue); } if (context.TryGet(metadata.ReferenceTracker, out object cacheFound)) { return(cacheFound); } ISerializer concreteSerializer = SerializerDependencies.SerializerCollection.GetOrAdd(instanceType); return(((CustomSerializer)concreteSerializer).ReadObjectData(list, context, metadata.ReferenceTracker)); }
public void SetUp() { var rules = RuleFactory.CreateAllRules(); var sourceTags = rules.Select(rule => rule.SourceTag); mainParser = new MainParser(sourceTags); }
private static Parser<object> GetArrayParser(MainParser mainParser) { return from openBracket in Parse.Char('[').Token() from firstItem in Parse.Ref(() => mainParser.Value).Optional() from otherItems in (from comma in Parse.Char(',').Token() from item in Parse.Ref(() => mainParser.Value) select item).Many() from closeBracket in Parse.Char(']').Token() select GetObjectArray(firstItem, otherItems); }
private static Parser <object> GetArrayParser(MainParser mainParser) { return (from openSquare in Parse.Char('[').Token() from first in Parse.Ref(() => mainParser.Value).Optional() from rest in (from comman in Parse.Char(',').Token() from value in Parse.Ref(() => mainParser.Value) select value).Many() from closeSquare in Parse.Char(']').Token() select GetObjectArray(first.GetOrDefault(), rest)); }
private static Parser<object> GetArrayParser(MainParser mainParser) { return from openSquare in Parse.Char('[').Token() from first in Parse.Ref(() => mainParser.Value).Optional() from rest in (from comman in Parse.Char(',').Token() from value in Parse.Ref(() => mainParser.Value) select value).Many() from closeSquare in Parse.Char(']').Token() select GetObjectArray(first.GetOrDefault(), rest); }
public static Func <string, object> GetJsonParser() { var mainParser = new MainParser(); var literalParser = GetLiteralParser(); var stringParser = GetStringParser(); var objectParser = GetObjectParser(stringParser, mainParser); var arrayParser = GetArrayParser(mainParser); mainParser.Value = literalParser.Or(stringParser).Or(objectParser).Or(arrayParser); return(mainParser.Value.Parse); }
public static Func<string, object> GetJsonParser() { var mainParser = new MainParser(); var literalParser = GetLiteralParser(); var stringParser = GetStringParser(); var objectParser = GetObjectParser(stringParser, mainParser); var arrayParser = GetArrayParser(mainParser); mainParser.Value = literalParser.Or(stringParser).Or(objectParser).Or(arrayParser); return mainParser.Value.Parse; }
private static Parser<object> GetArrayParser(MainParser mainParser) { var remainderParser = from comma in Parse.Char(',').Token() from item in Parse.Ref(() => mainParser.Value) select item; return from openBracket in Parse.Char('[').Token() from item in Parse.Ref(() => mainParser.Value).Optional() from rest in remainderParser.Many() from closeBracket in Parse.Char(']').Token() select GetObjectArray(item, rest); }
/// <summary> /// example code using the parser to index into mongo /// </summary> /// <param name="args"></param> static void Main(string[] args) { DBAdapter mongoAdapter = new MongoAdapter(); MainParser mp = new MainParser(); string content1 = File.ReadAllText(path1); string output1 = mp.ParseInput(content1); mongoAdapter.Index(output1); string content2 = File.ReadAllText(path2); string output2 = mp.ParseInput(content2); mongoAdapter.Index(output2); }
public static int Main(string[] args) { var modeParser = new MainParser(CanvasVersionInfo.VersionString, CanvasVersionInfo.CopyrightString, new GermlineWgsModeParser("Germline-WGS", "CNV calling of a germline sample from whole genome sequencing data"), new SomaticEnrichmentModeParser("Somatic-Enrichment", "CNV calling of a somatic sample from targeted sequencing data"), new TumorNormalWgsModeParser("Somatic-WGS", "CNV calling of a somatic sample from whole genome sequencing data"), new TumorNormalEnrichmentModeParser("Tumor-normal-enrichment", "CNV calling of a tumor/normal pair from targeted sequencing data")); var result = modeParser.Parse(args, Console.Out, Console.Error); if (!result.Success) { return(-1); } return(result.Result.Launch()); }
public static string Render(string markdown) { var rules = RuleFactory.CreateAllRules(); var sourceTags = rules.Select(rule => rule.SourceTag); var renderedLines = new List <string>(); var parser = new MainParser(sourceTags); var render = new Render(rules); var escapedText = EscapeSpecialSymbols(markdown); foreach (var line in Regex.Split(escapedText, Environment.NewLine)) { var tokens = parser.ParseLine(line); var renderedLine = render.RenderLine(line, tokens); renderedLines.Add(renderedLine); } return(string.Join(Environment.NewLine, renderedLines)); }
public void GermlineWgsParse_WithRequiredArguments_ReturnsSuccessfulCallsetResult(string name, string description, StringWriter standardWriter, StringWriter errorWriter, TemporaryDirectoryFixture tempDirectory) { // arrange GermlineWgsModeParser germlineWgsModeParser = new GermlineWgsModeParser(name, description); MainParser parser = GetMainParser(germlineWgsModeParser); string[] args = { "-h" }; // act var result = parser.Parse(args, standardWriter, errorWriter); // assert Assert.True(result.Success); }
public static int Main(string[] args) { if (args.Length == 0) { return(Help()); } if (File.Exists(args[0])) { XmlDocument doc = new XmlDocument(); doc.Load(args[0]); IParser mainParser = new MainParser(); BaseParser.SourcePath = new FileInfo(args[0]).DirectoryName; mainParser.Parse(doc.DocumentElement); mainParser.Process(); doc.Save("Setup.wxs"); return(0); } return(-1); }
object ISerializerInternal.DeserializeInternal(string data, DeserializationContext context) { if (data.Equals(EmptySymbol)) { return(EmptyValue); } MainParser parser = new MainParser(); IList <INodeData> list; parser.ExtractNodeData(data, out list); // get the metadata List <INodeData> validNodes = list[0].SubNodes[1].SubNodes.Where(n => !NodeUtils.IgnoreOnDeserialization(n.Type)).ToList(); INodeData typeNode = list[0].SubNodes[1].SubNodes.FirstOrDefault(n => n.Type == NodeType.METADATA); CustomSerializer serializer = SerializerUtils.MetadataSerializer; Metadata metadata = (Metadata)serializer.ReadObjectData(new List <INodeData>() { typeNode }, context, -1); // check if the object is already in cache // if that's the case then return it if (context.TryGet(metadata.ReferenceTracker, out object cacheFound)) { return(cacheFound); } // validate the node structure if (!ValidateNodes(list)) { return(EmptyValue); } // else do the normal deserialization object result = ReadObjectData(list, context, metadata.ReferenceTracker); return(result); }
public void Parse_ModeWithMissingRequiredArgument_DisplaysError(string messageToDisplay, string name, string description, StringWriter standardWriter, StringWriter errorWriter) { // arrange GermlineWgsModeParser germlineWgsModeParser = new GermlineWgsModeParser("WGS", "Run Canvas from WGS data"); MainParser parser = GetMainParser(germlineWgsModeParser); string[] modeArgs = { "WGS" }; // act parser.Parse(modeArgs, standardWriter, errorWriter); string errorOutput = errorWriter.ToString(); // assert Assert.Contains(messageToDisplay, errorOutput); Assert.Empty(standardWriter.ToString()); }
public void Parse_NoArguments_DisplaysError(string messageToDisplay, string name, string description, StringWriter standardWriter, StringWriter errorWriter) { // arrange GermlineWgsModeParser germlineWgsModeParser = new GermlineWgsModeParser(name, description); MainParser parser = GetMainParser(germlineWgsModeParser); string[] noArgs = { }; // act var result = parser.Parse(noArgs, standardWriter, errorWriter); string errorOutput = errorWriter.ToString(); // assert Assert.False(result.Success); Assert.Contains(messageToDisplay, errorOutput); Assert.Empty(standardWriter.ToString()); }
public void Parse_WithHelpArgument_ReturnsSuccecssAndDisplaysHelp(string messageToDisplay, string name, string description, StringWriter standardWriter, StringWriter errorWriter) { // arrange GermlineWgsModeParser germlineWgsModeParser = new GermlineWgsModeParser(name, description); MainParser parser = GetMainParser(germlineWgsModeParser); string[] args = { "-h" }; // act var result = parser.Parse(args, standardWriter, errorWriter); string standardOutput = standardWriter.ToString(); // assert Assert.True(result.Success); Assert.Contains(messageToDisplay, standardOutput); Assert.Empty(errorWriter.ToString()); }
public void Parse_ModeWithVersion_ReturnsSuccecssAndDisplaysVersion(string messageToDisplay, string name, string description, StringWriter standardWriter, StringWriter errorWriter) { // arrange GermlineWgsModeParser germlineWgsModeParser = new GermlineWgsModeParser("WGS", "Run Canvas from WGS data"); MainParser parser = GetMainParser(germlineWgsModeParser); string[] modeArgs = { "WGS", "-v" }; // act var result = parser.Parse(modeArgs, standardWriter, errorWriter); string output = standardWriter.ToString().Trim(); // assert Assert.True(result.Success); Assert.Equal(Version, output); Assert.Empty(errorWriter.ToString()); }
public void GermlineWgsParse_WithRequiredArguments_ReturnsSuccessfulCallsetResult() { string name = "Hello"; string description = "World"; StringWriter standardWriter = new StringWriter(); StringWriter errorWriter = new StringWriter(); // arrange GermlineWgsModeParser germlineWgsModeParser = new GermlineWgsModeParser(name, description); MainParser parser = GetMainParser(germlineWgsModeParser); string[] args = { "-h" }; // act var result = parser.Run(args, standardWriter, errorWriter); // assert Assert.Equal(0, result); }
private static Parser <object> GetObjectParser( Parser <string> stringParser, MainParser mainParser) { var memberParser = from name in stringParser from colon in Parse.Char(':').Token() from value in Parse.Ref(() => mainParser.Value) select new Member { Name = name, Value = value }; var objectParser = from openCurly in Parse.Char('{').Token() from first in memberParser.Optional() from rest in (from comma in Parse.Char(',').Token() from member in memberParser select member).Many() from closeCurly in Parse.Char('}').Token() select GetExpandoObject(first.GetOrDefault(), rest); return(objectParser); }
public void Parse_WithHelpArgumentAndUnkownArgument_DisplaysError(string messageToDisplay, string name, string description) { StringWriter standardWriter = new StringWriter(); StringWriter errorWriter = new StringWriter(); // arrange GermlineWgsModeParser germlineWgsModeParser = new GermlineWgsModeParser(name, description); MainParser parser = GetMainParser(germlineWgsModeParser); string[] args = { "-h", "--unknown-option" }; // act var result = parser.Run(args, standardWriter, errorWriter); string errorOutput = errorWriter.ToString(); // assert Assert.Equal(-1, result); Assert.Contains(messageToDisplay, errorOutput); Assert.Empty(standardWriter.ToString()); }
public void Parse_ModeWithHelp_ReturnsSuccessAndDisplaysHelp(string messageToDisplay) { StringWriter standardWriter = new StringWriter(); StringWriter errorWriter = new StringWriter(); // arrange GermlineWgsModeParser germlineWgsModeParser = new GermlineWgsModeParser("WGS", "Run Canvas from WGS data"); MainParser parser = GetMainParser(germlineWgsModeParser); string[] modeArgs = { "WGS", "-h" }; // act var result = parser.Run(modeArgs, standardWriter, errorWriter); string output = standardWriter.ToString().Trim(); // assert Assert.Equal(0, result); Assert.Contains(messageToDisplay, output); Assert.Empty(errorWriter.ToString()); }
public static int Main(string[] args) { try { var mainParser = new MainParser(CanvasVersionInfo.VersionString, CanvasVersionInfo.CopyrightString, new GermlineWgsModeParser("Germline-WGS", "CNV calling of a germline sample from whole genome sequencing data"), new SomaticEnrichmentModeParser("Somatic-Enrichment", "CNV calling of a somatic sample from targeted sequencing data"), new TumorNormalWgsModeParser("Somatic-WGS", "CNV calling of a somatic sample from whole genome sequencing data"), new TumorNormalEnrichmentModeParser("Tumor-normal-enrichment", "CNV calling of a tumor/normal pair from targeted sequencing data"), new SmallPedigreeModeParser("SmallPedigree-WGS", "CNV calling of a small pedigree from whole genome sequencing data")); var result = mainParser.Run(args, Console.Out, Console.Error); return(result); } catch (Exception e) { Console.Error.WriteLine(e); return(-1); } }
public void Parse_SomaticEnrichmentModeWithMissingRequiredArgument_DisplaysError() { string messageToDisplay = "required"; StringWriter standardWriter = new StringWriter(); StringWriter errorWriter = new StringWriter(); // arrange var modeParser = new SomaticEnrichmentModeParser("Somatic-Enrichment", "Run Canvas from somatic enrichment data"); MainParser parser = GetMainParser(modeParser); string[] modeArgs = { "Somatic-Enrichment" }; // act var result = parser.Run(modeArgs, standardWriter, errorWriter); string errorOutput = errorWriter.ToString(); // assert Assert.NotEqual(0, result); Assert.Contains(messageToDisplay, errorOutput); Assert.Empty(standardWriter.ToString()); }
public void Parse_ModeWithMissingRequiredArgument_DisplaysError() { string messageToDisplay = "required"; StringWriter standardWriter = new StringWriter(); StringWriter errorWriter = new StringWriter(); // arrange GermlineWgsModeParser germlineWgsModeParser = new GermlineWgsModeParser("WGS", "Run Canvas from WGS data"); MainParser parser = GetMainParser(germlineWgsModeParser); string[] modeArgs = { "WGS" }; // act var result = parser.Run(modeArgs, standardWriter, errorWriter); string errorOutput = errorWriter.ToString(); // assert Assert.NotEqual(0, result); Assert.Contains(messageToDisplay, errorOutput); Assert.Empty(standardWriter.ToString()); }
public static void Main() { MainParser mainparse = new MainParser(); mainparse.Start(); }
public bool IsValid(string data, out IList <INodeData> nodeDatas, int position, out string patched) { if (string.IsNullOrEmpty(data)) { nodeDatas = null; patched = data; return(false); } if (data.Length < 2) { nodeDatas = null; patched = data; return(false); } cachedList.Clear(); int startIndex; int endIndex; AllIndexesOf(data, START_SYMBOL, cachedList); if (cachedList.Count == 0) { nodeDatas = null; patched = data; return(false); } startIndex = cachedList[0]; AllIndexesOf(data, END_SYMBOL, cachedList); if (cachedList.Count == 0) { nodeDatas = null; patched = data; return(false); } endIndex = cachedList[0]; if (startIndex != 0) { patched = data; nodeDatas = new List <INodeData>(); return(false); } var content = data.Substring(startIndex + 1, endIndex - startIndex - 1); var fullText = data.Substring(startIndex, endIndex - startIndex + 1); NodeDataBase obj = new NodeDataBase(NodeType, fullText, position); nodeDatas = new List <INodeData>(1); INodeData symbolStart = new NodeDataBase(NodeType.SYMBOL, START_SYMBOL, position); INodeData nodeData = new NodeDataBase(NodeType.METADATA_CONTENT, content, position); INodeData symbolEnd = new NodeDataBase(NodeType.SYMBOL, END_SYMBOL, position); var firstPart = data.Substring(0, startIndex); var secondPart = data.Substring(endIndex + 1, data.Length - 1 - endIndex); patched = firstPart + secondPart; MainParser mainParser = new MainParser(); IList <INodeData> list; mainParser.ExtractNodeData(content, out list); nodeData.SubNodes.AddRange(list); obj.SubNodes.Add(symbolStart); obj.SubNodes.Add(nodeData); obj.SubNodes.Add(symbolEnd); nodeDatas.Add(obj); return(true); }
public void Setup() { _mainParser = new MainParser(new MainVisitor()); }
private static Parser<object> GetObjectParser(Parser<string> stringParser, MainParser mainParser) { var memberParser = from name in stringParser from colon in Parse.Char(':').Token() from value in Parse.Ref(() => mainParser.Value) select new Member { Name = name, Value = value }; var objectParser = from openBrace in Parse.Char('{').Token() from firstMember in memberParser.Optional() from otherMembers in (from comma in Parse.Char(',').Token() from member in memberParser select member).Many() from closeBrace in Parse.Char('}').Token() select GetExpandoObject(firstMember, otherMembers); return objectParser; }