本文整理汇总了C#中Neo.IronLua.LuaLexer.Next方法的典型用法代码示例。如果您正苦于以下问题:C# LuaLexer.Next方法的具体用法?C# LuaLexer.Next怎么用?C# LuaLexer.Next使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Neo.IronLua.LuaLexer
的用法示例。
在下文中一共展示了LuaLexer.Next方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TokenTest
} // func T
private bool TokenTest(string sToken, params KeyValuePair<LuaToken, string>[] token)
{
using (LuaLexer l = new LuaLexer("test.lua", new StringReader(sToken)))
{
l.Next();
for (int i = 0; i < token.Length; i++)
{
Debug.Write(String.Format("Test: {0} = {1} ==>", l.Current.Typ, token[i].Key));
if (l.Current.Typ != token[i].Key)
{
Debug.WriteLine("tokens FAILED");
return false;
}
else if (l.Current.Value != token[i].Value)
{
Debug.WriteLine("values '{0}' != '{1}' FAILED", l.Current.Value, token[i].Value);
return false;
}
Debug.WriteLine("OK");
l.Next();
}
if (l.Current.Typ != LuaToken.Eof)
return false;
return true;
}
} // func TokenTest
示例2: ParseChunk
/// <summary>Parses the chunk to an function.</summary>
/// <param name="runtime">Binder</param>
/// <param name="options">Compile options for the script.</param>
/// <param name="lHasEnvironment">Creates the _G parameter.</param>
/// <param name="code">Lexer for the code.</param>
/// <param name="typeDelegate">Type for the delegate. <c>null</c>, for an automatic type</param>
/// <param name="returnType">Defines the return type of the chunk.</param>
/// <param name="args">Arguments of the function.</param>
/// <returns>Expression-Tree for the code.</returns>
public static LambdaExpression ParseChunk(Lua runtime, LuaCompileOptions options, bool lHasEnvironment, LuaLexer code, Type typeDelegate, Type returnType, IEnumerable<KeyValuePair<string, Type>> args)
{
List<ParameterExpression> parameters = new List<ParameterExpression>();
if (returnType == null)
returnType = typeof(LuaResult);
var globalScope = new GlobalScope(runtime, options, returnType, returnType == typeof(LuaResult) ? Expression.Property(null, Lua.ResultEmptyPropertyInfo) : null);
// Registers the global LuaTable
if (lHasEnvironment)
parameters.Add(globalScope.RegisterParameter(typeof(LuaTable), csEnv));
if (args != null)
{
foreach (var c in args)
parameters.Add(globalScope.RegisterParameter(c.Value, c.Key)); // Add alle arguments
}
// Get the first token
if (code.Current == null)
code.Next();
// Get the name for the chunk and clean it from all unwanted chars
string sChunkName = CreateNameFromFile(code.Current.Start.FileName);
if ((globalScope.EmitDebug & LuaDebugLevel.RegisterMethods) == LuaDebugLevel.RegisterMethods)
sChunkName = Lua.RegisterUniqueName(sChunkName);
// Create the block
ParseBlock(globalScope, code);
if (code.Current.Typ != LuaToken.Eof)
throw ParseError(code.Current, Properties.Resources.rsParseEof);
// Create the function
return typeDelegate == null ?
Expression.Lambda(globalScope.ExpressionBlock, sChunkName, parameters) :
Expression.Lambda(typeDelegate, globalScope.ExpressionBlock, sChunkName, parameters);
}
示例3: ParseExpressionBitXOr
private static Expression ParseExpressionBitXOr(Scope scope, LuaLexer code, InvokeResult result, ref bool lWrap)
{
// exprBitXOr ::= exprBitAnd { ~ exprBitAnd }
var expr = ParseExpressionBitAnd(scope, code, result, ref lWrap);
while (code.Current.Typ == LuaToken.Dilde)
{
code.Next();
expr = BinaryOperationExpression(scope.Runtime, code.Current, ExpressionType.ExclusiveOr,
expr,
ParseExpressionBitAnd(scope, code, InvokeResult.Object, ref lWrap)
);
lWrap |= true;
}
return expr;
}
示例4: ParseLamdaDefinition
private static Expression ParseLamdaDefinition(Scope parent, LuaLexer code, string sName, bool lSelfParameter, Action<Type> functionTypeCollected)
{
List<ParameterExpression> parameters = new List<ParameterExpression>();
LambdaScope scope = new LambdaScope(parent);
// Lese die Parameterliste ein
FetchToken(LuaToken.BracketOpen, code);
if (lSelfParameter)
parameters.Add(scope.RegisterParameter(typeof(object), "self"));
if (code.Current.Typ == LuaToken.Identifier || code.Current.Typ == LuaToken.DotDotDot)
{
if (code.Current.Typ == LuaToken.DotDotDot)
{
code.Next();
ParseLamdaDefinitionArgList(scope, parameters);
}
else
{
Token tName;
Type typeArgument;
ParseIdentifierAndType(scope, code, out tName, out typeArgument);
parameters.Add(scope.RegisterParameter(typeArgument, tName.Value));
while (code.Current.Typ == LuaToken.Comma)
{
code.Next();
if (code.Current.Typ == LuaToken.DotDotDot)
{
code.Next();
ParseLamdaDefinitionArgList(scope, parameters); // last argument
break;
}
else
{
ParseIdentifierAndType(scope, code, out tName, out typeArgument);
parameters.Add(scope.RegisterParameter(typeArgument, tName.Value));
}
}
}
}
FetchToken(LuaToken.BracketClose, code);
// Is there a specific result
if (code.Current.Typ == LuaToken.Colon)
{
var t = code.Current;
code.Next();
Type typeResult = ParseType(scope, code, true);
scope.ResetReturnLabel(typeResult, null);
}
else
scope.ResetReturnLabel(typeof(LuaResult), Expression.Property(null, Lua.ResultEmptyPropertyInfo));
// register the delegate
if (functionTypeCollected != null)
{
functionTypeCollected(
Expression.GetFuncType(
(from p in parameters select p.Type).Concat(new Type[] { scope.ReturnType }).ToArray()
)
);
}
// Lese den Code-Block
ParseBlock(scope, code);
FetchToken(LuaToken.KwEnd, code);
return Expression.Lambda(
scope.ExpressionBlock,
(parent.EmitDebug & LuaDebugLevel.RegisterMethods) == LuaDebugLevel.RegisterMethods ? Lua.RegisterUniqueName(sName) : sName,
parameters);
}
示例5: ParseExpressionBitAnd
private static Expression ParseExpressionBitAnd(Scope scope, LuaLexer code, InvokeResult result, ref bool lWrap)
{
// exprBitAnd ::= exprCmp { & exprCmp }
var expr = ParseExpressionCmp(scope, code, result, ref lWrap);
while (code.Current.Typ == LuaToken.BitAnd)
{
code.Next();
expr = BinaryOperationExpression(scope.Runtime, code.Current, ExpressionType.And,
expr,
ParseExpressionCmp(scope, code, InvokeResult.Object, ref lWrap)
);
lWrap |= true;
}
return expr;
}
示例6: ParseExpressionShift
private static Expression ParseExpressionShift(Scope scope, LuaLexer code, InvokeResult result, ref bool lWrap)
{
// exprBitAnd ::= exprCmp { ( << | >> ) exprCmp }
var expr = ParseExpressionPlus(scope, code, result, ref lWrap);
while (true)
{
LuaToken tokenTyp = code.Current.Typ;
ExpressionType exprTyp;
if (tokenTyp == LuaToken.ShiftLeft)
exprTyp = ExpressionType.LeftShift;
else if (tokenTyp == LuaToken.ShiftRight)
exprTyp = ExpressionType.RightShift;
else
return expr;
code.Next();
expr = BinaryOperationExpression(scope.Runtime, code.Current, exprTyp, expr, ParseExpressionPlus(scope, code, InvokeResult.Object, ref lWrap));
lWrap |= true;
}
}
示例7: ParseExpressionUnary
private static Expression ParseExpressionUnary(Scope scope, LuaLexer code, InvokeResult result, ref bool lWrap)
{
// expUn ::= { 'not' | - | # | ~ } expPow
LuaToken typ = code.Current.Typ;
if (typ == LuaToken.KwNot ||
typ == LuaToken.Minus ||
typ == LuaToken.Dilde ||
typ == LuaToken.Cross)
{
code.Next();
Expression expr = ParseExpressionUnary(scope, code, InvokeResult.Object, ref lWrap);
lWrap |= true;
ExpressionType exprType;
if (typ == LuaToken.KwNot)
exprType = ExpressionType.Not;
else if (typ == LuaToken.Minus)
exprType = ExpressionType.Negate;
else if (typ == LuaToken.Dilde)
exprType = ExpressionType.OnesComplement;
else
exprType = ExpressionType.ArrayLength;
lWrap |= true;
return UnaryOperationExpression(scope.Runtime, code.Current, exprType, expr);
}
else
return ParseExpressionPower(scope, code, result, ref lWrap);
}
示例8: FetchToken
private static Token FetchToken(LuaToken typ, LuaLexer code, bool lOptional = false)
{
if (code.Current.Typ == typ)
{
var t = code.Current;
code.Next();
return t;
}
else if (lOptional)
return null;
else
throw ParseError(code.Current, String.Format(Properties.Resources.rsParseUnexpectedToken, LuaLexer.GetTokenName(code.Current.Typ), LuaLexer.GetTokenName(typ)));
}
示例9: ParseExpressionPlus
private static Expression ParseExpressionPlus(Scope scope, LuaLexer code, InvokeResult result, ref bool lWrap)
{
// expPlus ::= expMul { ( + | - ) expMul}
var expr = ParseExpressionMultiply(scope, code, result, ref lWrap);
while (true)
{
LuaToken tokenTyp = code.Current.Typ;
ExpressionType exprTyp;
if (tokenTyp == LuaToken.Plus)
exprTyp = ExpressionType.Add;
else if (tokenTyp == LuaToken.Minus)
exprTyp = ExpressionType.Subtract;
else
return expr;
code.Next();
expr = BinaryOperationExpression(scope.Runtime, code.Current, exprTyp, expr, ParseExpressionMultiply(scope, code, InvokeResult.Object, ref lWrap));
lWrap |= true;
}
}
示例10: ParseTableField
private static void ParseTableField(ParameterExpression tableVar, Scope scope, LuaLexer code, ref int iIndex)
{
// field ::= '[' exp ']' '=' exp | Name '=' exp | exp
if (code.Current.Typ == LuaToken.BracketSquareOpen)
{
// Parse the index
code.Next();
var index = ParseExpression(scope, code, InvokeResult.Object, scope.EmitExpressionDebug);
FetchToken(LuaToken.BracketSquareClose, code);
FetchToken(LuaToken.Assign, code);
// Expression that results in a value
scope.AddExpression(
IndexSetExpression(scope.Runtime, code.Current, tableVar, new Expression[] { index },
ParseExpression(scope, code, InvokeResult.Object, scope.EmitExpressionDebug)
)
);
}
else if (code.Current.Typ == LuaToken.Identifier && code.LookAhead.Typ == LuaToken.Assign)
{
// Read the identifier
Token tMember = code.Current;
code.Next();
FetchToken(LuaToken.Assign, code);
// Expression
scope.AddExpression(
IndexSetExpression(scope.Runtime, code.Current, tableVar, new Expression[] { Expression.Constant(tMember.Value) },
ParseExpression(scope, code, InvokeResult.Object, scope.EmitExpressionDebug)
)
);
}
else
{
Token tStart = code.Current;
Expression expr = ParseExpression(scope, code, InvokeResult.None, scope.EmitExpressionDebug);
// Last assign, enroll parameter
if (code.Current.Typ == LuaToken.BracketCurlyClose && LuaEmit.IsDynamicType(expr.Type))
{
scope.AddExpression(
Expression.Call(Lua.TableSetObjectsMethod,
tableVar,
Expression.Convert(expr, typeof(object)),
Expression.Constant(iIndex, typeof(int))
)
);
}
else // Normal index set
{
scope.AddExpression(
IndexSetExpression(scope.Runtime, code.Current, tableVar, new Expression[] { Expression.Constant(iIndex++, typeof(object)) }, expr)
);
}
}
}
示例11: ParseExpressionCon
private static Expression ParseExpressionCon(Scope scope, LuaLexer code, InvokeResult result, ref bool lWrap)
{
// exprCon::= exprShift { '..' exprShift }
List<Expression> exprs = new List<Expression>();
exprs.Add(ParseExpressionShift(scope, code, result, ref lWrap));
while (code.Current.Typ == LuaToken.DotDot)
{
code.Next();
exprs.Add(ParseExpressionShift(scope, code, InvokeResult.Object, ref lWrap));
}
// Erzeuge Concat
if (exprs.Count > 1)
{
lWrap |= true;
return ConcatOperationExpression(scope.Runtime, code.Current, exprs.ToArray());
}
else
return exprs[0];
}
示例12: ParseSuffix
private static PrefixMemberInfo ParseSuffix(Scope scope, LuaLexer code, PrefixMemberInfo info)
{
// suffix_opt ::= [ suffix ]
// suffix ::= { '[' exp ']' | '.' Identifier | args | ':' Identifier args }
// args ::= tablector | string | '(' explist ')'
while (true)
{
switch (code.Current.Typ)
{
case LuaToken.BracketSquareOpen: // Index
code.Next();
info.GenerateGet(scope, InvokeResult.Object);
if (code.Current.Typ == LuaToken.BracketSquareClose)
info.Indices = new Expression[0];
else
info.Indices = ParseExpressionList(scope, code).ToArray();
FetchToken(LuaToken.BracketSquareClose, code);
break;
case LuaToken.Dot: // Property of an class
code.Next();
info.GenerateGet(scope, InvokeResult.Object);
info.SetMember(FetchToken(LuaToken.Identifier, code), false);
break;
case LuaToken.BracketOpen: // List of arguments
info.GenerateGet(scope, InvokeResult.Object);
info.Arguments = ParseArgumentList(scope, code);
break;
case LuaToken.BracketCurlyOpen: // LuaTable as an argument
info.GenerateGet(scope, InvokeResult.Object);
info.Arguments = new ArgumentsList(ParseTableConstructor(scope, code));
break;
case LuaToken.String: // String as an argument
info.GenerateGet(scope, InvokeResult.Object);
info.Arguments = new ArgumentsList(Expression.Constant(FetchToken(LuaToken.String, code).Value, typeof(object)));
break;
case LuaToken.Colon: // Methodenaufruf
code.Next();
// Lese den Namen um den Member zu belegen
info.GenerateGet(scope, InvokeResult.Object);
info.SetMember(FetchToken(LuaToken.Identifier, code), true);
// Parse die Parameter
switch (code.Current.Typ)
{
case LuaToken.BracketOpen: // Argumentenliste
info.Arguments = ParseArgumentList(scope, code);
break;
case LuaToken.BracketCurlyOpen: // LuaTable als Argument
info.Arguments = new ArgumentsList(ParseTableConstructor(scope, code) );
break;
case LuaToken.String: // String als Argument
info.Arguments = new ArgumentsList(Expression.Constant(FetchToken(LuaToken.String, code).Value, typeof(string)));
break;
}
break;
default:
return info;
}
}
}
示例13: ParseTableConstructor
private static Expression ParseTableConstructor(Scope scope, LuaLexer code)
{
// table ::= '{' [field] { fieldsep field } [fieldsep] '}'
// fieldsep ::= ',' | ';'
FetchToken(LuaToken.BracketCurlyOpen, code);
if (code.Current.Typ != LuaToken.BracketCurlyClose)
{
int iIndex = 1;
Scope scopeTable = new Scope(scope);
// Create the variable for the table
ParameterExpression tableVar = scopeTable.RegisterVariable(typeof(LuaTable), "#table");
scopeTable.AddExpression(Expression.Assign(tableVar, CreateEmptyTableExpression()));
// fiest field
ParseTableField(tableVar, scopeTable, code, ref iIndex);
// collect more table fields
while (code.Current.Typ == LuaToken.Comma || code.Current.Typ == LuaToken.Semicolon)
{
code.Next();
// Optional last separator
if (code.Current.Typ == LuaToken.BracketCurlyClose)
break;
// Parse the field
ParseTableField(tableVar, scopeTable, code, ref iIndex);
}
scopeTable.AddExpression(tableVar);
scopeTable.ExpressionBlockType = typeof(LuaTable);
// Closing bracket
FetchToken(LuaToken.BracketCurlyClose, code);
return scopeTable.ExpressionBlock;
}
else
{
FetchToken(LuaToken.BracketCurlyClose, code);
return CreateEmptyTableExpression();
}
}
示例14: ParseStatement
private static bool ParseStatement(Scope scope, LuaLexer code)
{
switch (code.Current.Typ)
{
case LuaToken.Identifier: // Expression
case LuaToken.DotDotDot:
case LuaToken.BracketOpen:
case LuaToken.String:
case LuaToken.Number:
case LuaToken.KwFalse:
case LuaToken.KwTrue:
case LuaToken.KwNil:
case LuaToken.BracketCurlyOpen:
case LuaToken.Minus:
case LuaToken.KwCast:
ParseExpressionStatement(scope, code, false);
return true;
case LuaToken.ColonColon: // Start of a label
ParseLabel(scope, code);
return true;
case LuaToken.KwGoto:
ParseGoto(scope, code);
return true;
case LuaToken.KwDo:
ParseDoLoop(scope, code);
return true;
case LuaToken.KwWhile:
ParseWhileLoop(scope, code);
return true;
case LuaToken.KwRepeat:
ParseRepeatLoop(scope, code);
return true;
case LuaToken.KwIf:
ParseIfStatement(scope, code);
return true;
case LuaToken.KwFor:
ParseForLoop(scope, code);
return true;
case LuaToken.KwForEach:
ParseForEachLoop(scope, code);
return true;
case LuaToken.KwFunction:
ParseFunction(scope, code, false);
return true;
case LuaToken.KwLocal:
code.Next();
if (code.Current.Typ == LuaToken.KwFunction)
ParseFunction(scope, code, true);
else
ParseExpressionStatement(scope, code, true);
return true;
case LuaToken.KwConst:
code.Next();
ParseConst(scope, code);
return true;
case LuaToken.InvalidString:
throw ParseError(code.Current, Properties.Resources.rsParseInvalidString);
case LuaToken.InvalidComment:
throw ParseError(code.Current, Properties.Resources.rsParseInvalidComment);
case LuaToken.InvalidChar:
throw ParseError(code.Current, Properties.Resources.rsParseInvalidChar);
default:
return false;
}
}
示例15: ParseReturn
private static void ParseReturn(Scope scope, LuaLexer code)
{
// eat return
code.Next();
// Build the return expression for all parameters
Expression exprReturnValue;
if (IsExpressionStart(code)) // there is a return value
{
if (scope.ReturnType == typeof(LuaResult))
{
exprReturnValue = GetLuaResultExpression(scope, code.Current, ParseExpressionList(scope, code).ToArray());
}
else if (scope.ReturnType.IsArray)
{
Type typeArray = scope.ReturnType.GetElementType();
exprReturnValue = Expression.NewArrayInit(
typeArray,
from c in ParseExpressionList(scope, code) select ConvertExpression(scope.Runtime, code.Current, c, typeArray));
}
else
{
List<Expression> exprList = new List<Expression>(ParseExpressionList(scope, code));
if (exprList.Count == 1)
exprReturnValue = ConvertExpression(scope.Runtime, code.Current, exprList[0], scope.ReturnType);
else
{
ParameterExpression tmpVar = Expression.Variable(scope.ReturnType);
exprList[0] = Expression.Assign(tmpVar, ConvertExpression(scope.Runtime, code.Current, exprList[0], scope.ReturnType));
exprList.Add(tmpVar);
exprReturnValue = Expression.Block(scope.ReturnType, new ParameterExpression[] { tmpVar }, exprList);
}
}
}
else // use the default-value
{
if (scope.ReturnType == typeof(LuaResult))
exprReturnValue = Expression.Property(null, Lua.ResultEmptyPropertyInfo);
else if (scope.ReturnType.IsArray)
exprReturnValue = Expression.NewArrayInit(scope.ReturnType.GetElementType());
else
exprReturnValue = Expression.Default(scope.ReturnType);
}
if (code.Current.Typ == LuaToken.Semicolon)
code.Next();
scope.AddExpression(Expression.Goto(scope.LookupLabel(scope.ReturnType, csReturnLabel), exprReturnValue));
}