/vqdr/trunk

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/vqdr/trunk

« back to all changes in this revision

Viewing changes to src/libvqdr/token.vala

  • Committer: Gustav Hartvigsson
  • Date: 2022-06-01 12:14:52 UTC
  • Revision ID: gustav.hartvigsson@gmail.com-20220601121452-ntu94w67q3dhhfeq
More work torwards inperementing the parser.

Show diffs side-by-side

added added

removed removed

Lines of Context:
57
57
      
58
58
      /** get the name of the priority */
59
59
      public string to_string () {
 
60
        // We have to add 1 as we have an invalid case at zero.
 
61
        static_assert (_NUM_VAL == 12 + 1);
60
62
        switch (this) {
61
63
          case ASSIGNMENT:
62
 
            return "prio: assigment";
 
64
            return "ASSIGNMENT";
63
65
          case CONDITIONAL_OR:
64
 
            return "prio: conditonal OR";
 
66
            return "CONDITIONAL_OR";
65
67
          case CONDITIONAL_AND:
66
 
            return "prio: conidonal AND";
 
68
            return "CONDITIONAL_AND";
67
69
          case EQUALITY:
68
 
            return "prio: equality";
 
70
            return "EQUALITY";
 
71
          case COMPARISON:
 
72
            return "COMPARISON";
 
73
          case ADDICTIVE:
 
74
            return "ADDICTIVE";
69
75
          case MULTIPLICATIVE:
70
 
            return "prio: multiplicative";
 
76
            return "MULTIPLICATIVE";
71
77
          case UNARY:
72
 
            return "prio: unary";
 
78
            return "UNARY";
73
79
          case LABEL:
74
 
            return "prio: label";
 
80
            return "LABEL";
75
81
          case DICE:
76
 
            return "prio: dice";
 
82
            return "DICE";
77
83
          case FUNCTION:
78
 
            return "prio: function";
 
84
            return "FUNCTION";
79
85
          case VALUE:
80
 
            return "prio: value";
 
86
            return "VALUE";
81
87
          default:
82
88
            assert_not_reached ();
83
89
        }
84
90
      }
85
91
 
86
92
      public Prio from_string (string name) {
87
 
        var collected = collect_string (name.split (" ")).up ();
 
93
        // We have to add 1 as we have an invalid case at zero.
 
94
        static_assert (_NUM_VAL == 12 + 1);
 
95
        var collected = name.up ();
88
96
        switch (collected) {
89
97
          case "ASSIGMENT":
90
 
          case "PRIO:ASSIGNMENT":
91
98
            return ASSIGNMENT;
92
99
          case "CONDITIONAL_OR":
93
 
          case "PRIO:CONDITIONAL_OR":
94
100
            return CONDITIONAL_OR;
95
101
          case "CONDITIONAL_AND":
96
 
          case "PRINO:CONDITIONAL_AND":
97
102
            return CONDITIONAL_AND;
98
103
          case "EQUALITY":
99
 
          case "PRINO:EQUALITY":
100
104
            return EQUALITY;
 
105
          case "COMPARISON":
 
106
            return COMPARISON;
 
107
          case "ADDICTIVE":
 
108
            return ADDICTIVE;
101
109
          case "MULTIPLICATIVE":
102
 
          case "PRINO:MULTIPLICATIVE":
103
110
            return MULTIPLICATIVE;
104
111
          case "UNARY":
105
 
          case "PRINO:UNARY":
106
112
            return UNARY;
107
113
          case "LABEL":
108
 
          case "PRINO:LABEL":
109
114
            return LABEL;
110
115
          case "DICE":
111
 
          case "PRINO:DICE":
112
116
            return DICE;
113
117
          case "FUNCTON":
114
 
          case "PRINO:FUNCTON":
115
118
            return FUNCTION;
116
119
          case "VALUE":
117
 
          case "PRINO:VALUE":
118
120
            return VALUE;
119
121
          default:
120
122
            assert_not_reached ();
135
137
    /** The parent token of this token*/
136
138
    protected unowned Token? parent {protected get; protected set;}
137
139
    
138
 
    public virtual int priority {public get; protected construct set;}
 
140
    public virtual Prio priority {public get; protected construct set;}
139
141
    
140
142
    /** Starting position of the token in the expression */
141
 
    protected int position;
 
143
    public int position {get; protected set;}
142
144
    
 
145
    private int internal_next_child_num;
143
146
    /** The index of the next child */
144
 
    private int next_child;
 
147
    public int next_child_num {get {return internal_next_child_num;}
 
148
                 protected set{internal_next_child_num = value;}}
145
149
    
146
150
    /** 
147
151
     * The optional that this child represents.
179
183
    
180
184
    construct {
181
185
      children = new Token[max_num_child];
182
 
      next_child = 0;
 
186
      next_child_num = 0;
183
187
      
184
188
      result_value = FastNumber ();
185
189
      result_max_value = FastNumber ();
217
221
      return children[index -1 ];
218
222
    }
219
223
    
 
224
    public void set_next_child (Token child) throws ArgError {
 
225
      next_child_num++;
 
226
      set_child (next_child_num, child);
 
227
    }
220
228
    
221
229
    /**
222
230
     * Set a child token to this this token.