Esempio n. 1
0
 protected internal virtual void ReadLexerActions(ATN atn)
 {
     //
     // LEXER ACTIONS
     //
     if (atn.grammarType == ATNType.Lexer)
     {
         atn.lexerActions = new ILexerAction[ReadInt()];
         for (int i_10 = 0; i_10 < atn.lexerActions.Length; i_10++)
         {
             LexerActionType actionType = (LexerActionType)ReadInt();
             int             data1      = ReadInt();
             if (data1 == unchecked ((int)(0xFFFF)))
             {
                 data1 = -1;
             }
             int data2 = ReadInt();
             if (data2 == unchecked ((int)(0xFFFF)))
             {
                 data2 = -1;
             }
             ILexerAction lexerAction = LexerActionFactory(actionType, data1, data2);
             atn.lexerActions[i_10] = lexerAction;
         }
     }
 }
Esempio n. 2
0
        protected internal virtual ILexerAction LexerActionFactory(LexerActionType type, int data1, int data2)
        {
            switch (type)
            {
            case LexerActionType.Channel:
            {
                return(new LexerChannelAction(data1));
            }

            case LexerActionType.Custom:
            {
                return(new LexerCustomAction(data1, data2));
            }

            case LexerActionType.Mode:
            {
                return(new LexerModeAction(data1));
            }

            case LexerActionType.More:
            {
                return(LexerMoreAction.Instance);
            }

            case LexerActionType.PopMode:
            {
                return(LexerPopModeAction.Instance);
            }

            case LexerActionType.PushMode:
            {
                return(new LexerPushModeAction(data1));
            }

            case LexerActionType.Skip:
            {
                return(LexerSkipAction.Instance);
            }

            case LexerActionType.Type:
            {
                return(new LexerTypeAction(data1));
            }

            default:
            {
                string message = string.Format(CultureInfo.CurrentCulture, "The specified lexer action type {0} is not valid.", type);
                throw new ArgumentException(message);
            }
            }
        }
Esempio n. 3
0
        protected internal virtual ILexerAction LexerActionFactory(LexerActionType type, int data1, int data2)
        {
            switch (type)
            {
                case LexerActionType.Channel:
                {
                    return new LexerChannelAction(data1);
                }

                case LexerActionType.Custom:
                {
                    return new LexerCustomAction(data1, data2);
                }

                case LexerActionType.Mode:
                {
                    return new LexerModeAction(data1);
                }

                case LexerActionType.More:
                {
                    return LexerMoreAction.Instance;
                }

                case LexerActionType.PopMode:
                {
                    return LexerPopModeAction.Instance;
                }

                case LexerActionType.PushMode:
                {
                    return new LexerPushModeAction(data1);
                }

                case LexerActionType.Skip:
                {
                    return LexerSkipAction.Instance;
                }

                case LexerActionType.Type:
                {
                    return new LexerTypeAction(data1);
                }

                default:
                {
                    string message = string.Format(CultureInfo.CurrentCulture, "The specified lexer action type {0} is not valid.", type);
                    throw new ArgumentException(message);
                }
            }
        }
