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


C# System.ParserState类代码示例

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


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

示例1: Parse

        public override ParseTree Parse(Lexer lexer, ParserState state)
        {
            state.RuntimeState.Runtime.ParseTrace.Enter(this, lexer.CurrentSource(), "Pattern " + Type.Name);
            
            int start = lexer.Position;
            
            if (state.Excluded.Contains(this))
            {
                state.RuntimeState.Runtime.ParseTrace.No(this, lexer.CurrentSource(), "Excluded");
                return ParseTree.No;
            }
            
		    Precedence oldCurrentPrecedence = state.CurrentPrecedence;
		    
		    if (Precedence.Overwrites(state.CurrentPrecedence))
		        state.CurrentPrecedence = Precedence;

            ParseTree tree = ParseGraph.Parse(lexer, state);
            
            state.CurrentPrecedence = oldCurrentPrecedence;

            if (tree == ParseTree.No)
            {
                state.RuntimeState.Runtime.ParseTrace.No(this, lexer.SourceFrom(start));
                return ParseTree.No;
            }

            state.RuntimeState.Runtime.ParseTrace.Yes(this, lexer.SourceFrom(start));
            
            return tree;
        }
开发者ID:KevinKelley,项目名称:katahdin,代码行数:31,代码来源:AbstractPattern.cs

示例2: EndBlock

 private void EndBlock()
 {
     AddParameter(parameter);
     parameter = new Parameter();
     PullParent();
     parserState = ParserState.BeginParameterName;
 }
开发者ID:BackupTheBerlios,项目名称:puzzle-svn,代码行数:7,代码来源:Parser.cs

示例3: Parse

 /// <summary>
 /// Parses a stream chunking based on STX/ETX framing. Calls are re-entrant and hold state internally.
 /// </summary>
 /// <param name="bytes">A byte array of data to append</param>
 private void Parse(ArraySegment<byte> bytes)
 {
     byte[] data = bytes.Array;
     for (int i = bytes.Offset; i < bytes.Offset + bytes.Count; i++)
     {
         if ((data[i] > 3 || data[i] == 1) && _currentState == ParserState.AwaitingEtx)
         {
             if (_bufferIndex == _messageBuffer.Length)
             {
                 var tmp = new byte[_messageBuffer.Length * 2];
                 Buffer.BlockCopy(_messageBuffer, 0, tmp, 0, _messageBuffer.Length);
                 _messageBuffer = tmp;
             }
             _messageBuffer[_bufferIndex] = data[i];
             _bufferIndex++;
         }
         else if (data[i] == STX)
         {
             _currentState = ParserState.AwaitingEtx;
             _bufferIndex = 0;
         }
         else if (data[i] == ETX && _currentState == ParserState.AwaitingEtx)
         {
             _currentState = ParserState.AwaitingStx;
             if (_receivedHandler != null)
                 _receivedHandler(new ArraySegment<byte>(_messageBuffer, 0, _bufferIndex));
             _bufferIndex = 0;
         }
     }
 }
开发者ID:danieldeb,项目名称:EventStore,代码行数:34,代码来源:StxEtxMessageFramer.cs

示例4: Parse

 public override ParseTree Parse(Lexer lexer, ParserState state)
 {
     lexer.Whitespace(state.RuntimeState);
     
     int start = lexer.Position;
     
     state.RuntimeState.Runtime.ParseTrace.Enter(this, lexer.CurrentSource(), range.ToString());
     
     char character = lexer.Peek();
     
     if (!range.Contains(character))
     {
         lexer.ErrorStrings[start].Add(range.ToString());
         
         state.RuntimeState.Runtime.ParseTrace.No(this,
             lexer.SourceFrom(start), TextEscape.Quote(character));
         
         return ParseTree.No;
     }
     
     lexer.Read();
     
     state.RuntimeState.Runtime.ParseTrace.Yes(this,
         lexer.SourceFrom(start), TextEscape.Quote(character));
     
     if (state.BuildTextNodes)
         return new ParseTree(Convert.ToString(character));
     else
         return ParseTree.Yes;
 }
