当前位置: 首页>>代码示例>>C#>>正文


C# ParserContext类代码示例

本文整理汇总了C#中ParserContext的典型用法代码示例。如果您正苦于以下问题:C# ParserContext类的具体用法?C# ParserContext怎么用?C# ParserContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


ParserContext类属于命名空间,在下文中一共展示了ParserContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Parse

        public static Terminal_StringValue Parse(
            ParserContext context, 
            string regex)
        {
            context.Push("StringValue", regex);

            bool parsed = true;

            Terminal_StringValue stringValue = null;
            try
            {
                string value = context.text.Substring(context.index, regex.Length);

                if ((parsed = value.ToLower().Equals(regex.ToLower())))
                {
                    context.index += regex.Length;
                    stringValue = new Terminal_StringValue(value, null);
                }
            }
            catch (ArgumentOutOfRangeException) {parsed = false;}

            context.Pop("StringValue", parsed);

            return stringValue;
        }
开发者ID:p-kaczynski,项目名称:GeolocationUri,代码行数:25,代码来源:Terminal_StringValue.cs

示例2: Parse

        public string[][] Parse(TextReader reader)
        {
            var context = new ParserContext();

            ParserState currentState = ParserState.LineStartState;
            string next;
            while ((next = reader.ReadLine()) != null)
            {
                foreach (char ch in next)
                {
                    switch (ch)
                    {
                        case CommaCharacter:
                            currentState = currentState.Comma(context);
                            break;
                        case QuoteCharacter:
                            currentState = currentState.Quote(context);
                            break;
                        default:
                            currentState = currentState.AnyChar(ch, context);
                            break;
                    }
                }
                currentState = currentState.EndOfLine(context);
            }
            List<string[]> allLines = context.GetAllLines();
            return allLines.ToArray();
        }
开发者ID:sdpatro,项目名称:doc-onlook,代码行数:28,代码来源:CsvParser.cs

示例3: Execute

        public override CommandExecutionResult Execute()
        {
            AskSingleValue environmentAsk = new AskSingleValue();
            environmentAsk.Text = Resources.EnvironmentAsk;
            environmentAsk.Prefix = Resources.EnvironmentName;
            if (environmentAsk.ShowDialog() != DialogResult.OK)
            {
                return new CommandExecutionResult(this);
            }

            DirectoryInfo envDir = new DirectoryInfo(Path.Combine(project.BuildFile.DirectoryName, EnvIncludeConstants.ENV_FOLDER_NAME));
            if (!envDir.Exists)
            {
                envDir.Create();
            }

            string targetFileName = string.Format("{0}.{1}.config", project.ProjectName, environmentAsk.Value);
            FileInfo targetFileInfo = new FileInfo(Path.Combine(envDir.FullName, targetFileName));
            if (targetFileInfo.Exists)
            {
                CommandExecutionResult result = new CommandExecutionResult(this);
                result.Error = new ApplicationException(string.Format(Resources.EnvironmnentFileExists, targetFileInfo.FullName));
                return result;
            }

            ParserContext context = new ParserContext();
            context.Set("projectName", project.ProjectName);

            TemplateHelper.GenerateFile(targetFileInfo, @"EnvFile\env.config", context, Encoding.UTF8);

            return new CommandExecutionResult(this);
        }
开发者ID:julienblin,项目名称:NAntConsole,代码行数:32,代码来源:NewEnvironmentConfigFileCommand.cs

示例4: ParseLine

        private string[] ParseLine(string data)
        {
            var context = new ParserContext();
            ParserState currentState = ParserState.LineStartState;

            foreach (var ch in data)
            {
                switch (ch)
                {
                    case CommaCharacter:
                        currentState = currentState.Comma(context);
                        break;

                    case QuoteCharacter:
                        currentState = currentState.Quote(context);
                        break;

                    default:
                        currentState = currentState.AnyChar(ch, context);
                        break;
                }
            }

            currentState.EndOfLine(context);
            return context.Values.ToArray();
        }
开发者ID:thwaringiii,项目名称:Rosetta,代码行数:26,代码来源:CommaSeperatedFileDataStore.cs