Esempio n. 4
0
        public virtual string Decode(char[] data)
        {
            data = data.Clone();
            // don't adjust the first value since that's the version number
            for (int i = 1; i < data.Length; i++)
            {
                data[i] = (char)(data[i] - 2);
            }
            StringBuilder buf     = new StringBuilder();
            int           p       = 0;
            int           version = ATNDeserializer.ToInt(data[p++]);

            if (version != ATNDeserializer.SerializedVersion)
            {
                string reason = string.Format("Could not deserialize ATN with version {0} (expected {1}).", version, ATNDeserializer.SerializedVersion);
                throw new NotSupportedException(new InvalidClassException(typeof(ATN).FullName, reason));
            }
            UUID uuid = ATNDeserializer.ToUUID(data, p);

            p += 8;
            if (!uuid.Equals(ATNDeserializer.SerializedUuid))
            {
                string reason = string.Format(CultureInfo.CurrentCulture, "Could not deserialize ATN with UUID {0} (expected {1}).", uuid, ATNDeserializer.SerializedUuid);
                throw new NotSupportedException(new InvalidClassException(typeof(ATN).FullName, reason));
            }
            p++;
            // skip grammarType
            int maxType = ATNDeserializer.ToInt(data[p++]);

            buf.Append("max type ").Append(maxType).Append("\n");
            int nstates = ATNDeserializer.ToInt(data[p++]);

            for (int i_1 = 0; i_1 < nstates; i_1++)
            {
                StateType stype = StateType.Values()[ATNDeserializer.ToInt(data[p++])];
                if (stype == StateType.InvalidType)
                {
                    continue;
                }
                // ignore bad type of states
                int ruleIndex = ATNDeserializer.ToInt(data[p++]);
                if (ruleIndex == char.MaxValue)
                {
                    ruleIndex = -1;
                }
                string arg = string.Empty;
                if (stype == StateType.LoopEnd)
                {
                    int loopBackStateNumber = ATNDeserializer.ToInt(data[p++]);
                    arg = " " + loopBackStateNumber;
                }
                else
                {
                    if (stype == StateType.PlusBlockStart || stype == StateType.StarBlockStart || stype == StateType.BlockStart)
                    {
                        int endStateNumber = ATNDeserializer.ToInt(data[p++]);
                        arg = " " + endStateNumber;
                    }
                }
                buf.Append(i_1).Append(":").Append(ATNState.serializationNames[(int)(stype)]).Append(" ").Append(ruleIndex).Append(arg).Append("\n");
            }
            int numNonGreedyStates = ATNDeserializer.ToInt(data[p++]);

            for (int i_2 = 0; i_2 < numNonGreedyStates; i_2++)
            {
                int stateNumber = ATNDeserializer.ToInt(data[p++]);
            }
            int numSllStates = ATNDeserializer.ToInt(data[p++]);

            for (int i_3 = 0; i_3 < numSllStates; i_3++)
            {
                int stateNumber = ATNDeserializer.ToInt(data[p++]);
            }
            int numPrecedenceStates = ATNDeserializer.ToInt(data[p++]);

            for (int i_4 = 0; i_4 < numPrecedenceStates; i_4++)
            {
                int stateNumber = ATNDeserializer.ToInt(data[p++]);
            }
            int nrules = ATNDeserializer.ToInt(data[p++]);

            for (int i_5 = 0; i_5 < nrules; i_5++)
            {
                int  s            = ATNDeserializer.ToInt(data[p++]);
                bool leftFactored = ATNDeserializer.ToInt(data[p++]) != 0;
                if (atn.grammarType == ATNType.Lexer)
                {
                    int arg1 = ATNDeserializer.ToInt(data[p++]);
                    buf.Append("rule ").Append(i_5).Append(":").Append(s).Append(" ").Append(arg1).Append('\n');
                }
                else
                {
                    buf.Append("rule ").Append(i_5).Append(":").Append(s).Append('\n');
                }
            }
            int nmodes = ATNDeserializer.ToInt(data[p++]);

            for (int i_6 = 0; i_6 < nmodes; i_6++)
            {
                int s = ATNDeserializer.ToInt(data[p++]);
                buf.Append("mode ").Append(i_6).Append(":").Append(s).Append('\n');
            }
            int nsets = ATNDeserializer.ToInt(data[p++]);

            for (int i_7 = 0; i_7 < nsets; i_7++)
            {
                int nintervals = ATNDeserializer.ToInt(data[p++]);
                buf.Append(i_7).Append(":");
                bool containsEof = data[p++] != 0;
                if (containsEof)
                {
                    buf.Append(GetTokenName(TokenConstants.Eof));
                }
                for (int j = 0; j < nintervals; j++)
                {
                    if (containsEof || j > 0)
                    {
                        buf.Append(", ");
                    }
                    buf.Append(GetTokenName(ATNDeserializer.ToInt(data[p]))).Append("..").Append(GetTokenName(ATNDeserializer.ToInt(data[p + 1])));
                    p += 2;
                }
                buf.Append("\n");
            }
            int nedges = ATNDeserializer.ToInt(data[p++]);

            for (int i_8 = 0; i_8 < nedges; i_8++)
            {
                int src   = ATNDeserializer.ToInt(data[p]);
                int trg   = ATNDeserializer.ToInt(data[p + 1]);
                int ttype = ATNDeserializer.ToInt(data[p + 2]);
                int arg1  = ATNDeserializer.ToInt(data[p + 3]);
                int arg2  = ATNDeserializer.ToInt(data[p + 4]);
                int arg3  = ATNDeserializer.ToInt(data[p + 5]);
                buf.Append(src).Append("->").Append(trg).Append(" ").Append(Transition.serializationNames[ttype]).Append(" ").Append(arg1).Append(",").Append(arg2).Append(",").Append(arg3).Append("\n");
                p += 6;
            }
            int ndecisions = ATNDeserializer.ToInt(data[p++]);

            for (int i_9 = 0; i_9 < ndecisions; i_9++)
            {
                int s = ATNDeserializer.ToInt(data[p++]);
                buf.Append(i_9).Append(":").Append(s).Append("\n");
            }
            if (atn.grammarType == ATNType.Lexer)
            {
                int lexerActionCount = ATNDeserializer.ToInt(data[p++]);
                for (int i_10 = 0; i_10 < lexerActionCount; i_10++)
                {
                    LexerActionType actionType = LexerActionType.Values()[ATNDeserializer.ToInt(data[p++])];
                    int             data1      = ATNDeserializer.ToInt(data[p++]);
                    int             data2      = ATNDeserializer.ToInt(data[p++]);
                }
            }
            return(buf.ToString());
        }