src/HOL/Tools/Nitpick/nitpick_util.ML
changeset 36483 db71041b596b
parent 36385 ff5f88702590
child 36555 8ff45c2076da
equal deleted inserted replaced
36482:1281be23bd23 36483:db71041b596b
   246 
   246 
   247 val indent_size = 2
   247 val indent_size = 2
   248 
   248 
   249 val pstrs = Pretty.breaks o map Pretty.str o space_explode " "
   249 val pstrs = Pretty.breaks o map Pretty.str o space_explode " "
   250 
   250 
   251 fun plain_string_from_xml_tree t =
   251 val unyxml = Sledgehammer_Util.unyxml
   252   Buffer.empty |> XML.add_content t |> Buffer.content
   252 val maybe_quote = Sledgehammer_Util.maybe_quote
   253 val unyxml = plain_string_from_xml_tree o YXML.parse
       
   254 
       
   255 val is_long_identifier = forall Syntax.is_identifier o space_explode "."
       
   256 fun maybe_quote y =
       
   257   let val s = unyxml y in
       
   258     y |> ((not (is_long_identifier (perhaps (try (unprefix "'")) s)) andalso
       
   259            not (is_long_identifier (perhaps (try (unprefix "?")) s))) orelse
       
   260            OuterKeyword.is_keyword s) ? quote
       
   261   end
       
   262 
   253 
   263 (* This hash function is recommended in Compilers: Principles, Techniques, and
   254 (* This hash function is recommended in Compilers: Principles, Techniques, and
   264    Tools, by Aho, Sethi and Ullman. The hashpjw function, which they
   255    Tools, by Aho, Sethi, and Ullman. The "hashpjw" function, which they
   265    particularly recommend, triggers a bug in versions of Poly/ML up to 4.2.0. *)
   256    particularly recommend, triggers a bug in versions of Poly/ML up to 4.2.0. *)
   266 fun hashw (u, w) = Word.+ (u, Word.* (0w65599, w))
   257 fun hashw (u, w) = Word.+ (u, Word.* (0w65599, w))
   267 fun hashw_char (c, w) = hashw (Word.fromInt (Char.ord c), w)
   258 fun hashw_char (c, w) = hashw (Word.fromInt (Char.ord c), w)
   268 fun hashw_string (s:string, w) = CharVector.foldl hashw_char w s
   259 fun hashw_string (s:string, w) = CharVector.foldl hashw_char w s
   269 
   260