我有在jsdoc風格註釋的js文件:蟒蛇正則表達式解析js文件
/****************************************************************************
Copyright (c) 2010-2012 cocos2d-x.org
Copyright (c) 2008-2010 Ricardo Quesada
Copyright (c) 2011 Zynga Inc.
http://www.cocos2d-x.org
****************************************************************************/
cc.g_NumberOfDraws = 0;
//Possible OpenGL projections used by director
/**
* sets a 2D projection (orthogonal projection)
* @constant
* @type Number
*/
cc.DIRECTOR_PROJECTION_2D = 0;
/**
* sets a 3D projection with a fovy=60, znear=0.5f and zfar=1500.
* @constant
* @type Number
*/
cc.DIRECTOR_PROJECTION_3D = 1;
//----------------------------------------------------------------------------------------------------------------------
/**
* <p>
* </p>
* @class
* @extends cc.Class
*/
cc.Director = cc.Class.extend(/** @lends cc.Director# */{
//Variables
_landscape:false,
_nextDeltaTimeZero:false,
/**
* <p>
* </p>
*/
popToRootScene:function() {
// ...
},
/**
* <p>
* </p>
* @param {Number} level
*/
popToSceneStackLevel: function (level) {
// ...
}
});
/**
* returns a shared instance of the director
* @function
* @return {cc.Director}
*/
cc.Director.getInstance = function() {
// ...
};
/**
* is director first run
* @type Boolean
*/
cc.firstRun = true;
現在我想提取所有變量和函數使用正則表達式的Python評論jsdoc。
對於我要提取的節段上面的例子有:
段1:
/**
* sets a 2D projection (orthogonal projection)
* @constant
* @type Number
*/
cc.DIRECTOR_PROJECTION_2D = 0;
段2:
/**
* sets a 3D projection with a fovy=60, znear=0.5f and zfar=1500.
* @constant
* @type Number
*/
cc.DIRECTOR_PROJECTION_3D = 1;
段3:
/**
* <p>
* </p>
*/
popToRootScene:function() {
// ...
},
第4部分:
/**
* <p>
* </p>
* @param {Number} level
*/
popToSceneStackLevel: function (level) {
// ...
}
段5:
/**
* returns a shared instance of the director
* @function
* @return {cc.Director}
*/
cc.Director.getInstance = function() {
// ...
};
段6:
/**
* is director first run
* @type Boolean
*/
cc.firstRun = true;
正如你可以看到我想要的是提取所有變量,實例函數,類函數具有jsdoc風格評論並列出類似:
變量:
個name: cc.DIRECTOR_PROJECTION_2D type: number
name: cc.DIRECTOR_PROJECTION_3D type: number
實例功能:
name: popToRootScene param: xxxx return: xxxx
name: popToSceneStackLevel param: number - level return: xxxx
類功能:
name: cc.Director.getInstance param: xxxx return: cc.Director
我試着用解析文件的類函數:
re.findall('\s*/\*\*.*?\*/.*?function.*?};', content, re.S)
和實例功能:
re.findall('\s*/\*\*.*?\*/.*?function.*?},', content, re.S)
但失敗...
任何建議將讚賞,感謝:)
更新時間:
re.findall(r"(^(?P<identation> *)/\*\*.*$(\r?\n?^(?P=identation) * .*$)*\r?\n?(?P=identation) \*/\r?\n?^.*$)", content, re.M)
模式的偉大工程時,有空行除在評論之間如:
/**1
2
3
*/
cc.Node = cc.Class.extend(/** @lends cc.Node# */{
});
版權所有(c)2010-2012 cocos2d-x.org –