Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

print_implem loops printing record contents #4452

Closed
vicuna opened this issue Nov 18, 2007 · 1 comment
Closed

print_implem loops printing record contents #4452

vicuna opened this issue Nov 18, 2007 · 1 comment
Milestone

Comments

@vicuna
Copy link

vicuna commented Nov 18, 2007

Original bug ID: 4452
Reporter: eaubin
Assigned to: @bobzhang
Status: closed (set by @xavierleroy on 2015-12-11T18:21:12Z)
Resolution: not a bug
Priority: normal
Severity: minor
Version: 3.10.0
Target version: 4.01.0+dev
Category: -for Camlp4 use https://github.com/ocaml/camlp4/issues

Bug description

Camlp4.PreCast.Printers.OCaml.print_implem loops printing

module rec b :
sig
type record =
{ key : int; f1 : f1.record; f2 : f2.record;
(((((((((((((((((((((((((((((((((((((((((((...

I'm probably doing something wrong creating the list of fields. How should this be done? Thanks

Additional information

open Camlp4.PreCast

let _loc = Loc.mk "?"

let base base fields ty =
let fields = List.fold_right (fun field acc ->
let c = <:ctyp< $lid:field$ : $uid:field$.record >> in
<:ctyp< $c$ ; $acc$ >>) fields <:ctyp< >>
in
<:module_binding< $uid:base$ :
sig type record = {
key : $ty$;
$fields$
} end = struct
type record = {
key : $ty$;
$fields$
} end
>>

let _ =
let b = base "b" ["f1"; "f2"] <:ctyp< int >> in
Camlp4.PreCast.Printers.OCaml.print_implem
<:str_item< module rec $b$ >>

@vicuna
Copy link
Author

vicuna commented Nov 19, 2007

Comment author: ertai

You should use CleanAst to remove useless nil nodes.

module CleanAst = Camlp4.Struct.CleanAst.Make(Ast)
let _ =
let b = base "b" ["f1"; "f2"] <:ctyp< int >> in
Camlp4.PreCast.Printers.OCaml.print_implem
((new CleanAst.clean_ast)#str_item
<:str_item< module rec $b$ >>)

However I don't know if clean ast should be called by print_implem. I've not done it since I don't want it to be called too often since it costs. For now it's called in the main of camlp4 before printing (camlp4/Camlp4Bin.ml).

@vicuna vicuna closed this as completed Dec 11, 2015
@vicuna vicuna added the camlp4 label Mar 14, 2019
@vicuna vicuna added this to the 4.01.0 milestone Mar 14, 2019
@vicuna vicuna added the bug label Mar 19, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant