@@ -6,6 +6,7 @@ const { group, indent, indentIfBreak, dedent, join, ifBreak, breakParent, line,
6
6
7
7
import { iml2json } from './iml2json.bc' ;
8
8
import { assert } from 'node:console' ;
9
+ import { DEFAULT_ENCODING } from 'node:crypto' ;
9
10
10
11
export const languages = [
11
12
{
@@ -330,11 +331,16 @@ function print_string_loc(node: AST, options: Options): Doc {
330
331
}
331
332
332
333
function print_attributes ( node : AST , level : number , options : Options ) : Doc {
334
+ let filter = [
335
+ "ocaml.comment" ,
336
+ "imandra_verify" , "imandra_instance" , "imandra_theorem" ,
337
+ "imandra_eval" , "imandra_axiom" , "imandra_rule_spec"
338
+ ] ;
333
339
return join ( line , node . map ( x => {
334
- if ( x . attr_name . txt != "ocaml.comment" )
335
- return print_attribute ( x , level , options ) ;
336
- else
340
+ if ( filter . find ( y => y == x . attr_name . txt ) )
337
341
return [ ] ;
342
+ else
343
+ return print_attribute ( x , level , options ) ;
338
344
} ) ) ;
339
345
}
340
346
@@ -344,12 +350,8 @@ function print_comment(node: AST, options: Options) {
344
350
}
345
351
346
352
function print_comments ( node : AST , options : Options ) : Doc {
347
- return join ( line , node . map ( x => {
348
- if ( x . attr_name . txt == "ocaml.comment" )
349
- return print_comment ( x , options ) ;
350
- else
351
- return [ ] ;
352
- } ) ) ;
353
+ let filtered = node . filter ( x => x . attr_name . txt == "ocaml.comment" ) ;
354
+ return join ( line , filtered . map ( x => print_comment ( x , options ) ) ) ;
353
355
}
354
356
355
357
function print_arg_label ( node : AST , options : Options ) : Doc {
@@ -1041,7 +1043,7 @@ function print_expression_desc(node: AST, options: Options, need_pars: boolean):
1041
1043
case "Pexp_match" :
1042
1044
// | Pexp_match of expression * case list
1043
1045
// (** [match E0 with P1 -> E1 | ... | Pn -> En] *)
1044
- const cs = join ( [ line , "|" , " "] , args [ 1 ] . map ( x => {
1046
+ const cs = join ( [ line , "| " ] , args [ 1 ] . map ( x => {
1045
1047
return f ( [ print_pattern ( x . pc_lhs , options ) , " " , "->" , line , print_expression ( x . pc_rhs , options , true ) ] ) ;
1046
1048
} ) ) ;
1047
1049
return g ( [ "match" , indent ( [ line , print_expression ( args [ 0 ] , options , true ) , line ] ) , "with" , line ,
@@ -1361,7 +1363,7 @@ function print_module_binding(node: AST, options: Options): Doc {
1361
1363
1362
1364
function get_attr_payload_string ( node : AST ) : Doc {
1363
1365
// Comments have special string payloads without quotes. Sigh.
1364
- return join ( line , node . attr_payload [ 1 ] [ 0 ] . pstr_desc [ 1 ] . pexp_desc [ 1 ] . pconst_desc [ 1 ] . split ( " " ) ) ;
1366
+ return node . attr_payload [ 1 ] [ 0 ] . pstr_desc [ 1 ] . pexp_desc [ 1 ] . pconst_desc [ 1 ] ;
1365
1367
}
1366
1368
1367
1369
function print_attribute ( node : AST , level : number , options : Options ) : Doc {
@@ -1461,13 +1463,10 @@ function print_structure_item_desc(node: AST, options: Options): Doc {
1461
1463
let r : Doc [ ] = [ ] ;
1462
1464
const comments = ifnonempty ( line , print_comments ( args [ 1 ] , options ) ) ;
1463
1465
if ( args . length > 1 && has_attribute ( args [ 1 ] , "imandra_eval" ) )
1464
- r = [ comments , "eval" , line , print_expression ( args [ 0 ] , options , false ) ] ;
1466
+ r = [ comments , "eval" , line , "(" , softline , print_expression ( args [ 0 ] , options , false ) , softline , ")" ] ;
1465
1467
else
1466
1468
r = [ comments , print_expression ( args [ 0 ] , options , false ) ] ;
1467
- if ( args [ 1 ] . length == 0 )
1468
- return [ r ] ;
1469
- else
1470
- return [ r , line , print_attributes ( args [ 1 ] , 3 , options ) ] ;
1469
+ return f ( [ r , ifnonempty ( line , print_attributes ( args [ 1 ] , 3 , options ) ) ] ) ;
1471
1470
}
1472
1471
case "Pstr_value" :
1473
1472
// | Pstr_value of rec_flag * value_binding list
@@ -1531,16 +1530,17 @@ function print_structure_item_desc(node: AST, options: Options): Doc {
1531
1530
// For function definitions we want to hoist the arguments
1532
1531
return g ( [ comments , r ,
1533
1532
f ( [ indent ( [ line , print_pattern ( pvb . pvb_pat , options ) , line ,
1534
- join ( line , pvb . pvb_expr . pexp_desc [ 1 ] . map ( x => print_function_param ( x , options ) ) ) , line ,
1535
- "=" , line ] ) ,
1533
+ join ( line , pvb . pvb_expr . pexp_desc [ 1 ] . map ( x => print_function_param ( x , options ) ) ) ,
1534
+ ] ) ,
1535
+ line , "=" , line ,
1536
1536
g ( [ indent ( [ print_function_body ( pvb . pvb_expr . pexp_desc [ 3 ] , options ) ] ) ,
1537
1537
ifnonempty ( hardline , print_attributes ( attrs , 2 , options ) ) , ] ) ] ) ] ) ;
1538
1538
}
1539
1539
}
1540
1540
// Generic version
1541
1541
return g ( [ comments , r , indent ( [ line , join ( [ line , "and" , line ] , args [ 1 ] . map ( x => print_value_binding ( x , options ) ) ) ] ) ,
1542
1542
ifnonempty ( hardline , print_attributes ( attrs , 2 , options ) ) ] ) ;
1543
- case "Pstr_primitive" : // TODO
1543
+ case "Pstr_primitive" :
1544
1544
// | Pstr_primitive of value_description
1545
1545
// (** - [val x: T]
1546
1546
// - [external x: T = "s1" ... "sn" ]*)
@@ -1689,7 +1689,18 @@ function print(path: AstPath<Tree>, options: Options, print
1689
1689
) {
1690
1690
return join ( [ hardline , hardline ] , path . node . top_defs . map ( n => {
1691
1691
let q = print_toplevel_phrase ( n , options ) ;
1692
- // console.log(q);
1692
+ if ( false ) {
1693
+ if ( n [ 0 ] == "Ptop_def" ) {
1694
+ let src = get_source ( n [ 1 ] [ 0 ] . pstr_loc , n [ 1 ] [ 0 ] . pstr_loc , options ) ;
1695
+ console . log ( src ) ;
1696
+ }
1697
+ else {
1698
+ let src = get_source ( n [ 1 ] . pdir_loc , n [ 1 ] . pdir_loc , options ) ;
1699
+ console . log ( src ) ;
1700
+ }
1701
+ console . log ( n ) ;
1702
+ console . log ( q ) ;
1703
+ }
1693
1704
return [ q ] ;
1694
1705
}
1695
1706
) ) ;
0 commit comments