Quote

Generic module providing useful primitives for quoting

Author: Raphael Pinson raphael.nosp@m..pinson@camptoc.nosp@m.amp.com

Summary
QuoteGeneric module providing useful primitives for quoting
LicenseThis file is licenced under the LGPL v2+, like the rest of Augeas.
Lens UsageThis is a generic module which doesn’t apply to files directly.
ExamplesThe Test_Quote file contains various examples and tests.
QUOTE SEPARATORS
dquoteA double quote
dquote_optAn optional double quote, default to double
dquote_opt_nilAn optional double quote, default to nothing
squoteA single quote
squote_optAn optional single quote, default to single
squote_opt_nilAn optional single quote, default to nothing
quoteA quote, either double or single, default to double
quote_optAn optional quote, either double or single, default to double
quote_opt_nilAn optional quote, either double or single, default to nothing
QUOTING FUNCTIONS
do_dquoteEnclose a lens in dquotes
do_dquote_optEnclose a lens in optional dquotes, use dquotes by default.
do_dquote_opt_nilEnclose a lens in optional dquotes, default to no quotes.
do_squoteEnclose a lens in squotes
do_squote_optEnclose a lens in optional squotes, use squotes by default.
do_squote_opt_nilEnclose a lens in optional squotes, default to no quotes.
do_quoteEnclose a lens in quotes.
do_quoteEnclose a lens in options quotes.
do_quoteEnclose a lens in options quotes, default to no quotes.
QUOTED VALUES
doubleA double-quoted value
double_opt_reThe regexp to store when value is optionally double-quoted
double_optAn optionally double-quoted value Double quotes are not allowed in value Value cannot begin or end with spaces
singleA single-quoted value
single_opt_reThe regexp to store when value is optionally single-quoted
single_optAn optionally single-quoted value Single quotes are not allowed in value Value cannot begin or end with spaces
anyA quoted value
any_opt_reThe regexp to store when value is optionally single- or double-quoted
any_optAn optionally quoted value Double or single quotes are not allowed in value Value cannot begin or end with spaces
quote_spacesMake quotes mandatory if value contains spaces, and optional if value doesn’t contain spaces.
dquote_spacesMake double quotes mandatory if value contains spaces, and optional if value doesn’t contain spaces.
squote_spacesMake single quotes mandatory if value contains spaces, and optional if value doesn’t contain spaces.

License

This file is licenced under the LGPL v2+, like the rest of Augeas.

Lens Usage

This is a generic module which doesn’t apply to files directly.  You can use its definitions to build lenses that require quoted values.  It provides several levels of definitions, allowing to define more or less fine-grained quoted values:

  • the quote separators are separators that are useful to define quoted values;
  • the quoting functions are useful wrappers to easily enclose a lens in various kinds of quotes (single, double, any, optional or not);
  • the quoted values definitions are common quoted patterns.  They use the quoting functions in order to provide useful shortcuts for commonly met needs.  In particular, the quote_spaces (and similar) function force values that contain spaces to be quoted, but allow values without spaces to be unquoted.

Examples

The Test_Quote file contains various examples and tests.

QUOTE SEPARATORS

dquote

let dquote = Util.del_str "\""

A double quote

dquote_opt

let dquote_opt = del /"?/ "\""

An optional double quote, default to double

dquote_opt_nil

let dquote_opt_nil = del /"?/ ""

An optional double quote, default to nothing

squote

let squote = Util.del_str "'"

A single quote

squote_opt

let squote_opt = del /'?/ "'"

An optional single quote, default to single

squote_opt_nil

let squote_opt_nil = del /'?/ ""

An optional single quote, default to nothing

quote

