2010-12-27 20:56:36 -05:00
|
|
|
/**
|
|
|
|
* Property keyword parser module
|
|
|
|
*
|
2011-12-23 00:09:01 -05:00
|
|
|
* Copyright (C) 2010,2011 Mike Gerwitz
|
2010-12-27 20:56:36 -05:00
|
|
|
*
|
|
|
|
* This file is part of ease.js.
|
|
|
|
*
|
|
|
|
* ease.js is free software: you can redistribute it and/or modify it under the
|
|
|
|
* terms of the GNU Lesser General Public License as published by the Free
|
|
|
|
* Software Foundation, either version 3 of the License, or (at your option)
|
|
|
|
* any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
|
|
|
* for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
* @author Mike Gerwitz
|
|
|
|
*/
|
|
|
|
|
2011-05-22 22:11:57 -04:00
|
|
|
/**
|
|
|
|
* Known (permitted) keywords
|
|
|
|
* @type {Object.<string,boolean>}
|
|
|
|
*/
|
|
|
|
var _keywords = {
|
|
|
|
'public': true,
|
|
|
|
'protected': true,
|
|
|
|
'private': true,
|
|
|
|
'static': true,
|
|
|
|
'abstract': true,
|
|
|
|
'const': true,
|
2011-06-08 01:11:53 -04:00
|
|
|
'virtual': true,
|
2011-08-04 00:32:10 -04:00
|
|
|
'override': true,
|
2011-05-22 22:11:57 -04:00
|
|
|
};
|
|
|
|
|
2010-12-27 20:56:36 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Parses property keywords
|
|
|
|
*
|
|
|
|
* @param {string} prop property string, which may contain keywords
|
|
|
|
*
|
|
|
|
* @return {{name: string, keywords: Object.<string, boolean>}}
|
|
|
|
*/
|
2010-12-27 23:12:37 -05:00
|
|
|
exports.parseKeywords = function ( prop )
|
2010-12-27 20:56:36 -05:00
|
|
|
{
|
|
|
|
var name = prop,
|
|
|
|
keywords = [],
|
|
|
|
keyword_obj = {};
|
|
|
|
|
|
|
|
prop = ''+( prop );
|
|
|
|
|
2010-12-27 23:04:50 -05:00
|
|
|
// only perform parsing if the string contains a space
|
|
|
|
if ( / /.test( prop ) )
|
2010-12-27 20:56:36 -05:00
|
|
|
{
|
2010-12-27 23:04:50 -05:00
|
|
|
// the keywords are all words, except for the last, which is the
|
|
|
|
// property name
|
2011-01-18 19:33:33 -05:00
|
|
|
keywords = prop.split( /\s+/ );
|
2010-12-27 23:04:50 -05:00
|
|
|
name = keywords.pop();
|
2010-12-27 20:56:36 -05:00
|
|
|
|
2011-05-22 22:11:57 -04:00
|
|
|
var i = keywords.length,
|
|
|
|
keyword = '';
|
|
|
|
|
2010-12-27 23:04:50 -05:00
|
|
|
while ( i-- )
|
|
|
|
{
|
2011-05-22 22:11:57 -04:00
|
|
|
keyword = keywords[ i ];
|
|
|
|
|
|
|
|
// ensure the keyword is recognized
|
|
|
|
if ( !_keywords[ keyword ] )
|
|
|
|
{
|
|
|
|
throw Error(
|
|
|
|
"Unexpected keyword for '" + name + "': " + keyword
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
keyword_obj[ keyword ] = true;
|
2010-12-27 20:56:36 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
name: name,
|
|
|
|
keywords: keyword_obj,
|
|
|
|
};
|
|
|
|
}
|