Exemplo n.º 1
0
        private SourceObject CreateSourceObject(SymbolRecord record)
        {
            SourceObject srcObj;

            switch (record.Type)
            {
            case TokenRef.Type.Keyword:
            case TokenRef.Type.Modifier:
            case TokenRef.Type.Identifier:
            case TokenRef.Type.Operator:
                srcObj = new SourceObject(record.Token, record.Type);
                break;

            default:
                throw InvalidEnumValueException.InvalidArgument(typeof(TokenRef.Type), record.Type, nameof(record.Type));
            }
            return(srcObj);
        }
Exemplo n.º 2
0
        public static NextStateRec CreateTokenRef(string name, TokenRef.Type type, ParseResponse response)
        {
            NextStateRec nsRec;

            switch (type)
            {
            case TokenRef.Type.Null:
                throw new FormatException($"SourceObject Type {type.ToString()} is valid BUT NOT in the context as a Next State Token Ref!");

            case TokenRef.Type.Empty:
                nsRec = new NextStateRec(Type.TokenRef, TokenRef.CreateEmpty(), null, response);
                break;

            case TokenRef.Type.Identifier:
                if (!(name is null))
                {
                    throw new ArgumentNullException(nameof(name), $"NextStateRecords can not contain Identifier Tokens with predefined names -{nameof(name)} must be set to 'null', not '{name}'!");
                }

                nsRec = new NextStateRec(Type.TokenRef, TokenRef.CreateIdentifier(), response);
                break;

            case TokenRef.Type.Keyword:
                nsRec = new NextStateRec(Type.TokenRef, TokenRef.CreateKeyword(name), name, response);
                break;

            case TokenRef.Type.Operator:
                nsRec = new NextStateRec(Type.TokenRef, TokenRef.CreateOperator(name), name, response);
                break;

            case TokenRef.Type.Error:
                throw new NotImplementedException("Error types yet to be implemented!");

            default:
                throw InvalidEnumValueException.InvalidArgument(typeof(TokenRef.Type), type, nameof(name));
            }

            return(nsRec);
        }