开发者ID:KevinKelley,项目名称:katahdin,代码行数:30,代码来源:CharNode.cs

示例5: Handle

        public static void Handle(string timestamp, string data, ParserState state)
        {
            data = data.Trim();
            var match = Regexes.OptionsEntityRegex.Match(data);
            if(match.Success)
            {
                var id = match.Groups[1].Value;
                state.Options = new Options {Id = int.Parse(id), OptionList = new List<Option>(), TimeStamp = timestamp};
                state.UpdateCurrentNode(typeof(Game));
                if(state.Node.Type == typeof(Game))
                    ((Game)state.Node.Object).Data.Add(state.Options);
                else
                    throw new Exception("Invalid node " + state.Node.Type + " -- " + data);
                return;
            }
            match = Regexes.OptionsOptionRegex.Match(data);
            if(match.Success)
            {
                var index = match.Groups[1].Value;
                var rawType = match.Groups[2].Value;
                var rawEntity = match.Groups[3].Value;
                var entity = Helper.ParseEntity(rawEntity, state);
                var type = Helper.ParseEnum<OptionType>(rawType);
                var option = new Option {Entity = entity, Index = int.Parse(index), Type = type, OptionItems = new List<OptionItem>()};
                state.Options.OptionList.Add(option);
                state.CurrentOption = option;
                state.LastOption = option;
                return;
            }
            match = Regexes.OptionsSuboptionRegex.Match(data);
            if(match.Success)
            {
                var subOptionType = match.Groups[1].Value;
                var index = match.Groups[2].Value;
                var rawEntity = match.Groups[3].Value;
                var entity = Helper.ParseEntity(rawEntity, state);

                if(subOptionType == "subOption")
                {
                    var subOption = new SubOption {Entity = entity, Index = int.Parse(index), Targets = new List<Target>()};
                    state.CurrentOption.OptionItems.Add(subOption);
                    state.LastOption = subOption;
                }
                else if(subOptionType == "target")
                {
                    var target = new Target {Entity = entity, Index = int.Parse(index)};
                    var lastOption = state.LastOption as Option;
                    if(lastOption != null)
                    {
                        lastOption.OptionItems.Add(target);
                        return;
                    }
                    var lastSubOption = state.LastOption as SubOption;
                    if(lastSubOption != null)
                        lastSubOption.Targets.Add(target);
                }
                else
                    throw new Exception("Unexpected suboption type: " + subOptionType);
            }
        }
开发者ID:sebastientromp,项目名称:HSReplay,代码行数:60,代码来源:OptionsHandler.cs

示例6: Handle

		public static void Handle(string timestamp, string data, ParserState state)
		{
			data = data.Trim();
			var match = Regexes.EntitiesChosenRegex.Match(data);
			if(match.Success)
			{
				/*NOTE: in 10357, "Player" is bugged, it's treating a player ID
				as an entity ID, resulting in "Player=GameEntity"
				For our own sanity we keep the old playerID logic from the
				previous builds, we'll change to "player" when it's fixed.*/
				var rawEntity = match.Groups[1].Value;
				var rawPlayer = match.Groups[2].Value;
				var count = int.Parse(match.Groups[3].Value);
				var entity = Helper.ParseEntity(rawEntity, state);
				var player = Helper.ParseEntity(rawPlayer, state);
				var cEntities = new ChosenEntities {Entity = entity, PlayerId = player, Count = count, Choices = new List<Choice>(), TimeStamp = timestamp};
				state.CurrentGame.Data.Add(cEntities);
				state.CurrentChosenEntites = cEntities;
				return;
			}
			match = Regexes.EntitiesChosenEntitiesRegex.Match(data);
			if(match.Success)
			{
				var index = int.Parse(match.Groups[1].Value);
				var rawEntity = match.Groups[2].Value;
				var entity = Helper.ParseEntity(rawEntity, state);
				var choice = new Choice {Entity = entity, Index = index};
				state.CurrentChosenEntites.Choices.Add(choice);
				return;
			}
			Console.WriteLine("Warning: Unhandled chosen entities: " + data);
		}
