Re: [isabelle] sloccount for .thy files?



On Wed, 25 Jul 2012, Rafal Kolanski wrote:

We need something like sloccount (count lines of code in a file with comments removed) for Isabelle.

This threads appear to be inconclusive.  Did you prefer awk or Scala?

Anyway, here is a little toy for isabelle scala (as of Isabelle2012), which can be run on its toplevel loop:


import isabelle._

def lines_without_comments(text: String): Int =
{
  val newlines =
    for {
      token <- Outer_Syntax.empty.scan(text).iterator
      if !token.is_comment
      c <- token.source.iterator
      if c == '\n'
    } yield 1
  val n = (0 /: newlines)(_ + _)
  if (text.endsWith("\n")) n else n + 1
}


To get the text of a file, you can use scala.io like this:

  val text = scala.io.fromFile("A.thy").mkString

Next time there will be more Isabelle-ish I/O operations.


	Makarius





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