Skip to content

Instantly share code, notes, and snippets.

@mravey
Created May 4, 2012 12:42
Show Gist options
  • Save mravey/2594591 to your computer and use it in GitHub Desktop.
Save mravey/2594591 to your computer and use it in GitHub Desktop.
SVG Path Parser
Conflict in grammar: multiple actions possible when lookahead token is DOT in state 25
- reduce by rule: integer_constant -> digit_sequence
- shift token (then go to state 42)
Conflict in grammar: multiple actions possible when lookahead token is DIGIT in state 27
- reduce by rule: digit_sequence -> DIGIT
- shift token (then go to state 27)
Conflict in grammar: multiple actions possible when lookahead token is DIGIT in state 42
- reduce by rule: fractional_constant -> digit_sequence DOT
- shift token (then go to state 27)
States with conflicts:
State 25
integer_constant -> digit_sequence . #lookaheads= DIGIT SIGN DOT Q C L Z EOF M quadratic_bezier_curveto_argument_sequance
fractional_constant -> digit_sequence .DOT digit_sequence #lookaheads= DOT SIGN DIGIT Q C L Z M EOF quadratic_bezier_curveto_argument_sequance
fractional_constant -> digit_sequence .DOT #lookaheads= DOT SIGN DIGIT Q C L Z M EOF quadratic_bezier_curveto_argument_sequance
State 27
digit_sequence -> DIGIT . #lookaheads= DOT SIGN DIGIT Q C L Z M EOF quadratic_bezier_curveto_argument_sequance
digit_sequence -> DIGIT .digit_sequence #lookaheads= DOT SIGN DIGIT Q C L Z M EOF quadratic_bezier_curveto_argument_sequance
digit_sequence -> .DIGIT
digit_sequence -> .DIGIT digit_sequence
State 42
fractional_constant -> digit_sequence DOT .digit_sequence #lookaheads= DOT SIGN DIGIT Q C L Z M EOF quadratic_bezier_curveto_argument_sequance
fractional_constant -> digit_sequence DOT . #lookaheads= DOT SIGN DIGIT Q C L Z M EOF quadratic_bezier_curveto_argument_sequance
digit_sequence -> .DIGIT
digit_sequence -> .DIGIT digit_sequence
%lex
%%
\s+ /* skip whitespace */
"," /* skip comma */
[0-9] return 'DIGIT'
"+"|"-" return 'SIGN'
"." return 'DOT'
"M"|"m" return 'M'
"Z"|"z" return 'Z'
"L"|"l" return 'L'
"C"|"c" return 'C'
"Q"|"q" return 'Q'
<<EOF>> return 'EOF'
/lex
%start svg_path
%%
svg_path
: moveto_drawto_command_groups EOF
;
moveto_drawto_command_groups
: moveto_drawto_command_group
| moveto_drawto_command_group moveto_drawto_command_groups
;
moveto_drawto_command_group
: moveto
| moveto drawto_commands
;
drawto_commands
: drawto_command
| drawto_command drawto_commands
;
drawto_command
: closepath
| lineto
| curveto
| quadratic_bezier_curveto
;
moveto
: M moveto_argument_sequence
;
moveto_argument_sequence
: coordinate_pair
| coordinate_pair lineto_argument_sequence
;
closepath
: Z
;
lineto
: L lineto_argument_sequence
;
lineto_argument_sequence
: coordinate_pair
| coordinate_pair lineto_argument_sequence
;
curveto
: C curveto_argument_sequence
;
curveto_argument_sequence
: curveto_argument
| curveto_argument curveto_argument_sequence
;
curveto_argument
: coordinate_pair coordinate_pair coordinate_pair
;
quadratic_bezier_curveto
: Q quadratic_bezier_curveto_argument_sequence
;
quadratic_bezier_curveto_argument_sequence
: quadratic_bezier_curveto_argument
| quadratic_bezier_curveto_argument quadratic_bezier_curveto_argument_sequance
;
quadratic_bezier_curveto_argument
: coordinate_pair coordinate_pair
;
coordinate_pair
: coordinate coordinate
;
coordinate
: number
;
number
: integer_constant
| SIGN integer_constant
| floating_point_constant
| SIGN floating_point_constant
;
integer_constant
: digit_sequence
;
floating_point_constant
: fractional_constant
;
fractional_constant
: digit_sequence DOT digit_sequence
| DOT digit_sequence
| digit_sequence DOT
;
digit_sequence
: DIGIT
| DIGIT digit_sequence
;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment