|
|
@@ -30,6 +30,10 @@ const associativityRightToLeft = [
|
|
|
':'
|
|
|
];
|
|
|
|
|
|
+const glslToTSL = {
|
|
|
+ inversesqrt: 'inverseSqrt'
|
|
|
+};
|
|
|
+
|
|
|
const spaceRegExp = /^((\t| )\n*)+/;
|
|
|
const lineRegExp = /^\n+/;
|
|
|
const commentRegExp = /^\/\*[\s\S]*?\*\//;
|
|
|
@@ -46,6 +50,12 @@ const operatorsRegExp = new RegExp( '^(\\' + [
|
|
|
'.', ',', ';', '!', '=', '~', '*', '/', '%', '+', '-', '<', '>', '&', '^', '|', '?', ':', '#'
|
|
|
].join( '$' ).split( '' ).join( '\\' ).replace( /\\\$/g, '|' ) + ')' );
|
|
|
|
|
|
+function getFunctionName( str ) {
|
|
|
+
|
|
|
+ return glslToTSL[ str ] || str;
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
function getGroupDelta( str ) {
|
|
|
|
|
|
if ( str === '(' || str === '[' || str === '{' ) return 1;
|
|
|
@@ -485,62 +495,84 @@ class GLSLDecoder {
|
|
|
|
|
|
// function call
|
|
|
|
|
|
- const paramsTokens = this.parseFunctionParametersFromTokens( tokens.slice( 2, tokens.length - 1 ) );
|
|
|
+ const internalTokens = this.getTokensUntil( ')', tokens, 1 ).slice( 1, - 1 );
|
|
|
+
|
|
|
+ const paramsTokens = this.parseFunctionParametersFromTokens( internalTokens );
|
|
|
+
|
|
|
+ const functionCall = new FunctionCall( getFunctionName( firstToken.str ), paramsTokens );
|
|
|
+
|
|
|
+ const accessTokens = tokens.slice( 3 + internalTokens.length );
|
|
|
|
|
|
- return new FunctionCall( firstToken.str, paramsTokens );
|
|
|
+ if ( accessTokens.length > 0 ) {
|
|
|
+
|
|
|
+ const elements = this.parseAccessorElementsFromTokens( accessTokens );
|
|
|
+
|
|
|
+ return new AccessorElements( functionCall, elements );
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ return functionCall;
|
|
|
|
|
|
} else if ( secondToken.str === '[' ) {
|
|
|
|
|
|
// array accessor
|
|
|
|
|
|
- const elements = [];
|
|
|
+ const elements = this.parseAccessorElementsFromTokens( tokens.slice( 1 ) );
|
|
|
|
|
|
- let currentTokens = tokens.slice( 1 );
|
|
|
+ return new AccessorElements( new Accessor( firstToken.str ), elements );
|
|
|
|
|
|
- while ( currentTokens.length > 0 ) {
|
|
|
+ }
|
|
|
|
|
|
- const token = currentTokens[ 0 ];
|
|
|
+ }
|
|
|
|
|
|
- if ( token.str === '[' ) {
|
|
|
+ return new Accessor( firstToken.str );
|
|
|
|
|
|
- const accessorTokens = this.getTokensUntil( ']', currentTokens );
|
|
|
+ }
|
|
|
|
|
|
- const element = this.parseExpressionFromTokens( accessorTokens.slice( 1, accessorTokens.length - 1 ) );
|
|
|
+ }
|
|
|
|
|
|
- currentTokens = currentTokens.slice( accessorTokens.length );
|
|
|
+ parseAccessorElementsFromTokens( tokens ) {
|
|
|
|
|
|
- elements.push( new DynamicElement( element ) );
|
|
|
+ const elements = [];
|
|
|
|
|
|
- } else if ( token.str === '.' ) {
|
|
|
+ let currentTokens = tokens;
|
|
|
|
|
|
- const accessorTokens = currentTokens.slice( 1, 2 );
|
|
|
+ while ( currentTokens.length > 0 ) {
|
|
|
|
|
|
- const element = this.parseExpressionFromTokens( accessorTokens );
|
|
|
+ const token = currentTokens[ 0 ];
|
|
|
|
|
|
- currentTokens = currentTokens.slice( 2 );
|
|
|
+ if ( token.str === '[' ) {
|
|
|
|
|
|
- elements.push( new StaticElement( element ) );
|
|
|
+ const accessorTokens = this.getTokensUntil( ']', currentTokens );
|
|
|
|
|
|
- } else {
|
|
|
+ const element = this.parseExpressionFromTokens( accessorTokens.slice( 1, accessorTokens.length - 1 ) );
|
|
|
|
|
|
- console.error( 'Unknown accessor expression', token );
|
|
|
+ currentTokens = currentTokens.slice( accessorTokens.length );
|
|
|
|
|
|
- break;
|
|
|
+ elements.push( new DynamicElement( element ) );
|
|
|
|
|
|
- }
|
|
|
+ } else if ( token.str === '.' ) {
|
|
|
|
|
|
- }
|
|
|
+ const accessorTokens = currentTokens.slice( 1, 2 );
|
|
|
|
|
|
- return new AccessorElements( firstToken.str, elements );
|
|
|
+ const element = this.parseExpressionFromTokens( accessorTokens );
|
|
|
|
|
|
- }
|
|
|
+ currentTokens = currentTokens.slice( 2 );
|
|
|
|
|
|
- }
|
|
|
+ elements.push( new StaticElement( element ) );
|
|
|
|
|
|
- return new Accessor( firstToken.str );
|
|
|
+ } else {
|
|
|
+
|
|
|
+ console.error( 'Unknown accessor expression', token );
|
|
|
+
|
|
|
+ break;
|
|
|
+
|
|
|
+ }
|
|
|
|
|
|
}
|
|
|
|
|
|
+ return elements;
|
|
|
+
|
|
|
}
|
|
|
|
|
|
parseFunctionParametersFromTokens( tokens ) {
|