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


C# CharStream.SkipCharacter方法代码示例

本文整理汇总了C#中CharStream.SkipCharacter方法的典型用法代码示例。如果您正苦于以下问题:C# CharStream.SkipCharacter方法的具体用法?C# CharStream.SkipCharacter怎么用?C# CharStream.SkipCharacter使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CharStream的用法示例。


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

示例1: Parse

				public static AST.INode Parse(CharStream stream)
				{
					var startingPos = stream.Position;
					
					try
					{
						// skip open char
						stream.SkipCharacter('[');

						// we need at least one index
						var index = new AST.Index(ParseExpression(stream));

						// others are optional
						while (stream.SkipIfPossible(','))
						{
							index.AddIndex(ParseExpression(stream));
						}

						// skip close char
						stream.SkipCharacter(']');

						return index;
					} catch (Exception e)
					{
						string msg = String.Format(
							"something went wrong parsing an <index> starting at {0}",
							stream.ComputeDetailedPosition(startingPos));
						throw new Exceptions.ParseException(msg, e);
					}
				}
开发者ID:GlenDC,项目名称:L20n.cs,代码行数:30,代码来源:Index.cs

示例2: Parse

				public static void Parse(
					CharStream stream,
					string identifier, Internal.LocaleContext.Builder builder)
				{
					var startingPos = stream.Position;
					
					try
					{
						var macroAST = new AST.Macro(identifier);
						
						stream.SkipCharacter('(');
						WhiteSpace.Parse(stream, true);

						// variables are optional,
						// but we do have them, we need at least one (duh)
						if (Expressions.Variable.Peek(stream))
						{
							macroAST.AddParameter(Macro.ParseVariable(stream));

							// more than 1 is possible as well
							while (stream.SkipIfPossible(','))
							{
								WhiteSpace.Parse(stream, true);
								macroAST.AddParameter(Macro.ParseVariable(stream));
							}
						}

						stream.SkipCharacter(')');
						WhiteSpace.Parse(stream, false);

						stream.SkipCharacter('{');
						WhiteSpace.Parse(stream, true);

						// Parse the Actual Macro Expression
						macroAST.SetExpression(Expression.Parse(stream));

						WhiteSpace.Parse(stream, true);
						stream.SkipCharacter('}');
						WhiteSpace.Parse(stream, true);
						stream.SkipCharacter('>');

						// return the fully parsed macro
						try
						{
							var macro = (Objects.Macro)macroAST.Eval();
							builder.AddMacro(identifier, macro);
						} catch (Exception e)
						{
							throw new Exceptions.EvaluateException(
								String.Format("couldn't evaluate `{0}`", macroAST.Display()),
								e);
						}
					} catch (Exception e)
					{
						string msg = String.Format(
							"something went wrong parsing a <macro> starting at {0}",
							stream.ComputeDetailedPosition(startingPos));
						throw new Exceptions.ParseException(msg, e);
					}
				}
开发者ID:GlenDC,项目名称:L20n.cs,代码行数:60,代码来源:Macro.cs

示例3: Parse

				public static AST.INode Parse(CharStream stream)
				{
					var startingPos = stream.Position;
					
					try
					{
						var condition = Expressions.Logic.Parse(stream);

						// check if we have an IfElse case or simply a logical expression
						string s;
						if (stream.ReadReg(@"\s*\?\s*", out s))
						{
							var first = Expression.Parse(stream);
							WhiteSpace.Parse(stream, true);
							stream.SkipCharacter(':');
							WhiteSpace.Parse(stream, true);
							var second = Expression.Parse(stream);
							return new AST.Conditional(condition, first, second);
						} else
						{ // it's simply a logical expression
							return condition;
						}
					} catch (Exception e)
					{
						string msg = String.Format(
							"something went wrong parsing an <expression> starting at {0}",
							stream.ComputeDetailedPosition(startingPos));
						throw new Exceptions.ParseException(msg, e);
					}
				}
开发者ID:GlenDC,项目名称:L20n.cs,代码行数:30,代码来源:Expression.cs

示例4: Parse

				public static void Parse(
					CharStream stream, string identifier,
					Internal.LocaleContext.Builder builder)
				{
					var startingPos = stream.Position;

					try
					{
						// private identifiers start with an underscore
						// and can only be referenced from within an l20n file
						bool isPrivate = (identifier.IndexOf('_') == 0);

						// an optional index is possible
						AST.INode index = null;
						Index.PeekAndParse(stream, out index);

						// White Space is required
						WhiteSpace.Parse(stream, false);

						var valuePos = stream.Position;

						// Now we need the actual value
						var value = Value.Parse(stream);

						if ((value as IO.AST.HashValue) == null && index != null)
						{
							string msg = String.Format(
								"an index was given, but a stringValue was given, while a hashValue was expected",
								stream.ComputeDetailedPosition(valuePos));
							throw new Exceptions.ParseException(msg);
						}

						// an optional attributes collection is possible
						AST.Attributes attributes;
						Attributes.PeekAndParse(stream, out attributes);

						// White Space is optional
						WhiteSpace.Parse(stream, true);

						stream.SkipCharacter('>');
						
						var entityAST = new AST.Entity(identifier, isPrivate, index, value, attributes);
						try
						{
							var entity = (Objects.Entity)entityAST.Eval();
							builder.AddEntity(identifier, entity);
						} catch (Exception e)
						{
							throw new Exceptions.EvaluateException(
								String.Format("couldn't evaluate `{0}`", entityAST.Display()),
								e);
						}
					} catch (Exception e)
					{
						string msg = String.Format(
							"something went wrong parsing an <entity> starting at {0}",
							stream.ComputeDetailedPosition(startingPos));
						throw new Exceptions.ParseException(msg, e);
					}
				}
