[antlr-interest] Space in values

DELZANT Bruno (BMB) Bruno.Delzant at proximus.net
Tue Nov 23 08:40:57 PST 2004


Hi,
 
I have a small problem. I would like to parse the following text file:
 
 message BMB.JAN.PROVISIONING.REQUEST = {
  string PRIORITY = "3"
  string REQ_USER_ID = "PTS_JDA"
  string REQ_PROC_ID = "process"
  string REQUEST_DATE = "20020101"
  string PRIMARY_SUBS_ID = "004741112770000"
  string SECONDARY_SUBS_ID = "058739 21"
  message TASK = {
    string TASK_TYPE = "Add_Subscr iber"
    string IMSI = "206011000000530"
    string GSM_NUMBER = "004741112770000"
    string KI_NUMBER="BB9803224E50F02E0053BD681E0F8E88"
    string SUPP_SERV = "ADTBELADTIN4ADTSO0"
    string CUSTOMER_ACCOUNT="00003639"
  }
}

As you can see in bolded values, I have introduced spaces, and my
current grammar failed on this !
 
Here is the grammar:
 
header {
package be.belgacom.mobile.pft.generated;
}
 
class PftParser extends Parser;
{ String prefix = null; 
}
 
message
{ prefix = "- "; }
  :  "message" {System.out.println("New message");}
    ALPHA_NUM_STRING EQUAL BRACE_OPEN entries BRACE_CLOSE
  ;
  
entries
  :  (entry | task) +
  ;
 
entry
  :  "string" a:ALPHA_NUM_STRING EQUAL QUOTE b:ALPHA_NUM_STRING QUOTE 
    { System.out.println(prefix + a.getText() + " - " + b.getText()); }
  ;
 
task
  :  "message" {System.out.println("Task start detected !"); prefix =
"|-- ";}
    "TASK" EQUAL BRACE_OPEN (entry)+ BRACE_CLOSE
    { System.out.println("Task end detected !"); prefix = "- ";}
  ;
 
class PftLexer extends Lexer;
 
ALPHA_NUM_STRING
  :  ( 'a'..'z' | 'A'..'Z' | '0'..'9' | '_' | '.' )+
  ;
 
QUOTE
  :  '\"'
  ;
 
EQUAL
  :  '='
  ;  
  
BRACE_OPEN
  :  '{'
  ;  
 
BRACE_CLOSE
  :  '}'
  ;  
  
WS  :   (   ' ' 
        |   '\t'
        |   '\r' '\n' { newline(); }
        |   '\n'      { newline(); }
        )
        {$setType(Token.SKIP);}
        ;

With this grammar file, I get an error on spaces in bolded value. the
parser is expecting a double quote and not a space.
But I do not see how to solve this (I am new with antlr).
 
If someone has 2 minutes to spend helping me, I will be grateful !
 
Thanks,
Bruno
 


**** DISCLAIMER ****

"This e-mail and any attachment thereto may contain information which is confidential and/or protected by intellectual property rights and are intended for the sole use of the recipient(s) named above. This email is not intended to create or affect any contractual arrangements between the parties.
Any use of the information contained herein (including, but not limited to, total or partial reproduction, communication or distribution in any form) by other persons than the designated recipient(s) is prohibited. 
If you have received this e-mail in error, please notify the sender either by telephone or by e-mail and delete the material from any computer".

Thank you for your cooperation.

For further information about Proximus mobile phone services please see our website at http://www.proximus.be or refer to any Proximus agent.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20041123/d423aa5e/attachment.html


More information about the antlr-interest mailing list