Commit 9b59837e authored by gerd's avatar gerd

Improvement: Adajcent literals are merged, and emtpy

literal are removed (suggested by Mike Potanin)


git-svn-id: https://godirepo.camlcity.org/svn/lib-xstrp4/trunk@19 56444827-45db-0310-81c6-95464f7ca4c4
parent 39ecee5e
(* $Id: xstrp4_here.ml,v 1.2 2001/04/21 16:53:15 gerd Exp $
(* $Id: xstrp4_here.ml,v 1.3 2003/01/13 01:36:39 gerd Exp $
* ----------------------------------------------------------------------
*
*)
......@@ -15,10 +15,25 @@ let interpolated_expr s =
| x -> x :: parse_here_expr lexbuf
in
let rec normalize_literals =
(* - Concat adjacent literals
* - Remove empty literals
*)
function
[] ->
[]
| (Literal "") :: tl ->
normalize_literals tl
| (Literal s1) :: (Literal s2) :: tl ->
normalize_literals((Literal(s1^s2))::tl)
| hd :: tl ->
hd :: (normalize_literals tl)
in
let loc = (0, String.length s) in
let buf = Lexing.from_string s in
let toklist = parse_here_expr buf in
let toklist = normalize_literals (parse_here_expr buf) in
let toklist_ast =
List.map
......@@ -68,7 +83,15 @@ let interpolated_expr s =
let concat_ast = <:expr< $string_concat_ast$ $str:""$ >> in
let list_ast = mk_list_ast toklist_ast in
let result_ast = <:expr< $concat_ast$ $list_ast$ >> in
result_ast
match toklist with
[] ->
<:expr< $str:""$ >>
| [Literal s] ->
List.hd toklist_ast (* = <:expr< $str:s$ >> *)
| _ ->
(* General case: *)
result_ast
;;
......@@ -137,6 +160,10 @@ Quotation.add
* History:
*
* $Log: xstrp4_here.ml,v $
* Revision 1.3 2003/01/13 01:36:39 gerd
* Improvement: Adajcent literals are merged, and emtpy
* literal are removed (suggested by Mike Potanin)
*
* Revision 1.2 2001/04/21 16:53:15 gerd
* Added "include file".
*
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment