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


C# TokenStream.Expect方法代码示例

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


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

示例1: ParseClass

		private static AstNode ParseClass (TokenStream stream)
		{
			stream.Expect (TokenClass.Keyword, "class");
			string name = stream.Expect (TokenClass.Identifier).Value;

			List<string> baseClass = new List<string> ();
			if (stream.Accept (TokenClass.Colon)) {
				do {
					baseClass.Add (ParseClassName (stream));
				} while (stream.Accept (TokenClass.Comma));
			}

			ClassDeclaration clazz = new ClassDeclaration (stream.Location, name, baseClass);

			stream.Expect (TokenClass.OpenBrace);

			while (!stream.Match (TokenClass.CloseBrace)) {
				if (stream.Match (TokenClass.Keyword, "func") || stream.Match (TokenClass.Operator,
					    "@")) {
					FunctionDeclaration func = ParseFunction (stream, false, clazz) as FunctionDeclaration;
					if (func.Name == name) {
						clazz.Constructor = func;
					} else {
						clazz.Add (func);
					}
				} else {
					clazz.Add (ParseStatement (stream));
				}
			}

			stream.Expect (TokenClass.CloseBrace);

			return clazz;
		}
开发者ID:GruntTheDivine,项目名称:Iodine,代码行数:34,代码来源:Parser.cs

示例2: ParseReturn

 private static AstNode ParseReturn(TokenStream stream)
 {
     stream.Expect (TokenClass.Keyword, "return");
     if (stream.Accept (TokenClass.SemiColon)) {
         return new ReturnStatement (stream.Location, new CodeBlock (stream.Location));
     } else {
         return new ReturnStatement (stream.Location, ParseExpression (stream));
     }
 }
开发者ID:splitandthechro,项目名称:nginz,代码行数:9,代码来源:Parser.cs

示例3: ParseMatch

 private static AstNode ParseMatch(TokenStream stream)
 {
     MatchExpression expr = new MatchExpression (stream.Location);
     stream.Expect (TokenClass.Keyword, "match");
     expr.Add (ParseExpression (stream));
     stream.Expect (TokenClass.OpenBrace);
     while (stream.Accept (TokenClass.Keyword, "case")) {
         AstNode condition = null;
         AstNode pattern = ParsePattern (stream);
         if (stream.Accept (TokenClass.Keyword, "when")) {
             condition = ParseExpression (stream);
         }
         stream.Expect (TokenClass.Operator, "=>");
         AstNode value = ParseExpression (stream);
         expr.Children.Add (new CaseExpression (pattern.Location, pattern, condition, value));
     }
     stream.Expect (TokenClass.CloseBrace);
     return expr;
 }
开发者ID:splitandthechro,项目名称:nginz,代码行数:19,代码来源:Parser.cs

示例4: ParseLambda

        private static AstNode ParseLambda(TokenStream stream)
        {
            stream.Expect (TokenClass.Keyword, "lambda");
            bool isInstanceMethod;
            bool isVariadic;
            bool acceptsKwargs;

            List<string> parameters = ParseFuncParameters (stream,
                out isInstanceMethod,
                out isVariadic,
                out acceptsKwargs);

            LambdaExpression decl = new LambdaExpression (stream.Location, isInstanceMethod, isVariadic, acceptsKwargs, parameters);
            if (stream.Accept (TokenClass.Operator, "=>"))
                decl.Add (new ReturnStatement (stream.Location, ParseExpression (stream)));
            else
                decl.Add (ParseStatement (stream));
            return decl;
        }
开发者ID:splitandthechro,项目名称:nginz,代码行数:19,代码来源:Parser.cs

示例5: ParseIndexer

 private static AstNode ParseIndexer(AstNode lvalue, TokenStream stream)
 {
     stream.Expect (TokenClass.OpenBracket);
     AstNode index = ParseExpression (stream);
     stream.Expect (TokenClass.CloseBracket);
     return new IndexerExpression (stream.Location, lvalue, index);
 }
开发者ID:splitandthechro,项目名称:nginz,代码行数:7,代码来源:Parser.cs