开发者ID:amw2104,项目名称:HSReplay,代码行数:32,代码来源:EntityChosenHandler.cs

示例7: Parse

 public override ParseTree Parse(Lexer lexer, ParserState state)
 {
     lexer.Whitespace(state.RuntimeState);
     
     int start = lexer.Position;
     
     state.RuntimeState.Runtime.ParseTrace.Enter(this, lexer.CurrentSource(), "[]");
     
     char character = lexer.Peek();
     
     if (character == '\0')
     {
         state.RuntimeState.Runtime.ParseTrace.No(this, lexer.SourceFrom(start), "End of source");
         return ParseTree.No;
     }
     
     lexer.Read();
     
     state.RuntimeState.Runtime.ParseTrace.Yes(this, lexer.SourceFrom(start), TextEscape.Quote(character));
     
     if (state.BuildTextNodes)
         return new ParseTree(Convert.ToString(character));
     else
         return ParseTree.Yes;
 }
开发者ID:KevinKelley,项目名称:katahdin,代码行数:25,代码来源:AnyNode.cs

示例8: Handle

		public static void Handle(string timestamp, string data, ParserState state)
		{
			data = data.Trim();
			var match = Regexes.SendChoicesChoicetypeRegex.Match(data);
			if(match.Success)
			{
				var id = match.Groups[1].Value;
				var rawType = match.Groups[2].Value;
			    var type = Helper.ParseEnum<ChoiceType>(rawType);
				state.SendChoices = new SendChoices {Choices = new List<Choice>(), Entity = int.Parse(id), Type = type, TimeStamp = timestamp};
				if(state.Node.Type == typeof(Game))
					((Game)state.Node.Object).Data.Add(state.SendChoices);
				else if(state.Node.Type == typeof(Action))
					((Action)state.Node.Object).Data.Add(state.SendChoices);
				else
					throw new Exception("Invalid node " + state.Node.Type + " -- " + data);
				return;
			}
			match = Regexes.SendChoicesEntitiesRegex.Match(data);
			if(match.Success)
			{
				var index = Helper.ParseEntity(match.Groups[1].Value, state);
				var id = Helper.ParseEntity(match.Groups[2].Value, state);
				var choice = new Choice {Entity = id, Index = index};
				state.SendChoices.Choices.Add(choice);
			}
		}
开发者ID:amw2104,项目名称:HSReplay,代码行数:27,代码来源:SendChoicesHandler.cs

示例9: Parse

 void Parse()
 {
     for (var i = 0; i < _data.Length; i++)
     {
         var c = _data[i];
         if (c == '<' && State == ParserState.None)
         {
             State = ParserState.StartElement;
             _elementNameStart = i + 1;
             _elementNameEnd = null;
         }
         else if (State == ParserState.StartElement && CheckPrev(i, CommentStart))
         {
             State = ParserState.InsideComment;
         }
         else if (State == ParserState.InsideComment && CheckPrev(i, CommentEnd))
         {
             State = ParserState.None;
         }
         else if (State == ParserState.StartElement && CheckPrev(i, CdataStart))
         {
             State = ParserState.InsideCdata;
         }
         else if (State == ParserState.InsideCdata && CheckPrev(i, CdataEnd))
         {
             State = ParserState.None;
         }
         else if (State == ParserState.StartElement && char.IsWhiteSpace(c))
         {
             State = ParserState.InsideElement;
             _attributeNameStart = i;
             _elementNameEnd = i - 1;
         }
         else if ((State == ParserState.InsideElement || State == ParserState.StartElement) && c == '>')
         {
             State = ParserState.None;
         }
         else if (State == ParserState.InsideElement && (char.IsLetter(c) || c=='_' || c==':'))
         {
             State = ParserState.StartAttribute;
             _attributeNameStart = i;
             _attributeNameEnd = null;
         }
         else if (State == ParserState.StartAttribute && (c == '=' || char.IsWhiteSpace(c)))
         {
             State = ParserState.BeforeAttributeValue;
             _attributeNameEnd = i - 1;
         }
         else if (State == ParserState.BeforeAttributeValue && c == '"')
         {
             State = ParserState.AttributeValue;
             _attributeValueStart = i + 1;
         }
         else if (State == ParserState.AttributeValue && c == '"')
         {
             State = ParserState.InsideElement;
         }
     }
 }
