예제 #1
0
        private static TemplateParam ParseTemplVarRefParam(TemplateParam paramType, string strname, ref int pos)
        {
            StringBuilder varrefstr       = new StringBuilder();
            TemplateParam leafType        = paramType.GetLeafType();
            bool          isGuid          = leafType is TagTemplParam && ((TagTemplParam)leafType).Tag.ToString() == "_GUID";
            int           dollarPos       = -1;
            int           beforeDollarLen = 0;
            int           state           = 0;

            for (; pos < strname.Length; pos++)
            {
                char ch = strname[pos];
                switch (state)
                {
                case 0:
                    if (ch == '$')
                    {
                        if (isGuid)
                        {
                            dollarPos       = pos;
                            beforeDollarLen = varrefstr.Length;
                            varrefstr.Append('_');
                            state = 1;
                        }
                        else
                        {
                            return(new ImmTemplParam(varrefstr.ToString()));
                        }
                    }
                    else
                    {
                        varrefstr.Append(ch);
                    }
                    break;

                case 1:
                    if (ch == '$')
                    {
                        return(new ImmTemplParam(varrefstr.ToString()));
                    }
                    else if (!char.IsLetter(ch) || !char.IsUpper(ch))
                    {
                        pos = dollarPos;
                        varrefstr.Length = dollarPos;
                        return(new ImmTemplParam(varrefstr.ToString()));
                    }
                    else
                    {
                        varrefstr.Append(ch);
                    }
                    break;
                }
            }
            throw new ApplicationException("Unexpected end of string while parsing variable reference in template parameters");
        }
예제 #2
0
 public virtual void Combine(ComplexTemplParam param, out ComplexTemplParam current)
 {
     InternalType = param;
     current      = param;
 }
예제 #3
0
 public void Combine(TemplateParam param)
 {
     InternalType = param;
 }
예제 #4
0
        private static Name TranslateUdtNameV2(string strname)
        {
            Name                 result         = new Name();
            StringBuilder        tag            = new StringBuilder();
            List <TemplateParam> templateParams = null;
            int           state           = 0;
            StringBuilder constTemplParam = null;
            StringBuilder specialName     = null;
            TemplateParam templParam      = null;

            int i = 0;

            for (; i < strname.Length; i++)
            {
                char ch = strname[i];
                switch (state)
                {
                case 0:
                    switch (ch)
                    {
                    case '@':
                        if (result.Namespaces == null)
                        {
                            result.Namespaces = new List <Name>();
                        }
                        Name currentName = new Name();
                        currentName.Tag = tag.ToString();
                        currentName.TemplateParameters = templateParams;
                        result.Namespaces.Add(currentName);
                        tag            = new StringBuilder();
                        templateParams = null;
                        break;

                    case '%':
                        templateParams = new List <TemplateParam>();
                        state          = 1;
                        break;

                    case '$':
                        if (tag.Length == 0)
                        {
                            state = 9;
                        }
                        else
                        {
                            state = 11;                                             // parameters
                        }
                        break;

                    default:
                        tag.Append(ch);
                        break;
                    }
                    break;

                case 1:
                    switch (ch)
                    {
                    case '$':
                        state = 2;
                        break;

                    default:
                        tag.Append(ch);
                        break;
                    }
                    break;

                case 2:
                    switch (ch)
                    {
                    case 't':
                        state = 12;
                        break;

                    case '%':
                        state = 0;
                        break;

                    default:
                        templParam = ParseParam(strname, ref i);
                        if (templParam != null)
                        {
                            state = 3;
                        }
                        else
                        {
                            throw new ApplicationException("Invalid character while in state 2: " + ch + ", in string: " + strname);
                        }
                        break;
                    }
                    break;

                case 3:                         // template param type grabbed
                    switch (ch)
                    {
                    case '$':
                        state = 4;
                        break;

                    default:
                        state = 2;
                        i--;
                        templateParams.Add(templParam);
                        break;
                    }
                    break;

                case 4:                         // begin constant in template
                    switch (ch)
                    {
                    case 'i':                                     // numeric constant
                        state           = 5;
                        constTemplParam = new StringBuilder();
                        break;

                    case 'e':                                     // reference to static variable
                        i++;
                        templateParams.Add(ParseTemplVarRefParam(templParam, strname, ref i));
                        state = 2;
                        break;

                    case 'g':
                        state           = 5;
                        constTemplParam = new StringBuilder();
                        break;

                    default:
                        throw new ApplicationException("Invalid character while in state 4: " + ch + ", in string: " + strname);
                    }
                    break;

                case 5:                         // constant in template
                    if (ch == '$')
                    {
                        templateParams.Add(new ImmTemplParam(constTemplParam.ToString()));
                        state = 2;
                    }
                    else
                    {
                        constTemplParam.Append(ch);
                    }
                    break;

                case 9:
                    if (ch == 'b')
                    {
                        state       = 10;                           // special name
                        specialName = new StringBuilder();
                    }
                    else
                    {
                        throw new ApplicationException("Invalid character in state 9: " + ch);
                    }
                    break;

                case 10:
                    if (ch == '$')
                    {
                        result.IsSpecial   = true;
                        result.SpecialName = StrToSpcName(specialName.ToString());
                        specialName        = null;
                        state = 11;
                        break;
                    }
                    else
                    {
                        specialName.Append(ch);
                    }
                    break;

                case 11:
                    // ignoring parameters
                    break;

                case 12:
                    templateParams.Add(templateParams[(int)char.GetNumericValue(ch) - 1]);
                    state = 2;
                    break;

                default:
                    Debug.Fail("Invalid state: " + state.ToString());
                    break;
                }
            }
            if (state != 0 && state != 11)
            {
                throw new ApplicationException("Unexpected end of name while in state: " + state.ToString());
            }
            result.Tag = tag.ToString();
            result.TemplateParameters = templateParams;
            return(result);
        }
예제 #5
0
 public virtual void Combine(ComplexTemplParam param, out ComplexTemplParam current)
 {
     InternalType = param;
     current = param;
 }
예제 #6
0
 public void Combine(TemplateParam param)
 {
     InternalType = param;
 }
예제 #7
0
 private static TemplateParam ParseTemplVarRefParam(TemplateParam paramType, string strname, ref int pos)
 {
     StringBuilder varrefstr = new StringBuilder();
     TemplateParam leafType = paramType.GetLeafType();
     bool isGuid = leafType is TagTemplParam && ((TagTemplParam)leafType).Tag.ToString() == "_GUID";
     int dollarPos = -1;
     int beforeDollarLen = 0;
     int state = 0;
     for (; pos < strname.Length; pos++)
     {
         char ch = strname[pos];
         switch (state)
         {
             case 0:
                 if (ch == '$')
                 {
                     if (isGuid)
                     {
                         dollarPos = pos;
                         beforeDollarLen = varrefstr.Length;
                         varrefstr.Append('_');
                         state = 1;
                     }
                     else
                     {
                         return new ImmTemplParam(varrefstr.ToString());
                     }
                 }
                 else
                 {
                     varrefstr.Append(ch);
                 }
                 break;
             case 1:
                 if (ch == '$')
                 {
                     return new ImmTemplParam(varrefstr.ToString());
                 }
                 else if (!char.IsLetter(ch) || !char.IsUpper(ch))
                 {
                     pos = dollarPos;
                     varrefstr.Length = dollarPos;
                     return new ImmTemplParam(varrefstr.ToString());
                 }
                 else
                 {
                     varrefstr.Append(ch);
                 }
                 break;
         }
     }
     throw new ApplicationException("Unexpected end of string while parsing variable reference in template parameters");
 }