Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/add drw pda #19

Merged
merged 2 commits into from
Sep 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions daidepp/parser/grammar.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
arrangement = pce / aly_vss / drw / slo / not / nar / xdo / dmz / and / orr / scd / occ / cho / for / xoy / ydo / snd / fwd / bcc
pce = "PCE" lpar power (ws power)* rpar
aly_vss = "ALY" lpar power (ws power)* rpar "VSS" lpar power (ws power)* rpar
drw = "DRW"
drw = "DRW" (lpar power (ws power)+ rpar)?
slo = "SLO" lpar power rpar
not = "NOT" lpar arrangement rpar
nar = "NAR" lpar arrangement rpar
Expand All @@ -52,7 +52,7 @@
order = hld / mto / sup/ cvy / move_by_cvy / retreat / build
hld = lpar unit rpar "HLD"
mto = lpar unit rpar "MTO" ws province
sup = lpar unit rpar "SUP" lpar unit rpar ("MTO" ws prov_no_coast)?
sup = lpar unit rpar "SUP" lpar unit rpar ("MTO" ws province)?
cvy = lpar unit rpar "CVY" lpar unit rpar "CTO" ws province
move_by_cvy = lpar unit rpar "CTO" ws province ws "VIA" lpar prov_sea (ws prov_sea)* rpar
retreat = rto / dsb
Expand All @@ -66,7 +66,8 @@
unit_type = "AMY" / "FLT"
unit = power ws unit_type ws province
power = "AUS" / "ENG" / "FRA" / "GER" / "ITA" / "RUS" / "TUR"
province = prov_coast / prov_no_coast / prov_sea
province = prov_coast / prov_no_coast / prov_sea / (lpar prov_coast ws coast rpar)
coast = "NCS" / "ECS" / "SCS" / "WCS"
prov_coast = "ALB" / "ANK" / "APU" / "ARM" / "BEL" / "BER" / "BRE" / "BUL" / "CLY" / "CON" / "DEN" / "EDI" / "FIN" / "GAS" / "GRE" / "HOL" / "KIE" / "LON" / "LVN" / "LVP" / "MAR" / "NAF" / "NAP" / "NWY" / "PIC" / "PIE" / "POR" / "PRU" / "ROM" / "RUM" / "SEV" / "SMY" / "SPA" / "STP" / "SWE" / "SYR" / "TRI" / "TUN" / "TUS" / "VEN" / "YOR" / "WAL"
prov_no_coast = "BOH" / "BUD" / "BUR" / "MOS" / "MUN" / "GAL" / "PAR" / "RUH" / "SER" / "SIL" / "TYR" / "UKR" / "VIE" / "WAR"
prov_sea = "ADR" / "AEG" / "BAL" / "BAR" / "BLA" / "BOT" / "EAS" / "ENG" / "HEL" / "ION" / "IRI" / "LYO" / "MAO" / "NAO" / "NTH" / "NWG" / "SKA" / "TYS" / "WES"
Expand Down
22 changes: 21 additions & 1 deletion daidepp/parser/node_visitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,19 @@ def visit_aly_vss(self, node, visited_children):
return ("ALY_VSS", (aly_list, vss_list))

def visit_drw(self, node, visited_children):
return node.text
_, par_powers = visited_children

if isinstance(par_powers, Node) and not par_powers.text:
return "DRW"

# For Partial draws are allowed (PDA) variant game
_, power, ws_powers, _ = par_powers[0]
pow_list = [power]
for ws_pow in ws_powers:
_, pow = ws_pow
pow_list.append(pow)

return ("DRW", pow_list)

def visit_slo(self, node, visited_children):
_, _, power, _ = visited_children
Expand Down Expand Up @@ -359,6 +371,14 @@ def visit_power(self, node, visited_children):
return node.text

def visit_province(self, node, visited_children):
if isinstance(visited_children[0], str):
return node.text

_, province, _, coast, _ = visited_children[0]

return province + " " + coast

def visit_coast(self, node, visited_children):
return node.text

def visit_prov_coast(self, node, visited_children):
Expand Down