Avoiding second or further occurances of a token as separator

19 views
Skip to first unread message

Amrit Atmajit

unread,
Aug 20, 2015, 5:36:45 AM8/20/15
to antlr-discussion
Hi, 

I am parsing a log file using ANTLR grammar which contains key-value pairs those are separated by a delimiter (COLON ':').
So, in the rule I have specified COLON as delimiter/separator. 
But, the problem I am facing is, if the value in key-value pair contains the COLON then it is considering the same as separator which I don't want.
I want the COLON available in value should be considered.

Below is the sample format of file pattern that is to be parsed.
===================================================
          Sequential Read :   404.309 MB/s
          Sequential Write :   183.446 MB/s
         Random Read 512KB :   169.463 MB/s
        Random Write 512KB :   180.138 MB/s
    Random Read 4KB (QD=1) :    20.800 MB/s [  5078.1 IOPS]
   Random Write 4KB (QD=1) :    48.432 MB/s [ 11824.2 IOPS]
   Random Read 4KB (QD=32) :    26.155 MB/s [  6385.4 IOPS]
  Random Write 4KB (QD=32) :   111.335 MB/s [ 27181.5 IOPS]
                                     Test : 4000 MB [C: 40.8% (48.5/118.9 GB)] (x5)
                                     Date : 2015/02/11 6:23:47
                                       OS : Windows 8 Professional [6.2 Build 9200] (x64)
====================================================

Above the highlighted value in the key-value pair contains COLON  which is considered as a separator.

Please find the grammar file and java file that I have created is attached with this post. Please correct me if I have done any mistakes.

I am new to ANTLR and need some valuable suggestions for mentioned issue.

Thanks
Amrit
DelimSepareated.g4
TestTextMain.java

Jim Idle

unread,
Aug 20, 2015, 7:30:49 AM8/20/15
to antlr-discussion
If you can change the format then change it but otherwiseet your parser rule should allow the COLON token and append them. Or use lexer Modes. Or if it cannot occur at the start of a value just eat it in the value token. 

But I think you are making life difficult for yourself - you don't need ANTLR for this. 


_____________________________
From: Amrit Atmajit <amrit....@gmail.com>
Sent: Thursday, August 20, 2015 17:36
Subject: [antlr-discussion] Avoiding second or further occurances of a token as separator
To: antlr-discussion <antlr-di...@googlegroups.com>
--
You received this message because you are subscribed to the Google Groups "antlr-discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to antlr-discussi...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Reply all
Reply to author
Forward
0 new messages