Пример #1
0
        private CsvNode ParseINTEGER()
        {
            CsvNode node = new CsvNode(CsvNodeType.INTEGER, this._token.Value);

            this._token = this._tokenizer.Tokenize(this._reader);
            return(node);
        }
Пример #2
0
        private CsvNode ParseNEWLINE()
        {
            CsvNode node = new CsvNode(CsvNodeType.NEWLINE, this._token.Value);

            this._token = this._tokenizer.Tokenize(this._reader);
            return(node);
        }
Пример #3
0
        private CsvNode ParseCellList()
        {
            CsvNode node = new CsvNode(CsvNodeType.CellList);

            switch (this._token.Type)
            {
            case CsvTokenType.BOOLEAN:
            case CsvTokenType._EOF_:
            case CsvTokenType.FLOAT:
            case CsvTokenType.INTEGER:
            case CsvTokenType.NEWLINE:
            case CsvTokenType.QUOTED_STRING:
            case CsvTokenType.STRING:
            {
                node.Nodes.Add(ParseCell());
                node.Nodes.Add(ParseCellListTail());
                return(node);
            }

            default:
            {
                throw new System.Exception("Syntax error.");
            }
            }
        }
Пример #4
0
        private CsvNode ParseSTRING()
        {
            CsvNode node = new CsvNode(CsvNodeType.STRING, this._token.Value);

            this._token = this._tokenizer.Tokenize(this._reader);
            return(node);
        }
Пример #5
0
        private CsvNode ParseBOOLEAN()
        {
            CsvNode node = new CsvNode(CsvNodeType.BOOLEAN, this._token.Value);

            this._token = this._tokenizer.Tokenize(this._reader);
            return(node);
        }
Пример #6
0
        private CsvNode ParseFLOAT()
        {
            CsvNode node = new CsvNode(CsvNodeType.FLOAT, this._token.Value);

            this._token = this._tokenizer.Tokenize(this._reader);
            return(node);
        }
Пример #7
0
 protected override object EvaluateCellCellListTail(CsvNode node)
 {
     this._row.Add(Evaluate(node.Nodes[0]));
     if (node.Nodes[1].Nodes.Count > 0)
     {
         Evaluate(node.Nodes[1]);
     }
     return(null);
 }
Пример #8
0
 protected override object EvaluateCOMMACellCellListTail(CsvNode node)
 {
     if (node.Nodes[1].Nodes.Count == 0)
     {
         this._row.Add(null);
     }
     else
     {
         this._row.Add(Evaluate(node.Nodes[1]));
     }
     if (node.Nodes[2].Nodes.Count > 0)
     {
         Evaluate(node.Nodes[2]);
     }
     return(null);
 }
Пример #9
0
        private CsvNode ParseCell()
        {
            CsvNode node = new CsvNode(CsvNodeType.Cell);

            switch (this._token.Type)
            {
            case CsvTokenType.BOOLEAN:
            {
                node.Nodes.Add(ParseBOOLEAN());
                return(node);
            }

            case CsvTokenType.INTEGER:
            {
                node.Nodes.Add(ParseINTEGER());
                return(node);
            }

            case CsvTokenType.FLOAT:
            {
                node.Nodes.Add(ParseFLOAT());
                return(node);
            }

            case CsvTokenType.STRING:
            {
                node.Nodes.Add(ParseSTRING());
                return(node);
            }

            case CsvTokenType.QUOTED_STRING:
            {
                node.Nodes.Add(ParseQUOTED_STRING());
                return(node);
            }

            default:
            {
                return(node);
            }
            }
        }
Пример #10
0
        private CsvNode ParseCellListTail()
        {
            CsvNode node = new CsvNode(CsvNodeType.CellListTail);

            switch (this._token.Type)
            {
            case CsvTokenType.COMMA:
            {
                node.Nodes.Add(ParseCOMMA());
                node.Nodes.Add(ParseCell());
                node.Nodes.Add(ParseCellListTail());
                return(node);
            }

            default:
            {
                return(node);
            }
            }
        }
Пример #11
0
        private CsvNode ParseRowEnd()
        {
            CsvNode node = new CsvNode(CsvNodeType.RowEnd);

            switch (this._token.Type)
            {
            case CsvTokenType.NEWLINE:
            {
                node.Nodes.Add(ParseNEWLINE());
                return(node);
            }

            case CsvTokenType._EOF_:
            {
                return(node);
            }

            default:
            {
                throw new System.Exception("Syntax error.");
            }
            }
        }
