Skip to content

Advanced parameter values #8

@mrmaxguns

Description

@mrmaxguns

Type primitives and types

  • number
    • unitless
    • distance (always positive, internally m)
    • angle (always positive, internally deg)
  • color
  • string (used also as an enum type)

Numbers

  • 11
  • -16.8
  • 19.5deg
  • 14mm
  • 1MI (all uppercase means real-life distance scaled to the current map scale)

Operators:

  • +
  • -
  • *
  • /

Operator semantics:

  • Same types: add normally
  • Different types (except unitless): error
  • Some type and unitless: add, assuming the unitless number is the default unit of the other input's type

Colors

  • #f0f0f0
  • #000

Strings

  • 'text'
  • "text"

Fallback operator |

The fallback operator returns the first non-falsy value.

  • 0|"text" -> "text"
  • 1|"text" -> 1
  • ""|"hi" -> "hi"

Value variables (treated as strings)

  • ${"name"}
  • ${"name:en"}
  • ${concatenate("name:", %{lang})}

Global variables (treated as strings)

  • %{"lang"}

Functions

  • rgb(255, 255, 255)
  • concatenate("German: ", ${"name:de"})

number as a function parameter: any number type works
unitless as a function parameter: only unitless numbers work

Function list

  • color rgb(unitless r, unitless g, unitless b)
  • distance to_distance(unitless val, string unit)
  • angle to_angle(unitless val, string unit)
  • unitless n(string) - parse number

Recipes

  • !"label": short for ${concatenate("name:", %{lang})|${name}}

Grammar

digit = "0".."9" ;
numeric literal = digit + , [ "." , digit + ] ;
distance unit = "mm" | "MM" | "in" | "IN" | "ft" | "FT" | "cm" | "CM" | "m" | "M" | "km" | "KM" | "mi" | "MI" | "px" | "PX" | "pt" | "PT" ;
angular unit = "deg" | "rad" ;
unit = distance unit | angular unit ;
number = numeric literal [ unit ] ;

hex digit = digit | "a".."f" | "A".."F" ;
color = ( "#" , hex digit , hex digit , hex digit , hex digit , hex digit , hex digit ) | ( "#" , hex digit , hex digit , hex digit ) ;

string = <a string enclosed in single or double quotes> ;

global = "%" , "{" , string , "}" ;

value variable = "$" , "{" , expression , "}" ;

alpha = "A".."Z" | "a".."z" ;
function identifier character = ( alpha | "_" ) , { alpha | digit | "_" } ;
function identifier = function identifier character + ;
function call = function identifier , "(" , expression , { "," , expression } , ")" ;

numeric factor = ( "-" , factor ) | number | function call | ( numeric expression ) ;
numeric term = factor { ( "*" | "/" ) , factor } ;
numeric expression = numeric term { ( "+" | "-" ) , numeric term } ;

primary expression = color | string | global | value variable | function call | numeric expression ;
expression = primary expression , { "|" , primary expression } ;

recipe = "!" , string ;

parameter = recipe | expression ;

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions