D
Donn Ingle
Hi - I have been trying, but I need some help:
Here's my test code to parse an SVG path element, can anyone steer me right?
d1="""
M 209.12237 , 172.2415
L 286.76739 , 153.51369
L 286.76739 , 275.88534
L 209.12237 , 294.45058
L 209.12237 , 172.2415
z """
#Try it with no enters
d1="""M 209.12237,172.2415 L 286.76739,153.51369 L 286.76739,275.88534 L
209.12237,294.45058 L 209.12237,172.2415 z """
#Try it with no spaces
d1="""M209.12237,172.2415L286.76739,153.51369L286.76739,275.88534L209.12237,294.45058L209.12237,172.2415z"""
#For later, has more commands
d2="""
M 269.78326 , 381.27104
C 368.52151 , 424.27023
90.593578 , -18.581883
90.027729 , 129.28708
C 89.461878 , 277.15604
171.04501 , 338.27184
269.78326 , 381.27104
z """
## word :: M, L, C, Z
## number :: group of numbers
## dot :: "."
## comma :: ","
## couple :: number dot number comma number dot number
## command :: word
##
## phrase :: command couple
from pyparsing import Word, Literal, alphas, nums, Optional, OneOrMore
command = Word("MLCZ")
comma = Literal(",")
dot = Literal(".")
float = nums + dot + nums
couple = float + comma + float
phrase = OneOrMore(command + OneOrMore(couple | ( couple + couple ) ) )
print phrase
print phrase.parseString(d1.upper())
Thanks
\d
Here's my test code to parse an SVG path element, can anyone steer me right?
d1="""
M 209.12237 , 172.2415
L 286.76739 , 153.51369
L 286.76739 , 275.88534
L 209.12237 , 294.45058
L 209.12237 , 172.2415
z """
#Try it with no enters
d1="""M 209.12237,172.2415 L 286.76739,153.51369 L 286.76739,275.88534 L
209.12237,294.45058 L 209.12237,172.2415 z """
#Try it with no spaces
d1="""M209.12237,172.2415L286.76739,153.51369L286.76739,275.88534L209.12237,294.45058L209.12237,172.2415z"""
#For later, has more commands
d2="""
M 269.78326 , 381.27104
C 368.52151 , 424.27023
90.593578 , -18.581883
90.027729 , 129.28708
C 89.461878 , 277.15604
171.04501 , 338.27184
269.78326 , 381.27104
z """
## word :: M, L, C, Z
## number :: group of numbers
## dot :: "."
## comma :: ","
## couple :: number dot number comma number dot number
## command :: word
##
## phrase :: command couple
from pyparsing import Word, Literal, alphas, nums, Optional, OneOrMore
command = Word("MLCZ")
comma = Literal(",")
dot = Literal(".")
float = nums + dot + nums
couple = float + comma + float
phrase = OneOrMore(command + OneOrMore(couple | ( couple + couple ) ) )
print phrase
print phrase.parseString(d1.upper())
Thanks
\d