123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103 |
- import { TempNode } from './TempNode.js';
- var declarationRegexp = /^struct\s*([a-z_0-9]+)\s*{\s*((.|\n)*?)}/img,
- propertiesRegexp = /\s*(\w*?)\s*(\w*?)(\=|\;)/img;
- function StructNode( src ) {
- TempNode.call( this );
- this.parse( src );
- }
- StructNode.prototype = Object.create( TempNode.prototype );
- StructNode.prototype.constructor = StructNode;
- StructNode.prototype.nodeType = 'Struct';
- StructNode.prototype.getType = function ( builder ) {
- return builder.getTypeByFormat( this.name );
- };
- StructNode.prototype.getInputByName = function ( name ) {
- var i = this.inputs.length;
- while ( i -- ) {
- if ( this.inputs[ i ].name === name ) {
- return this.inputs[ i ];
- }
- }
- };
- StructNode.prototype.generate = function ( builder, output ) {
- if ( output === 'source' ) {
- return this.src + ';';
- } else {
- return builder.format( '( ' + this.src + ' )', this.getType( builder ), output );
- }
- };
- StructNode.prototype.parse = function ( src ) {
- this.src = src || '';
- this.inputs = [];
- var declaration = declarationRegexp.exec( this.src );
- if ( declaration ) {
- var properties = declaration[ 2 ], match;
- while ( match = propertiesRegexp.exec( properties ) ) {
- this.inputs.push( {
- type: match[ 1 ],
- name: match[ 2 ]
- } );
- }
- this.name = declaration[ 1 ];
- } else {
- this.name = '';
- }
- this.type = this.name;
- };
- StructNode.prototype.toJSON = function ( meta ) {
- var data = this.getJSONNode( meta );
- if ( ! data ) {
- data = this.createJSONNode( meta );
- data.src = this.src;
- }
- return data;
- };
- export { StructNode };
|