some sanity checks for Isabelle sources;
authorwenzelm
Tue, 29 Apr 2014 16:14:27 +0200
changeset 56791 23883e1879c5
parent 56790 f54097170704
child 56792 792dd0e9cebb
some sanity checks for Isabelle sources;
src/Pure/Tools/check_source.scala
src/Pure/build-jars
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/Pure/Tools/check_source.scala	Tue Apr 29 16:14:27 2014 +0200
@@ -0,0 +1,41 @@
+/*  Title:      Pure/Tools/check_source.scala
+    Author:     Makarius
+
+Some sanity checks for Isabelle sources.
+*/
+
+package isabelle
+
+
+object Check_Source
+{
+  def check_file(path: Path)
+  {
+    val file_name = path.implode
+    val file_pos = path.position
+    def line_pos(i: Int) = Position.Line_File(i + 1, file_name)
+
+    val content = File.read(path)
+
+    for { (line, i) <- split_lines(content).iterator.zipWithIndex }
+    {
+      try {
+        Symbol.decode_strict(line)
+
+        for { c <- Word.codepoint_iterator(line); if c > 128 && !Character.isAlphabetic(c) }
+        {
+          Output.warning("Suspicious Unicode character " + quote(new String(Array(c), 0, 1)) +
+            Position.here(line_pos(i)))
+        }
+      }
+      catch { case ERROR(msg) => Output.error_message(msg + Position.here(line_pos(i))) }
+
+      if (line.contains('\t'))
+        Output.warning("TAB character " + Position.here(line_pos(i)))
+    }
+
+    if (content.contains('\r'))
+      Output.warning("CR character " + Position.here(file_pos))
+  }
+}
+
--- a/src/Pure/build-jars	Tue Apr 29 16:02:02 2014 +0200
+++ b/src/Pure/build-jars	Tue Apr 29 16:14:27 2014 +0200
@@ -81,6 +81,7 @@
   Thy/thy_header.scala
   Thy/thy_info.scala
   Thy/thy_syntax.scala
+  Tools/check_source.scala
   Tools/build.scala
   Tools/build_doc.scala
   Tools/doc.scala