All pastes #191012 Raw Edit

Anonymous

public text v1 · immutable
·published 2006-10-04 15:29 UTC
rendered paste body
updateExpr [PathExpr path]
returns [Expression step]
throws XPathException, PermissionDeniedException, EXistException
{
}:
	#( updateAST:"update"
		{ 
			PathExpr p1 = new PathExpr(context);
			PathExpr p2 = new PathExpr(context);
			int type;
			int position = Insert.INSERT_APPEND;
		}
		(
			"replace" { type = 0; }
			|
			"value" { type = 1; }
			|
			"insert"{ type = 2; }
			|
			"delete" { type = 3; }
			|
			"rename" { type = 4; }
			|
			"batch start" { type = 5; }
			|
			"batch finish" { type = 6; }
		)
		step=expr [p1]
		(
			"preceding" { position = Insert.INSERT_BEFORE; }
			|
			"following" { position = Insert.INSERT_AFTER; }
			|
			"into" { position = Insert.INSERT_APPEND; }
		)?
		( step=expr [p2] )?
		{
			AbstractExpression mod = null;
			if (type == 0)
				mod = new Replace(context, p1, p2);
			else if (type == 1)
				mod = new Update(context, p1, p2);
			else if (type == 2)
				mod = new Insert(context, p2, p1, position);
			else if (type == 3)
				mod = new Delete(context, p1);
			else if(type == 4)
				mod = new Rename(context, p1, p2);
			else if(type == 5)
				mod = new BatchStart(context);
			else if(type == 6)
				mod = new BatchFinish(context);

			if(mod != null)
			{
				mod.setASTNode(updateAST);
				path.add(mod);
				step = mod;
			}
		}
	)
	;