Ejemplo n.º 1
0
        /// <summary>
        ///		Interpreta un bloque de sentencias
        /// </summary>
        private SentenceCollection ParseBlockSentences(TokenSqlSeparator.SeparatorType endBlock)
        {
            SentenceCollection sentences = new SentenceCollection();
            TokenSqlBase       token     = Lexer.LookUp();

            // Mientras haya algún token que leer
            while (!HasError && !(token is TokenSqlEof) && !FoundToken(token, endBlock))
            {
                // Añade las sentencias
                sentences.Add(ParseSentence());
                // Mira el siguiente token (sin sacarlo de la pila)
                token = Lexer.LookUp();
            }
            // Si el token que hemos encontrado no es el de fin de bloque, añadimos un error
            if (!FoundToken(token, endBlock))
            {
                AddError("Error when read sentences block. Waiting end block", token);
            }
            else                     // quita el token de fin de sentencia de la pila
            {
                Lexer.Next();
            }
            // Devuelve la colección de sentencias
            return(sentences);
        }
Ejemplo n.º 2
0
 /// <summary>
 ///		Ejecuta una serie de sentencias creando un contexto nuevo
 /// </summary>
 protected void ExecuteWithContext(SentenceCollection sentences)
 {
     // Crea el contexto
     Context.Add();
     // Ejecuta las sentencias
     Execute(sentences);
     // Elimina el contexto
     Context.Pop();
 }
        /// <summary>
        ///		Transforma una serie de sentencias
        /// </summary>
        private void Transform(SentenceCollection sentences)
        {
            // Crea un contexto nuevo
            Context.Add();
            // Añade las sentencias
            foreach (SentenceBase sentenceBase in sentences)
            {
                switch (sentenceBase)
                {
                case SentenceDeclare sentence:
                    TransformDeclare(sentence);
                    break;

                case SentenceLet sentence:
                    TransformLet(sentence);
                    break;

                case SentenceFunction sentence:
                    TransformFunction(sentence);
                    break;

                case SentenceCallFunction sentence:
                    TransformCallFunction(sentence);
                    break;

                case SentenceIf sentence:
                    TransformIf(sentence);
                    break;

                case SentenceDo sentence:
                    TransformDo(sentence);
                    break;

                case SentenceWhile sentence:
                    TransformWhile(sentence);
                    break;

                case SentenceFor sentence:
                    TransformFor(sentence);
                    break;

                case SentenceSql sentence:
                    TransformSql(sentence);
                    break;

                case SentenceReturn sentence:
                    TransformReturn(sentence);
                    break;

                default:
                    throw new NotImplementedException($"Unknown sentence: {sentenceBase.GetType().ToString()}");
                }
            }
            // Limpia el contexto
            Context.Pop();
        }
Ejemplo n.º 4
0
        public SentenceCollection CreateCollection()
        {
            SentenceCollection list = new SentenceCollection();
            foreach (var pair in this)
            {
                list.Add(new Sentence { Zin = pair.Key, Vertaald = pair.Value != null, Translation = pair.Value});
            }

            return list;
        }
Ejemplo n.º 5
0
        /// <summary>
        ///		Ejecuta una serie de sentencias creando un contexto nuevo
        /// </summary>
        protected async Task ExecuteWithContextAsync(SentenceCollection sentences, CancellationToken cancellationToken)
        {
            // Crea el contexto
            Context.Add();
            // Ejecuta las sentencias
            await ExecuteAsync(sentences, cancellationToken);

            // Elimina el contexto
            Context.Pop();
        }
