本文整理汇总了C#中Block.Append方法的典型用法代码示例。如果您正苦于以下问题:C# Block.Append方法的具体用法?C# Block.Append怎么用?C# Block.Append使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Block
的用法示例。
在下文中一共展示了Block.Append方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ParseStatements
//---------------------------------------------------------------------------------------
// ParseStatements
//
// statements :
// <empty> |
// statement statements
//
//---------------------------------------------------------------------------------------
private Block ParseStatements()
{
m_program = new Block(m_sourceContext.Clone(), this);
m_blockType.Add(BlockType.Block);
m_errorToken = null;
try
{
GetNextToken();
m_noSkipTokenSet.Add(NoSkipTokenSet.s_StartStatementNoSkipTokenSet);
m_noSkipTokenSet.Add(NoSkipTokenSet.s_TopLevelNoSkipTokenSet);
try
{
while (m_currentToken.Token != JSToken.EndOfFile)
{
AstNode ast = null;
try
{
// parse a statement -- pass true because we really want a SourceElement,
// which is a Statement OR a FunctionDeclaration. Technically, FunctionDeclarations
// are not statements!
ast = ParseStatement(true);
}
catch (RecoveryTokenException exc)
{
if (TokenInList(NoSkipTokenSet.s_TopLevelNoSkipTokenSet, exc)
|| TokenInList(NoSkipTokenSet.s_StartStatementNoSkipTokenSet, exc))
{
ast = exc._partiallyComputedNode;
GetNextToken();
}
else
{
m_errorToken = null;
do
{
GetNextToken();
} while (m_currentToken.Token != JSToken.EndOfFile && !TokenInList(NoSkipTokenSet.s_TopLevelNoSkipTokenSet, m_currentToken.Token)
&& !TokenInList(NoSkipTokenSet.s_StartStatementNoSkipTokenSet, m_currentToken.Token));
}
}
if (null != ast)
m_program.Append(ast);
}
if (m_scanner.HasImportantComments
&& m_settings.PreserveImportantComments
&& m_settings.IsModificationAllowed(TreeModifications.PreserveImportantComments))
{
// we have important comments before the EOF. Add the comment(s) to the program.
Context commentContext;
while((commentContext = m_scanner.PopImportantComment()) != null)
{
m_program.Append(new ImportantComment(commentContext, this));
}
}
}
finally
{
m_noSkipTokenSet.Remove(NoSkipTokenSet.s_TopLevelNoSkipTokenSet);
m_noSkipTokenSet.Remove(NoSkipTokenSet.s_StartStatementNoSkipTokenSet);
}
}
catch (EndOfFileException)
{
}
catch (ScannerException se)
{
// a scanner exception implies that the end of file has been reached with an error.
// Mark the end of file as the error location
EOFError(se.Error);
}
return m_program;
}
示例2: ParseBlock
Block ParseBlock(out Context closingBraceContext)
{
closingBraceContext = null;
m_blockType.Add(BlockType.Block);
Block codeBlock = new Block(m_currentToken.Clone(), this);
GetNextToken();
m_noSkipTokenSet.Add(NoSkipTokenSet.s_StartStatementNoSkipTokenSet);
m_noSkipTokenSet.Add(NoSkipTokenSet.s_BlockNoSkipTokenSet);
try
{
try
{
while (JSToken.RightCurly != m_currentToken.Token)
{
try
{
// pass false because we really only want Statements, and FunctionDeclarations
// are technically not statements. We'll still handle them, but we'll issue a warning.
codeBlock.Append(ParseStatement(false));
}
catch (RecoveryTokenException exc)
{
if (exc._partiallyComputedNode != null)
codeBlock.Append(exc._partiallyComputedNode);
if (IndexOfToken(NoSkipTokenSet.s_StartStatementNoSkipTokenSet, exc) == -1)
throw;
}
}
}
catch (RecoveryTokenException exc)
{
if (IndexOfToken(NoSkipTokenSet.s_BlockNoSkipTokenSet, exc) == -1)
{
exc._partiallyComputedNode = codeBlock;
throw;
}
}
}
finally
{
m_noSkipTokenSet.Remove(NoSkipTokenSet.s_BlockNoSkipTokenSet);
m_noSkipTokenSet.Remove(NoSkipTokenSet.s_StartStatementNoSkipTokenSet);
m_blockType.RemoveAt(m_blockType.Count - 1);
}
closingBraceContext = m_currentToken.Clone();
// update the block context
codeBlock.Context.UpdateWith(m_currentToken);
GetNextToken();
return codeBlock;
}
示例3: ParseFunction
//.........这里部分代码省略.........
}
else
ReportError(JSError.NoComma);
}
}
GetNextToken();
}
catch (RecoveryTokenException exc)
{
if (IndexOfToken(NoSkipTokenSet.s_FunctionDeclNoSkipTokenSet, exc) == -1)
throw;
}
finally
{
m_noSkipTokenSet.Remove(NoSkipTokenSet.s_FunctionDeclNoSkipTokenSet);
}
}
fncCtx.UpdateWith(m_currentToken);
GetNextToken();
}
// read the function body of non-abstract functions.
if (JSToken.LeftCurly != m_currentToken.Token)
ReportError(JSError.NoLeftCurly, true);
m_blockType.Add(BlockType.Block);
m_noSkipTokenSet.Add(NoSkipTokenSet.s_BlockNoSkipTokenSet);
m_noSkipTokenSet.Add(NoSkipTokenSet.s_StartStatementNoSkipTokenSet);
try
{
// parse the block locally to get the exact end of function
body = new Block(m_currentToken.Clone(), this);
GetNextToken();
while (JSToken.RightCurly != m_currentToken.Token)
{
try
{
// function body's are SourceElements (Statements + FunctionDeclarations)
body.Append(ParseStatement(true));
}
catch (RecoveryTokenException exc)
{
if (exc._partiallyComputedNode != null)
{
body.Append(exc._partiallyComputedNode);
}
if (IndexOfToken(NoSkipTokenSet.s_StartStatementNoSkipTokenSet, exc) == -1)
throw;
}
}
body.Context.UpdateWith(m_currentToken);
fncCtx.UpdateWith(m_currentToken);
}
catch (RecoveryTokenException exc)
{
if (IndexOfToken(NoSkipTokenSet.s_BlockNoSkipTokenSet, exc) == -1)
{
exc._partiallyComputedNode = new FunctionObject(
name,
this,
(inExpression ? FunctionType.Expression : FunctionType.Declaration),
formalParameters == null ? null : formalParameters.ToArray(),
body,
fncCtx,
functionScope
);
throw;
}
}
finally
{
m_blockType.RemoveAt(m_blockType.Count - 1);
m_noSkipTokenSet.Remove(NoSkipTokenSet.s_StartStatementNoSkipTokenSet);
m_noSkipTokenSet.Remove(NoSkipTokenSet.s_BlockNoSkipTokenSet);
}
GetNextToken();
}
finally
{
// pop the scope off the stack
ScopeStack.Pop();
// restore state
m_blockType = blockType;
m_labelTable = labelTable;
}
return new FunctionObject(
name,
this,
functionType,
formalParameters == null ? null : formalParameters.ToArray(),
body,
fncCtx,
functionScope);
}
示例4: ParseTryStatement
//---------------------------------------------------------------------------------------
// ParseTryStatement
//
// TryStatement :
// 'try' Block Catch Finally
//
// Catch :
// <empty> | 'catch' '(' Identifier ')' Block
//
// Finally :
// <empty> |
// 'finally' Block
//---------------------------------------------------------------------------------------
private AstNode ParseTryStatement()
{
Context tryCtx = m_currentToken.Clone();
Context tryEndContext = null;
Block body = null;
Context idContext = null;
Block handler = null;
CatchScope catchScope = null;
Block finally_block = null;
RecoveryTokenException excInFinally = null;
m_blockType.Add(BlockType.Block);
try
{
bool catchOrFinally = false;
GetNextToken();
if (JSToken.LeftCurly != m_currentToken.Token)
{
ReportError(JSError.NoLeftCurly);
}
m_noSkipTokenSet.Add(NoSkipTokenSet.s_NoTrySkipTokenSet);
try
{
body = ParseBlock(out tryEndContext);
}
catch (RecoveryTokenException exc)
{
if (IndexOfToken(NoSkipTokenSet.s_NoTrySkipTokenSet, exc) == -1)
{
// do nothing and just return the containing block, if any
throw;
}
else
{
body = exc._partiallyComputedNode as Block;
if (body == null)
{
body = new Block(exc._partiallyComputedNode.Context, this);
body.Append(exc._partiallyComputedNode);
}
}
}
finally
{
m_noSkipTokenSet.Remove(NoSkipTokenSet.s_NoTrySkipTokenSet);
}
if (JSToken.Catch == m_currentToken.Token)
{
m_noSkipTokenSet.Add(NoSkipTokenSet.s_NoTrySkipTokenSet);
try
{
catchOrFinally = true;
GetNextToken();
if (JSToken.LeftParenthesis != m_currentToken.Token)
{
ReportError(JSError.NoLeftParenthesis);
}
GetNextToken();
if (JSToken.Identifier != m_currentToken.Token)
{
string identifier = JSKeyword.CanBeIdentifier(m_currentToken.Token);
if (null != identifier)
{
idContext = m_currentToken.Clone();
}
else
{
ReportError(JSError.NoIdentifier);
}
}
else
{
idContext = m_currentToken.Clone();
}
GetNextToken();
m_noSkipTokenSet.Add(NoSkipTokenSet.s_BlockConditionNoSkipTokenSet);
try
{
if (JSToken.RightParenthesis != m_currentToken.Token)
{
ReportError(JSError.NoRightParenthesis);
}
GetNextToken();
}
catch (RecoveryTokenException exc)
{
//.........这里部分代码省略.........
示例5: ParseSwitchStatement
//.........这里部分代码省略.........
{
// ignore the current case or default
exc._partiallyComputedNode = null;
throw;
}
else
{
caseValue = exc._partiallyComputedNode;
if (exc._token == JSToken.Colon)
{
GetNextToken();
}
}
}
finally
{
m_noSkipTokenSet.Remove(NoSkipTokenSet.s_CaseNoSkipTokenSet);
}
m_blockType.Add(BlockType.Block);
try
{
Block statements = new Block(m_currentToken.Clone(), this);
m_noSkipTokenSet.Add(NoSkipTokenSet.s_SwitchNoSkipTokenSet);
m_noSkipTokenSet.Add(NoSkipTokenSet.s_StartStatementNoSkipTokenSet);
try
{
while (JSToken.RightCurly != m_currentToken.Token && JSToken.Case != m_currentToken.Token && JSToken.Default != m_currentToken.Token)
{
try
{
// parse a Statement, not a SourceElement
statements.Append(ParseStatement(false));
}
catch (RecoveryTokenException exc)
{
if (exc._partiallyComputedNode != null)
{
statements.Append(exc._partiallyComputedNode);
exc._partiallyComputedNode = null;
}
if (IndexOfToken(NoSkipTokenSet.s_StartStatementNoSkipTokenSet, exc) == -1)
{
throw;
}
}
}
}
catch (RecoveryTokenException exc)
{
if (IndexOfToken(NoSkipTokenSet.s_SwitchNoSkipTokenSet, exc) == -1)
{
caseClause = new SwitchCase(caseCtx, this, caseValue, statements);
cases.Append(caseClause);
throw;
}
}
finally
{
m_noSkipTokenSet.Remove(NoSkipTokenSet.s_StartStatementNoSkipTokenSet);
m_noSkipTokenSet.Remove(NoSkipTokenSet.s_SwitchNoSkipTokenSet);
}
if (JSToken.RightCurly == m_currentToken.Token)
{
statements.Context.UpdateWith(m_currentToken);
示例6: ParseWithStatement
//---------------------------------------------------------------------------------------
// ParseWithStatement
//
// WithStatement :
// 'with' '(' Expression ')' Statement
//---------------------------------------------------------------------------------------
private WithNode ParseWithStatement()
{
Context withCtx = m_currentToken.Clone();
AstNode obj = null;
Block block = null;
m_blockType.Add(BlockType.Block);
try
{
GetNextToken();
if (JSToken.LeftParenthesis != m_currentToken.Token)
ReportError(JSError.NoLeftParenthesis);
GetNextToken();
m_noSkipTokenSet.Add(NoSkipTokenSet.s_BlockConditionNoSkipTokenSet);
try
{
obj = ParseExpression();
if (JSToken.RightParenthesis != m_currentToken.Token)
{
withCtx.UpdateWith(obj.Context);
ReportError(JSError.NoRightParenthesis);
}
else
withCtx.UpdateWith(m_currentToken);
GetNextToken();
}
catch (RecoveryTokenException exc)
{
if (IndexOfToken(NoSkipTokenSet.s_BlockConditionNoSkipTokenSet, exc) == -1)
{
// give up
exc._partiallyComputedNode = null;
throw;
}
else
{
if (exc._partiallyComputedNode == null)
obj = new ConstantWrapper(true, PrimitiveType.Boolean, CurrentPositionContext(), this);
else
obj = exc._partiallyComputedNode;
withCtx.UpdateWith(obj.Context);
if (exc._token == JSToken.RightParenthesis)
GetNextToken();
}
}
finally
{
m_noSkipTokenSet.Remove(NoSkipTokenSet.s_BlockConditionNoSkipTokenSet);
}
// if the statements aren't withing curly-braces, throw a possible error
if (JSToken.LeftCurly != m_currentToken.Token)
{
ReportError(JSError.StatementBlockExpected, withCtx, true);
}
WithScope withScope = new WithScope(ScopeStack.Peek(), withCtx, this);
ScopeStack.Push(withScope);
try
{
// parse a Statement, not a SourceElement
AstNode statement = ParseStatement(false);
// but make sure we save it as a block
block = statement as Block;
if (block == null)
{
block = new Block(statement.Context, this);
block.Append(statement);
}
}
catch (RecoveryTokenException exc)
{
if (exc._partiallyComputedNode == null)
{
block = new Block(CurrentPositionContext(), this);
}
else
{
block = exc._partiallyComputedNode as Block;
if (block == null)
{
block = new Block(exc._partiallyComputedNode.Context, this);
block.Append(exc._partiallyComputedNode);
}
}
block.BlockScope = withScope;
exc._partiallyComputedNode = new WithNode(withCtx, this, obj, block);
throw;
}
finally
{
// pop off the with-scope
ScopeStack.Pop();
//.........这里部分代码省略.........
示例7: Visit
//.........这里部分代码省略.........
Var varInitializer = forNode.Initializer as Var;
if (varInitializer != null)
{
// transform: var decls1;for(var decls2;...) to for(var decls1,decls2;...)
// we want to PREPEND the initializers in the previous var-statement
// to our for-statement's initializer var-statement list
varInitializer.InsertAt(0, previousVar);
// then remove the previous var statement
node.RemoveAt(ndx - 1);
// this will bump the for node up one position in the list, so the next iteration
// will be right back on this node in case there are other var statements we need
// to combine
}
else
{
// we want to see if the initializer expression is a series of one or more
// simple assignments to variables that are in the previous var statement.
// if all the expressions are assignments to variables that are defined in the
// previous var statement, then we can just move the var statement into the
// for statement.
BinaryOperator binaryOp = forNode.Initializer as BinaryOperator;
if (binaryOp != null && AreAssignmentsInVar(binaryOp, previousVar))
{
// transform: var decls;for(expr1;...) to for(var decls,expr1;...)
// create a list and fill it with all the var-decls created from the assignment
// operators in the expression
var varDecls = new List<VariableDeclaration>();
ConvertAssignmentsToVarDecls(binaryOp, varDecls, m_parser);
// then go through and append each one to the var statement before us
foreach (var varDecl in varDecls)
{
previousVar.Append(varDecl);
}
// move the previous var-statement into our initializer
forNode.ReplaceChild(forNode.Initializer, previousVar);
// and remove the previous var-statement from the list.
node.RemoveAt(ndx - 1);
// this will bump the for node up one position in the list, so the next iteration
// will be right back on this node, but the initializer will not be null
}
}
}
else
{
// transform: var decls;for(;...) to for(var decls;...)
// if it's empty, then we're free to add the previous var statement
// to this for statement's initializer. remove it from it's current
// position and add it as the initializer
node.RemoveAt(ndx - 1);
forNode.SetInitializer(previousVar);
// this will bump the for node up one position in the list, so the next iteration
// will be right back on this node, but the initializer will not be null
}
}
}
}
// see if the last statement is a return statement
ReturnNode lastReturn;
if ((lastReturn = FindLastStatement(node) as ReturnNode) != null)
{