示例6: ParseHash

 private static AstNode ParseHash(TokenStream stream)
 {
     stream.Expect (TokenClass.OpenBrace);
     HashExpression ret = new HashExpression (stream.Location);
     while (!stream.Match (TokenClass.CloseBrace)) {
         ret.Add (ParseExpression (stream));
         stream.Expect (TokenClass.Colon);
         ret.Add (ParseExpression (stream));
         if (!stream.Accept (TokenClass.Comma)) {
             break;
         }
     }
     stream.Expect (TokenClass.CloseBrace);
     return ret;
 }
开发者ID:splitandthechro,项目名称:nginz,代码行数:15,代码来源:Parser.cs

示例7: ParseGet

 private static AstNode ParseGet(AstNode lvalue, TokenStream stream)
 {
     stream.Expect (TokenClass.Operator, ".");
     Token ident = stream.Expect (TokenClass.Identifier);
     return new GetExpression (stream.Location, lvalue, ident.Value);
 }
开发者ID:splitandthechro,项目名称:nginz,代码行数:6,代码来源:Parser.cs

示例8: ParseFuncParameters

        private static List<string> ParseFuncParameters(TokenStream stream,
			out bool isInstanceMethod,
			out bool isVariadic,
			out bool hasKeywordArgs)
        {
            isVariadic = false;
            hasKeywordArgs = false;
            isInstanceMethod = false;
            List<string> ret = new List<string> ();
            stream.Expect (TokenClass.OpenParan);
            if (stream.Accept (TokenClass.Keyword, "self")) {
                isInstanceMethod = true;
                if (!stream.Accept (TokenClass.Comma)) {
                    stream.Expect (TokenClass.CloseParan);
                    return ret;
                }
            }
            while (!stream.Match (TokenClass.CloseParan)) {
                if (!hasKeywordArgs && stream.Accept (TokenClass.Operator, "*")) {
                    if (stream.Accept (TokenClass.Operator, "*")) {
                        hasKeywordArgs = true;
                        Token ident = stream.Expect (TokenClass.Identifier);
                        ret.Add (ident.Value);
                    } else {
                        isVariadic = true;
                        Token ident = stream.Expect (TokenClass.Identifier);
                        ret.Add (ident.Value);
                    }
                } else {
                    if (hasKeywordArgs) {
                        stream.ErrorLog.AddError (ErrorType.ParserError, stream.Location,
                            "Argument after keyword arguments!");
                    }
                    if (isVariadic) {
                        stream.ErrorLog.AddError (ErrorType.ParserError, stream.Location,
                            "Argument after params keyword!");
                    }
                    Token param = stream.Expect (TokenClass.Identifier);
                    ret.Add (param.Value);
                }
                if (!stream.Accept (TokenClass.Comma)) {
                    break;
                }
            }
            stream.Expect (TokenClass.CloseParan);
            return ret;
        }
开发者ID:splitandthechro,项目名称:nginz,代码行数:47,代码来源:Parser.cs

示例9: ParseYield

 private static AstNode ParseYield(TokenStream stream)
 {
     stream.Expect (TokenClass.Keyword, "yield");
     return new YieldStatement (stream.Location, ParseExpression (stream));
 }
开发者ID:splitandthechro,项目名称:nginz,代码行数:5,代码来源:Parser.cs

示例10: ParseWith

 private static AstNode ParseWith(TokenStream stream)
 {
     WithStatement ret = new WithStatement (stream.Location);
     stream.Expect (TokenClass.Keyword, "with");
     stream.Expect (TokenClass.OpenParan);
     ret.Add (ParseExpression (stream));
     stream.Expect (TokenClass.CloseParan);
     ret.Add (ParseStatement (stream));
     return ret;
 }
开发者ID:splitandthechro,项目名称:nginz,代码行数:10,代码来源:Parser.cs

示例11: ParseWhen

 private static AstNode ParseWhen(TokenStream stream)
 {
     WhenStatement caseStmt = new WhenStatement (stream.Location);
     stream.Expect (TokenClass.Keyword, "when");
     AstNode value = ParseExpression (stream);
     AstNode body = ParseStatement (stream);
     AstNode lambda = new LambdaExpression (body.Location, false, false, false,
         new System.Collections.Generic.List<string> ());
     lambda.Add (body);
     caseStmt.Add (value);
     caseStmt.Add (lambda);
     return caseStmt;
 }
