本文整理汇总了C#中SourceCode.Peek方法的典型用法代码示例。如果您正苦于以下问题:C# SourceCode.Peek方法的具体用法?C# SourceCode.Peek怎么用?C# SourceCode.Peek使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SourceCode
的用法示例。
在下文中一共展示了SourceCode.Peek方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Build
public override Token Build(Token lastToken, ScriptEngine engine, Script script, ref SourceCode sourceCode)
{
while ((++sourceCode).SpecialChar)
{
}
if (sourceCode.Peek() != '{')
{
sourceCode.Throw(String.Format("Error parsing a 'do' statement, expected a '{' but got '{0}' instead.",
sourceCode.Peek()));
}
List<List<List<Token>>> code = engine.BuildLongTokens(ref sourceCode, ref script, new[] {'}'});
if (!sourceCode.SeekToNext("while"))
{
sourceCode.Throw("Error parsing a 'do' statement, was expecting a 'while' after the { } block.");
}
if (!sourceCode.SeekToNext('('))
{
sourceCode.Throw("Error parsing a 'do' statement, was expecting a '(' after 'while'.");
}
List<List<Token>> exitCondition = engine.BuildTokensAdvanced(ref sourceCode, ref script, new[] {')'});
return new DoWhileToken(code, exitCondition);
}
示例2: ConditionMatch
public override bool ConditionMatch(Token lastToken, SourceCode sourceCode)
{
if (sourceCode.CurrentCode == '-' && char.IsNumber(sourceCode.Peek(true)))
{
return true;
}
return char.IsNumber(sourceCode.Script, sourceCode.Offset);
}
示例3: AdvancedBuild
public override bool AdvancedBuild(ScriptEngine engine, ref SourceCode sourceCode, ref Script script)
{
_returnElements = new Dictionary<string, List<object>>();
string id = "";
// Seek past the original text...
sourceCode += _pattern.Length;
if (sourceCode.Peek() == '"')
{
// We are being given an "id" as well.
sourceCode.SeekToNext('"');
while ((++sourceCode).CurrentCode != '"')
{
id += sourceCode.CurrentCode;
}
}
if (!sourceCode.SeekToNext('{'))
{
throw new Exception("Excpected {");
}
while ((++sourceCode).Peek() != '}')
{
while (sourceCode.SpecialChar)
{
sourceCode++;
}
// Find a match.
int index = sourceCode.Offset;
for (int i = 0; i < _structure._elements.Count; i++)
{
if (_structure._elements[i].ConditionMatch(sourceCode))
{
_structure._elements[i].Build(ref sourceCode, ref script, engine, this);
break;
}
}
if (index == sourceCode.Offset)
{
// We haven't progressed.
throw new Exception(String.Format("Unexpected string {0}...", sourceCode.CurrentCode));
}
}
if (_builtEvent == null)
{
// Should throw an exception or something?
}
else
{
_builtEvent(id, _returnElements);
}
return true;
}
示例4: Build
public override Token Build(Token lastToken, ScriptEngine engine, Script script, ref SourceCode sourceCode)
{
// if (condition) { ... } [else [if (condition) { ... }] { ... }]
var ifStatement = new Statement();
sourceCode.SeekToNext('(');
ifStatement.Condition = engine.BuildTokensAdvanced(ref sourceCode, ref script, new[] {')'});
sourceCode++;
sourceCode.SeekToNext('{');
ifStatement.Code = engine.BuildLongTokens(ref sourceCode, ref script, new[] {'}'});
sourceCode++;
var elseIfStatements = new List<Statement>();
Statement elseStatement = null;
while ((++sourceCode).Peek() == 'e')
{
bool isElseIf = false;
sourceCode.SeekToNext('e');
sourceCode += 4;
var s = new Statement();
if (sourceCode.Peek() == 'i')
{
isElseIf = true;
// Get the condition;
sourceCode.SeekToNext('i');
sourceCode++;
sourceCode.SeekToNext('(');
s.Condition = engine.BuildTokensAdvanced(ref sourceCode, ref script, new[] {')'});
sourceCode++;
}
sourceCode.SeekToNext('{');
s.Code = engine.BuildLongTokens(ref sourceCode, ref script, new[] {'}'});
sourceCode++;
if (isElseIf)
{
elseIfStatements.Add(s);
}
else
{
elseStatement = s;
}
}
return new IfToken(ifStatement, elseIfStatements, elseStatement);
}
示例5: Build
public override void Build(ref SourceCode code, ref Script script, ScriptEngine engine, ConfigBuilder config)
{
string id = "";
code += _identifier.Length;
if (code.Peek() == '{' && _requiresID)
{
throw new Exception("Script block requires an ID.");
}
if (code.Peek() != '{')
{
code.SeekToNext('"');
while (!(++code).EOF && code.CurrentCode != '"')
{
id += code.CurrentCode;
}
if (code.EOF)
{
code.Throw("Unexpected EOF");
}
}
code.SeekToNext('{');
var c = new Code(engine.BuildLongTokens(ref code, ref script, new[] {'}'}),
new Script(engine) {UseEngineGlobals = false});
config.AddReturnElement(_identifier, new ScriptBlock {Code = c, Identifier = id});
}