Revision 44379

View differences:

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/function/programming/PrintFunction.java
32 32
        Object value = null;
33 33
        for (Object arg : args) {
34 34
            value = arg;
35
            System.err.print(Objects.toString(arg, ""));
35
            System.out.print(Objects.toString(arg, ""));
36 36
        }
37
        System.err.println();
37
        System.out.println();
38 38
        return value;
39 39
    }
40 40
}
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/SQLLexicalAnalyzer.java
35 35
        return other;
36 36
    }
37 37

  
38
    private void skipcomments() {
39
        if (isEOF()) {
40
            return;
41
        }
42
        char ch = getch();
43
        while( ch == '-' ) {
44
            ch = lookch();
45
            if( ch == '-' ) {
46
                while( ch != EOF && ch != '\n' ) {
47
                    ch = getch();
48
                }
49
                ungetch();
50
                skipblanks();
51
                ch = getch();
52
            }
53
        }
54
        ungetch();
55
    }
38 56
    
39 57
    @Override
40 58
    protected Token getToken() {
41 59
        skipblanks();
60
        skipcomments();
42 61
        char ch = getch();
43 62
        switch( ch ) {
44 63
        case EOF:
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/DefaultInterpreter.java
287 287
                    } catch(Exception ex2) {
288 288
                        // Ignore.
289 289
                    }
290
                    throw new ExpressionRuntimeException(code, I18N.Problems_calling_function_XIdentifierX_with_args_XargsX(function.name(),argsstr));
290
                    throw new ExpressionRuntimeException(code, I18N.Problems_calling_function_XIdentifierX_with_args_XargsX(function.name(),argsstr), ex);
291 291
                }
292 292
                break;
293 293

  
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
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) {
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/DefaultCompiler.java
16 16
import org.gvsig.expressionevaluator.impl.DefaultCodeBuilder.BaseCodes;
17 17
import org.gvsig.expressionevaluator.impl.DefaultCodeBuilder.BaseConstant;
18 18
import org.gvsig.expressionevaluator.impl.function.operator.NegOperator;
19
import org.gvsig.expressionevaluator.impl.function.programming.CodeBlockFunction;
19 20

  
20 21
public class DefaultCompiler implements Compiler {
21 22

  
......
47 48
            this.codes.put(id, code);
48 49
        }
49 50

  
51
        @Override
50 52
        public Code getCode(String id) {
51 53
            return this.codes.get(id);
52 54
        }
......
448 450
                            lexer
449 451
                        );
450 452
                    }
451
                    return codeBuilder.method(op1, id, args);
453
                    op1 = codeBuilder.method(op1, id, args);
452 454
                } else {
453
                    return codeBuilder.getattr(op1, id);
455
                    op1 = codeBuilder.getattr(op1, id);
454 456
                }
457
                break;
455 458
            default:
456 459
                return op1;
457 460
            }
......
513 516
                    }
514 517
                    return codeBuilder.function(id, args);
515 518
                } else {
519
                    if( StringUtils.equalsIgnoreCase(id, "TRUE") ) {
520
                        return codeBuilder.constant(true);
521
                    }
522
                    if( StringUtils.equalsIgnoreCase(id, "FALSE") ) {
523
                        return codeBuilder.constant(false);
524
                    }
516 525
                    return codeBuilder.identifier(id);
517 526
                }
518 527
            }
......
579 588

  
580 589
    private Code parse_grammars() {
581 590
        StatementContext context = new DefaultStatementContext();
591
        Code code;
592
        BaseCodes args = (BaseCodes) this.codeBuilder.args();
582 593
        Statement stmt = this.grammars.getApplicableStatement(context);
583
        if( stmt!=null ) {
584
            Code code1 = stmt.parse(context);
585
            return code1;
594
        while( stmt!=null ) {
595
            code = stmt.parse(context);
596
            args.add(code);
597
            stmt = this.grammars.getApplicableStatement(context);
586 598
        }
587
        return null;
599
        switch(args.size()) {
600
            case 0 :
601
                code = null;
602
                break;
603
            case 1 :
604
                code = args.get(0);
605
                break;
606
            default:
607
                code = this.codeBuilder.function(CodeBlockFunction.NAME, args);
608
                break;
609
        }
610
        return code;
588 611
    }
589 612
}
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/DefaultCodeBuilder.java
462 462
            if( formatter.canApply(this) ) {
463 463
                return formatter.format(this);
464 464
            }
465
            Code code;
465 466
            StringBuilder builder = new StringBuilder();