示例5: BaseTestWithHeaderRow

        public void BaseTestWithHeaderRow(string filename)
        {
            ParserContext context = new ParserContext(TestDataSample.GetExcelPath(filename));
            ISpreadsheetParser parser = ParserFactory.CreateSpreadsheet(context);
            parser.Context.Properties.Add("HasHeader", "1");
            ToxySpreadsheet ss = parser.Parse();

            Assert.AreEqual(1, ss.Tables[0].HeaderRows.Count);
            Assert.AreEqual("A", ss.Tables[0].HeaderRows[0].Cells[0].Value);
            Assert.AreEqual("B", ss.Tables[0].HeaderRows[0].Cells[1].Value);
            Assert.AreEqual("C", ss.Tables[0].HeaderRows[0].Cells[2].Value);
            Assert.AreEqual("D", ss.Tables[0].HeaderRows[0].Cells[3].Value);
            Assert.AreEqual(3, ss.Tables[0].Rows.Count);
            Assert.AreEqual("1", ss.Tables[0].Rows[0].Cells[0].Value);
            Assert.AreEqual("2", ss.Tables[0].Rows[0].Cells[1].Value);
            Assert.AreEqual("3", ss.Tables[0].Rows[0].Cells[2].Value);
            Assert.AreEqual("4", ss.Tables[0].Rows[0].Cells[3].Value);

            Assert.AreEqual("A1", ss.Tables[0].Rows[1].Cells[0].Value);
            Assert.AreEqual("A2", ss.Tables[0].Rows[1].Cells[1].Value);
            Assert.AreEqual("A3", ss.Tables[0].Rows[1].Cells[2].Value);
            Assert.AreEqual("A4", ss.Tables[0].Rows[1].Cells[3].Value);

            Assert.AreEqual("B1", ss.Tables[0].Rows[2].Cells[0].Value);
            Assert.AreEqual("B2", ss.Tables[0].Rows[2].Cells[1].Value);
            Assert.AreEqual("B3", ss.Tables[0].Rows[2].Cells[2].Value);
            Assert.AreEqual("B4", ss.Tables[0].Rows[2].Cells[3].Value);
        }
开发者ID:iraychen,项目名称:toxy,代码行数:28,代码来源:ExcelParserBaseTest.cs

示例6: ProcessProperty

            internal override void ProcessProperty(int index, LineTypes.Property line, IParentObject obj, Stack<GameObject> objectStack, ParserContext context)
            {
                if (objectStack.Count > 0) {
                    base.ObjectProcessProperty(index, line, obj, objectStack, context);
                    return;
                }

                if (context == this.context) {
                    ShipTilePrefab tile = (ShipTilePrefab)obj;

                    switch (index) {
                        case 0:
                            tile.ID = line.argumentsData[0].ToString();
                            break;
                        case 1:
                            tile.EditorName = line.argumentsData[0].ToString();
                            break;
                        case 2:
                            tile.EditorDescription = line.argumentsData[0].ToString();
                            break;
                        case 3:
                            tile.EditorThumbnail = (Texture2D)line.argumentsData[0];
                            break;
                        case 4:
                            tile.Mass = (float)line.argumentsData[0];
                            break;
                        case 5:
                            tile.HP = (int)line.argumentsData[0];
                            break;
                    }
                    return;
                }

                throw new Exception("Invalid member in parsed lines list");
            }
开发者ID:Bullshitzu,项目名称:SGU,代码行数:35,代码来源:ShipTileParser.cs

示例7: Parse

        public string[][] Parse(string csvData)
        {
            var context = new ParserContext();

            string[] lines = csvData.Split('\n');

            ParserState currentState = ParserState.LineStartState;
            foreach (string next in lines)
            {
                foreach (char ch in next)
                {
                    switch (ch)
                    {
                        case CommaCharacter:
                            currentState = currentState.Comma(context);
                            break;
                        case QuoteCharacter:
                            currentState = currentState.Quote(context);
                            break;
                        default:
                            currentState = currentState.AnyChar(ch, context);
                            break;
                    }
                }
                currentState = currentState.EndOfLine(context);
            }
            List<string[]> allLines = context.GetAllLines();
            return allLines.ToArray();
        }