Пример #12
0
        public int CompareTo(object obj)
        {
            CsvNode node = (CsvNode)obj;
            int     cmp  = this.Type.CompareTo(node.Type);

            if (cmp != 0)
            {
                return(cmp);
            }
            if (this.Value != null && node.Value != null)
            {
                cmp = this.Value.CompareTo(node.Value);
                if (cmp != 0)
                {
                    return(cmp);
                }
            }
            else if (this.Value != null)
            {
                return(1);
            }
            else if (node.Value != null)
            {
                return(-1);
            }
            int min = Math.Min(this.Nodes.Count, node.Nodes.Count);

            for (int i = 0; i < min; i++)
            {
                cmp = this.Nodes[i].CompareTo(node.Nodes[i]);
                if (cmp != 0)
                {
                    return(cmp);
                }
            }
            return((this.Nodes.Count == node.Nodes.Count) ? 0 : ((this.Nodes.Count > node.Nodes.Count) ? -1 : 1));
        }
Пример #13
0
        private CsvNode ParseRow()
        {
            CsvNode node = new CsvNode(CsvNodeType.Row);

            switch (this._token.Type)
            {
            case CsvTokenType.BOOLEAN:
            case CsvTokenType.COMMA:
            case CsvTokenType.FLOAT:
            case CsvTokenType.INTEGER:
            case CsvTokenType.QUOTED_STRING:
            case CsvTokenType.STRING:
            {
                node.Nodes.Add(ParseCellList());
                node.Nodes.Add(ParseRowEnd());
                return(node);
            }

            default:
            {
                return(node);
            }
            }
        }
Пример #14
0
 protected override object EvaluateCellListRowEnd(CsvNode node)
 {
     Evaluate(node.Nodes[0]);
     return(null);
 }
Пример #15
0
        private void Generate(CsvNode node, System.IO.TextWriter writer, ref bool writeWhitespace)
        {
            switch (node.Type)
            {
            case CsvNodeType.Cell:
            {
                for (int i = 0; i < node.Nodes.Count; i++)
                {
                    Generate(node.Nodes[i], writer, ref writeWhitespace);
                }
                break;
            }

            case CsvNodeType.CellList:
            {
                for (int i = 0; i < node.Nodes.Count; i++)
                {
                    Generate(node.Nodes[i], writer, ref writeWhitespace);
                }
                break;
            }

            case CsvNodeType.CellListTail:
            {
                for (int i = 0; i < node.Nodes.Count; i++)
                {
                    Generate(node.Nodes[i], writer, ref writeWhitespace);
                }
                break;
            }

            case CsvNodeType.Row:
            {
                for (int i = 0; i < node.Nodes.Count; i++)
                {
                    Generate(node.Nodes[i], writer, ref writeWhitespace);
                }
                break;
            }

            case CsvNodeType.RowEnd:
            {
                for (int i = 0; i < node.Nodes.Count; i++)
                {
                    Generate(node.Nodes[i], writer, ref writeWhitespace);
                }
                break;
            }

            case CsvNodeType.BOOLEAN:
            {
                if (writeWhitespace)
                {
                    writer.Write(" ");
                }
                writer.Write(node.Value);
                writeWhitespace = true;
                break;
            }

            case CsvNodeType.COMMA:
            {
                if (writeWhitespace)
                {
                    writer.Write(" ");
                }
                writer.Write(node.Value);
                writeWhitespace = true;
                break;
            }

            case CsvNodeType.EOF:
            {
                if (writeWhitespace)
                {
                    writer.Write(" ");
                }
                writer.Write(node.Value);
                writeWhitespace = true;
                break;
            }

            case CsvNodeType.EPSILON:
            {
                if (writeWhitespace)
                {
                    writer.Write(" ");
                }
                writer.Write(node.Value);
                writeWhitespace = true;
                break;
            }

            case CsvNodeType.FLOAT:
            {
                if (writeWhitespace)
                {
                    writer.Write(" ");
                }
                writer.Write(node.Value);
                writeWhitespace = true;
                break;
            }

            case CsvNodeType.INTEGER:
            {
                if (writeWhitespace)
                {
                    writer.Write(" ");
                }
                writer.Write(node.Value);
                writeWhitespace = true;
                break;
            }

            case CsvNodeType.NEWLINE:
            {
                if (writeWhitespace)
                {
                    writer.Write(" ");
                }
                writer.Write(node.Value);
                writeWhitespace = true;
                break;
            }

            case CsvNodeType.QUOTED_STRING:
            {
                if (writeWhitespace)
                {
                    writer.Write(" ");
                }
                writer.Write(node.Value);
                writeWhitespace = true;
                break;
            }

            case CsvNodeType.STRING:
            {
                if (writeWhitespace)
                {
                    writer.Write(" ");
                }
                writer.Write(node.Value);
                writeWhitespace = true;
                break;
            }

            default:
            {
                throw new System.Exception("Invalid node type.");
            }
            }
        }
