ShaderInterpreter.Converter.ConvertSemantics C# (CSharp) Method

ConvertSemantics() private static method

Converts all semantics syntax (: NAME) into an attribute inserted above the line with semantic
private static ConvertSemantics ( string _Source ) : string
_Source string
return string
        private static string ConvertSemantics( string _Source )
        {
            // Regex	REX = new Regex( @"^[^?]*:([ \t]*[a-zA-Z0-9_]*)[ \t]*;.*$", RegexOptions.IgnoreCase | RegexOptions.Multiline );
            // string	Captures = "";
            // MatchCollection	Koll = REX.Matches( Test );
            // foreach ( Match K in Koll )
            // {
            // 	Captures += K.Value + "(" + K.Index + ", " + K.Length + ")\n";
            // 	foreach ( Capture C in K.Captures )
            // 	{
            // 		Captures += "\t Capture = " + C.Value;
            // 	}
            // 	foreach ( Group G in K.Groups )
            // 	{
            // 		Captures += "\t Group = " + G.Value;
            // 	}
            // }

            // _Source =	"Hey ? Dont : GetMe ;  // Don't get him!\n"
            // 			+	"float	Bisou : SEMANTIC;\n"
            // 			+	"truite  Aglamou : MOISI2;	// Hey!\n"
            // 			+	"truite  Aglamou : MOISI1 sqdqsd;	// Hey!\n"
            // 			+	"End of file...";

            int	CurrentPosition = 0;
            while ( true )
            {
                int	SemanticStart = _Source.IndexOf( ":", CurrentPosition, StringComparison.InvariantCultureIgnoreCase );
                if ( SemanticStart == -1 )
                    break;

                // Ensure there's no "?" on the same line to avoid grabbing ?: ternary operators
                int	BOLIndex = FindBOL( _Source, SemanticStart );
                int	EOLIndex = FindEOL( _Source, SemanticStart );

                if ( IsCommentedLine( _Source, SemanticStart ) )
                {	// Skip this line if it's a comment
                    CurrentPosition = SemanticStart+1;
                    continue;
                }

                // Ensure we're not mistaking this as part of a ternary operator...
                if ( IndexOfBetween( _Source, "?", BOLIndex, SemanticStart ) != -1 )
                {	// Skip that match...
                    CurrentPosition = SemanticStart+1;
                    continue;
                }

                // Find the ; end marker
                int	SemanticEnd = IndexOfBetween( _Source, ";", SemanticStart, EOLIndex );
                if ( SemanticEnd == -1 )
                    throw new ConverterException( "Failed to retrieve closing ; for semantic specification!", _Source, SemanticStart, EOLIndex );

                // Isolate & remove unsupported semantic syntax
                string	Semantic = _Source.Substring( SemanticStart+1, SemanticEnd-SemanticStart-1 );
                        Semantic = Semantic.Trim();

                // Ensure it's alphanumeric!
                if ( !EnsureAlphanumeric( Semantic ) )
                    throw new ConverterException( "Retrieved semantic \"" + Semantic + "\" is not recognized as an alpha numeric string!", _Source, SemanticStart, SemanticEnd );

                _Source = _Source.Remove( SemanticStart, SemanticEnd-SemanticStart );

                // Replace by inserting a semantic attribute
                string	SemanticAttrib = "[Semantic( \"" + Semantic + "\" )]\n";
                _Source = _Source.Insert( BOLIndex, SemanticAttrib );

                // New position for starting our search...
                CurrentPosition = SemanticStart;
            }

            return _Source;
        }