本文整理汇总了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;
}
示例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));
}
}
示例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;
}
示例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;
}
示例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);
}
示例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;
}
示例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);
}
示例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;
}
示例9: ParseYield
private static AstNode ParseYield(TokenStream stream)
{
stream.Expect (TokenClass.Keyword, "yield");
return new YieldStatement (stream.Location, ParseExpression (stream));
}
示例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;
}
示例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;
}
示例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);
}
示例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;
}
示例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;
}
示例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;
}