let quote = del /["']/ "\""

A quote, either double or single, default to double

quote_opt

let quote_opt = del /["']?/ "\""

An optional quote, either double or single, default to double

quote_opt_nil

let quote_opt_nil = del /["']?/ ""

An optional quote, either double or single, default to nothing

QUOTING FUNCTIONS

do_dquote

let do_dquote (body:lens) = square dquote body dquote

Enclose a lens in dquotes

Parameters

body:lensthe lens to be enclosed

do_dquote_opt

let do_dquote_opt (body:lens) = square dquote_opt body dquote_opt

Enclose a lens in optional dquotes, use dquotes by default.

Parameters

body:lensthe lens to be enclosed

do_dquote_opt_nil

let do_dquote_opt_nil (body:lens) = square dquote_opt_nil body dquote_opt_nil

Enclose a lens in optional dquotes, default to no quotes.

Parameters

body:lensthe lens to be enclosed

do_squote

let do_squote (body:lens) = square squote body squote

Enclose a lens in squotes

Parameters

body:lensthe lens to be enclosed

do_squote_opt

let do_squote_opt (body:lens) = square squote_opt body squote_opt

Enclose a lens in optional squotes, use squotes by default.

Parameters

body:lensthe lens to be enclosed

do_squote_opt_nil

let do_squote_opt_nil (body:lens) = square squote_opt_nil body squote_opt_nil

Enclose a lens in optional squotes, default to no quotes.

Parameters

body:lensthe lens to be enclosed

do_quote

let do_quote (body:lens) = square quote body quote

Enclose a lens in quotes.

Parameters

body:lensthe lens to be enclosed

do_quote

let do_quote_opt (body:lens) = square quote_opt body quote_opt

Enclose a lens in options quotes.

Parameters

body:lensthe lens to be enclosed

do_quote

let do_quote_opt_nil (body:lens) = square quote_opt_nil body quote_opt_nil

Enclose a lens in options quotes, default to no quotes.

Parameters

body:lensthe lens to be enclosed

QUOTED VALUES

double

let double = let body = store /[^\n]*/ in do_dquote body

A double-quoted value

double_opt_re

let double_opt_re = /[^\n\t "]([^\n"]*[^\n\t "])?/

The regexp to store when value is optionally double-quoted

double_opt

let double_opt = let body = store double_opt_re in do_dquote_opt body

An optionally double-quoted value Double quotes are not allowed in value Value cannot begin or end with spaces

single

let single = let body = store /[^\n]*/ in do_squote body

A single-quoted value

single_opt_re

let single_opt_re = /[^\n\t ']([^\n']*[^\n\t '])?/

The regexp to store when value is optionally single-quoted

single_opt

let single_opt = let body = store single_opt_re in do_squote_opt body

An optionally single-quoted value Single quotes are not allowed in value Value cannot begin or end with spaces

any

let any = let body = store /[^\n]*/ in do_quote body

A quoted value

any_opt_re

let any_opt_re = /[^\n\t "']([^\n"']*[^\n\t "'])?/

The regexp to store when value is optionally single- or double-quoted

any_opt

let any_opt = let body = store any_opt_re in do_quote_opt body

An optionally quoted value Double or single quotes are not allowed in value Value cannot begin or end with spaces

quote_spaces

let quote_spaces (lns:lens) =

Make quotes mandatory if value contains spaces, and optional if value doesn’t contain spaces.

Parameters

lns:lensthe lens to be enclosed

dquote_spaces

let dquote_spaces (lns:lens) =

Make double quotes mandatory if value contains spaces, and optional if value doesn’t contain spaces.

Parameters

lns:lensthe lens to be enclosed

squote_spaces

let squote_spaces (lns:lens) =

Make single quotes mandatory if value contains spaces, and optional if value doesn’t contain spaces.

Parameters

lns:lensthe lens to be enclosed
Provides unit tests and examples for the Quote lens.
let dquote = Util.del_str "\""
A double quote
let dquote_opt = del /"?/ "\""
An optional double quote, default to double
let dquote_opt_nil = del /"?/ ""
An optional double quote, default to nothing
let squote = Util.del_str "'"
A single quote
let squote_opt = del /'?/ "'"
An optional single quote, default to single
let squote_opt_nil = del /'?/ ""
An optional single quote, default to nothing
let quote = del /["']/ "\""
A quote, either double or single, default to double
let quote_opt = del /["']?/ "\""
An optional quote, either double or single, default to double
let quote_opt_nil = del /["']?/ ""
An optional quote, either double or single, default to nothing
let do_dquote (body:lens) = square dquote body dquote
Enclose a lens in dquotes
let do_dquote_opt (body:lens) = square dquote_opt body dquote_opt
Enclose a lens in optional dquotes, use dquotes by default.
let do_dquote_opt_nil (body:lens) = square dquote_opt_nil body dquote_opt_nil
Enclose a lens in optional dquotes, default to no quotes.
let do_squote (body:lens) = square squote body squote
Enclose a lens in squotes
let do_squote_opt (body:lens) = square squote_opt body squote_opt
Enclose a lens in optional squotes, use squotes by default.
let do_squote_opt_nil (body:lens) = square squote_opt_nil body squote_opt_nil
Enclose a lens in optional squotes, default to no quotes.
let do_quote (body:lens) = square quote body quote
Enclose a lens in quotes.
let double = let body = store /[^\n]*/ in do_dquote body
A double-quoted value
let double_opt_re = /[^\n\t "]([^\n"]*[^\n\t "])?/
The regexp to store when value is optionally double-quoted
let double_opt = let body = store double_opt_re in do_dquote_opt body
An optionally double-quoted value Double quotes are not allowed in value Value cannot begin or end with spaces
let single = let body = store /[^\n]*/ in do_squote body
A single-quoted value
let single_opt_re = /[^\n\t ']([^\n']*[^\n\t '])?/
The regexp to store when value is optionally single-quoted
let single_opt = let body = store single_opt_re in do_squote_opt body
An optionally single-quoted value Single quotes are not allowed in value Value cannot begin or end with spaces
let any = let body = store /[^\n]*/ in do_quote body
A quoted value
let any_opt_re = /[^\n\t "']([^\n"']*[^\n\t "'])?/
The regexp to store when value is optionally single- or double-quoted
let any_opt = let body = store any_opt_re in do_quote_opt body
An optionally quoted value Double or single quotes are not allowed in value Value cannot begin or end with spaces
let quote_spaces (lns:lens) =
Make quotes mandatory if value contains spaces, and optional if value doesn’t contain spaces.
let dquote_spaces (lns:lens) =
Make double quotes mandatory if value contains spaces, and optional if value doesn’t contain spaces.
let squote_spaces (lns:lens) =
Make single quotes mandatory if value contains spaces, and optional if value doesn’t contain spaces.
Close