开发者ID:GlenDC,项目名称:L20n.cs,代码行数:60,代码来源:Entity.cs

示例5: Parse

				public static AST.HashValue.Item Parse(CharStream stream)
				{
					var startingPos = stream.Position;
					
					try
					{
						// check if a hash item is supposed to be a default
						bool isDefault = stream.SkipIfPossible('*');
						
						// parse the raw identifier (key)
						var identifier = Identifier.Parse(stream, false);
						
						// whitespace is optional
						WhiteSpace.Parse(stream, true);
						// the seperator char is required as it seperates the key and the value
						stream.SkipCharacter(':');
						// more optional whitespace
						WhiteSpace.Parse(stream, true);
						
						// get the actual value, which is identified by the key
						var value = Value.Parse(stream);
						
						return new AST.HashValue.Item(identifier, value, isDefault);
					} catch (Exception e)
					{
						string msg = String.Format(
							"something went wrong parsing a <hash_item> starting at {0}",
							stream.ComputeDetailedPosition(startingPos));
						throw new Exceptions.ParseException(msg, e);
					}
				}
开发者ID:GlenDC,项目名称:L20n.cs,代码行数:31,代码来源:HashItem.cs

示例6: Parse

					public static AST.INode Parse(CharStream stream)
					{
						var startingPos = stream.Position;
						
						try
						{
							AST.INode root;
							if(!Property.PeekAndParse(stream, out root)) {
								root = IdentifierExpression.Parse(stream);
							}
							stream.SkipString("::");

							// we either have an expression or a simple identifier
							AST.INode identifier;
							if (stream.SkipIfPossible('['))
							{
								identifier = Expression.Parse(stream);
								stream.SkipCharacter(']');
							} else
							{
								identifier = new AST.Identifier(Identifier.Parse(stream, false));
							}

							// We can also have optionally a property expression,
							// starting with a simple identifier or straight away with an expression
							AST.PropertyExpression propertyExpression = null;
							if (stream.SkipIfPossible('.'))
							{
								propertyExpression = Property.Parse(stream) as AST.PropertyExpression;
							}
							else if (stream.SkipIfPossible('['))
							{
								var expression = Expression.Parse(stream);
								propertyExpression = new AST.PropertyExpression(expression);
								stream.SkipCharacter(']');
								Property.Parse(stream, propertyExpression);
							}

							return new AST.AttributeExpression(root, identifier, propertyExpression);
						} catch (Exception e)
						{
							string msg = String.Format(
								"something went wrong parsing an <property_expression> starting at {0}",
								stream.ComputeDetailedPosition(startingPos));
							throw new Exceptions.ParseException(msg, e);
						}
					}
开发者ID:GlenDC,项目名称:L20n.cs,代码行数:47,代码来源:Attribute.cs

示例7: Parse

				public static AST.INode Parse(CharStream stream)
				{
					var startingPos = stream.Position;
					
					try
					{
						// skip opening tag
						stream.SkipCharacter('{');

						// at least 1 hashItem is required with optional whitespace surrounding it
						var hashValue = new AST.HashValue();
						WhiteSpace.Parse(stream, true);
						hashValue.AddItem(HashItem.Parse(stream));
						WhiteSpace.Parse(stream, true);

						// parse all other (optional) hashItems
						while (stream.SkipIfPossible(','))
						{
							if (!HashValue.ParseHashItem(stream, hashValue))
							{
								// if we have a  trailing comma, it will be break here
								break;
							}
						}

						// skip closing tag
						stream.SkipCharacter('}');

						return hashValue;
					} catch (Exception e)
					{
						string msg = String.Format(
							"something went wrong parsing a <hash_value> starting at {0}",
							stream.ComputeDetailedPosition(startingPos));
						throw new Exceptions.ParseException(msg, e);
					}
				}
开发者ID:GlenDC,项目名称:L20n.cs,代码行数:37,代码来源:HashValue.cs