开发者ID:mraue,项目名称:minijam_june_2015,代码行数:29,代码来源:CsvParser.cs

示例8: BindLiteralOrReference

        public static bool BindLiteralOrReference(ParserContext context, XObject xmlObject, string xmlValue, PropertyInfo boundProperty)
        {
            object convertedLiteralValue;

            if (LiteralTypeConverter.TryConvert(boundProperty.PropertyType, xmlValue, out convertedLiteralValue))
            {
                if (BindExpression(context, xmlObject, xmlValue, boundProperty))
                {
                    return true;
                }
             
                BindFinalValue(boundProperty, context.FrameworkItem, convertedLiteralValue, xmlObject, true);
                return true;
            }

            if (xmlObject is XAttribute)
            {
                if (BindExpression(context, xmlObject, xmlValue, boundProperty))
                {
                    return true;
                }

                DelayedBind(context, xmlObject, xmlValue, boundProperty);
                return true;
            }

            return false;
        }
开发者ID:japj,项目名称:vulcan,代码行数:28,代码来源:PropertyBinder.cs

示例9: TestParseHtml

        public void TestParseHtml()
        {
            string path = Path.GetFullPath(TestDataSample.GetHtmlPath("mshome.html"));

            ParserContext context = new ParserContext(path);
            IDomParser parser = (IDomParser)ParserFactory.CreateDom(context);
            ToxyDom toxyDom = parser.Parse();

            List<ToxyNode> metaNodeList = toxyDom.Root.SelectNodes("//meta");
            Assert.AreEqual(7, metaNodeList.Count);

            ToxyNode aNode = toxyDom.Root.SingleSelect("//a");
            Assert.AreEqual(1, aNode.Attributes.Count);
            Assert.AreEqual("href", aNode.Attributes[0].Name);
            Assert.AreEqual("http://www.microsoft.com/en/us/default.aspx?redir=true", aNode.Attributes[0].Value);

            ToxyNode titleNode = toxyDom.Root.ChildrenNodes[0].ChildrenNodes[0].ChildrenNodes[0];
            Assert.AreEqual("title", titleNode.Name);
            Assert.AreEqual("Microsoft Corporation", titleNode.ChildrenNodes[0].ToText());

            ToxyNode metaNode = toxyDom.Root.ChildrenNodes[0].ChildrenNodes[0].ChildrenNodes[7];
            Assert.AreEqual("meta", metaNode.Name);
            Assert.AreEqual(3, metaNode.Attributes.Count);
            Assert.AreEqual("name", metaNode.Attributes[0].Name);
            Assert.AreEqual("SearchDescription", metaNode.Attributes[0].Value);
            Assert.AreEqual("scheme", metaNode.Attributes[2].Name);
            Assert.AreEqual(string.Empty, metaNode.Attributes[2].Value);
        }
开发者ID:bosstjann,项目名称:toxy,代码行数:28,代码来源:HtmlParserTest.cs

示例10: TestParseLineEvent

 public void TestParseLineEvent()
 {
     string path = TestDataSample.GetTextPath("utf8.txt");
     ParserContext context = new ParserContext(path);
     PlainTextParser parser = (PlainTextParser)ParserFactory.CreateText(context);
     parser.ParseLine += (sender, args) => 
     {
         if (args.LineNumber == 0)
         {
             Assert.AreEqual("hello world", args.Text);
         }
         else if(args.LineNumber==1)
         {
             Assert.AreEqual("a2", args.Text);
         }
         else if (args.LineNumber == 2)
         {
             Assert.AreEqual("a3", args.Text);
         }
         else if (args.LineNumber == 3)
         {
             Assert.AreEqual("bbb4", args.Text);
         }
     };
     string text = parser.Parse();
 }
开发者ID:bosstjann,项目名称:toxy,代码行数:26,代码来源:PlainTextParserTest.cs