Пример #16
0
 protected virtual object EvaluateCOMMACellCellListTail(CsvNode node)
 {
     throw new System.Exception("Implement.");
 }
Пример #17
0
 public static void Print(CsvNode node, System.IO.TextWriter writer)
 {
     Print(node, writer, 0);
 }
Пример #18
0
        public object Evaluate(CsvNode node)
        {
            switch (node.Type)
            {
            case CsvNodeType.Cell:
            {
                if (node.Nodes.Count == 1 && node.Nodes[0].Type == CsvNodeType.BOOLEAN)
                {
                    return(EvaluateBOOLEAN(node.Nodes[0].Value));
                }
                if (node.Nodes.Count == 1 && node.Nodes[0].Type == CsvNodeType.INTEGER)
                {
                    return(EvaluateINTEGER(node.Nodes[0].Value));
                }
                if (node.Nodes.Count == 1 && node.Nodes[0].Type == CsvNodeType.FLOAT)
                {
                    return(EvaluateFLOAT(node.Nodes[0].Value));
                }
                if (node.Nodes.Count == 1 && node.Nodes[0].Type == CsvNodeType.STRING)
                {
                    return(EvaluateSTRING(node.Nodes[0].Value));
                }
                if (node.Nodes.Count == 1 && node.Nodes[0].Type == CsvNodeType.QUOTED_STRING)
                {
                    return(EvaluateQUOTED_STRING(node.Nodes[0].Value));
                }
                throw new System.Exception("Invalid expression.");
            }

            case CsvNodeType.CellList:
            {
                if (node.Nodes.Count == 2 && node.Nodes[0].Type == CsvNodeType.Cell && node.Nodes[1].Type == CsvNodeType.CellListTail)
                {
                    return(EvaluateCellCellListTail(node));
                }
                throw new System.Exception("Invalid expression.");
            }

            case CsvNodeType.CellListTail:
            {
                if (node.Nodes.Count == 3 && node.Nodes[0].Type == CsvNodeType.COMMA && node.Nodes[1].Type == CsvNodeType.Cell && node.Nodes[2].Type == CsvNodeType.CellListTail)
                {
                    return(EvaluateCOMMACellCellListTail(node));
                }
                throw new System.Exception("Invalid expression.");
            }

            case CsvNodeType.Row:
            {
                if (node.Nodes.Count == 2 && node.Nodes[0].Type == CsvNodeType.CellList && node.Nodes[1].Type == CsvNodeType.RowEnd)
                {
                    return(EvaluateCellListRowEnd(node));
                }
                throw new System.Exception("Invalid expression.");
            }

            case CsvNodeType.RowEnd:
            {
                if (node.Nodes.Count == 1 && node.Nodes[0].Type == CsvNodeType.NEWLINE)
                {
                    return(EvaluateNEWLINE(node.Nodes[0].Value));
                }
                if (node.Nodes.Count == 1 && node.Nodes[0].Type == CsvNodeType.EOF)
                {
                    return(EvaluateEOF(node.Nodes[0].Value));
                }
                throw new System.Exception("Invalid expression.");
            }

            case CsvNodeType.BOOLEAN:
            {
                return(EvaluateBOOLEAN(node.Value));
            }

            case CsvNodeType.COMMA:
            {
                return(EvaluateCOMMA(node.Value));
            }

            case CsvNodeType.EOF:
            {
                return(EvaluateEOF(node.Value));
            }

            case CsvNodeType.FLOAT:
            {
                return(EvaluateFLOAT(node.Value));
            }

            case CsvNodeType.INTEGER:
            {
                return(EvaluateINTEGER(node.Value));
            }

            case CsvNodeType.NEWLINE:
            {
                return(EvaluateNEWLINE(node.Value));
            }

            case CsvNodeType.QUOTED_STRING:
            {
                return(EvaluateQUOTED_STRING(node.Value));
            }

            case CsvNodeType.STRING:
            {
                return(EvaluateSTRING(node.Value));
            }

            default:
            {
                throw new System.Exception("Invalid expression.");
            }
            }
        }
