@@ -58,6 +58,15 @@ let record_pattern_info = record_pats =>
5858 ([] , Asttypes . Closed ),
5959 );
6060
61+ // This normalizes STRING items in the parsetree that aren't constants so we don't need
62+ // to scatter them throughout the rest of the compiler.
63+ let normalize_string = (~loc, item) => {
64+ switch (Grain_utils . Literals . conv_string(item. txt)) {
65+ | Ok (i ) => {loc: item. loc, txt: i}
66+ | Error (msg ) => raise (SyntaxError (loc, msg))
67+ };
68+ };
69+
6170module Constant = {
6271 let bytes = b => PConstBytes (b);
6372 let string = s => PConstString (s);
@@ -67,25 +76,18 @@ module Constant = {
6776 let int16 = i => PConstInt16 (i);
6877 let int32 = i => PConstInt32 (i);
6978 let int64 = i => PConstInt64 (i);
70- let uint8 = (is_neg , i) => PConstUint8 (is_neg , i);
71- let uint16 = (is_neg , i) => PConstUint16 (is_neg , i);
72- let uint32 = (is_neg , i) => PConstUint32 (is_neg , i);
73- let uint64 = (is_neg , i) => PConstUint64 (is_neg , i);
79+ let uint8 = i => PConstUint8 (i);
80+ let uint16 = i => PConstUint16 (i);
81+ let uint32 = i => PConstUint32 (i);
82+ let uint64 = i => PConstUint64 (i);
7483 let float32 = f => PConstFloat32 (f);
7584 let float64 = f => PConstFloat64 (f);
7685 let wasmi32 = i => PConstWasmI32 (i);
7786 let wasmi64 = i => PConstWasmI64 (i);
7887 let wasmf32 = f => PConstWasmF32 (f);
7988 let wasmf64 = f => PConstWasmF64 (f);
8089 let bigint = i => PConstBigInt (i);
81- let rational = r => {
82- let (n , d ) =
83- switch (String . split_on_char('/' , r)) {
84- | [ n , d ] => (n, d)
85- | _ => failwith ("Impossible: rational literal without forward slash" )
86- };
87- PConstRational (n, d);
88- };
90+ let rational = r => PConstRational (r);
8991 let bool = b => PConstBool (b);
9092 let void = PConstVoid ;
9193};
@@ -467,14 +469,18 @@ module Toplevel = {
467469
468470module PrimitiveDescription = {
469471 let mk = (~loc, ~ident, ~name, () ) => {
470- {pprim_ident: ident, pprim_name: name, pprim_loc: loc};
472+ {
473+ pprim_ident: ident,
474+ pprim_name: normalize_string(~loc, name),
475+ pprim_loc: loc,
476+ };
471477 };
472478};
473479
474480module ValueDescription = {
475481 let mk = (~loc, ~mod_, ~name, ~alias, ~typ, () ) => {
476482 {
477- pval_mod: mod_,
483+ pval_mod: normalize_string(~loc , mod_) ,
478484 pval_name: name,
479485 pval_name_alias: alias,
480486 pval_type: typ,
@@ -497,7 +503,11 @@ module MatchBranch = {
497503
498504module IncludeDeclaration = {
499505 let mk = (~loc, path, alias) => {
500- {pinc_alias: alias, pinc_path: path, pinc_loc: loc};
506+ {
507+ pinc_alias: alias,
508+ pinc_path: normalize_string(~loc, path),
509+ pinc_loc: loc,
510+ };
501511 };
502512};
503513
@@ -545,3 +555,9 @@ module ModuleDeclaration = {
545555 {pmod_name: name, pmod_stmts: stmts, pmod_loc: loc};
546556 };
547557};
558+
559+ module Attribute = {
560+ let mk = (~loc, name, args) => {
561+ (name, List . map(normalize_string(~loc), args));
562+ };
563+ };
0 commit comments