示例8: Parse

					public static AST.INode Parse(CharStream stream, AST.INode member)
					{
						var startingPos = stream.Position;

						try
						{
							// skip opening tag
							stream.SkipCharacter('(');
							WhiteSpace.Parse(stream, true);

							var call = new AST.CallExpression(member);

							// parse arguments if possible
							if (!stream.SkipIfPossible(')'))
							{
								call.AddParameter(ParseExpression(stream));

								// but we can also have moreß
								while (stream.SkipIfPossible(','))
								{
									call.AddParameter(ParseExpression(stream));
								}

								// skip closing tag
								stream.SkipCharacter(')');
							}

							return call;
						} catch (Exception e)
						{
							string msg = String.Format(
								"something went wrong parsing an <call_expression> starting at {0}",
								stream.ComputeDetailedPosition(startingPos));
							throw new Exceptions.ParseException(msg, e);
						}
					}
开发者ID:GlenDC,项目名称:L20n.cs,代码行数:36,代码来源:Call.cs

示例9: Parse

				public static AST.Attributes.Item Parse(CharStream stream)
				{
					var startingPos = stream.Position;
					
					try
					{	
						WhiteSpace.Parse(stream, false);

						// parse the raw identifier (key)
						var identifier = Identifier.Parse(stream, false);

						// parse the index if possible
						AST.INode index;
						Index.PeekAndParse(stream, out index);

						WhiteSpace.Parse(stream, true);
						// required seperator
						stream.SkipCharacter(':');

						WhiteSpace.Parse(stream, true);

						var valuePos = stream.Position;

						// the actual value (StringValue or HashTable)
						var value = Value.Parse(stream);

						if ((value as IO.AST.HashValue) == null && index != null)
						{
							string msg = String.Format(
								"an index was given, but a stringValue was given, while a hashValue was expected",
								stream.ComputeDetailedPosition(valuePos));
							throw new Exceptions.ParseException(msg);
						}
						
						return new AST.Attributes.Item(identifier, index, value);
					} catch (Exception e)
					{
						string msg = String.Format(
							"something went wrong parsing a <key_value_pair> starting at {0}",
							stream.ComputeDetailedPosition(startingPos));
						throw new Exceptions.ParseException(msg, e);
					}
				}
开发者ID:GlenDC,项目名称:L20n.cs,代码行数:43,代码来源:KeyValuePair.cs

示例10: Parse

				public static void Parse(CharStream stream, Internal.LocaleContext.Builder builder)
				{
					var startingPos = stream.Position;
					
					try
					{
						stream.SkipString("import(");
						WhiteSpace.Parse(stream, true);
						var path = PureStringValue.Parse(stream);
						WhiteSpace.Parse(stream, true);
						stream.SkipCharacter(')');

						LocalizableObjectsList.ImportAndParse(path, builder);
					} catch (Exception e)
					{
						string msg = String.Format(
							"something went wrong parsing an <import_statement> starting at {0}",
							stream.ComputeDetailedPosition(startingPos));
						throw new Exceptions.ParseException(msg, e);
					}
				}
开发者ID:GlenDC,项目名称:L20n.cs,代码行数:21,代码来源:ImportStatement.cs

示例11: Parse

					public static AST.INode Parse(CharStream stream)
					{
						var startingPos = stream.Position;
						
						try
						{
							if (stream.SkipIfPossible('('))
							{
								var e = Expression.Parse(stream);
								stream.SkipCharacter(')');
								return e;
							} else
							{ // than we /should/ have a primary expressions
								return Primary.Parse(stream);
							}
						} catch (Exception e)
						{
							string msg = String.Format(
								"something went wrong parsing an <parenthesis_expression> starting at {0}",
								stream.ComputeDetailedPosition(startingPos));
							throw new Exceptions.ParseException(msg, e);
						}
					}
开发者ID:GlenDC,项目名称:L20n.cs,代码行数:23,代码来源:Parenthesis.cs

示例12: Parse

					public static AST.INode Parse(CharStream stream, AST.PropertyExpression property = null)
					{
						var startingPos = stream.Position;
						
						try
						{
							if (property == null)
							{
								var obj = IdentifierExpression.Parse(stream);
								property = new AST.PropertyExpression(obj);
							}

							char c;
							// can be either a simple identifier ('.') or expression ('[')
							while (stream.SkipAnyIfPossible(new char[] {'.', '['}, out c))
							{
								if (c == '.')
								{
									property.Add(Identifier.Parse(stream, false));
								} else
								{
									WhiteSpace.Parse(stream, true);
									property.Add(Expression.Parse(stream));
									WhiteSpace.Parse(stream, true);
									stream.SkipCharacter(']');
								}
							}
							
							return property;
						} catch (Exception e)
						{
							string msg = String.Format(
								"something went wrong parsing an <property_expression> starting at {0}",
								stream.ComputeDetailedPosition(startingPos));
							throw new Exceptions.ParseException(msg, e);
						}
					}
开发者ID:GlenDC,项目名称:L20n.cs,代码行数:37,代码来源:Property.cs

示例13: Parse

					public static AST.INode Parse(CharStream stream)
					{
						stream.SkipCharacter('$');
						var identifier = Identifier.Parse(stream, false);
						return new AST.Variable(identifier);
					}
开发者ID:GlenDC,项目名称:L20n.cs,代码行数:6,代码来源:Variable.cs


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