466 467
            switch(this.type) {
467 468
                case UNARY_OPERATOR:
......
476 477
                    break;
477 478
                case BINARY_OPERATOR:
478 479
                    builder.append("(");
479
                    builder.append(this.parameters().get(0).toString(formatter));
480
                    code = this.parameters().get(0);
481
                    if( code == null ) {                    
482
                        builder.append("?NULL?");
483
                    } else {
484
                        builder.append(code.toString(formatter));
485
                    }
480 486
                    builder.append(" ");
481 487
                    builder.append(this.name());
482 488
                    builder.append(" ");
483
                    builder.append(this.parameters().get(1).toString(formatter));
489
                    code = this.parameters().get(1);
490
                    if( code == null ) {                    
491
                        builder.append("?NULL?");
492
                    } else {
493
                        builder.append(code.toString(formatter));
494
                    }
484 495
                    builder.append(")");
485 496
                    break;
486 497
                case FUNCTION:
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/grammars/BasicGrammarFactory.java
51 51
            theGrammar.addReservedWord("TRY");
52 52
            theGrammar.addReservedWord("EXCEPT");
53 53
            
54
            stmt = theGrammar.createStatement("LET");
55
            stmt.addRule(stmt.require_any_token("LET", "SET"));
56
            stmt.addRule(stmt.require_identifier("NAME"));
57
            stmt.addRule(stmt.require_any_token("="));
58
            stmt.addRule(stmt.require_expression("VALUE"));
59
            stmt.code(
60
                    LetFunction.NAME, 
61
                    stmt.args_names("NAME", "VALUE")
62
            ); 
63
            theGrammar.addStatement(stmt);
64

  
65 54
/*
66 55
            
67 56
BEGIN
......
97 86
            stmt = theGrammar.createStatement("IF");
98 87
            stmt.addRule(stmt.require_any_token("IF"));
99 88
            stmt.addRule(stmt.require_expression("CONDITION"));
100
            stmt.addRule(stmt.optional_any_token("THEN"));
101
            stmt.addRule(stmt.optional_any_token(":"));
102
            stmt.addRule(stmt.require_expression("ONTRUE"));
89
            stmt.addRule(stmt.require_any_token("THEN", ":"));
90
            stmt.addRule(stmt.require_expressions("ONTRUE", ";"));
103 91
            stmt.addRule(stmt.optional_any_token("ELSE")
104 92
                    .addRuleOnTrue(stmt.optional_any_token(":"))
105
                    .addRuleOnTrue(stmt.require_expression("ONFALSE"))
93
                    .addRuleOnTrue(stmt.require_expressions("ONFALSE", ";"))
106 94
            );
95
            stmt.addRule(stmt.require_any_token("END"));
96
            stmt.addRule(stmt.optional_any_token("IF"));
107 97
            stmt.code(
108 98
                    IIFFunction.NAME,
109 99
                    stmt.args_names("CONDITION","ONTRUE","ONFALSE")
......
113 103
            stmt = theGrammar.createStatement("WHILE");
114 104
            stmt.addRule(stmt.require_any_token("WHILE"));
115 105
            stmt.addRule(stmt.require_expression("CONDITION"));
116
            stmt.addRule(stmt.optional_any_token("DO"));
117
            stmt.addRule(stmt.optional_any_token(":"));
118
            stmt.addRule(stmt.require_expression("BODY"));
119
            stmt.addRule(stmt.optional_any_token("DONE"));
106
            stmt.addRule(stmt.require_any_token("BEGIN", ":"));
107
            stmt.addRule(stmt.require_expressions("BODY", ";"));
108
            stmt.addRule(stmt.require_any_token("END"));
109
            stmt.addRule(stmt.optional_any_token("WHILE"));
120 110
            stmt.code(
121 111
                    WhileFunction.NAME,
122 112
                    stmt.args_names("CONDITION","BODY")
123 113
            ); 
124 114
            theGrammar.addStatement(stmt);
125 115

  
126
            stmt = theGrammar.createStatement("CAST");
127
            stmt.addRule(stmt.require_any_token("CAST"));
128
            stmt.addRule(stmt.optional_any_token("(")
129
                .addRuleOnTrue(stmt.require_expression("VALUE"))
130
                .addRuleOnTrue(stmt.require_any_token("AS"))
131
                .addRuleOnTrue(stmt.require_identifier("TYPE"))
132
                .addRuleOnTrue(stmt.require_any_token(")"))                    
133
                .addRuleOnFalse(stmt.require_expression("VALUE"))
134
                .addRuleOnFalse(stmt.require_any_token("AS"))
135
                .addRuleOnFalse(stmt.require_identifier("TYPE"))
136
            );
137
            stmt.code(
138
                    FUNCTION_CAST,
139
                    stmt.args_names("VALUE","TYPE")
140
            );
141
            theGrammar.addStatement(stmt);
142
            
143
            stmt = theGrammar.createStatement("MATCH");
144
            stmt.addRule(stmt.require_any_token("MATCH"));
145
            stmt.addRule(stmt.optional_any_token("(")
146
                .addRuleOnTrue(stmt.require_expression("VALUE"))
147
                .addRuleOnTrue(stmt.require_any_token(","))
148
                .addRuleOnTrue(stmt.require_expression("PATTERN"))
149
                .addRuleOnTrue(stmt.require_any_token(")"))                    
150
                .addRuleOnFalse(stmt.require_expression("VALUE"))
151
                .addRuleOnFalse(stmt.optional_any_token(","))
152
                .addRuleOnFalse(stmt.require_expression("PATTERN"))
153
            );
154
            stmt.code(
155
                    OPERATOR_REGEXP,
156
                    stmt.args_names("VALUE","PATTERN")
157
            );
158
            theGrammar.addStatement(stmt);
159
            
160 116
//            stmt = theGrammar.createStatement("FOR");
161 117
//            stmt.addRule(stmt.require_token("FOR"));
162 118
//            stmt.addRule(stmt.require_expression("INIT"));
......
175 131
            stmt.addRule(stmt.require_identifier("VAR"));
176 132
            stmt.addRule(stmt.require_any_token("IN"));
177 133
            stmt.addRule(stmt.require_expression("ITERABLE"));
178
            stmt.addRule(stmt.optional_any_token(":"));
179
            stmt.addRule(stmt.require_expression("BODY"));
134
            stmt.addRule(stmt.require_any_token("BEGIN", ":"));
135
            stmt.addRule(stmt.require_expressions("BODY", ";"));
136
            stmt.addRule(stmt.require_any_token("END"));
137
            stmt.addRule(stmt.optional_any_token("FOR"));
180 138
            stmt.code(
181 139
                    ForEachFunction.NAME,
182 140
                    stmt.args_names("VAR","ITERABLE","BODY")
......
188 146
            stmt.addRule(
189 147
                stmt.repeat_until_any_tokens("END","ELSE")
190 148
                    .addRule(stmt.require_any_token("WHEN"))
191
                    .addRule(stmt.require_expression("CONDITION#"))
192
                    .addRule(stmt.optional_any_token("THEN"))
193
                    .addRule(stmt.optional_any_token(":"))
194
                    .addRule(stmt.require_expression("ONTRUE#"))
149
                    .addRule(stmt.require_expressions("CONDITION#",";"))
150
                    .addRule(stmt.require_any_token("THEN",":"))
151
                    .addRule(stmt.require_expressions("ONTRUE#", ";"))
195 152
            );
196 153
            stmt.addRule(stmt.optional_any_token("ELSE")
197 154
                    .addRuleOnTrue(stmt.optional_any_token(":"))
198
                    .addRuleOnTrue(stmt.require_expression("ELSE"))
155
                    .addRuleOnTrue(stmt.require_expressions("ELSE",";"))
199 156
            );
200
            stmt.addRule(stmt.optional_any_token("END"));
157
            stmt.addRule(stmt.require_any_token("END"));
158
            stmt.addRule(stmt.optional_any_token("CASE"));
201 159
            stmt.code(
202 160
                    CaseFunction.NAME,
203 161
                    stmt.args_names("CONDITION#","ONTRUE#","ELSE")
......
205 163
            theGrammar.addStatement(stmt);
206 164
            
207 165
            stmt = theGrammar.createStatement("USERFUNCTION");
208
            stmt.addRule(stmt.require_any_token("DEF"));
166
            stmt.addRule(stmt.require_any_token("DEF", "CREATE"));
167
            stmt.addRule(stmt.optional_any_token("FUNCTION"));
209 168
            stmt.addRule(stmt.require_identifier("FUNCTION_NAME"));
210 169
            stmt.addRule(stmt.require_any_token("("));
211 170
            stmt.addRule(stmt.optional_identifiers("PARAM_NAMES", ","));
212 171
            stmt.addRule(stmt.require_any_token(")"));
213 172
            stmt.addRule(stmt.optional_any_token(":"));
214
            stmt.addRule(stmt.require_expression("BODY"));
173
            stmt.addRule(stmt.require_expressions("BODY", ";"));
174
            stmt.addRule(stmt.require_any_token("END"));
175
            stmt.addRule(stmt.optional_any_token("FUNCTION"));
215 176
            stmt.code(
216 177
                    CreateFnFunction.NAME,
217 178
                    stmt.args_names("FUNCTION_NAME","PARAM_NAMES","BODY")
......
220 181

  
221 182
            stmt = theGrammar.createStatement("RETURN");
222 183
            stmt.addRule(stmt.require_any_token("RETURN"));
223
            stmt.addRule(stmt.require_expressions("VALUES", ","));
184
            stmt.addRule(stmt.optional_any_token(";")
185
                    .addRuleOnTrue(stmt.set_expression("VALUES", null))
186
                    .addRuleOnFalse(stmt.require_expression("VALUES"))
187
                    .addRuleOnFalse(stmt.require_any_token(";"))
188
            );
224 189
            stmt.code(
225 190
                    ReturnFunction.NAME,
226 191
                    stmt.args_expand("VALUES")
......
230 195
            stmt = theGrammar.createStatement("TRY");
231 196
            stmt.addRule(stmt.require_any_token("TRY"));
232 197
            stmt.addRule(stmt.optional_any_token(":"));
233
            stmt.addRule(stmt.require_expression("VALUE"));
198
            stmt.addRule(stmt.require_expressions("VALUE", ";"));
199
            stmt.addRule(stmt.optional_any_token(";"));
234 200
            stmt.addRule(stmt.require_any_token("EXCEPT","CATH"));
235 201
            stmt.addRule(stmt.optional_any_token(":"));
236
            stmt.addRule(stmt.require_expression("ONERROR"));            
202
            stmt.addRule(stmt.require_expressions("ONERROR", ";"));
203
            stmt.addRule(stmt.optional_any_token(";"));
204
            stmt.addRule(stmt.require_any_token("END"));
205
            stmt.addRule(stmt.optional_any_token("TRY"));
237 206
            stmt.code(
238 207
                    TryFunction.NAME,
239 208
                    stmt.args_names("VALUE","ONERROR")
240 209
            ); 
241 210
            theGrammar.addStatement(stmt);
242 211

  
212
            stmt = theGrammar.createStatement("LET");
213
            stmt.addRule(stmt.require_any_token("LET", "SET"));
214
            stmt.addRule(stmt.require_identifier("NAME"));
215
            stmt.addRule(stmt.require_any_token("="));
216
            stmt.addRule(stmt.require_expression("VALUE"));
217
            stmt.code(
218
                    LetFunction.NAME, 
219
                    stmt.args_names("NAME", "VALUE")
220
            ); 
221
            theGrammar.addStatement(stmt);
222

  
223
            stmt = theGrammar.createStatement("CAST");
224
            stmt.addRule(stmt.require_any_token("CAST"));
225
            stmt.addRule(stmt.optional_any_token("(")
226
                .addRuleOnTrue(stmt.require_expression("VALUE"))
227
                .addRuleOnTrue(stmt.require_any_token("AS"))
228
                .addRuleOnTrue(stmt.require_identifier("TYPE"))
229
                .addRuleOnTrue(stmt.require_any_token(")"))                    
230
                .addRuleOnFalse(stmt.require_expression("VALUE"))
231
                .addRuleOnFalse(stmt.require_any_token("AS"))
232
                .addRuleOnFalse(stmt.require_identifier("TYPE"))
233
            );
234
            stmt.code(
235
                    FUNCTION_CAST,
236
                    stmt.args_names("VALUE","TYPE")
237
            );
238
            theGrammar.addStatement(stmt);
239
            
240
            stmt = theGrammar.createStatement("MATCH");
241
            stmt.addRule(stmt.require_any_token("MATCH"));
242
            stmt.addRule(stmt.optional_any_token("(")
243
                .addRuleOnTrue(stmt.require_expression("VALUE"))
244
                .addRuleOnTrue(stmt.require_any_token(","))
245
                .addRuleOnTrue(stmt.require_expression("PATTERN"))
246
                .addRuleOnTrue(stmt.require_any_token(")"))                    
247
                .addRuleOnFalse(stmt.require_expression("VALUE"))
248
                .addRuleOnFalse(stmt.optional_any_token(","))
249
                .addRuleOnFalse(stmt.require_expression("PATTERN"))
250
            );
251
            stmt.code(
252
                    OPERATOR_REGEXP,
253
                    stmt.args_names("VALUE","PATTERN")
254
            );
255
            theGrammar.addStatement(stmt);
256
            
243 257
//            stmt = theGrammar.createStatement("FETCHFIRST");
244 258
//            stmt.addRule(stmt.require_token("FETCH"));
245 259
//            stmt.addRule(stmt.require_token("FIRST"));
trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.expressionevaluator/org.gvsig.expressionevaluator.lib/org.gvsig.expressionevaluator.lib.impl/src/test/resources/org/gvsig/expressionevaluator/impl/TestScript1_1.txt
1

  
2
create function form_onSetvalues(form, values)
3
  return;
4
end function
5

  
6
create function form_onFieldEnter(form, field)
7
  return;
8
end function
9

  
10
create function form_onFieldExit(form, field)
11
  return;
12
end function
13

  
14
create function form_onFieldChanged(form, field)
15
  return;
16
end function
17

  
18
create function form_validate(form)
19
  return true;
20
end function
21

  
22
create function form_onLoad(form)
23
  return false;
24
end function
25

  
26
create function form_clear(form)
27
  return;
28
end function
29

  
30
create function form_isReadOnly(form)
31
    if not user().isAuthenticated() then
32
      return true;
33
    end if
34
    return false;
35
    -- set fecha_accidente = form.getField('FECHA_ACCIDENTE').getValue();
36
    -- if fecha_accidente = null then
37
    --   return false;
38
    -- end if
39
    -- set fecha_de_cierre = application().getProperty('CEGESEV.accidentes.fecha_de_cierre');
40
    -- if fecha_de_cierre = null then
41
    --   return true;
42
    -- end if
43
    -- return Date(fecha_de_cierre) > Date(fecha_accidente);
44
end function
trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.expressionevaluator/org.gvsig.expressionevaluator.lib/org.gvsig.expressionevaluator.lib.impl/src/test/resources/org/gvsig/expressionevaluator/impl/TestScript1_2.txt
1

  
2
CREATE FUNCTION test1()
3
    SET x = ''; 
4
    FOR n IN LIST('hola','adios','fin'):
5
        SET x = x || ' ' || n; 
6
    END FOR
7
    RETURN x;
8
END FUNCTION
9
  
10
CREATE FUNCTION test2()
11
    SET s = ''; 
12
    SET x = LIST('hola','adios','fin'); 
13
    FOR n IN RANGE(3):
14
        SET s = s || ' ' || x[n]; 
15
    END FOR
16
    RETURN s;
17
END FUNCTION
trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.expressionevaluator/org.gvsig.expressionevaluator.lib/org.gvsig.expressionevaluator.lib.impl/src/test/java/org/gvsig/expresionevaluator/impl/TestScript1.java
1
package org.gvsig.expresionevaluator.impl;
2

  
3
import java.io.InputStream;
4
import junit.framework.TestCase;
5
import org.apache.commons.io.IOUtils;
6
import org.apache.commons.lang3.StringUtils;
7
import org.gvsig.expressionevaluator.Expression;
8
import org.gvsig.expressionevaluator.ExpressionEvaluatorLocator;
9
import org.gvsig.expressionevaluator.ExpressionEvaluatorManager;
10
import org.gvsig.tools.library.impl.DefaultLibrariesInitializer;
11
import org.gvsig.tools.script.Script;
12

  
13
public class TestScript1 extends TestCase {
14

  
15
    public TestScript1(String testName) {
16
        super(testName);
17
    }
18

  
19
    @Override
20
    protected void setUp() throws Exception {
21
        super.setUp();
22
        new DefaultLibrariesInitializer().fullInitialize();
23
    }
24

  
25
    @Override
26
    protected void tearDown() throws Exception {
27
        super.tearDown();
28
    }
29

  
30
    // TODO add test methods here. The name must begin with 'test'. For example:
31
    // public void testHello() {}
32
    public void testScript1() throws Exception {
33
        InputStream is = this.getClass().getResource("/org/gvsig/expressionevaluator/impl/TestScript1_1.txt").openStream();
34
        String source = StringUtils.join(IOUtils.readLines(is), "\n");
35
        ExpressionEvaluatorManager manager = ExpressionEvaluatorLocator.getManager();
36

  
37
        Object r;
38
        Script sc;
39
        try {
40
            sc = manager.createScript("test1", source, "COSA");
41
        } catch(Exception ex) {
42
            System.err.println(ex.getMessage());
43
            throw ex;
44
        }
45
        r = sc.invokeFunction("form_validate", new Object[]{"form"});
46
        assertEquals(true, r);
47

  
48
        r = sc.invokeFunction("form_isReadOnly", new Object[]{"form"});
49
        assertEquals(false, r);
50
    }
51

  
52
    public void testScript2() throws Exception {
53
        InputStream is = this.getClass().getResource("/org/gvsig/expressionevaluator/impl/TestScript1_2.txt").openStream();
54
        String source = StringUtils.join(IOUtils.readLines(is), "\n");
55
        ExpressionEvaluatorManager manager = ExpressionEvaluatorLocator.getManager();
56

  
57
        Object r;
58
        Script sc;
59
        try {
60
            sc = manager.createScript("test2", source, "COSA");
61
        } catch(Exception ex) {
62
            System.err.println(ex.getMessage());
63
            throw ex;
64
        }
65
        r = sc.invokeFunction("test1", null);
66
        assertEquals(" hola adios fin", r);
67

  
68
        r = sc.invokeFunction("test2", null);
69
        assertEquals(" hola adios fin", r);
70
        
71
        }
72
}
trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.expressionevaluator/org.gvsig.expressionevaluator.lib/org.gvsig.expressionevaluator.lib.impl/src/test/java/org/gvsig/expresionevaluator/impl/TestGrammarInterpreter.java
108 108
        Interpreter interpreter = createInterpreter(symbolTable);
109 109

  
110 110
        symbolTable.setVar("V1", 10);
111
        String source = "IF V1 = 11 THEN SET V2 = 22";
111
        String source = "IF V1 = 11 THEN SET V2 = 22; END IF";
112 112
        Code code = compiler.compileExpression(source);
113 113
        Object v = interpreter.run(code);
114 114

  
......
117 117
        assertEquals(null, symbolTable.value("V2"));
118 118

  
119 119
        symbolTable.setVar("V1", 11);
120
        source = "IF V1 = 11 THEN SET V2 = 22";
120
        source = "IF V1 = 11 THEN SET V2 = 22; END IF";
121 121
        code = compiler.compileExpression(source);
122 122
        v = interpreter.run(code);
123 123

  
......
132 132
        Interpreter interpreter = createInterpreter(symbolTable);
133 133

  
134 134
        symbolTable.setVar("V1", 10);
135
        String source = "IF V1 = 11 THEN SET V2 = 11 ELSE SET V2 = 22";
135
        String source = "IF V1 = 11 THEN SET V2 = 11; ELSE SET V2 = 22; END IF";
136 136
        Code code = compiler.compileExpression(source);
137 137
        Object v = interpreter.run(code);
138 138

  
......
147 147
        Interpreter interpreter = createInterpreter(symbolTable);
148 148

  
149 149
        symbolTable.setVar("V1", 11);
150
        String source = "IF V1 = 11 THEN BEGIN LET V2 = 22; LET V1 = 10 END";
150
        String source = "IF V1 = 11 THEN LET V2 = 22; LET V1 = 10; END IF";
151 151
        Code code = compiler.compileExpression(source);
152 152
        Object v = interpreter.run(code);
153 153

  
......
162 162
        Interpreter interpreter = createInterpreter(symbolTable);
163 163

  
164 164
        symbolTable.setVar("n",0);
165
        String source = "WHILE n < 10 SET n = n + 1";
165
        String source = "WHILE n < 10 BEGIN SET n = n + 1; END WHILE";
166 166
        Code code = compiler.compileExpression(source);
167 167
        Object v = interpreter.run(code);
168 168

  
......
221 221
        Compiler compiler = createCompiler();
222 222
        Interpreter interpreter = createInterpreter(symbolTable);
223 223

  
224
        String source = "FOR n in RANGE(10) print(n)";
224
        String source = "FOR n in RANGE(10) BEGIN print(n); END FOR";
225 225
        Code code = compiler.compileExpression(source);
226 226
        Object v = interpreter.run(code);
227 227

  
......
282 282
        Compiler compiler = createCompiler();
283 283
        Interpreter interpreter = createInterpreter(symbolTable);
284 284

  
285
        String source = "DEF test1() 'Hola'"; 
285
        String source = "CREATE FUNCTION test1() RETURN 'Hola'; END FUNCTION"; 
286 286
        Code code = compiler.compileExpression(source);
287 287
        Object v = interpreter.run(code);
288 288

  
......
298 298
        Compiler compiler = createCompiler();
299 299
        Interpreter interpreter = createInterpreter(symbolTable);
300 300

  
301
        String source = "DEF test1(nombre) 'Hola ' || nombre";
301
        String source = "CREATE FUNCTION test1(nombre) RETURN 'Hola ' || nombre; END FUNCTION";
302 302
        Code code = compiler.compileExpression(source);
303 303
        Object v = interpreter.run(code);
304 304

  
......
314 314
        Compiler compiler = createCompiler();
315 315
        Interpreter interpreter = createInterpreter(symbolTable);
316 316

  
317
        String source = "DEF test1(nombre) BEGIN RETURN 'Hola ' || nombre END";
317
        String source = "CREATE FUNCTION test1(nombre) RETURN 'Hola ' || nombre; END FUNCTION";
318 318
        Code code = compiler.compileExpression(source);
319 319
        Object v = interpreter.run(code);
320 320

  
......
330 330
        Compiler compiler = createCompiler();
331 331
        Interpreter interpreter = createInterpreter(symbolTable);
332 332

  
333
        String source = "DEF test1(nombre) BEGIN RETURN 'Hola ' || nombre; 'Oh!...'; END";
333
        String source = "CREATE FUNCTION test1(nombre) RETURN 'Hola ' || nombre; END FUNCTION";
334 334
        Code code = compiler.compileExpression(source);
335 335
        Object v = interpreter.run(code);
336 336

  
......
346 346
        Compiler compiler = createCompiler();
347 347
        Interpreter interpreter = createInterpreter(symbolTable);
348 348

  
349
        String source = "begin set x = ''; for n in list('hola','adios','fin'): let x = x || ' ' || n end";
349
        String source = "begin set x = ''; for n in list('hola','adios','fin'): let x = x || ' ' || n; end for; end";
350 350
        Code code = compiler.compileExpression(source);
351 351
        Object v = interpreter.run(code);
352 352

  
......
358 358
        Compiler compiler = createCompiler();
359 359
        Interpreter interpreter = createInterpreter(symbolTable);
360 360

  
361
        String source = "begin set s = ''; set x = LIST('hola','adios','fin'); FOR n in RANGE(3): set s = s || ' ' || x[n] end";
361
        String source = "begin set s = ''; set x = LIST('hola','adios','fin'); FOR n in RANGE(3): set s = s || ' ' || x[n]; end for; end";
362 362
        Code code = compiler.compileExpression(source);
363 363
        Object v = interpreter.run(code);
364 364

  
trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.expressionevaluator/org.gvsig.expressionevaluator.lib/org.gvsig.expressionevaluator.lib.impl/src/test/java/org/gvsig/expresionevaluator/impl/TestGrammarCompiler.java
1 1
package org.gvsig.expresionevaluator.impl;
2 2

  
3
import static junit.framework.Assert.assertEquals;
4 3
import junit.framework.TestCase;
5 4
import org.gvsig.expressionevaluator.Code;
6 5
import org.gvsig.expressionevaluator.ExpressionEvaluatorLocator;
......
74 73
    }
75 74

  
76 75
    public void testBlock() {
77
        String source = "BEGIN LET V1 = 23 END";
76
        String source = "BEGIN LET V1 = 23; END";
78 77

  
79 78
        Compiler compiler = createCompiler();
80 79

  
......
83 82
    }
84 83

  
85 84
    public void testBlock2() {
86
        String source = "BEGIN LET V1 = 11; LET V2 = 22  END";
85
        String source = "BEGIN LET V1 = 11; LET V2 = 22;  END";
87 86

  
88 87
        Compiler compiler = createCompiler();
89 88

  
......
104 103
    }
105 104

  
106 105
    public void testIfThen() {
107
        String source = "IF V1 = 11 THEN LET V2 = 22";
106
        String source = "IF V1 = 11 THEN LET V2 = 22; END IF";
108 107

  
109 108
        Compiler compiler = createCompiler();
110 109

  
......
112 111
        assertEquals("IFF((\"V1\" = 11), LET('V2', 22))", code.toString());
113 112
    }
114 113

  
115
    public void testIfThen2() {
116
        String source = "IF V1 = 11 LET V2 = 22";
117

  
118
        Compiler compiler = createCompiler();
119

  
120
        Code code = compiler.compileExpression(source);
121
        assertEquals("IFF((\"V1\" = 11), LET('V2', 22))", code.toString());
122
    }
123

  
124
    public void testIfThen3() {
125
        String source = "IF V1 = 11: LET V2 = 22";
126

  
127
        Compiler compiler = createCompiler();
128

  
129
        Code code = compiler.compileExpression(source);
130
        assertEquals("IFF((\"V1\" = 11), LET('V2', 22))", code.toString());
131
    }
132

  
133 114
    public void testIfThenElse() {
134
        String source = "IF V1 = 11 THEN LET V2 = 11 ELSE LET V2 = 22";
115
        String source = "IF V1 = 11 THEN LET V2 = 11; ELSE LET V2 = 22; END IF";
135 116

  
136 117
        Compiler compiler = createCompiler();
137 118

  
......
140 121
    }
141 122

  
142 123
    public void testIfThenBlock() {
143
        String source = "IF V1 = 11 THEN BEGIN LET V2 = 22; LET V1 = 10 END";
124
        String source = "IF V1 = 11 THEN LET V2 = 22; LET V1 = 10; END IF";
144 125

  
145 126
        Compiler compiler = createCompiler();
146 127

  
......
149 130
    }
150 131

  
151 132
    public void testWhile() {
152
        String source = "WHILE n < 10 LET n = n + 1";
133
        String source = "WHILE n < 10 BEGIN LET n = n + 1; END WHILE";
153 134

  
154 135
        Compiler compiler = createCompiler();
155 136

  
......
158 139
    }
159 140

  
160 141
    public void testWhileBlock() {
161
        String source = "WHILE n < 10 BEGIN LET n = n + 1; print(n) END";
142
        String source = "WHILE n < 10 BEGIN LET n = n + 1; print(n); END WHILE";
162 143

  
163 144
        Compiler compiler = createCompiler();
164 145

  
......
203 184
    }
204 185

  
205 186
    public void testForEach() {
206
        String source = "FOR n in RANGE(10) print(n)";
187
        String source = "FOR n in RANGE(10): print(n); END FOR";
207 188

  
208 189
        Compiler compiler = createCompiler();
209 190

  
......
221 202
//    }
222 203

  
223 204
    public void testCase() {
224
        String source = "CASE WHEN software LIKE '%gvSIG%' THEN 'gvSIG' ELSE 'Other' END"; // ;)
205
        String source = "CASE WHEN software LIKE '%gvSIG%' THEN 'gvSIG'; ELSE 'Other'; END CASE"; // ;)
225 206

  
226 207
        Compiler compiler = createCompiler();
227 208

  
......
230 211
    }
231 212

  
232 213
    public void testCase1() {
233
        String source = "CASE WHEN software LIKE '%gvSIG%' THEN 'gvSIG' ELSE 'Other'"; // ;)
214
        String source = "CASE WHEN software LIKE '%gvSIG%' THEN 'gvSIG'; ELSE 'Other'; END CASE"; // ;)
234 215

  
235 216
        Compiler compiler = createCompiler();
236 217

  
......
239 220
    }
240 221

  
241 222
    public void testCase2() {
242
        String source = "CASE WHEN Field_1 >= 75 AND Field_1 <=79 THEN 100 WHEN Field_1 >=80 AND Field_1 <=84 THEN 110 END"; // ;)
223
        String source = "CASE WHEN Field_1 >= 75 AND Field_1 <=79 THEN 100; WHEN Field_1 >=80 AND Field_1 <=84 THEN 110; END CASE"; // ;)
243 224

  
244 225
        Compiler compiler = createCompiler();
245 226

  
......
248 229
    }
249 230
    
250 231
    public void testCase3() {
251
        String source = "CASE WHEN Field_1 >= 75 AND Field_1 <=79 THEN 100 WHEN Field_1 >=80 AND Field_1 <=84 THEN 110 ELSE 120 END"; // ;)
232
        String source = "CASE WHEN Field_1 >= 75 AND Field_1 <=79 THEN 100; WHEN Field_1 >=80 AND Field_1 <=84 THEN 110; ELSE 120; END CASE"; // ;)
252 233

  
253 234
        Compiler compiler = createCompiler();
254 235

  
......
257 238
    }
258 239
    
259 240
    public void testDef1() {
260
        String source = "DEF test1() print('Hola')"; 
241
        String source = "CREATE FUNCTION test1() print('Hola'); END FUNCTION"; 
261 242

  
262 243
        Compiler compiler = createCompiler();
263 244

  
......
266 247
    }
267 248
    
268 249
    public void testDef2() {
269
        String source = "DEF test1(nombre) print('Hola '+nombre)";
250
        String source = "CREATE FUNCTION test1(nombre) print('Hola '+nombre); END FUNCTION";
270 251

  
271 252
        Compiler compiler = createCompiler();
272 253

  
......
275 256
    }
276 257

  
277 258
    public void testDef3() {
278
        String source = "DEF test1(nombre) BEGIN RETURN 'Hola '||nombre END";
259
        String source = "CREATE FUNCTION test1(nombre) RETURN 'Hola '||nombre; END FUNCTION";
279 260

  
280 261
        Compiler compiler = createCompiler();
281 262

  
282 263
        Code code = compiler.compileExpression(source);
283
        assertEquals("CREATE_FUNCTION('test1', LIST('nombre'), BLOCK(RETURN(('Hola ' || \"nombre\"))))", code.toString());
264
        assertEquals("CREATE_FUNCTION('test1', LIST('nombre'), RETURN(('Hola ' || \"nombre\")))", code.toString());
284 265
    }
285 266

  
286 267
    public void testUseCase1() {
287
        String source = "begin set x = ''; for n in list('hola','adios','fin'): let x = x || ' ' || n end";
268
        String source = "begin set x = ''; for n in list('hola','adios','fin'): let x = x || ' ' || n; end for; end";
288 269

  
289 270
        Compiler compiler = createCompiler();
290 271

  
......
293 274
    }
294 275

  
295 276
    public void testUseCase2() {
296
        String source = "begin set s = ''; set x = LIST('hola','adios','fin'); FOR n in RANGE(3): set s = s || ' ' || x[n] end";
277
        String source = "begin set s = ''; set x = LIST('hola','adios','fin'); FOR n in RANGE(3): set s = s || ' ' || x[n]; end for; end";
297 278

  
298 279
        Compiler compiler = createCompiler();
299 280

  
trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.expressionevaluator/org.gvsig.expressionevaluator.lib/org.gvsig.expressionevaluator.lib.api/src/main/java/org/gvsig/expressionevaluator/spi/AbstractLexicalAnalyzer.java
60 60
            return literal;
61 61
        }
62 62

  
63
        @Override
63 64
        public void setLiteral(String literal) {
64 65
            this.literal = literal;
65 66
        }
......
130 131
    private Stack<Integer> states;
131 132
    private String source;
132 133
    private int position;
134
    private int lineno;
135
    private int column;
133 136

  
134 137
    protected Buffer buffer;
135 138
    protected Token token;
......
213 216
    public int getPosition() {
214 217
        return position;
215 218
    }
219
    
220
    private void calcualteLineAndColumn() {
221
        final String s = this.source;
222
        int max = s.length();
223
        if( max > this.position ) {
224
            max = this.position;
225
        }
226
        int line = 1;
227
        int col = 0;
228
        for (int i = 0; i < max ; i++) {
229
            if( s.charAt(i)=='\n' ) {
230
                line++;
231
                col = 0;
232
            } 
233
            col++;
234
        }
235
        this.lineno = line;
236
        this.column = col;
237
    }
216 238

  
239
    @Override
240
    public int getLine() {
241
        this.calcualteLineAndColumn();
242
        return lineno;
243
    }
244

  
245
    @Override
246
    public int getColumn() {
247
        this.calcualteLineAndColumn();
248
        return column;
249
    }
250

  
251
    @Override
217 252
    public boolean isEOF() {
218 253
        return this.position >= this.source.length();
219 254
    }
......
240 275
        if (this.position >= this.source.length()) {
241 276
            return EOF;
242 277
        }
278
        this.column++;
243 279
        return this.source.charAt(this.position++);
244 280
    }
245 281

  
......
248 284
        if (this.position < 0) {
249 285
            this.position = 0;
250 286
        }
287
        this.column--;
288
        if (this.column < 0) {
289
            this.column = 0;
290
        }
251 291
    }
252 292

  
253 293
    protected void parseString() {
......
295 335
        }
296 336
    }
297 337
    
338
    @Override
298 339
    public void setUseBracketsForIdentifiers(boolean useBracketsForIdentifiers) {
299 340
        this.useBracketsForIdentifiers = useBracketsForIdentifiers;
300 341
    }
301 342
    
343
    @Override
302 344
    public boolean getUseBracketsForIdentifiers() {
303 345
        return this.useBracketsForIdentifiers;
304 346
    }
trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.expressionevaluator/org.gvsig.expressionevaluator.lib/org.gvsig.expressionevaluator.lib.api/src/main/java/org/gvsig/expressionevaluator/ExpressionSyntaxException.java
1 1
package org.gvsig.expressionevaluator;
2 2

  
3
import org.apache.commons.lang3.StringUtils;
4

  
3 5
/**
4 6
 *
5 7
 * @author jjdelcerro
......
7 9
public class ExpressionSyntaxException extends RuntimeException {
8 10

  
9 11
    private final int position;
12
    private final int line;
13
    private final int column;
10 14
    private final String phrase;
11 15
    private final String description;
12 16
    private String tip;
......
15 19
        super("Syntax error in expression.");
16 20
        this.phrase = null;
17 21
        this.position = -1;
22
        this.line = -1;
23
        this.column = -1;
18 24
        this.description = I18N.Syntax_error_in_expression();
19 25
        this.tip = null;
20 26
    }
21 27
    
22 28
    public ExpressionSyntaxException(LexicalAnalyzer lexer) {
23
        super("Syntax error in '"+lexer.getSource()+"' near character "+ lexer.getPosition()+".");
29
        super("Syntax error in '"+getSource(lexer.getSource(), lexer.getPosition())+"' near character "+ lexer.getPosition()+" ("+lexer.getLine()+":"+lexer.getColumn()+").");
24 30
        this.phrase = lexer.getSource();
25 31
        this.position = lexer.getPosition();
32
        this.line = lexer.getLine();
33
        this.column = lexer.getColumn();
26 34
        this.description = I18N.Syntax_error_near_character_XPositionX(position);
27 35
    }
28 36
    
29 37
    public ExpressionSyntaxException(String msg, LexicalAnalyzer lexer) {
30
        super("Syntax error in '"+lexer.getSource()+"' near character "+ lexer.getPosition()+". "+msg);
38
        super("Syntax error in '"+getSource(lexer.getSource(), lexer.getPosition()) +"' near character "+ lexer.getPosition()+" ("+lexer.getLine()+":"+lexer.getColumn()+"). "+msg);
31 39
        this.phrase = lexer.getSource();
32 40
        this.position = lexer.getPosition();
41
        this.line = lexer.getLine();
42
        this.column = lexer.getColumn();
33 43
        this.description = I18N.Syntax_error_near_character_XPositionX(position)+ " "+msg;
34 44
    }
35 45

  
......
39 49
    }
40 50
    
41 51
    public ExpressionSyntaxException(String phrase, int position) {
42
        super("Syntax error in '"+phrase+"' near character "+ position+".");
52
        super("Syntax error in '"+getSource(phrase, position) +"' near character "+ position+".");
43 53
        this.phrase = phrase;
44 54
        this.position = position;
55
        this.line = -1;
56
        this.column = -1;
45 57
        this.description = I18N.Syntax_error_near_character_XPositionX(position);
46 58
    }
47 59
    
48 60
    public ExpressionSyntaxException(String msg, String phrase, int position) {
49
        super("Syntax error in '"+phrase+"' near character "+ position+". "+msg);
61
        super("Syntax error in '"+ getSource(phrase, position) +"' near character "+ position+". "+msg);
50 62
        this.phrase = phrase;
51 63
        this.position = position;
64
        this.line = -1;
65
        this.column = -1;
52 66
        this.description = I18N.Syntax_error_near_character_XPositionX(position)+" "+msg;
53 67
    }
54 68
    
69
    private static String getSource(String source, int position) {
70
        String s = StringUtils.left(source, position) + "[*]" + StringUtils.mid(source, position, 200);
71
        if( s.length()>200 ) {
72
            s = "..."+StringUtils.mid(s, position-100, 200)+"...";
73
        }
74
        return s;
75
    }
76
    
55 77
    public String getPhrase() {
56 78
        return this.phrase;
57 79
    }
......
60 82
        return this.position;
61 83
    }
62 84
    
85
    public int getLine() {
86
        return this.line;
87
    }
88
    
89
    public int getColumn() {
90
        return this.column;
91
    }
92
    
63 93
    public String getDescription() {
64 94
        return this.description;
65 95
    }
trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.expressionevaluator/org.gvsig.expressionevaluator.lib/org.gvsig.expressionevaluator.lib.api/src/main/java/org/gvsig/expressionevaluator/LexicalAnalyzer.java
77 77
    
78 78
    public int getPosition(); 
79 79
    
80
    public int getLine();
81
    
82
    public int getColumn();
83
    
80 84
    public String getSource();
81 85
    
82 86
    public void setUseBracketsForIdentifiers(boolean useBracketsForIdentifiers);
trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.expressionevaluator/org.gvsig.expressionevaluator.lib/org.gvsig.expressionevaluator.lib.api/src/main/java/org/gvsig/expressionevaluator/Statement.java
64 64

  
65 65
    public Rule require_identifier(String id);
66 66

  
67
    public Rule set_expression(String id, Object value);
68

  
67 69
    public Rule require_expression(String id);
68 70

  
69 71
    public Rule require_expressions(String id, String separator);

Also available in: Unified diff