This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import scala.tools.nsc.interactive.{Global, RefinedBuildManager} | |
| import scala.tools.nsc.Settings | |
| import scala.tools.nsc.reporters.StoreReporter | |
| import scala.tools.nsc.io._ | |
| import scala.tools.nsc.util._ | |
| import scala.tools.nsc.interactive.Response | |
| import scala.tools.nsc.util.{Position, OffsetPosition} | |
| import scala.reflect.generic.Trees | |
| val settings = new Settings |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| object Interpreter { | |
| def main(args:Array[String]) = { | |
| (new SimpleParser).parseString("2*3.2 + 3*(36.07/4 - 10)").println | |
| } | |
| import scala.util.parsing.combinator._ | |
| class SimpleParser extends JavaTokenParsers { | |
| def expr: Parser[Double] = ( | |
| term~"+"~expr ^^ { case a~"+"~b => a + b } | |
| | term~"-"~expr ^^ { case a~"-"~b => a - b } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package socco | |
| abstract class SoccoTree(val children:List[SoccoTree]) extends Seq[SoccoTree] with SoccoNode[SoccoTree] { | |
| def apply(n:Int) = children(n) | |
| def iterator = children.iterator | |
| def length = children.length | |
| // def add(t:SoccoTree)(implicit builder:SoccoTreeBuilder[B]) = builder.build(this.asInstanceOf[B], children :+ t) | |
| } | |
| trait SoccoNode[B <: SoccoTree] { | |
| def soccoCompanion:SoccoTreeCompanion[B] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| test 1.2.3 (c) 2012 Mr Placeholder | |
| Usage: test [OPTION]... | |
| test is an awesome program, which does something funny | |
| Options: | |
| -Dkey=value [key=value]... | |
| some key-value pairs | |
| -d, --donkey | |
| use donkey mode | |
| -m, --monkeys <arg> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| object Main extends App { | |
| object Conf extends ScallopConf(arguments) { | |
| val apples:SOption[Int] = opt[Int]("apples") | |
| val bananas = opt[Int]("bananas") | |
| val file = trailArg[String] | |
| verify | |
| } | |
| Conf.apples.get | |
| Conf.bananas.option // not sure about option retreiving syntax | |
| // maybe I should copy the code for SOption from stdlib Option? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import org.rogach.scallop._ | |
| import org.scalatest.FunSuite | |
| import org.scalatest.matchers.ShouldMatchers | |
| /** | |
| * Created with IntelliJ IDEA. | |
| * User: Alexy | |
| * Date: 4/6/12 | |
| * Time: 10:34 AM |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| object Conf extends ScallopConf(List("-a","3","-b","5","tree")) { | |
| val apples = opt[Int]("apples") | |
| val bananas = opt[Int]("bananas") | |
| verify | |
| } | |
| Conf.apples() // 3 | |
| Conf.bananas.get // Some(5) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def LogConfig(configItem: String, configValue: Any) = { | |
| val logString = configValue match { | |
| case configValueMap: Map[_,_] => "Configured " + configItem + " to " + configValueMap.mkString("{",", ","}") + "." | |
| case _ => "Configured " + configItem + " to " + configValue + "." | |
| } | |
| info(logString) | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def readConfig(lines:List[String]):mutable.Map[String,Map[String,String]] = { | |
| // assuming that *all* properties have their sections | |
| if (lines.isEmpty) Map() | |
| else { | |
| val sectionRgx = """\s*\[(.*)\]\s*""".r | |
| val sectionRgx(sectName) = lines.head | |
| val pairs = lines.tail.takeWhile(!_.startsWith("[")).map(_.split("=")).map(a => (a(0),a(1))).toMap | |
| Map(sectName -> pairs) ++ readConfig(lines.tail.dropWhile(!_.startsWith("[")) | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import javax.xml.parsers.SAXParser; | |
| import javax.xml.parsers.SAXParserFactory; | |
| import org.xml.sax.Attributes; | |
| import org.xml.sax.SAXException; | |
| import org.xml.sax.helpers.DefaultHandler; | |
| object ReadXMLFile { | |
| def main(argv: Array[String]) { | |
| try { | |
| val factory = SAXParserFactory.newInstance |
OlderNewer