[ragel-users] Ragel compilation hangs

Petru Severin petru.severin at gmail.com
Fri Oct 21 02:34:01 UTC 2011


Hi,

I am trying to create a Ragel parser for SVG Path syntax. I lifted the 
grammar from SVG specification and adapted it to be compatible with 
Ragel. When I try to compile it, Ragel just hangs instead of finishing 
immediately like it usually does. I understand that the machine might 
need adjustments but it's difficult to guess what's wrong.

I'd like to get an advice from more experienced Ragel users.

Here's the machine for SVG path:

%%{
	machine PathParser;

	wsp = (" " | 9 | 13 | 10);
	digit_sequence = digit+;
	sign = "+" | "-";
	exponent = ( "e" | "E" ) sign? digit_sequence;
	fractional_constant = digit_sequence? "." digit_sequence | 
digit_sequence ".";
	floating_point_constant = fractional_constant exponent?  | 
digit_sequence exponent;
	integer_constant = digit_sequence;
	comma = ",";
	comma_wsp = (wsp+ comma? wsp*) | (comma wsp*);
	flag = "0" | "1";
	number = sign? integer_constant | sign? floating_point_constant;
	nonnegative_number = integer_constant | floating_point_constant;
	coordinate = number;
	coordinate_pair = coordinate comma_wsp? coordinate;
	elliptical_arc_argument = nonnegative_number comma_wsp? 
nonnegative_number comma_wsp?  number comma_wsp flag comma_wsp? flag 
comma_wsp? coordinate_pair;
	elliptical_arc_argument_sequence = elliptical_arc_argument (comma_wsp? 
elliptical_arc_argument)*;
	elliptical_arc = ( "A" | "a" ) wsp* elliptical_arc_argument_sequence;
	smooth_quadratic_bezier_curveto_argument_sequence = coordinate_pair 
(comma_wsp? coordinate_pair)*;
	smooth_quadratic_bezier_curveto = ( "T" | "t" ) wsp* 
smooth_quadratic_bezier_curveto_argument_sequence;
	quadratic_bezier_curveto_argument = coordinate_pair comma_wsp? 
coordinate_pair;
	quadratic_bezier_curveto_argument_sequence = 
quadratic_bezier_curveto_argument (comma_wsp? 
quadratic_bezier_curveto_argument)*;
	quadratic_bezier_curveto = ( "Q" | "q" ) wsp* 
quadratic_bezier_curveto_argument_sequence;
	smooth_curveto_argument = coordinate_pair comma_wsp? coordinate_pair;
	smooth_curveto_argument_sequence = smooth_curveto_argument (comma_wsp? 
smooth_curveto_argument)*;
	smooth_curveto = ( "S" | "s" ) wsp* smooth_curveto_argument_sequence;
	curveto_argument = coordinate_pair comma_wsp? coordinate_pair 
comma_wsp? coordinate_pair;
	curveto_argument_sequence = curveto_argument (comma_wsp? 
curveto_argument)*;
	curveto = ( "C" | "c" ) wsp* curveto_argument_sequence;
	vertical_lineto_argument_sequence = coordinate (comma_wsp? coordinate)*;
	vertical_lineto = ( "V" | "v" ) wsp* vertical_lineto_argument_sequence;
	horizontal_lineto_argument_sequence = coordinate (comma_wsp? coordinate)*;
	horizontal_lineto = ( "H" | "h" ) wsp* horizontal_lineto_argument_sequence;
	lineto_argument_sequence = coordinate_pair (comma_wsp? coordinate_pair)*;
	lineto = ( "L" | "l" ) wsp* lineto_argument_sequence;
	closepath = ("Z" | "z");
	moveto_argument_sequence = coordinate_pair | coordinate_pair comma_wsp? 
lineto_argument_sequence;
	moveto = ( "M" | "m" ) wsp* moveto_argument_sequence;
	drawto_command = closepath | lineto | horizontal_lineto | 
vertical_lineto | curveto | smooth_curveto | quadratic_bezier_curveto | 
smooth_quadratic_bezier_curveto | elliptical_arc;
	drawto_commands = drawto_command (wsp* drawto_command)*;
	moveto_drawto_command_group = moveto wsp* drawto_commands?;
	moveto_drawto_command_groups = moveto_drawto_command_group (wsp* 
moveto_drawto_command_group)*;
	svg_path := wsp* moveto_drawto_command_groups? wsp*;
}%%

package com.wireframesketcher.ui.svg.parser;

class PathParser
{	
%% write data;

	public void parse(String string)
	{
		int cs;
		int p;
		int pe;
		int eof;
		char[] data;
		int ts;
		int act;
		int te;
	
%% write init;

		data = string.toCharArray();
		p = 0;
		pe = string.length();
		eof = pe;
		
%% write exec;
	}
}

_______________________________________________
ragel-users mailing list
ragel-users at complang.org
http://www.complang.org/mailman/listinfo/ragel-users



More information about the ragel-users mailing list