Ejemplo n.º 6
0
        /// <summary>
        ///		Ejecuta una serie de sentencias
        /// </summary>
        protected void Execute(SentenceCollection sentences)
        {
            foreach (SentenceBase abstractSentence in sentences)
            {
                if (!Stopped)
                {
                    switch (abstractSentence)
                    {
                    case SentenceException sentence:
                        ExecuteException(sentence);
                        break;

                    case SentencePrint sentence:
                        ExecutePrint(sentence);
                        break;

                    case SentenceDeclare sentence:
                        ExecuteDeclare(sentence);
                        break;

                    case SentenceLet sentence:
                        ExecuteLet(sentence);
                        break;

                    case SentenceFor sentence:
                        ExecuteFor(sentence);
                        break;

                    case SentenceIf sentence:
                        ExecuteIf(sentence);
                        break;

                    case SentenceWhile sentence:
                        ExecuteWhile(sentence);
                        break;

                    case SentenceFunction sentence:
                        ExecuteFunctionDeclare(sentence);
                        break;

                    case SentenceCallFunction sentence:
                        ExecuteFunctionCall(sentence);
                        break;

                    case SentenceReturn sentence:
                        ExecuteFunctionReturn(sentence);
                        break;

                    default:
                        Execute(abstractSentence);
                        break;
                    }
                }
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        ///		Interpreta una colección de sentencias
        /// </summary>
        private SentenceCollection ParseSentences()
        {
            SentenceCollection sentences = new SentenceCollection();

            // Mientras haya algún token que leer
            do
            {
                sentences.Add(ParseSentence());
            }while (!HasError && !(Lexer.LookUp() is TokenSqlEof));
            // Devuelve la colección de sentencias
            return(sentences);
        }
Ejemplo n.º 8
0
 internal ProgramSentencesBuilder(ProgramBuilder main, ProgramSentencesBuilder parent, SentenceCollection sentences)
 {
     Main      = main;
     Parent    = parent;
     Sentences = sentences;
 }
Ejemplo n.º 9
0
        /// <summary>
        ///		Carga las instrucciones de una serie de nodos
        /// </summary>
        private SentenceCollection LoadSentences(MLNodesCollection nodesML, string pathBase)
        {
            SentenceCollection sentences = new SentenceCollection();

            // Lee las instrucciones
            foreach (MLNode nodeML in nodesML)
            {
                switch (nodeML.Name)
                {
                case TagImport:
                    sentences.AddRange(LoadByFile(System.IO.Path.Combine(pathBase, nodeML.Attributes[TagFileName].Value)).Sentences);
                    break;

                case TagSentenceBlock:
                    sentences.Add(LoadSentenceBlock(nodeML, pathBase));
                    break;

                case TagSentenceExecute:
                    sentences.Add(LoadSentenceExecute(nodeML));
                    break;

                case TagSentenceException:
                    sentences.Add(LoadSentenceException(nodeML));
                    break;

                case TagSentenceBulkCopy:
                    sentences.Add(LoadSentenceBulkCopy(nodeML));
                    break;

                case TagSentenceCopy:
                    sentences.Add(LoadSentenceCopy(nodeML));
                    break;

                case TagSentenceForEach:
                    sentences.Add(LoadSentenceForEach(nodeML, pathBase));
                    break;

                case TagSentenceIfExists:
                    sentences.Add(LoadSentenceIfExists(nodeML, pathBase));
                    break;

                case TagSentenceIf:
                    sentences.Add(LoadSentenceIf(nodeML, pathBase));
                    break;

                case TagSentenceString:
                    sentences.Add(LoadSentenceDeclare(nodeML, VariableModel.VariableType.String));
                    break;

                case TagSentenceNumeric:
                    sentences.Add(LoadSentenceDeclare(nodeML, VariableModel.VariableType.Numeric));
                    break;

                case TagSentenceBoolean:
                    sentences.Add(LoadSentenceDeclare(nodeML, VariableModel.VariableType.Boolean));
                    break;

                case TagSentenceDate:
                    sentences.Add(LoadSentenceDeclare(nodeML, VariableModel.VariableType.Date));
                    break;

                case TagSentenceLet:
                    sentences.Add(LoadSentenceLet(nodeML));
                    break;

                case TagSentenceFor:
                    sentences.Add(LoadSentenceFor(nodeML, pathBase));
                    break;

                case TagSentenceWhile:
                    sentences.Add(LoadSentenceWhile(nodeML, pathBase));
                    break;

                case TagSentencePrint:
                    sentences.Add(LoadSentencePrint(nodeML));
                    break;

                case TagSentenceBeginTransaction:
                    sentences.Add(LoadSentenceBatch(nodeML, SentenceDataBatch.BatchCommand.BeginTransaction));
                    break;

                case TagSentenceCommitTransaction:
                    sentences.Add(LoadSentenceBatch(nodeML, SentenceDataBatch.BatchCommand.CommitTransaction));
                    break;

                case TagSentenceRollbackTransaction:
                    sentences.Add(LoadSentenceBatch(nodeML, SentenceDataBatch.BatchCommand.RollbackTransaction));
                    break;

                case TagSentenceAssertExecute:
                    sentences.Add(LoadSentenceAssertExecute(nodeML));
                    break;

                case TagSentenceAssertScalar:
                    sentences.Add(LoadSentenceAssertScalar(nodeML));
                    break;

                case TagSentenceExecuteScript:
                    sentences.Add(LoadSentenceExecuteScript(nodeML));
                    break;

                case TagSentenceImportCsv:
                    sentences.Add(LoadSentenceImportCsv(nodeML));
                    break;

                case TagSentenceImportSchemaCsv:
                    sentences.Add(LoadSentenceImportSchema(nodeML));
                    break;

                case TagSentenceExportSchemaCsv:
                    sentences.Add(LoadSentenceExportSchema(nodeML));
                    break;

                case TagSentenceExportCsv:
                    sentences.Add(LoadSentenceExportCsv(nodeML));
                    break;

                case TagSentenceExportPartitionedCsv:
                    sentences.Add(LoadSentenceExportPartitionedCsv(nodeML));
                    break;

                case TagSentenceExportParquet:
                    sentences.Add(LoadSentenceExportParquet(nodeML));
                    break;

                case TagSentenceImportParquet:
                    sentences.Add(LoadSentenceImportParquet(nodeML));
                    break;

                default:
                    throw new ArgumentException($"Node unkwnown: {nodeML.Name}");
                }
            }
            // Devuelve la colección
            return(sentences);
        }
Ejemplo n.º 10
0
        /// <summary>
        ///		Ejecuta una serie de sentencias
        /// </summary>
        protected async Task ExecuteAsync(SentenceCollection sentences, CancellationToken cancellationToken)
        {
            foreach (SentenceBase abstractSentence in sentences)
            {
                if (!Stopped && !cancellationToken.IsCancellationRequested)
                {
                    switch (abstractSentence)
                    {
                    case SentenceException sentence:
                        ExecuteException(sentence);
                        break;

                    case SentenceDeclare sentence:
                        await ExecuteDeclareAsync(sentence, cancellationToken);

                        break;

                    case SentenceLet sentence:
                        await ExecuteLetAsync(sentence, cancellationToken);

                        break;

                    case SentenceFor sentence:
                        await ExecuteForAsync(sentence, cancellationToken);

                        break;

                    case SentenceIf sentence:
                        await ExecuteIfAsync(sentence, cancellationToken);

                        break;

                    case SentenceWhile sentence:
                        await ExecuteWhileAsync(sentence, cancellationToken);

                        break;

                    case SentenceDo sentence:
                        await ExecuteDoAsync(sentence, cancellationToken);

                        break;

                    case SentenceFunction sentence:
                        ExecuteFunctionDeclare(sentence);
                        break;

                    case SentenceCallFunction sentence:
                        await ExecuteFunctionCallAsync(sentence, cancellationToken);

                        break;

                    case SentenceReturn sentence:
                        await ExecuteFunctionReturnAsync(sentence, cancellationToken);

                        break;

                    case SentenceComment sentence:
                        ExecuteComment(sentence);
                        break;

                    default:
                        await ExecuteAsync(abstractSentence, cancellationToken);

                        break;
                    }
                }
            }
        }