parsing ingredient list with parsimonious
Clash Royale CLAN TAG #URR8PPP parsing ingredient list with parsimonious from parsimonious.grammar import Grammar grammar = Grammar( ''' # item = ( ( ingredient+ '(' ingredient+ ')' comma ws?) + / comma+ / ws+ / ingredient )+ item = ((ingredient '(' ingredient ')') / ingredient )+ ingredient = ( ( bold_tag? word+ ws? percent? )+ comma? ws? ) word = ~"[A-Z0-9:]+"i ws = ~"s*"+ comma = "," bold_tag = "<b>" percent = ~"([d.%]+)" ''') grammar = Grammar( """ ingredient_item = words open_bracket (subingredient)* closed_bracket comma text_preceding_colon = (text colon)* text = ~"[A-Z 0-9]*"i space = ~"[\s]*" colon = ":" words = text+ open_bracket = "(" closed_bracket = ")" subingredient = text / b_tag / percentage ...