~alexreg/mathtexdotnet/0.1

« back to all changes in this revision

Viewing changes to TexDotNet/Semantics/ParseNode.cs

  • Committer: Alex Regueiro
  • Date: 2009-10-02 01:30:36 UTC
  • Revision ID: alexreg@gmail.com-20091002013036-0tfciubgveydmtm5
Further improvements to TexComposer regarding emitting of operators/brackets.
Updated test cases.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
using System;
2
 
using System.Collections.Generic;
3
 
using System.Linq;
4
 
using System.Text;
5
 
 
6
 
namespace TexDotNet
7
 
{
8
 
    public class ParseNode
9
 
    {
10
 
        public ParseNode(Token token, IList<ParseNode> children)
11
 
            : this()
12
 
        {
13
 
            this.Kind = ParseNodeKind.Token;
14
 
            this.Token = token;
15
 
            this.Children = new ParseNodeCollection(children);
16
 
        }
17
 
 
18
 
        public ParseNode(Token token)
19
 
            : this()
20
 
        {
21
 
            this.Kind = ParseNodeKind.Token;
22
 
            this.Token = token;
23
 
            this.Children = null;
24
 
        }
25
 
 
26
 
        public ParseNode(ParseNodeKind kind, IList<ParseNode> children)
27
 
            : this()
28
 
        {
29
 
            this.Kind = kind;
30
 
            this.Token = Token.Null;
31
 
            this.Children = new ParseNodeCollection(children);
32
 
        }
33
 
 
34
 
        public ParseNode(ParseNodeKind kind)
35
 
            : this()
36
 
        {
37
 
            this.Kind = kind;
38
 
            this.Token = Token.Null;
39
 
            this.Children = new ParseNodeCollection();
40
 
        }
41
 
 
42
 
        private ParseNode()
43
 
        {
44
 
            this.IsArgument = false;
45
 
        }
46
 
 
47
 
        public ParseNodeKind Kind
48
 
        {
49
 
            get;
50
 
            set;
51
 
        }
52
 
 
53
 
        public Token Token
54
 
        {
55
 
            get;
56
 
            set;
57
 
        }
58
 
 
59
 
        public bool IsArgument
60
 
        {
61
 
            get;
62
 
            set;
63
 
        }
64
 
 
65
 
        public ParseNodeCollection Children
66
 
        {
67
 
            get;
68
 
            private set;
69
 
        }
70
 
 
71
 
        public override string ToString()
72
 
        {
73
 
            if (this.Kind == ParseNodeKind.Token)
74
 
            {
75
 
                return this.Token.ToString();
76
 
            }
77
 
            else
78
 
            {
79
 
                return this.Kind.ToString();
80
 
            }
81
 
        }
82
 
    }
83
 
 
84
 
    public enum ParseNodeKind
85
 
    {
86
 
        Operation,
87
 
        FunctionCall,
88
 
        Token,
89
 
    }
90
 
}