123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106 |
- import { TempNode } from './TempNode.js';
- const declarationRegexp = /^struct\s*([a-z_0-9]+)\s*{\s*((.|\n)*?)}/img,
- propertiesRegexp = /\s*(\w*?)\s*(\w*?)(\=|\;)/img;
- class StructNode extends TempNode {
- constructor( src ) {
- super();
- this.parse( src );
- }
- getType( builder ) {
- return builder.getTypeByFormat( this.name );
- }
- getInputByName( name ) {
- let i = this.inputs.length;
- while ( i -- ) {
- if ( this.inputs[ i ].name === name ) {
- return this.inputs[ i ];
- }
- }
- }
- generate( builder, output ) {
- if ( output === 'source' ) {
- return this.src + ';';
- } else {
- return builder.format( '( ' + this.src + ' )', this.getType( builder ), output );
- }
- }
- parse( src = '' ) {
- this.src = src;
- this.inputs = [];
- const declaration = declarationRegexp.exec( this.src );
- if ( declaration ) {
- const properties = declaration[ 2 ];
- let 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;
- }
- toJSON( meta ) {
- let data = this.getJSONNode( meta );
- if ( ! data ) {
- data = this.createJSONNode( meta );
- data.src = this.src;
- }
- return data;
- }
- }
- StructNode.prototype.nodeType = 'Struct';
- export { StructNode };
|