Re: [isabelle] sloccount for .thy files?



On Wed, 1 Aug 2012, Christian Sternagel wrote:

     } yield 1
   val n = (0 /: newlines)(_ + _)
   if (text.endsWith("\n")) n else n + 1
}

Furthermore, I think there is a typo in the script, the last if-then-else should have swapped branches, i.e., add 1 if the file ends with a newline character.

My idea was to count the lines independently of the termination of the last line. If the text ends with "\n" it had already been counted as part of the tokens. The example Scratch.thy has 20 lines but \n newline characters.

Anyway, this is just a toy. It shows that there are fine points that might need to be addressed, so a decent programming language helps.


import isabelle._
val text = scala.io.Source.fromFile("Scratch.thy").mkString
val tokens = Outer_Syntax.empty.scan(text).toList
tokens.foreach { x => print(x.toString + "\n") }

Thanks for the correction of scala.io.Source.fromFile.

The last line can be done like this:

  tokens foreach println


	Makarius





This archive was generated by a fusion of Pipermail (Mailman edition) and MHonArc.