示例11: Parse

        public static Terminal_NumericValue Parse(
            ParserContext context, 
            string spelling, 
            string regex, 
            int length)
        {
            context.Push("NumericValue", spelling + "," + regex);

            bool parsed = true;

            Terminal_NumericValue numericValue = null;
            try
            {
                string value = context.text.Substring(context.index, length);

                if ((parsed = Regex.IsMatch(value, regex)))
                {
                    context.index += length;
                    numericValue = new Terminal_NumericValue(value, null);
                }
            }
            catch (ArgumentOutOfRangeException) {parsed = false;}

            context.Pop("NumericValue", parsed);

            return numericValue;
        }
开发者ID:p-kaczynski,项目名称:GeolocationUri,代码行数:27,代码来源:Terminal_NumericValue.cs

示例12: Parse

        public static RouteStatement Parse(ParserContext context) {
            var keyword = context.ReadNextToken();
            if (keyword.Text != "ROUTE") {
                throw new InvalidVRMLSyntaxException("ROUTE expected");
            }

            var nodeOut = context.ParseNodeNameId();
            if (context.ReadNextToken().Text != ".") {
                throw new InvalidVRMLSyntaxException();
            }
            var eventOut = context.ParseEventOutId();
            if (context.ReadNextToken().Text != "TO") {
                throw new InvalidVRMLSyntaxException();
            }
            var nodeIn = context.ParseNodeNameId();
            if (context.ReadNextToken().Text != ".") {
                throw new InvalidVRMLSyntaxException();
            }
            var eventIn = context.ParseEventInId();

            return new RouteStatement {
                NodeOut = nodeOut,
                EventOut = eventOut,
                NodeIn = nodeIn,
                EventIn = eventIn
            };
        }
开发者ID:SavchukSergey,项目名称:graph3D.vrml,代码行数:27,代码来源:RouteStatement.cs

示例13: ToExpression

        public void ToExpression() {
            // Arrange
            ConstantExpression expression = Expression.Constant(42);
            ParserContext context = new ParserContext();
            context.HoistedValues.Add(null);
            context.HoistedValues.Add(null);

            ConstantExpressionFingerprint fingerprint = ConstantExpressionFingerprint.Create(expression, context);

            // Act
            Expression result = fingerprint.ToExpression(context);

            // Assert
            Assert.AreEqual(ExpressionType.Convert, result.NodeType, "Returned expression should have been a cast.");
            UnaryExpression castExpr = (UnaryExpression)result;
            Assert.AreEqual(typeof(int), castExpr.Type);

            Assert.AreEqual(ExpressionType.ArrayIndex, castExpr.Operand.NodeType, "Inner expression should have been an array lookup.");
            BinaryExpression arrayLookupExpr = (BinaryExpression)castExpr.Operand;
            Assert.AreEqual(ParserContext.HoistedValuesParameter, arrayLookupExpr.Left);

            Assert.AreEqual(ExpressionType.Constant, arrayLookupExpr.Right.NodeType, "Index of array lookup should be a constant expression.");
            ConstantExpression indexExpr = (ConstantExpression)arrayLookupExpr.Right;
            Assert.AreEqual(2, indexExpr.Value, "Wrong index output.");
        }
开发者ID:consumentor,项目名称:Server,代码行数:25,代码来源:ConstantExpressionFingerprintTest.cs

示例14: MarkupExtensionParser

 /// <summary>
 /// Constructor.
 /// </summary>
 internal MarkupExtensionParser(
     IParserHelper    parserHelper,
     ParserContext    parserContext)
 {
     _parserHelper = parserHelper;
     _parserContext = parserContext;
 }
开发者ID:JianwenSun,项目名称:cc,代码行数:10,代码来源:MarkupExtensionParser.cs

示例15: Parse

        public static CommandLineParameters Parse([NotNull] string commandline)
        {
            Verify.ArgumentNotNull(commandline, "commandline");

            var context = new ParserContext(commandline);
            return context.Parse();
        }
开发者ID:kapitanov,项目名称:jsr,代码行数:7,代码来源:CommandLineParser.cs


注:本文中的ParserContext类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。