开发者ID:splitandthechro,项目名称:nginz,代码行数:13,代码来源:Parser.cs

示例12: ParseUse

        private static UseStatement ParseUse(TokenStream stream)
        {
            stream.Expect (TokenClass.Keyword, "use");
            bool relative = stream.Accept (TokenClass.Operator, ".");
            string ident = "";
            if (!stream.Match (TokenClass.Operator, "*"))
                ident = ParseModuleName (stream);
            if (stream.Match (TokenClass.Keyword, "from") || stream.Match (TokenClass.Comma) ||
                stream.Match (TokenClass.Operator, "*")) {
                List<string> items = new List<string> ();
                bool wildcard = false;
                if (!stream.Accept (TokenClass.Operator, "*")) {
                    items.Add (ident);
                    stream.Accept (TokenClass.Comma);
                    while (!stream.Match (TokenClass.Keyword, "from")) {
                        Token item = stream.Expect (TokenClass.Identifier);
                        items.Add (item.Value);
                        if (!stream.Accept (TokenClass.Comma)) {
                            break;
                        }
                    }
                } else {
                    wildcard = true;
                }
                stream.Expect (TokenClass.Keyword, "from");

                relative = stream.Accept (TokenClass.Operator, ".");
                string module = ParseModuleName (stream);
                return new UseStatement (stream.Location, module, items, wildcard, relative);
            }
            return new UseStatement (stream.Location, ident, relative);
        }
开发者ID:splitandthechro,项目名称:nginz,代码行数:32,代码来源:Parser.cs

示例13: ParseTuple

 private static AstNode ParseTuple(AstNode firstVal, TokenStream stream)
 {
     TupleExpression tuple = new TupleExpression (stream.Location);
     tuple.Add (firstVal);
     while (!stream.Match (TokenClass.CloseParan)) {
         tuple.Add (ParseExpression (stream));
         if (!stream.Accept (TokenClass.Comma)) {
             break;
         }
     }
     stream.Expect (TokenClass.CloseParan);
     return tuple;
 }
开发者ID:splitandthechro,项目名称:nginz,代码行数:13,代码来源:Parser.cs

示例14: ParseTryExcept

 private static AstNode ParseTryExcept(TokenStream stream)
 {
     TryExceptStatement retVal = null;
     stream.Expect (TokenClass.Keyword, "try");
     AstNode tryBody = ParseStatement (stream);
     AstNode typeList = new ArgumentList (stream.Location);
     stream.Expect (TokenClass.Keyword, "except");
     if (stream.Accept (TokenClass.OpenParan)) {
         Token ident = stream.Expect (TokenClass.Identifier);
         if (stream.Accept (TokenClass.Operator, "as")) {
             typeList = ParseTypeList (stream);
         }
         stream.Expect (TokenClass.CloseParan);
         retVal = new TryExceptStatement (stream.Location, ident.Value);
     } else {
         retVal = new TryExceptStatement (stream.Location, null);
     }
     retVal.Add (tryBody);
     retVal.Add (ParseStatement (stream));
     retVal.Add (typeList);
     return retVal;
 }
开发者ID:splitandthechro,项目名称:nginz,代码行数:22,代码来源:Parser.cs

示例15: ParseTernaryIfElse

 private static AstNode ParseTernaryIfElse(TokenStream stream)
 {
     AstNode expr = ParsePipeline (stream);
     while (stream.Accept (TokenClass.Keyword, "when")) {
         AstNode condition = ParseExpression (stream);
         stream.Expect (TokenClass.Keyword, "else");
         AstNode altValue = ParseTernaryIfElse (stream);
         expr = new TernaryExpression (expr.Location, condition, expr, altValue);
     }
     return expr;
 }
开发者ID:splitandthechro,项目名称:nginz,代码行数:11,代码来源:Parser.cs


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