src/Tools/Code/code_scala.ML
changeset 34944 970e1466028d
parent 34900 9b12b0824bfe
child 35228 ac2cab4583f4
equal deleted inserted replaced
34943:e97b22500a5c 34944:970e1466028d
   402 val literals = let
   402 val literals = let
   403   fun char_scala c =
   403   fun char_scala c =
   404     let
   404     let
   405       val s = ML_Syntax.print_char c;
   405       val s = ML_Syntax.print_char c;
   406     in if s = "'" then "\\'" else s end;
   406     in if s = "'" then "\\'" else s end;
   407   fun bigint_scala k = "(" ^ (if k <= 2147483647
   407   fun numeral_scala k = if k < 0
   408     then string_of_int k else quote (string_of_int k)) ^ ")"
   408     then if k <= 2147483647 then "- " ^ string_of_int (~ k)
       
   409       else quote ("- " ^ string_of_int (~ k))
       
   410     else if k <= 2147483647 then string_of_int k
       
   411       else quote (string_of_int k)
   409 in Literals {
   412 in Literals {
   410   literal_char = Library.enclose "'" "'" o char_scala,
   413   literal_char = Library.enclose "'" "'" o char_scala,
   411   literal_string = quote o translate_string char_scala,
   414   literal_string = quote o translate_string char_scala,
   412   literal_numeral = fn unbounded => fn k => if k >= 0 then
   415   literal_numeral = fn k => "BigInt(" ^ numeral_scala k ^ ")",
   413       if unbounded then bigint_scala k
   416   literal_positive_numeral = fn k => "Nat.Nat(" ^ numeral_scala k ^ ")",
   414       else Library.enclose "(" ")" (string_of_int k)
   417   literal_naive_numeral = fn k => if k >= 0
   415     else
   418     then string_of_int k else "(- " ^ string_of_int (~ k) ^ ")",
   416       if unbounded then "(- " ^ bigint_scala (~ k) ^ ")"
       
   417       else Library.enclose "(" ")" (signed_string_of_int k),
       
   418   literal_list = fn [] => str "Nil" | ps => Pretty.block [str "List", enum "," "(" ")" ps],
   419   literal_list = fn [] => str "Nil" | ps => Pretty.block [str "List", enum "," "(" ")" ps],
   419   infix_cons = (6, "::")
   420   infix_cons = (6, "::")
   420 } end;
   421 } end;
   421 
   422 
   422 
   423 
   440       "match", "new", "null", "object", "override", "package", "private", "protected",
   441       "match", "new", "null", "object", "override", "package", "private", "protected",
   441       "requires", "return", "sealed", "super", "this", "throw", "trait", "try",
   442       "requires", "return", "sealed", "super", "this", "throw", "trait", "try",
   442       "true", "type", "val", "var", "while", "with"
   443       "true", "type", "val", "var", "while", "with"
   443     ]
   444     ]
   444   #> fold (Code_Target.add_reserved target) [
   445   #> fold (Code_Target.add_reserved target) [
   445       "error", "apply", "List", "Nil"
   446       "error", "apply", "List", "Nil", "BigInt"
   446     ];
   447     ];
   447 
   448 
   448 end; (*struct*)
   449 end; (*struct*)