Skip to content

Commit

Permalink
Improve abstraction of hosts
Browse files Browse the repository at this point in the history
A variable is basically a host or a port, and a host can be either an IP
address, a hostname, another variable, and so on.

Use our abstraction of host_list_item outside of lists when a single
host is expected, as a variable value, or in a rule.  This allows us to
have a better abstraction.
  • Loading branch information
smortex committed Jul 6, 2024
1 parent 67b0deb commit 0cdaf89
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions lib/puffy/parser.y
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,8 @@ rule
| variable_value_list variable_value { result = val[0] + [val[1]] }
| variable_value { result = [val[0]] }

variable_value: ADDRESS { result = val[0][:value] }
| STRING { result = val[0][:value] }
| VARIABLE { result = @variables.fetch(val[0][:value]) }
| port { result = val[0] }
variable_value: host_list_item { result = val[0] }
| port { result = val[0] }

service: SERVICE service_name block { @services[val[1]] = val[2] }

Expand Down Expand Up @@ -122,10 +120,9 @@ rule
| { result = {} }

hosts_host: ANY hosts_port { result = [{ host: nil, port: val[1] }] }
| host hosts_port { result = [{ host: val[0], port: val[1] }] }
| hosts_port { result = [{ host: nil, port: val[0] }] }
| host_list_item hosts_port { result = [{ host: val[0], port: val[1] }] }
| '{' host_list '}' hosts_port { result = [{ host: val[1], port: val[3] }] }
| VARIABLE hosts_port { result = [{ host: @variables.fetch(val[0][:value]), port: val[1] }] }
| SRV '(' STRING ')' { result = Resolver.instance.resolv_srv(val[2][:value]) }
| APT_MIRROR '(' STRING ')' { result = Resolver.instance.resolv_apt_mirror(val[2][:value]) }

Expand Down

0 comments on commit 0cdaf89

Please sign in to comment.