From 87cacfeddc02cb399d2f49120deea062b1fb7a60 Mon Sep 17 00:00:00 2001 From: Gert Vanthienen Date: Tue, 29 Apr 2008 13:35:21 +0200 Subject: [PATCH] Adding support for Scala (http://www.scala-lang.org) --- ext/ohcount_native/generator.rb | 2 + lib/ohcount/detector.rb | 1 + lib/ohcount/sloc_info.rb | 1 + test/expected_dir/scala1.scala/scala/blanks | 1 + test/expected_dir/scala1.scala/scala/code | 48 +++++++++++++++ test/expected_dir/scala1.scala/scala/comment | 11 ++++ test/src_dir/scala1.scala | 63 ++++++++++++++++++++ test/unit/scala_test.rb | 9 +++ 8 files changed, 136 insertions(+) create mode 100644 test/expected_dir/scala1.scala/scala/blanks create mode 100644 test/expected_dir/scala1.scala/scala/code create mode 100644 test/expected_dir/scala1.scala/scala/comment create mode 100644 test/src_dir/scala1.scala create mode 100644 test/unit/scala_test.rb diff --git a/ext/ohcount_native/generator.rb b/ext/ohcount_native/generator.rb index c30c9fd..73a7d33 100644 --- a/ext/ohcount_native/generator.rb +++ b/ext/ohcount_native/generator.rb @@ -82,6 +82,7 @@ module Ohcount ["btex", :metapost_code, :tex_code, :from, false, 'btex'], ["etex", :tex_code, :return, :to, false, 'etex'] ]); + scala = CMonoglot.new("scala", '//', [e('/*'), e('*/')], true, false) polyglots = [ actionscript , ada , @@ -122,6 +123,7 @@ module Ohcount ruby , rexx , scheme , + scala, shell , smalltalk , sql , diff --git a/lib/ohcount/detector.rb b/lib/ohcount/detector.rb index 9c8543a..9a6beb7 100644 --- a/lib/ohcount/detector.rb +++ b/lib/ohcount/detector.rb @@ -189,6 +189,7 @@ class Ohcount::Detector '.s' => "assembler", '.S' => "assembler", '.sc' => "scheme", + '.scala'=> "scala", '.scm' => "scheme", '.sh' => "shell", '.sql' => "sql", diff --git a/lib/ohcount/sloc_info.rb b/lib/ohcount/sloc_info.rb index 7895ad6..d5a44d8 100644 --- a/lib/ohcount/sloc_info.rb +++ b/lib/ohcount/sloc_info.rb @@ -79,6 +79,7 @@ class Ohcount::SlocInfo 'rexx' => {:nice_name => 'rexx' , :category => 0}, 'ruby' => {:nice_name => 'Ruby' , :category => 0}, 'scheme' => {:nice_name => 'Scheme' , :category => 0}, + 'scala' => {:nice_name => 'Scala' , :category => 0}, 'shell' => {:nice_name => 'shell script' , :category => 0}, 'smalltalk' => {:nice_name => 'Smalltalk' , :category => 0}, 'sql' => {:nice_name => 'SQL' , :category => 0}, diff --git a/test/expected_dir/scala1.scala/scala/blanks b/test/expected_dir/scala1.scala/scala/blanks new file mode 100644 index 0000000..bf0d87a --- /dev/null +++ b/test/expected_dir/scala1.scala/scala/blanks @@ -0,0 +1 @@ +4 \ No newline at end of file diff --git a/test/expected_dir/scala1.scala/scala/code b/test/expected_dir/scala1.scala/scala/code new file mode 100644 index 0000000..3392f0c --- /dev/null +++ b/test/expected_dir/scala1.scala/scala/code @@ -0,0 +1,48 @@ +import scala.actors.Actor +case object Ping +case object Pong +case object Stop +class Ping(count: int, pong: Actor) extends Actor { +def act() { +var pingsLeft = count - 1 +pong ! Ping +while (true) { +receive { +case Pong => +if (pingsLeft % 1000 == 0) +Console.println("Ping: pong") +if (pingsLeft > 0) { +pong ! Ping +pingsLeft -= 1 +} else { +Console.println("Ping: stop") +pong ! Stop +exit() +} +} +} +} +} +class Pong extends Actor { +def act() { +var pongCount = 0 +while (true) { +receive { +case Ping => +if (pongCount % 1000 == 0) +Console.println("Pong: ping "+pongCount) +sender ! Pong +pongCount = pongCount + 1 +case Stop => +Console.println("Pong: stop") +exit() +} +} +} +} +object PingPong extends Application { +val pong = new Pong +val ping = new Ping(100000, pong) +ping.start +pong.start +} diff --git a/test/expected_dir/scala1.scala/scala/comment b/test/expected_dir/scala1.scala/scala/comment new file mode 100644 index 0000000..3aaaee9 --- /dev/null +++ b/test/expected_dir/scala1.scala/scala/comment @@ -0,0 +1,11 @@ +/** +* Ping class +*/ +/** +* Pong class +*/ +//pong back the ping +//stop ping ponging +/* +* And this is the main application, playing a game of ping pong +*/ diff --git a/test/src_dir/scala1.scala b/test/src_dir/scala1.scala new file mode 100644 index 0000000..e02a23e --- /dev/null +++ b/test/src_dir/scala1.scala @@ -0,0 +1,63 @@ +import scala.actors.Actor + +case object Ping +case object Pong +case object Stop + +/** + * Ping class + */ +class Ping(count: int, pong: Actor) extends Actor { + def act() { + var pingsLeft = count - 1 + pong ! Ping + while (true) { + receive { + case Pong => + if (pingsLeft % 1000 == 0) + Console.println("Ping: pong") + if (pingsLeft > 0) { + pong ! Ping + pingsLeft -= 1 + } else { + Console.println("Ping: stop") + pong ! Stop + exit() + } + } + } + } +} + +/** + * Pong class + */ +class Pong extends Actor { + def act() { + var pongCount = 0 + while (true) { + receive { + //pong back the ping + case Ping => + if (pongCount % 1000 == 0) + Console.println("Pong: ping "+pongCount) + sender ! Pong + pongCount = pongCount + 1 + //stop ping ponging + case Stop => + Console.println("Pong: stop") + exit() + } + } + } +} + +/* + * And this is the main application, playing a game of ping pong + */ +object PingPong extends Application { + val pong = new Pong + val ping = new Ping(100000, pong) + ping.start + pong.start +} diff --git a/test/unit/scala_test.rb b/test/unit/scala_test.rb new file mode 100644 index 0000000..b6d4dd0 --- /dev/null +++ b/test/unit/scala_test.rb @@ -0,0 +1,9 @@ +require File.dirname(__FILE__) + '/../test_helper' + +class Ohcount::ScalaTest < Ohcount::Test + + def test_comprehensive + verify_parse("scala1.scala") + end + +end -- 2.32.0.93.g670b81a890