Пример #19
0
        public void Generate(CsvNode node, System.IO.TextWriter writer)
        {
            bool writeWhitespace = false;

            Generate(node, writer, ref writeWhitespace);
        }
Пример #20
0
 protected virtual object EvaluateCellListRowEnd(CsvNode node)
 {
     throw new System.Exception("Implement.");
 }
Пример #21
0
        private static void Print(CsvNode node, System.IO.TextWriter writer, int indentationLevel)
        {
            switch (node.Type)
            {
            case CsvNodeType.Cell:
            {
                for (int i = 0; i < indentationLevel; i++)
                {
                    System.Console.Write("   ");
                }
                System.Console.WriteLine("Cell:");
                foreach (CsvNode node2 in node.Nodes)
                {
                    Print(node2, writer, indentationLevel + 1);
                }
                break;
            }

            case CsvNodeType.CellList:
            {
                for (int i = 0; i < indentationLevel; i++)
                {
                    System.Console.Write("   ");
                }
                System.Console.WriteLine("CellList:");
                foreach (CsvNode node2 in node.Nodes)
                {
                    Print(node2, writer, indentationLevel + 1);
                }
                break;
            }

            case CsvNodeType.CellListTail:
            {
                for (int i = 0; i < indentationLevel; i++)
                {
                    System.Console.Write("   ");
                }
                System.Console.WriteLine("CellListTail:");
                foreach (CsvNode node2 in node.Nodes)
                {
                    Print(node2, writer, indentationLevel + 1);
                }
                break;
            }

            case CsvNodeType.Row:
            {
                for (int i = 0; i < indentationLevel; i++)
                {
                    System.Console.Write("   ");
                }
                System.Console.WriteLine("Row:");
                foreach (CsvNode node2 in node.Nodes)
                {
                    Print(node2, writer, indentationLevel + 1);
                }
                break;
            }

            case CsvNodeType.RowEnd:
            {
                for (int i = 0; i < indentationLevel; i++)
                {
                    System.Console.Write("   ");
                }
                System.Console.WriteLine("RowEnd:");
                foreach (CsvNode node2 in node.Nodes)
                {
                    Print(node2, writer, indentationLevel + 1);
                }
                break;
            }

            case CsvNodeType.BOOLEAN:
            {
                for (int i = 0; i < indentationLevel; i++)
                {
                    System.Console.Write("   ");
                }
                System.Console.WriteLine("BOOLEAN: " + node.Value);
                break;
            }

            case CsvNodeType.COMMA:
            {
                for (int i = 0; i < indentationLevel; i++)
                {
                    System.Console.Write("   ");
                }
                System.Console.WriteLine("COMMA: " + node.Value);
                break;
            }

            case CsvNodeType.EOF:
            {
                for (int i = 0; i < indentationLevel; i++)
                {
                    System.Console.Write("   ");
                }
                System.Console.WriteLine("EOF: " + node.Value);
                break;
            }

            case CsvNodeType.EPSILON:
            {
                for (int i = 0; i < indentationLevel; i++)
                {
                    System.Console.Write("   ");
                }
                System.Console.WriteLine("EPSILON: " + node.Value);
                break;
            }

            case CsvNodeType.FLOAT:
            {
                for (int i = 0; i < indentationLevel; i++)
                {
                    System.Console.Write("   ");
                }
                System.Console.WriteLine("FLOAT: " + node.Value);
                break;
            }

            case CsvNodeType.INTEGER:
            {
                for (int i = 0; i < indentationLevel; i++)
                {
                    System.Console.Write("   ");
                }
                System.Console.WriteLine("INTEGER: " + node.Value);
                break;
            }

            case CsvNodeType.NEWLINE:
            {
                for (int i = 0; i < indentationLevel; i++)
                {
                    System.Console.Write("   ");
                }
                System.Console.WriteLine("NEWLINE: " + node.Value);
                break;
            }

            case CsvNodeType.QUOTED_STRING:
            {
                for (int i = 0; i < indentationLevel; i++)
                {
                    System.Console.Write("   ");
                }
                System.Console.WriteLine("QUOTED_STRING: " + node.Value);
                break;
            }

            case CsvNodeType.STRING:
            {
                for (int i = 0; i < indentationLevel; i++)
                {
                    System.Console.Write("   ");
                }
                System.Console.WriteLine("STRING: " + node.Value);
                break;
            }

            default:
            {
                throw new System.Exception("Invalid node type.");
            }
            }
        }