Module property_file

Description

property_file is a configuration file parser.

It supports two popular configuration formats - Apache and C-like, property substitution and file inclusion. It works with Unix, DOS and Mac files. Both formats are line-oriented, declaration may be continued at next line with '\' before new line.

Property substitution may be used in quoted and unquoted string values. If property doesn't exists or its value is not a string, empty string is silently substituted. Syntax - ${property_name}.

C-like Grammar

  config := decls
 
  decls := decl*
 
  decl := bool_decl
       |  simple_decl
       |  struct_decl
       |  include_decl
 
 
  bool_decl := property_name : {property_name, true}
            |  property_name = bool : {property_name, bool}
  			
  bool := 'true' | 'false' | 'yes' | 'no'
 
  simple_decl := property_name '=' simple_value+
              : {property_name, [simple_value+]}
 
  struct_decl := property_name property_attr* '{' decl* '}'
              : {property_name, [property_attr], [decl]}
 
  property_attr := simple_value
 
  include_decl := '$INCLUDE' string
 
  simple_value := string
               |  integer
               |  float
               |  ipv4_address
               |  ipv4_netmask
 
  property_name := squoted_string
                | atom_string
 
  string := unquoted_string
         |  "double quoted string"
         |  'single quoted string'
  

apache-like Grammar

  config := decls
 
  decls := decl*
 
  decl := bool_decl
       |  simple_decl
       |  struct_decl
       |  include_decl
 
 
  bool_decl := property_name : {property_name, true}
            |  property_name = bool : {property_name, bool}
            |  property_name bool : {property_name, bool}
  			
  bool := 'true' | 'false' | 'yes' | 'no'
 
  simple_decl := property_name '=' simple_value+
              |  property_name simple_value+
              : {property_name, [simple_value+]}
 
  struct_decl := '<'property_name property_attr* '>' decl* '<'/property_name'>'
              : {property_name, [property_attr], [decl]}
 
  property_attr := simple_value
 
  include_decl := 'Include' string
 
  simple_value := string
               |  integer
               |  float
               |  ipv4_address
               |  ipv4_netmask
 
  property_name := squoted_string
                | atom_string
 
  string := unquoted_string
         |  "double quoted string"
         |  'single quoted string'
 
  ipv4_netmask := ipv4 '/' ipv4        : {ipv4, bitmask}
               | ipv4 '/' integer_mask : {ipv4, bitmask}
 
  integer_mask =< 32
 
  

Function Index

Exported Functions
format_error/1Format error returned by parse/3.
parse/2The same as parse/3 but with empty initial environment.
parse/3Parse file and return result or error.

Exported Functions

format_error/1

format_error(Error::term()) -> string()

Format error returned by parse/3

parse/2

parse(FileName::string(), Mode::mode()) -> Result | Error

The same as parse/3 but with empty initial environment

See also: parse/3.

parse/3

parse(FileName::string(), Mode::mode(), Env::env_list()) -> Result | {error, Error}

Parse file and return result or error. Error can be formatted with format_error/1. Env is a list of parameters which can be substituted in properties values.