Revision 44384 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 | ||
---|---|---|
26 | 26 |
public class DefaultStatement implements Statement { |
27 | 27 |
|
28 | 28 |
private final List<Rule> rules; |
29 |
private String codeId; |
|
30 |
private ArgsBuilder argsBuilder; |
|
31 | 29 |
private final String name; |
30 |
private StatementBuilder stmtBuilder; |
|
31 |
// private String codeId; |
|
32 |
// private ArgsBuilder argsBuilder; |
|
32 | 33 |
|
33 | 34 |
public interface RepeatRule extends CompoundRule { |
34 | 35 |
|
... | ... | |
49 | 50 |
if (!token.is(this.required_token)) { |
50 | 51 |
throw new ExpressionSyntaxException( |
51 | 52 |
I18N.A_XTokenX_was_expected_and_XliteralX_was_found( |
52 |
StringUtils.join(this.required_token), |
|
53 |
StringUtils.join(this.required_token,", "),
|
|
53 | 54 |
token.getLiteral() |
54 | 55 |
), |
55 | 56 |
context.getLexicalAnalyzer() |
... | ... | |
290 | 291 |
Token token = context.look_token(); |
291 | 292 |
while (token.getType() == Token.IDENTIFIER) { |
292 | 293 |
String identifier = (String) token.getLiteral(); |
294 |
if( context.isReservedWord(identifier) ) { |
|
295 |
break; |
|
296 |
} |
|
293 | 297 |
Code code = context.getCodeBuilder().constant(identifier); |
294 | 298 |
args.add(code); |
295 | 299 |
context.next_token(); |
... | ... | |
313 | 317 |
} |
314 | 318 |
} |
315 | 319 |
|
316 |
private static class ArgsBuilderFromNames implements ArgsBuilder {
|
|
320 |
public static class ArgsBuilderFromNames implements ArgsBuilder {
|
|
317 | 321 |
|
318 | 322 |
private final String[] argNames; |
319 | 323 |
|
320 |
public ArgsBuilderFromNames(String[] argNames) {
|
|
324 |
public ArgsBuilderFromNames(String... argNames) {
|
|
321 | 325 |
this.argNames = argNames; |
322 | 326 |
} |
323 | 327 |
|
... | ... | |
338 | 342 |
} |
339 | 343 |
} else { |
340 | 344 |
Code code = context.getCode(argName); |
341 |
args.add(code); |
|
345 |
if( code != null) { |
|
346 |
args.add(code); |
|
347 |
} |
|
342 | 348 |
} |
343 | 349 |
} |
344 | 350 |
return args; |
345 | 351 |
} |
346 | 352 |
} |
347 | 353 |
|
348 |
private static class ArgsBuilderExpand extends ArgsBuilderFromNames {
|
|
354 |
public static class ArgsBuilderExpand extends ArgsBuilderFromNames {
|
|
349 | 355 |
|
350 |
public ArgsBuilderExpand(String[] argNames) {
|
|
356 |
public ArgsBuilderExpand(String... argNames) {
|
|
351 | 357 |
super(argNames); |
352 | 358 |
} |
353 | 359 |
|
... | ... | |
371 | 377 |
} |
372 | 378 |
} |
373 | 379 |
|
380 |
public static class StatementBuilderBase implements StatementBuilder { |
|
381 |
protected ArgsBuilder argsBuilder; |
|
382 |
protected String codeID; |
|
383 |
|
|
384 |
public StatementBuilderBase(String codeID, ArgsBuilder argsBuilder) { |
|
385 |
this.codeID = codeID; |
|
386 |
this.argsBuilder = argsBuilder; |
|
387 |
} |
|
388 |
|
|
389 |
@Override |
|
390 |
public String getCodeID() { |
|
391 |
return this.codeID; |
|
392 |
} |
|
393 |
|
|
394 |
@Override |
|
395 |
public ArgsBuilder getArgsBuilder() { |
|
396 |
return this.argsBuilder; |
|
397 |
} |
|
398 |
|
|
399 |
@Override |
|
400 |
public Code build(StatementContext context) { |
|
401 |
Codes args = this.getArgsBuilder().build(context); |
|
402 |
Code code = null; |
|
403 |
if (this.getCodeID() == null) { |
|
404 |
code = args.get(0); |
|
405 |
} else { |
|
406 |
if (args.size() == 0) { |
|
407 |
code = context.getCodeBuilder().function(this.getCodeID(), null); |
|
408 |
} else { |
|
409 |
// Si es un bloque dentro de otro, dejamos solo uno. |
|
410 |
if( args.size()==1 && |
|
411 |
StringUtils.equalsIgnoreCase(CodeBlockFunction.NAME,this.getCodeID()) ) { |
|
412 |
Code code0 = args.get(0); |
|
413 |
if( code0.code() == Code.CALLER && |
|
414 |
StringUtils.equalsIgnoreCase(CodeBlockFunction.NAME,((Caller)code0).name()) |
|
415 |
) { |
|
416 |
code = code0; |
|
417 |
} |
|
418 |
} |
|
419 |
if( code == null ) { |
|
420 |
code = context.getCodeBuilder().function(this.getCodeID(), args); |
|
421 |
} |
|
422 |
} |
|
423 |
} |
|
424 |
return code; |
|
425 |
} |
|
426 |
} |
|
427 |
|
|
374 | 428 |
public DefaultStatement(String name) { |
375 | 429 |
this.rules = new ArrayList<>(); |
376 |
this.codeId = null; |
|
377 |
this.argsBuilder = null; |
|
430 |
this.stmtBuilder = null; |
|
378 | 431 |
this.name = name; |
379 | 432 |
} |
380 | 433 |
|
... | ... | |
454 | 507 |
} |
455 | 508 |
|
456 | 509 |
@Override |
457 |
public void code(String id, ArgsBuilder argsBuilder) { |
|
458 |
this.codeId = id; |
|
459 |
this.argsBuilder = argsBuilder; |
|
510 |
public void code(final String id, final ArgsBuilder argsBuilder) { |
|
511 |
this.builder(new StatementBuilderBase(id, argsBuilder)); |
|
460 | 512 |
} |
461 | 513 |
|
514 |
public void builder(StatementBuilder builder) { |
|
515 |
this.stmtBuilder = builder; |
|
516 |
} |
|
517 |
|
|
462 | 518 |
@Override |
463 | 519 |
public Code parse(StatementContext context) { |
464 | 520 |
// System.err.println("start parse "+this.getName()); |
465 | 521 |
for (Rule rule : rules) { |
466 | 522 |
rule.parse(context); |
467 | 523 |
} |
468 |
Codes args = this.argsBuilder.build(context); |
|
469 |
// System.err.println("end parse "+this.getName()+ ": "+ args.toString()); |
|
470 |
|
|
471 |
Code code; |
|
472 |
if (codeId == null) { |
|
473 |
code = args.get(0); |
|
474 |
} else { |
|
475 |
if (args.size() == 0) { |
|
476 |
code = context.getCodeBuilder().function(codeId, null); |
|
477 |
} else { |
|
478 |
code = context.getCodeBuilder().function(codeId, args); |
|
479 |
} |
|
480 |
} |
|
524 |
Code code = this.stmtBuilder.build(context); |
|
481 | 525 |
return code; |
482 | 526 |
} |
483 | 527 |
|
Also available in: Unified diff