2010-12-27 20:56:36 -05:00
|
|
|
/**
|
|
|
|
* Property keyword parser module
|
|
|
|
*
|
2014-04-09 18:59:22 -04:00
|
|
|
* Copyright (C) 2010, 2011, 2012, 2013, 2014 Free Software Foundation, Inc.
|
2010-12-27 20:56:36 -05:00
|
|
|
*
|
2013-12-22 09:37:21 -05:00
|
|
|
* This file is part of GNU ease.js.
|
2010-12-27 20:56:36 -05:00
|
|
|
*
|
2014-01-15 23:56:00 -05:00
|
|
|
* ease.js is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
2010-12-27 20:56:36 -05:00
|
|
|
*
|
2014-01-15 23:56:00 -05:00
|
|
|
* 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 General Public License for more details.
|
2010-12-27 20:56:36 -05:00
|
|
|
*
|
2014-01-15 23:56:00 -05:00
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2010-12-27 20:56:36 -05:00
|
|
|
*/
|
|
|
|
|
2011-05-22 22:11:57 -04:00
|
|
|
/**
|
|
|
|
* Known (permitted) keywords
|
|
|
|
* @type {Object.<string,boolean>}
|
|
|
|
*/
|
|
|
|
var _keywords = {
|
2014-04-20 02:28:38 -04:00
|
|
|
'public': 1,
|
|
|
|
'protected': 1<<1,
|
|
|
|
'private': 1<<2,
|
|
|
|
'static': 1<<3,
|
|
|
|
'abstract': 1<<4,
|
|
|
|
'const': 1<<5,
|
|
|
|
'virtual': 1<<6,
|
|
|
|
'override': 1<<7,
|
|
|
|
'proxy': 1<<8,
|
|
|
|
'weak': 1<<9,
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Keyword masks for conveniently checking the keyword bitfield
|
|
|
|
* @type {Object.<string,integer>}
|
|
|
|
*/
|
|
|
|
var _kmasks = {
|
|
|
|
amods: _keywords[ 'public' ]
|
|
|
|
| _keywords[ 'protected' ]
|
|
|
|
| _keywords[ 'private' ],
|
2014-04-20 02:31:28 -04:00
|
|
|
|
|
|
|
'virtual': _keywords[ 'abstract' ]
|
|
|
|
| _keywords[ 'virtual' ],
|
2011-05-22 22:11:57 -04:00
|
|
|
};
|
|
|
|
|
2010-12-27 20:56:36 -05:00
|
|
|
|
2014-04-20 02:40:36 -04:00
|
|
|
// expose magic values
|
|
|
|
exports.kvals = _keywords;
|
|
|
|
exports.kmasks = _kmasks;
|
|
|
|
|
|
|
|
|
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 = [],
|
2014-04-20 02:28:38 -04:00
|
|
|
bitwords = 0x00,
|
2010-12-27 20:56:36 -05:00
|
|
|
keyword_obj = {};
|
|
|
|
|
|
|
|
prop = ''+( prop );
|
|
|
|
|
2014-01-19 11:48:37 -05:00
|
|
|
// the keywords are all words, except for the last, which is the
|
|
|
|
// property name
|
|
|
|
if ( ( keywords = prop.split( /\s+/ ) ).length !== 1 )
|
2010-12-27 20:56:36 -05:00
|
|
|
{
|
2014-01-19 11:48:37 -05:00
|
|
|
name = keywords.pop();
|
2010-12-27 20:56:36 -05:00
|
|
|
|
2014-04-20 02:28:38 -04:00
|
|
|
var i = keywords.length;
|
2010-12-27 23:04:50 -05:00
|
|
|
while ( i-- )
|
|
|
|
{
|
2014-04-20 02:28:38 -04:00
|
|
|
var keyword = keywords[ i ],
|
|
|
|
kval = _keywords[ keyword ];
|
2011-05-22 22:11:57 -04:00
|
|
|
|
|
|
|
// ensure the keyword is recognized
|
2014-04-20 02:28:38 -04:00
|
|
|
if ( !kval )
|
2011-05-22 22:11:57 -04:00
|
|
|
{
|
|
|
|
throw Error(
|
|
|
|
"Unexpected keyword for '" + name + "': " + keyword
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2014-04-20 02:28:38 -04:00
|
|
|
// ease-of-access
|
2011-05-22 22:11:57 -04:00
|
|
|
keyword_obj[ keyword ] = true;
|
2014-04-20 02:28:38 -04:00
|
|
|
|
|
|
|
// permits quick and concise checks
|
|
|
|
bitwords |= kval;
|
2010-12-27 20:56:36 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-04-20 02:28:38 -04:00
|
|
|
// members with an underscore prefix are implicitly private, unless an
|
|
|
|
// access modifier is explicitly provided; double-underscore is ingored,
|
|
|
|
// as they denote special members that do not become part of the
|
|
|
|
// prototype and are reserved by ease.js
|
|
|
|
if ( ( name.match( /^_[^_]/ ) && !( bitwords & _kmasks.amods ) ) )
|
|
|
|
{
|
|
|
|
keyword_obj[ 'private' ] = true;
|
|
|
|
bitwords |= _keywords[ 'private' ];
|
|
|
|
}
|
|
|
|
|
2010-12-27 20:56:36 -05:00
|
|
|
return {
|
|
|
|
name: name,
|
|
|
|
keywords: keyword_obj,
|
2014-04-20 02:28:38 -04:00
|
|
|
bitwords: bitwords,
|
2010-12-27 20:56:36 -05:00
|
|
|
};
|
|
|
|
}
|