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

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -