Skip to main content

A Context is a logical expression built using dimensions as variables. In CAC configuration files, this expression is parsed using the pest crate.

expression = { SOI ~ whitespace* ~ logical ~ whitespace* ~ EOI }

logical = _{ logical_or }
logical_or = { logical_and ~ (whitespace* ~ "||" ~ whitespace* ~ logical_and)* }
logical_and = { comparison ~ (whitespace* ~ "&&" ~ whitespace* ~ comparison)* }

comparison = { term ~ whitespace* ~ comparison_operator ~ whitespace* ~ term }
comparison_operator = { ">=" | "<=" | "<" | ">" | "==" | "!=" }
term = { bool_literal | string_literal | float | integer | dimension }

string_literal = @{ "'" ~ char+ ~ "'" }
bool_literal = @{ "true" | "false" }
integer = @{ ASCII_DIGIT+ }
float = @{ ASCII_DIGIT+ ~ "." ~ ASCII_DIGIT+ }
char = { ASCII_ALPHANUMERIC | "." | "_" }
dimension = @{ "$" ~ char+ }

whitespace = _{ " " | "\t" | "\n" }

Overrides

Overrides are a subset of the configurations from Default Config typically with different values. Overrides are always associated with contexts and are applied when a context evaluates to true.

Context & Overrides

Request Queue
1
bangaloreauto
2
bangaloresedan
3
mumbaiauto
4
mumbaisedan
Evaluating:bangalore(w=1)×auto(w=2)= 3
Baseweight: 0
per_km_rate10
surge_factor1.0
timeout_ms5000
City: bangaloreweight: 1
per_km_rate12
surge_factor1.2
timeout_ms5000(inherited)
City: weight: 1SKIP
per_km_rate
surge_factor
City: bangalore, Vehicle: autoweight: 1+2=3
per_km_rate14
surge_factor1.5
timeout_ms3000
City: , Vehicle: weight: 1+2=3SKIP
per_km_rate
surge_factor
Resolved Config(highest weight: -)
per_km_rate-
surge_factor-
timeout_ms-

Example:

Let us configure different overrides for configuration keys under different contexts in our example.

[[overrides]]
_context_ = { vehicle_type = "bike", enable_stuff = true }
untest = "s"

[[overrides]]
_context_ = { vehicle_type = "auto" }
per_km_rate = 1

# [[overrides]]
# _context_ = { vehicle_type = "bike" }
# per_km_rate = 15.0

[[overrides]]
_context_ = { city = "Bangalore" }
per_km_rate = 22.0