Re: [isabelle] sloccount for .thy files?

On 01/08/12 06:53, Makarius wrote:
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:

I have ran your program on the attached Scratch.thy, and got back the result "19", which is identical to the result of wc -l. That can't be right! Any thoughts? I have just started learning scala today in order to understand this snippet, and I don't yet see what's wrong.


Rafal Kolanski.

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 like this:

   val text ="A.thy").mkString

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


theory Scratch imports Main begin

section "abacabb"

section {*

-- {* blah
  blah *}

(* more comments

section "a" subsection "b"

section "\"*}"


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