[antlr-interest] Reading a string of fixed size

Alexandre Hamez alexandre.hamez at lip6.fr
Mon Aug 27 00:33:26 PDT 2007


Hi everybody,

	I need to read a string of a fixed size. For example : '5:abcde'.  
The size of the string to be read is given by the number before the  
':'. So I've written the following:

CAMI_STRING
	:
	NUMBER ':'
	{
		// Get the current position in stream
		int start  = input.getCharPositionInLine();
		// Computing the position of the last character of the STRING to be  
read
		int end = start + Integer.parseInt($NUMBER.text) - 1;
		// Set the value of the returned value to STRING
		setText(input.substring(start,end));
		// Update the position in the stream
		input.seek(end+1);
	}
	;
	
NUMBER	
	: 	
	'0'..'9'+
	;


It works quite well until the string to be read contains a number  
itself. Have you an idea on this problem? Thanks for you help!


------------------------------------------------------------------------ 
---
Alexandre Hamez   LIP6 - MoVe / EPITA - LRDE
LIP6: tel: +33 1 44 27 31 92  / Bureau 818
104 Avenue du Président Kennedy 75016 Paris
http://www-src.lip6.fr/~Alexandre.Hamez


-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 2429 bytes
Desc: not available
Url : http://www.antlr.org/pipermail/antlr-interest/attachments/20070827/0060e9aa/attachment.bin 


More information about the antlr-interest mailing list