开发者ID:vishalishere,项目名称:PerspexVS,代码行数:59,代码来源:XmlParser.cs

示例10: BeginBlock

        private void BeginBlock()
        {
            parameter.Value = new List<Parameter>();
            AddParameter(parameter);
            PushParent(parameter);
            parameter = new Parameter();

            parserState = ParserState.BeginParameterName;
        }
开发者ID:BackupTheBerlios,项目名称:puzzle-svn,代码行数:9,代码来源:Parser.cs

示例11: TransitionAction

 public TransitionAction(ParserAction action, ParserState nextState)
     : this(action)
 {
     if (action != ParserAction.Shift && action != ParserAction.Goto)
         throw new Exception("Can only define the next state for the shift or goto actions.");
     if (nextState == null)
         throw new ArgumentNullException("nextState");
     NextState = nextState;
 }
开发者ID:mattchamb,项目名称:MParse,代码行数:9,代码来源:TransitionAction.cs

示例12: Parse

 public override ParseTree Parse(Lexer lexer, ParserState state)
 {
     int start = lexer.Position;
     
     ParseTree oldLHS = state.LeftHandSide;
     bool oldPrecedenceCanEqualCurrent = state.PrecedenceCanEqualCurrent;
     ConcretePattern oldRecursionExclude = null;
     
     ParseTree tree = ParseTree.Yes;
     
     for (int n = 0; n < nodes.Count; n++)
     {
         ParseGraphNode node = nodes[n];
         
         ParseTree nodeTree = node.Parse(lexer, state);
         
         if (nodeTree == ParseTree.No)
         {
             state.PrecedenceCanEqualCurrent = oldPrecedenceCanEqualCurrent;
             state.LeftHandSide = oldLHS;
             state.RecursionExclude = oldRecursionExclude;
             
             if (oldRecursionExclude != null)
                 state.Excluded.Add(oldRecursionExclude);
             
             lexer.Position = start;
             return ParseTree.No;
         }
         
         tree = tree.Extend(nodeTree);
         
         if (n == 0)
         {
             if (state.RecursionExclude != null)
             {
                 oldRecursionExclude = state.RecursionExclude;
                 state.Excluded.Remove(state.RecursionExclude);
                 state.RecursionExclude = null;
             }
             
             if (state.RecursionBehaviour == RecursionBehaviour.RightRecursive)
                 state.PrecedenceCanEqualCurrent = true;
             else if (state.RecursionBehaviour == RecursionBehaviour.LeftRecursive)
                 state.LeftHandSide = null;
         }
     }
     
     state.PrecedenceCanEqualCurrent = oldPrecedenceCanEqualCurrent;
     state.LeftHandSide = oldLHS;
     state.RecursionExclude = oldRecursionExclude;
     
     if (oldRecursionExclude != null)
         state.Excluded.Add(oldRecursionExclude);
     
     return tree;
 }
开发者ID:KevinKelley,项目名称:katahdin,代码行数:56,代码来源:SeqNode.cs

