parsing - A fast and optimize way to extract inner repeated identifiers using Scala parser -
i have defined these grammatic rules in scala:
def root = rep(block) def block = ("block" ~ blockname ~ "{" ~ definition ~ "}") def blockname = ident def definition = creation ~ destruction ~ upgrades def creation = "creation" ~ "{" ~ duration ~ cost ~ "}" def destruction = "destruction" ~ "{" ~ duration ~ "}" def upgrades = "upgrades" ~ "{" ~ rep(ident ~ "{" ~ duration ~ cost ~ "}") ~ "}" def duration = "duration" ~ "=" ~ wholenumber def cost = "cost" ~ "=" ~ repsep(resource, ",") def resource = (resourcetype ~ "*" ~ wholenumber) def resourcetype = "wood" | "metal" | "food"
and input string
""" block citytown { creation { duration = 100 cost = food * 10, wood * 10 } destruction { duration = 100 } upgrades { level1 { duration = 100 cost = wood * 200 , food * 10 } level2 { duration = 100 cost = food * 30 , food * 10 } } }"""
i need fast , optimize way extract identifiers , values of cost , duration in each block. tried use ^^
operator, did not seem useful repeated inner values
Comments
Post a Comment