Generic module providing useful primitives for quoting
Author: Raphael Pinson raphael@camptoc amp.com .pinson
Quote | Generic module providing useful primitives for quoting |
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. |
Examples | The Test_Quote file contains various examples and tests. |
QUOTE SEPARATORS | |
dquote | A double quote |
dquote_opt | An optional double quote, default to double |
dquote_opt_nil | An optional double quote, default to nothing |
squote | A single quote |
squote_opt | An optional single quote, default to single |
squote_opt_nil | An optional single quote, default to nothing |
quote | A quote, either double or single, default to double |
quote_opt | An optional quote, either double or single, default to double |
quote_opt_nil | An optional quote, either double or single, default to nothing |
QUOTING FUNCTIONS | |
do_dquote | Enclose a lens in dquotes |
do_dquote_opt | Enclose a lens in optional dquotes, use dquotes by default. |
do_dquote_opt_nil | Enclose a lens in optional dquotes, default to no quotes. |
do_squote | Enclose a lens in squotes |
do_squote_opt | Enclose a lens in optional squotes, use squotes by default. |
do_squote_opt_nil | Enclose a lens in optional squotes, default to no quotes. |
do_quote | Enclose a lens in quotes. |
do_quote | Enclose a lens in options quotes. |
do_quote | Enclose a lens in options quotes, default to no quotes. |
QUOTED VALUES | |
double | A double-quoted value |
double_opt_re | The regexp to store when value is optionally double-quoted |
double_opt | An optionally double-quoted value Double quotes are not allowed in value Value cannot begin or end with spaces |
single | A single-quoted value |
single_opt_re | The regexp to store when value is optionally single-quoted |
single_opt | An optionally single-quoted value Single quotes are not allowed in value Value cannot begin or end with spaces |
any | A quoted value |
any_opt_re | The regexp to store when value is optionally single- or double-quoted |
any_opt | An optionally quoted value Double or single quotes are not allowed in value Value cannot begin or end with spaces |
quote_spaces | Make quotes mandatory if value contains spaces, and optional if value doesn’t contain spaces. |
dquote_spaces | Make double quotes mandatory if value contains spaces, and optional if value doesn’t contain spaces. |
squote_spaces | Make single quotes mandatory if value contains spaces, and optional if value doesn’t contain spaces. |
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 Test_Quote file contains various examples and tests.
let do_dquote (body:lens) = square dquote body dquote
Enclose a lens in dquotes
body:lens | the lens to be enclosed |
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.
body:lens | the lens to be enclosed |
let do_squote (body:lens) = square squote body squote
Enclose a lens in squotes
body:lens | the lens to be enclosed |
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.
body:lens | the lens to be enclosed |
let do_quote (body:lens) = square quote body quote
Enclose a lens in quotes.
body:lens | the lens to be enclosed |
let do_quote_opt (body:lens) = square quote_opt body quote_opt
Enclose a lens in options quotes.
body:lens | the lens to be enclosed |
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.
body:lens | the lens to be enclosed |
A double quote
let dquote = Util.del_str "\""
An optional double quote, default to double
let dquote_opt = del /"?/ "\""
An optional double quote, default to nothing
let dquote_opt_nil = del /"?/ ""
A single quote
let squote = Util.del_str "'"
An optional single quote, default to single
let squote_opt = del /'?/ "'"
An optional single quote, default to nothing
let squote_opt_nil = del /'?/ ""
A quote, either double or single, default to double
let quote = del /["']/ "\""
An optional quote, either double or single, default to double
let quote_opt = del /["']?/ "\""
An optional quote, either double or single, default to nothing
let quote_opt_nil = del /["']?/ ""
Enclose a lens in dquotes
let do_dquote (body:lens) = square dquote body dquote
Enclose a lens in optional dquotes, use dquotes by default.
let do_dquote_opt (body:lens) = square dquote_opt body dquote_opt
Enclose a lens in optional dquotes, default to no quotes.
let do_dquote_opt_nil (body:lens) = square dquote_opt_nil body dquote_opt_nil
Enclose a lens in squotes
let do_squote (body:lens) = square squote body squote
Enclose a lens in optional squotes, use squotes by default.
let do_squote_opt (body:lens) = square squote_opt body squote_opt
Enclose a lens in optional squotes, default to no quotes.
let do_squote_opt_nil (body:lens) = square squote_opt_nil body squote_opt_nil
Enclose a lens in quotes.
let do_quote (body:lens) = square quote body quote
A double-quoted value
let double = let body = store /[^\n]*/ in do_dquote body
The regexp to store when value is optionally double-quoted
let double_opt_re = /[^\n\t "]([^\n"]*[^\n\t "])?/
An optionally double-quoted value Double quotes are not allowed in value Value cannot begin or end with spaces
let double_opt = let body = store double_opt_re in do_dquote_opt body
A single-quoted value
let single = let body = store /[^\n]*/ in do_squote body
The regexp to store when value is optionally single-quoted
let single_opt_re = /[^\n\t ']([^\n']*[^\n\t '])?/
An optionally single-quoted value Single quotes are not allowed in value Value cannot begin or end with spaces
let single_opt = let body = store single_opt_re in do_squote_opt body
A quoted value
let any = let body = store /[^\n]*/ in do_quote body
The regexp to store when value is optionally single- or double-quoted
let any_opt_re = /[^\n\t "']([^\n"']*[^\n\t "'])?/
An optionally quoted value Double or single quotes are not allowed in value Value cannot begin or end with spaces
let any_opt = let body = store any_opt_re in do_quote_opt body
Make quotes mandatory if value contains spaces, and optional if value doesn’t contain spaces.
let quote_spaces (lns:lens) =
Make double quotes mandatory if value contains spaces, and optional if value doesn’t contain spaces.
let dquote_spaces (lns:lens) =
Make single quotes mandatory if value contains spaces, and optional if value doesn’t contain spaces.
let squote_spaces (lns:lens) =