[antlr-interest] Antlr 3.0b6 - problem with '!' operator ? Or did I miss something...

David CROSSON david.crosson at wanadoo.fr
Thu Feb 8 07:10:22 PST 2007


Hi,

I can't achieve to make the operator '!' working in order to change text returned by a rule.
In the following test grammar and test unit, I'm using the string "32 secs" as input and I expect
to get the string "32" but this not the case I got "32 secs".

-----------------------------------
grammar Debug;
options {
    filter=false;
    output=AST;
}
@header {
  package logparser.parsers;
}
@lexer::header {
  package logparser.parsers;
}
duration returns [String value] :
    ts=timestamp
    {$duration.value = $ts.text;}
    ;
timestamp :
    INT 'secs'!
    ;
INT :
    ('0'..'9')+
    ;
WS :
    ' '+ {$channel=HIDDEN;}
    ;

-----------------------------------
And the test unit :

package logparser.test;

import junit.framework.*;
import logparser.parsers.DebugLexer;
import org.antlr.runtime.ANTLRStringStream;
import org.antlr.runtime.CharStream;
import org.antlr.runtime.CommonTokenStream;
import logparser.parsers.DebugParser;

public class DebugTest extends TestCase {
    public DebugTest(String testName) {super(testName);}
    protected void setUp() throws Exception {}
    protected void tearDown() throws Exception {}
    
    public void testDebug() throws Exception {
        CharStream in = new ANTLRStringStream("32 secs");
        DebugLexer lexer = new DebugLexer(in);
        CommonTokenStream tokens = new CommonTokenStream(lexer);
        DebugParser parser = new DebugParser(tokens);
        String value = parser.duration().value;
        assertTrue("ERR returned value : '" + value+"'","32".equals(value));
    }
}
-----------------------------------
Thanks for all,
David Crosson.





More information about the antlr-interest mailing list