示例13: TestParseErrorGetsReported

        public void TestParseErrorGetsReported()
        {
            // Create an instance of our language grammar and set handlers for its rules.
            LanguageGrammar<Expression> g = new LanguageGrammar<Expression>();

            g.DivideRule.Action = (e1, e2) => Expression.Divide(e1, e2);
            g.DoubleLiteralRule.Action = (d) => Expression.Constant(d);
            g.IntLiteralRule.Action = (i) => Expression.Constant(i);
            g.StringLiteralRule.Action = (s) => Expression.Constant(s);
            g.MinusRule.Action = (e1, e2) => Expression.Subtract(e1, e2);
            g.ModRule.Action = (e1, e2) => Expression.Modulo(e1, e2);
            g.MultiplyRule.Action = (e1, e2) => Expression.Multiply(e1, e2);
            g.NegateRule.Action = (e) => Expression.Negate(e);
            g.PlusRule.Action = (e1, e2) => Expression.Add(e1, e2);
            g.VariableRefRule.SetStatefulAction<ParserState>((s, name) => s.GetVariable(name));

            // Spin up a parser for our language.
            // TODO: Package this up and simplify it.
            var expressionHelper = new ExpressionHelper();
            var classifierSession = new TerminalClassifierSession<char, ParserState, int>()
                .AddSkipTerminal(new Terminal<char> { Name = "Whitespace", InitialState = RegexCharNFABuilder.RegexCompiler(@"\s+") })
                .CurrentCharExprIs(x => x.CurrentChar())
                .GetFromMarkExprIs(x => x.GetFromMarkedPos())
                .HasCurrentCharExprIs(x => x.HasCurrentChar())
                .MarkPosExprIs(x => x.MarkPos())
                .MoveNextCharExprIs(x => x.MoveNextChar())
                .GetLocationIs(x=>new ParseLocation {Line = 1, Column = x.GetPos()})
                .ErrorCollectionIs(x=>x.Errors)
                .UnmarkPosExprIs(x => x.UnmarkPos());

            var parserGen = new ParserGenerator<char>(expressionHelper);
            var parseTableBuilder = new LRParseTableBuilder();
            var parseTable = parseTableBuilder.BuildParseTable(g);
            var session = parserGen.NewSession<ParserState>()
                .NonTerminalValueExprIs<object>(x => x.NonTerminalValue)
                .TerminalValueExprIs<string>(x => x.TerminalStringValue)
                .TerminalValueExprIs<int>(x => x.TerminalIntValue)
                .TerminalValueExprIs<double>(x => x.TerminalDoubleValue)
                .TerminalIs(x => x.Terminal)
                .NonTerminalIs(x => x.NonTerminal)
                .IncludeSymbols(true)
                .DebugOutputIs(x => Debug.WriteLine(x))
                .Generate("LanguageParser", parseTable, classifierSession);
            // At this point, session is an Expression<ParserState,int> representing our parser.
            // We can compile it into a delegate or a MethodBuilder.  For the examples, we'll use a delegate.
            var compiler = session.Compile();

            // Create a parser state object and initialize it.
            ParserState ps = new ParserState("x*y +* 2.0");
            ps.SetParameters(
                Expression.Parameter(typeof(double), "x"),
                Expression.Parameter(typeof(double), "y"));
            Assert.AreNotEqual(0, compiler(ps));
            Assert.AreNotEqual(0, ps.Errors.Count);
            Assert.Less(ps.Errors.First().ExpectedTerminalNames.Count, g.Terminals.Count);
        }
开发者ID:kennethuil,项目名称:LINQParserGenerator,代码行数:56,代码来源:GrammarTests.cs

示例14: AddTransition

 public void AddTransition(ParserState transitionFrom, GrammarSymbol symbol, ParserState transitionTo)
 {
     if(!_stateTransitions.ContainsKey(transitionFrom))
         _stateTransitions.Add(transitionFrom, new Dictionary<GrammarSymbol,ParserState>());
     if (_stateTransitions[transitionFrom].ContainsKey(symbol))
         throw new Exception("State conflict. Trying to add a transition for a state when one already exists for the specified grammar symbol.");
     _stateTransitions[transitionFrom][symbol] = transitionTo;
     _states.Add(transitionFrom);
     _states.Add(transitionTo);
 }
开发者ID:mattchamb,项目名称:MParse,代码行数:10,代码来源:StateTransitionMap.cs

示例15: RPN_CalculatorEngine

 public RPN_CalculatorEngine()
 {
     curr_state = ParserState.ParserState_Ok;
     op_stack = new Stack<CalculatorToken>(32);
     output_queue = new Stack<CalculatorToken>(32);
     func_table_ = new FunctionTable();
     input_string = null;
     input_iter = 0;
     input_end_marker = 0;
 }
开发者ID:adihodos,项目名称:shunting_yard_calc,代码行数:10,代码来源:ShuntingYard.cs


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