Revision 44379 trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.expressionevaluator/org.gvsig.expressionevaluator.lib/org.gvsig.expressionevaluator.lib.impl/src/main/java/org/gvsig/expressionevaluator/impl/DefaultStatement.java
DefaultStatement.java | ||
---|---|---|
2 | 2 |
|
3 | 3 |
import java.util.ArrayList; |
4 | 4 |
import java.util.List; |
5 |
import java.util.Objects; |
|
5 | 6 |
import org.apache.commons.lang3.ArrayUtils; |
6 | 7 |
import org.apache.commons.lang3.StringUtils; |
7 | 8 |
import org.gvsig.expressionevaluator.Code; |
... | ... | |
17 | 18 |
import org.gvsig.expressionevaluator.Statement.StatementContext; |
18 | 19 |
import org.gvsig.expressionevaluator.impl.function.programming.CodeBlockFunction; |
19 | 20 |
import org.gvsig.expressionevaluator.impl.DefaultCodeBuilder.BaseCodes; |
20 |
import org.gvsig.expressionevaluator.impl.function.programming.ListFunction; |
|
21 | 21 |
|
22 | 22 |
/** |
23 | 23 |
* |
... | ... | |
43 | 43 |
this.required_token = required_token; |
44 | 44 |
} |
45 | 45 |
|
46 |
@Override |
|
46 | 47 |
public void parse(StatementContext context) { |
47 | 48 |
Token token = context.look_token(); |
48 | 49 |
if (!token.is(this.required_token)) { |
... | ... | |
77 | 78 |
this.id = id; |
78 | 79 |
} |
79 | 80 |
|
81 |
@Override |
|
80 | 82 |
public void parse(StatementContext context) { |
81 | 83 |
Token token = context.look_token(); |
82 | 84 |
if (token.getType() != Token.IDENTIFIER) { |
... | ... | |
105 | 107 |
this.id = id; |
106 | 108 |
} |
107 | 109 |
|
110 |
@Override |
|
108 | 111 |
public void parse(StatementContext context) { |
109 | 112 |
Code code = context.parse_expression(); |
110 | 113 |
if (code == null) { |
... | ... | |
119 | 122 |
} |
120 | 123 |
} |
121 | 124 |
|
125 |
|
|
126 |
public class RuleSetExpression implements Rule { |
|
127 |
|
|
128 |
private final String id; |
|
129 |
private final Object value; |
|
130 |
|
|
131 |
public RuleSetExpression(String id, Object value) { |
|
132 |
this.id = id; |
|
133 |
this.value = value; |
|
134 |
} |
|
135 |
|
|
136 |
@Override |
|
137 |
public void parse(StatementContext context) { |
|
138 |
if( this.value instanceof Code ) { |
|
139 |
context.setCode(id, (Code) this.value); |
|
140 |
} else { |
|
141 |
context.setCode(id, context.getCodeBuilder().constant(value)); |
|
142 |
} |
|
143 |
} |
|
144 |
|
|
145 |
@Override |
|
146 |
public String toString() { |
|
147 |
return "set_expression('" + this.id + "', "+Objects.toString(value)+")"; |
|
148 |
} |
|
149 |
} |
|
150 |
|
|
122 | 151 |
public class RuleRequiereExpressions implements Rule { |
123 | 152 |
|
124 | 153 |
private final String id; |
... | ... | |
129 | 158 |
this.separator = separator; |
130 | 159 |
} |
131 | 160 |
|
161 |
@Override |
|
132 | 162 |
public void parse(StatementContext context) { |
133 | 163 |
Codes codes = context.parse_expressions(this.separator); |
134 | 164 |
if (codes == null) { |
135 | 165 |
throw new ExpressionSyntaxException(context.getLexicalAnalyzer()); |
136 | 166 |
} |
137 |
Code code = context.getCodeBuilder().function(CodeBlockFunction.NAME, codes); |
|
167 |
Code code; |
|
168 |
if( codes.size()==1 ) { |
|
169 |
code = codes.get(0); |
|
170 |
} else { |
|
171 |
code = context.getCodeBuilder().function(CodeBlockFunction.NAME, codes); |
|
172 |
} |
|
138 | 173 |
context.setCode(id, code); |
139 | 174 |
} |
140 | 175 |
|
... | ... | |
156 | 191 |
this.onFalseRules = new ArrayList<>(); |
157 | 192 |
} |
158 | 193 |
|
194 |
@Override |
|
159 | 195 |
public void parse(StatementContext context) { |
160 | 196 |
Token token = context.look_token(); |
161 | 197 |
if (token.is(this.optional_token)) { |
... | ... | |
170 | 206 |
} |
171 | 207 |
} |
172 | 208 |
|
209 |
@Override |
|
173 | 210 |
public RuleOptionalAnyToken addRuleOnTrue(Rule rule) { |
174 | 211 |
this.onTrueRules.add(rule); |
175 | 212 |
return this; |
176 | 213 |
} |
177 | 214 |
|
215 |
@Override |
|
178 | 216 |
public RuleOptionalAnyToken addRuleOnFalse(Rule rule) { |
179 | 217 |
this.onFalseRules.add(rule); |
180 | 218 |
return this; |
... | ... | |
197 | 235 |
this.rules = new ArrayList<>(); |
198 | 236 |
} |
199 | 237 |
|
238 |
@Override |
|
200 | 239 |
public void parse(StatementContext context) { |
201 | 240 |
String save = context.getCodeClassifier(); |
202 | 241 |
try { |
... | ... | |
217 | 256 |
} |
218 | 257 |
} |
219 | 258 |
|
259 |
@Override |
|
220 | 260 |
public RuleRepeatUntilAnyTokens addRule(Rule rule) { |
221 | 261 |
this.rules.add(rule); |
222 | 262 |
return this; |
... | ... | |
244 | 284 |
this.separator = separator; |
245 | 285 |
} |
246 | 286 |
|
287 |
@Override |
|
247 | 288 |
public void parse(StatementContext context) { |
248 | 289 |
BaseCodes args = (BaseCodes) context.getCodeBuilder().args(); |
249 | 290 |
Token token = context.look_token(); |
... | ... | |
280 | 321 |
this.argNames = argNames; |
281 | 322 |
} |
282 | 323 |
|
324 |
@Override |
|
283 | 325 |
public Codes build(StatementContext context) { |
284 | 326 |
BaseCodes args = (BaseCodes) context.getCodeBuilder().args(); |
285 | 327 |
for (String argName : argNames) { |
... | ... | |
309 | 351 |
super(argNames); |
310 | 352 |
} |
311 | 353 |
|
354 |
@Override |
|
312 | 355 |
public Codes build(StatementContext context) { |
313 | 356 |
BaseCodes args = (BaseCodes) context.getCodeBuilder().args(); |
314 | 357 |
|
... | ... | |
335 | 378 |
this.name = name; |
336 | 379 |
} |
337 | 380 |
|
381 |
@Override |
|
338 | 382 |
public String getName() { |
339 | 383 |
return name; |
340 | 384 |
} |
... | ... | |
350 | 394 |
} |
351 | 395 |
|
352 | 396 |
@Override |
397 |
public Rule set_expression(String id, Object value) { |
|
398 |
return new RuleSetExpression(id, value); |
|
399 |
} |
|
400 |
|
|
401 |
@Override |
|
353 | 402 |
public Rule require_expression(String id) { |
354 | 403 |
return new RuleRequireExpression(id); |
355 | 404 |
} |
... | ... | |
412 | 461 |
|
413 | 462 |
@Override |
414 | 463 |
public Code parse(StatementContext context) { |
464 |
// System.err.println("start parse "+this.getName()); |
|
415 | 465 |
for (Rule rule : rules) { |
416 | 466 |
rule.parse(context); |
417 | 467 |
} |
418 | 468 |
Codes args = this.argsBuilder.build(context); |
469 |
// System.err.println("end parse "+this.getName()+ ": "+ args.toString()); |
|
419 | 470 |
|
420 | 471 |
Code code; |
421 | 472 |
if (codeId == null) { |
Also available in: Unified diff