|
Packit Service |
a2ae7a |
(*
|
|
Packit Service |
a2ae7a |
Module: Quote
|
|
Packit Service |
a2ae7a |
Generic module providing useful primitives for quoting
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
Author: Raphael Pinson <raphael.pinson@camptocamp.com>
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
About: License
|
|
Packit Service |
a2ae7a |
This file is licenced under the LGPL v2+, like the rest of Augeas.
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
About: Lens Usage
|
|
Packit Service |
a2ae7a |
This is a generic module which doesn't apply to files directly.
|
|
Packit Service |
a2ae7a |
You can use its definitions to build lenses that require quoted values.
|
|
Packit Service |
a2ae7a |
It provides several levels of definitions, allowing to define more or less fine-grained quoted values:
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
- the quote separators are separators that are useful to define quoted values;
|
|
Packit Service |
a2ae7a |
- the quoting functions are useful wrappers to easily enclose a lens in various kinds of quotes (single, double, any, optional or not);
|
|
Packit Service |
a2ae7a |
- 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.
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
About: Examples
|
|
Packit Service |
a2ae7a |
The <Test_Quote> file contains various examples and tests.
|
|
Packit Service |
a2ae7a |
*)
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
module Quote =
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
(* Group: QUOTE SEPARATORS *)
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
(* Variable: dquote
|
|
Packit Service |
a2ae7a |
A double quote *)
|
|
Packit Service |
a2ae7a |
let dquote = Util.del_str "\""
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
(* Variable: dquote_opt
|
|
Packit Service |
a2ae7a |
An optional double quote, default to double *)
|
|
Packit Service |
a2ae7a |
let dquote_opt = del /"?/ "\""
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
(* Variable: dquote_opt_nil
|
|
Packit Service |
a2ae7a |
An optional double quote, default to nothing *)
|
|
Packit Service |
a2ae7a |
let dquote_opt_nil = del /"?/ ""
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
(* Variable: squote
|
|
Packit Service |
a2ae7a |
A single quote *)
|
|
Packit Service |
a2ae7a |
let squote = Util.del_str "'"
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
(* Variable: squote_opt
|
|
Packit Service |
a2ae7a |
An optional single quote, default to single *)
|
|
Packit Service |
a2ae7a |
let squote_opt = del /'?/ "'"
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
(* Variable: squote_opt_nil
|
|
Packit Service |
a2ae7a |
An optional single quote, default to nothing *)
|
|
Packit Service |
a2ae7a |
let squote_opt_nil = del /'?/ ""
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
(* Variable: quote
|
|
Packit Service |
a2ae7a |
A quote, either double or single, default to double *)
|
|
Packit Service |
a2ae7a |
let quote = del /["']/ "\""
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
(* Variable: quote_opt
|
|
Packit Service |
a2ae7a |
An optional quote, either double or single, default to double *)
|
|
Packit Service |
a2ae7a |
let quote_opt = del /["']?/ "\""
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
(* Variable: quote_opt_nil
|
|
Packit Service |
a2ae7a |
An optional quote, either double or single, default to nothing *)
|
|
Packit Service |
a2ae7a |
let quote_opt_nil = del /["']?/ ""
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
(* Group: QUOTING FUNCTIONS *)
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
(*
|
|
Packit Service |
a2ae7a |
View: do_dquote
|
|
Packit Service |
a2ae7a |
Enclose a lens in <dquote>s
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
Parameters:
|
|
Packit Service |
a2ae7a |
body:lens - the lens to be enclosed
|
|
Packit Service |
a2ae7a |
*)
|
|
Packit Service |
a2ae7a |
let do_dquote (body:lens) =
|
|
Packit Service |
a2ae7a |
square dquote body dquote
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
(*
|
|
Packit Service |
a2ae7a |
View: do_dquote_opt
|
|
Packit Service |
a2ae7a |
Enclose a lens in optional <dquote>s,
|
|
Packit Service |
a2ae7a |
use <dquote>s by default.
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
Parameters:
|
|
Packit Service |
a2ae7a |
body:lens - the lens to be enclosed
|
|
Packit Service |
a2ae7a |
*)
|
|
Packit Service |
a2ae7a |
let do_dquote_opt (body:lens) =
|
|
Packit Service |
a2ae7a |
square dquote_opt body dquote_opt
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
(*
|
|
Packit Service |
a2ae7a |
View: do_dquote_opt_nil
|
|
Packit Service |
a2ae7a |
Enclose a lens in optional <dquote>s,
|
|
Packit Service |
a2ae7a |
default to no quotes.
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
Parameters:
|
|
Packit Service |
a2ae7a |
body:lens - the lens to be enclosed
|
|
Packit Service |
a2ae7a |
*)
|
|
Packit Service |
a2ae7a |
let do_dquote_opt_nil (body:lens) =
|
|
Packit Service |
a2ae7a |
square dquote_opt_nil body dquote_opt_nil
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
(*
|
|
Packit Service |
a2ae7a |
View: do_squote
|
|
Packit Service |
a2ae7a |
Enclose a lens in <squote>s
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
Parameters:
|
|
Packit Service |
a2ae7a |
body:lens - the lens to be enclosed
|
|
Packit Service |
a2ae7a |
*)
|
|
Packit Service |
a2ae7a |
let do_squote (body:lens) =
|
|
Packit Service |
a2ae7a |
square squote body squote
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
(*
|
|
Packit Service |
a2ae7a |
View: do_squote_opt
|
|
Packit Service |
a2ae7a |
Enclose a lens in optional <squote>s,
|
|
Packit Service |
a2ae7a |
use <squote>s by default.
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
Parameters:
|
|
Packit Service |
a2ae7a |
body:lens - the lens to be enclosed
|
|
Packit Service |
a2ae7a |
*)
|
|
Packit Service |
a2ae7a |
let do_squote_opt (body:lens) =
|
|
Packit Service |
a2ae7a |
square squote_opt body squote_opt
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
(*
|
|
Packit Service |
a2ae7a |
View: do_squote_opt_nil
|
|
Packit Service |
a2ae7a |
Enclose a lens in optional <squote>s,
|
|
Packit Service |
a2ae7a |
default to no quotes.
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
Parameters:
|
|
Packit Service |
a2ae7a |
body:lens - the lens to be enclosed
|
|
Packit Service |
a2ae7a |
*)
|
|
Packit Service |
a2ae7a |
let do_squote_opt_nil (body:lens) =
|
|
Packit Service |
a2ae7a |
square squote_opt_nil body squote_opt_nil
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
(*
|
|
Packit Service |
a2ae7a |
View: do_quote
|
|
Packit Service |
a2ae7a |
Enclose a lens in <quote>s.
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
Parameters:
|
|
Packit Service |
a2ae7a |
body:lens - the lens to be enclosed
|
|
Packit Service |
a2ae7a |
*)
|
|
Packit Service |
a2ae7a |
let do_quote (body:lens) =
|
|
Packit Service |
a2ae7a |
square quote body quote
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
(*
|
|
Packit Service |
a2ae7a |
View: do_quote
|
|
Packit Service |
a2ae7a |
Enclose a lens in options <quote>s.
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
Parameters:
|
|
Packit Service |
a2ae7a |
body:lens - the lens to be enclosed
|
|
Packit Service |
a2ae7a |
*)
|
|
Packit Service |
a2ae7a |
let do_quote_opt (body:lens) =
|
|
Packit Service |
a2ae7a |
square quote_opt body quote_opt
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
(*
|
|
Packit Service |
a2ae7a |
View: do_quote
|
|
Packit Service |
a2ae7a |
Enclose a lens in options <quote>s,
|
|
Packit Service |
a2ae7a |
default to no quotes.
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
Parameters:
|
|
Packit Service |
a2ae7a |
body:lens - the lens to be enclosed
|
|
Packit Service |
a2ae7a |
*)
|
|
Packit Service |
a2ae7a |
let do_quote_opt_nil (body:lens) =
|
|
Packit Service |
a2ae7a |
square quote_opt_nil body quote_opt_nil
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
(* Group: QUOTED VALUES *)
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
(* View: double
|
|
Packit Service |
a2ae7a |
A double-quoted value *)
|
|
Packit Service |
a2ae7a |
let double =
|
|
Packit Service |
a2ae7a |
let body = store /[^\n]*/
|
|
Packit Service |
a2ae7a |
in do_dquote body
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
(* Variable: double_opt_re
|
|
Packit Service |
a2ae7a |
The regexp to store when value
|
|
Packit Service |
a2ae7a |
is optionally double-quoted *)
|
|
Packit Service |
a2ae7a |
let double_opt_re = /[^\n\t "]([^\n"]*[^\n\t "])?/
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
(* View: double_opt
|
|
Packit Service |
a2ae7a |
An optionally double-quoted value
|
|
Packit Service |
a2ae7a |
Double quotes are not allowed in value
|
|
Packit Service |
a2ae7a |
Value cannot begin or end with spaces *)
|
|
Packit Service |
a2ae7a |
let double_opt =
|
|
Packit Service |
a2ae7a |
let body = store double_opt_re
|
|
Packit Service |
a2ae7a |
in do_dquote_opt body
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
(* View: single
|
|
Packit Service |
a2ae7a |
A single-quoted value *)
|
|
Packit Service |
a2ae7a |
let single =
|
|
Packit Service |
a2ae7a |
let body = store /[^\n]*/
|
|
Packit Service |
a2ae7a |
in do_squote body
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
(* Variable: single_opt_re
|
|
Packit Service |
a2ae7a |
The regexp to store when value
|
|
Packit Service |
a2ae7a |
is optionally single-quoted *)
|
|
Packit Service |
a2ae7a |
let single_opt_re = /[^\n\t ']([^\n']*[^\n\t '])?/
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
(* View: single_opt
|
|
Packit Service |
a2ae7a |
An optionally single-quoted value
|
|
Packit Service |
a2ae7a |
Single quotes are not allowed in value
|
|
Packit Service |
a2ae7a |
Value cannot begin or end with spaces *)
|
|
Packit Service |
a2ae7a |
let single_opt =
|
|
Packit Service |
a2ae7a |
let body = store single_opt_re
|
|
Packit Service |
a2ae7a |
in do_squote_opt body
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
(* View: any
|
|
Packit Service |
a2ae7a |
A quoted value *)
|
|
Packit Service |
a2ae7a |
let any =
|
|
Packit Service |
a2ae7a |
let body = store /[^\n]*/
|
|
Packit Service |
a2ae7a |
in do_quote body
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
(* Variable: any_opt_re
|
|
Packit Service |
a2ae7a |
The regexp to store when value
|
|
Packit Service |
a2ae7a |
is optionally single- or double-quoted *)
|
|
Packit Service |
a2ae7a |
let any_opt_re = /[^\n\t "']([^\n"']*[^\n\t "'])?/
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
(* View: any_opt
|
|
Packit Service |
a2ae7a |
An optionally quoted value
|
|
Packit Service |
a2ae7a |
Double or single quotes are not allowed in value
|
|
Packit Service |
a2ae7a |
Value cannot begin or end with spaces *)
|
|
Packit Service |
a2ae7a |
let any_opt =
|
|
Packit Service |
a2ae7a |
let body = store any_opt_re
|
|
Packit Service |
a2ae7a |
in do_quote_opt body
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
(*
|
|
Packit Service |
a2ae7a |
View: quote_spaces
|
|
Packit Service |
a2ae7a |
Make quotes mandatory if value contains spaces,
|
|
Packit Service |
a2ae7a |
and optional if value doesn't contain spaces.
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
Parameters:
|
|
Packit Service |
a2ae7a |
lns:lens - the lens to be enclosed
|
|
Packit Service |
a2ae7a |
*)
|
|
Packit Service |
a2ae7a |
let quote_spaces (lns:lens) =
|
|
Packit Service |
a2ae7a |
(* bare has no spaces, and is optionally quoted *)
|
|
Packit Service |
a2ae7a |
let bare = Quote.do_quote_opt (store /[^"' \t\n]+/)
|
|
Packit Service |
a2ae7a |
(* quoted has at least one space, and must be quoted *)
|
|
Packit Service |
a2ae7a |
in let quoted = Quote.do_quote (store /[^"'\n]*[ \t]+[^"'\n]*/)
|
|
Packit Service |
a2ae7a |
in [ lns . bare ] | [ lns . quoted ]
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
(*
|
|
Packit Service |
a2ae7a |
View: dquote_spaces
|
|
Packit Service |
a2ae7a |
Make double quotes mandatory if value contains spaces,
|
|
Packit Service |
a2ae7a |
and optional if value doesn't contain spaces.
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
Parameters:
|
|
Packit Service |
a2ae7a |
lns:lens - the lens to be enclosed
|
|
Packit Service |
a2ae7a |
*)
|
|
Packit Service |
a2ae7a |
let dquote_spaces (lns:lens) =
|
|
Packit Service |
a2ae7a |
(* bare has no spaces, and is optionally quoted *)
|
|
Packit Service |
a2ae7a |
let bare = Quote.do_dquote_opt (store /[^" \t\n]+/)
|
|
Packit Service |
a2ae7a |
(* quoted has at least one space, and must be quoted *)
|
|
Packit Service |
a2ae7a |
in let quoted = Quote.do_dquote (store /[^"\n]*[ \t]+[^"\n]*/)
|
|
Packit Service |
a2ae7a |
in [ lns . bare ] | [ lns . quoted ]
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
(*
|
|
Packit Service |
a2ae7a |
View: squote_spaces
|
|
Packit Service |
a2ae7a |
Make single quotes mandatory if value contains spaces,
|
|
Packit Service |
a2ae7a |
and optional if value doesn't contain spaces.
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
Parameters:
|
|
Packit Service |
a2ae7a |
lns:lens - the lens to be enclosed
|
|
Packit Service |
a2ae7a |
*)
|
|
Packit Service |
a2ae7a |
let squote_spaces (lns:lens) =
|
|
Packit Service |
a2ae7a |
(* bare has no spaces, and is optionally quoted *)
|
|
Packit Service |
a2ae7a |
let bare = Quote.do_squote_opt (store /[^' \t\n]+/)
|
|
Packit Service |
a2ae7a |
(* quoted has at least one space, and must be quoted *)
|
|
Packit Service |
a2ae7a |
in let quoted = Quote.do_squote (store /[^'\n]*[ \t]+[^'\n]*/)
|
|
Packit Service |
a2ae7a |
in [ lns . bare ] | [ lns . quoted ]
|