本文整理汇总了C#中SourceCode.GetOffset方法的典型用法代码示例。如果您正苦于以下问题:C# SourceCode.GetOffset方法的具体用法?C# SourceCode.GetOffset怎么用?C# SourceCode.GetOffset使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SourceCode
的用法示例。
在下文中一共展示了SourceCode.GetOffset方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Build
public override Token Build(Token lastToken, ScriptEngine engine, Script script, ref SourceCode sourceCode)
{
string text = "";
bool space = false;
bool isFloat = false;
if (sourceCode.CurrentCode == '-')
{
text = "-";
sourceCode++;
while (sourceCode.SpecialChar)
{
sourceCode++;
}
}
while (!sourceCode.EOF && !engine.IsStatementEnd(sourceCode.CurrentCode, true))
{
if (sourceCode.CurrentCode == ' ')
{
space = true;
}
else
{
if (space)
{
throw new Exception("Unexpected Whitespace");
}
if (sourceCode.CurrentCode == '.')
{
if (!char.IsNumber(sourceCode.GetOffset(1)))
{
break;
}
}
if (sourceCode.CurrentCode == 'f' || sourceCode.CurrentCode == 'F')
{
isFloat = true;
}
else
{
if (isFloat)
{
throw new Exception("Expected ending condition.");
}
text += sourceCode.CurrentCode;
}
}
sourceCode++;
}
if (sourceCode.EOF)
{
throw new Exception("Unexpected EOF");
}
return new ObjectToken<Number>(new Number(double.Parse(text)));
}
示例2: Build
public override Token Build(Token lastToken, ScriptEngine engine, Script script, ref SourceCode sourceCode)
{
//sourceCode++;
var arguments = new List<List<Token>>();
while (!sourceCode.EOF && sourceCode.GetOffset(1) != ']')
{
arguments.Add(engine.BuildTokens(ref sourceCode, ref script, new[] {',', ']'}));
if (sourceCode.CurrentCode == ']')
{
break;
}
sourceCode++;
}
return new ArrayAccessToken(arguments);
}
示例3: Build
public override Token Build(Token lastToken, ScriptEngine engine, Script script, ref SourceCode sourceCode)
{
string text = "";
bool space = false;
bool isLocal = (sourceCode.CurrentCode == '@');
if (sourceCode.GetOffset(1) == '$')
{
// Special code.
}
sourceCode++;
while (!sourceCode.EOF)
{
if (sourceCode.CurrentCode == ' ')
{
space = true;
}
else
{
if (engine.IsStatementEnd(sourceCode.CurrentCode))
{
return new VaraibleToken(text, isLocal);
}
else
{
if (space)
{
//throw new Exception("Unexpected whitespace.");
// Treat this as another statement, return what we have.
sourceCode--;
return new VaraibleToken(text, isLocal);
}
text += sourceCode.CurrentCode;
}
}
sourceCode++;
}
if (sourceCode.EOF)
{
throw new Exception("Unexpected EOF");
}
return null;
}
示例4: Build
public override Token Build(Token lastToken, ScriptEngine engine, Script script, ref SourceCode sourceCode)
{
if (lastToken is VaraibleToken)
{
var arguments = new List<List<Token>>();
// We are invoking a method.
while (!sourceCode.EOF && sourceCode.GetOffset(1) != ')')
{
arguments.Add(engine.BuildTokens(ref sourceCode, ref script, new[] {',', ')'}));
if (sourceCode.CurrentCode == ')')
{
break;
}
sourceCode++;
}
return new MethodInvokeToken(arguments);
}
else
{
List<Token> code = engine.BuildTokens(ref sourceCode, ref script, new[] {')'});
return new RoundBracketToken(code);
}
}
示例5: Build
public override Token Build(Token lastToken, ScriptEngine engine, Script script, ref SourceCode sourceCode)
{
// Variable
// Method()
// Method<T>()
// Method(args...)
// Method<T>(args...)
string name = "";
var templates = new List<string>();
var arguments = new List<List<Token>>();
bool space = false;
sourceCode++;
// Firstly, get the name of the method.
while (!sourceCode.EOF && !IsEndCondition(sourceCode.CurrentCode))
{
if (sourceCode.CurrentCode == ' ')
{
space = true;
}
else
{
if (space)
{
throw new Exception("Unexpected Whitespace");
}
name += sourceCode.CurrentCode;
}
sourceCode++;
}
if (sourceCode.EOF)
{
throw new Exception("Unexpected EOF");
}
var opens = new[] {'[', '.', '+', '-', '/', '%', '*', '&', ')', ']'};
if (opens.Contains(sourceCode.CurrentCode))
{
// Opening statement, return what we have.
return new TypeFunctionToken(name, new List<List<Token>>(), new List<string>(), false);
}
space = false;
// Once we get here...
if (sourceCode.CurrentCode == '<')
{
// Do Generics.
string currentG = "";
while (!sourceCode.EOF && sourceCode.CurrentCode != '>')
{
if (sourceCode.CurrentCode == ' ')
{
space = true;
}
else
{
if (sourceCode.CurrentCode == ',')
{
templates.Add(currentG);
space = false;
currentG = "";
}
else
{
if (space)
{
throw new Exception("Unexpected Whitespace");
}
currentG += sourceCode.CurrentCode;
}
}
}
if (sourceCode.EOF)
{
throw new Exception("Unexpected EOF");
}
}
// We then expect a (...
if (sourceCode.CurrentCode != '(' && sourceCode.CurrentCode != ';')
{
throw new Exception("Expected a (");
}
else
{
if (sourceCode.CurrentCode == ';')
{
return new TypeFunctionToken(name, arguments, templates, false);
}
while (!sourceCode.EOF && sourceCode.GetOffset(1) != ')')
{
arguments.Add(engine.BuildTokens(ref sourceCode, ref script, new[] {',', ')'}));
if (sourceCode.CurrentCode == ')')
{
break;
//.........这里部分代码省略.........
示例6: Build
public override Token Build(Token lastToken, ScriptEngine engine, Script script, ref SourceCode sourceCode)
{
// new {objectID}[<{templateArgs}
sourceCode += 3;
while (sourceCode.SpecialChar)
{
sourceCode++;
}
string name = "";
var templates = new List<string>();
var arguments = new List<List<Token>>();
bool space = false;
// Firstly, get the name of the method.
while (!sourceCode.EOF && (sourceCode.CurrentCode != '<' && sourceCode.CurrentCode != '('))
{
if (sourceCode.CurrentCode == ' ')
{
space = true;
}
else
{
if (space)
{
throw new Exception("Unexpected Whitespace");
}
name += sourceCode.CurrentCode;
}
sourceCode++;
}
if (sourceCode.EOF)
{
throw new Exception("Unexpected EOF");
}
space = false;
// Once we get here...
if (sourceCode.CurrentCode == '<')
{
// Do Generics.
string currentG = "";
while (!sourceCode.EOF && sourceCode.CurrentCode != '>')
{
if (sourceCode.CurrentCode == ' ')
{
space = true;
}
else
{
if (sourceCode.CurrentCode == ',')
{
templates.Add(currentG);
space = false;
currentG = "";
}
else
{
if (space)
{
throw new Exception("Unexpected Whitespace");
}
currentG += sourceCode.CurrentCode;
}
}
}
if (sourceCode.EOF)
{
throw new Exception("Unexpected EOF");
}
}
// We then expect a (...
if (sourceCode.CurrentCode != '(' && sourceCode.CurrentCode != ';')
{
throw new Exception("Expected a (");
}
else
{
if (sourceCode.CurrentCode == ';')
{
return new TypeFunctionToken(name, arguments, templates, false);
}
while (!sourceCode.EOF && sourceCode.GetOffset(1) != ')')
{
arguments.Add(engine.BuildTokens(ref sourceCode, ref script, new[] {',', ')'}));
if (sourceCode.CurrentCode == ')')
{
break;
}
sourceCode++;
}
}
return new NewTypeToken(name, arguments, templates);
}