Skip to content

Commit

Permalink
bugfix: fixed string parsing to ommit the quotes
Browse files Browse the repository at this point in the history
added function mkString to stdlib
  • Loading branch information
edofic committed Aug 26, 2012
1 parent fb84b01 commit 129e017
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
2 changes: 1 addition & 1 deletion main/src/com/edofic/scrat/Parser.scala
Expand Up @@ -21,7 +21,7 @@ object Parser extends RegexParsers {
}

private def string: Parser[SString] = "\".*?\"".r ^^ {
s => SString(s)
s => SString(s.substring(1, s.length - 1))
}

private def list: Parser[ExpList] = repsep(expr, ",") ^^ {
Expand Down
2 changes: 1 addition & 1 deletion main/src/com/edofic/scrat/Repl.scala
Expand Up @@ -28,7 +28,7 @@ object Repl {
| println("x is ", x)
|-standard library
| constants: pi, e
| functions: ln, log, print, println, readln
| functions: ln, log, print, println, readln, mkString
""".stripMargin

def repl() {
Expand Down
10 changes: 8 additions & 2 deletions main/src/com/edofic/scrat/ScratRuntime.scala
Expand Up @@ -23,6 +23,7 @@ class ScratRuntime {
("e" -> math.E),
("ln" -> functions.ln),
("log" -> functions.log),
("mkString" -> functions.mkString),
("print" -> functions.sprint),
("println" -> functions.sprintln),
("readln" -> functions.sreadln)
Expand All @@ -44,13 +45,18 @@ class ScratRuntime {
case other => throw ScratInvalidTypeError("expected single double but got " + other)
}

lazy val mkString: FunctionVarArg = {
case lst: List[_] => lst.mkString(" ")
case other => throw ScratInvalidTypeError("expected a list but got " + other)
}

lazy val sprint: FunctionVarArg = {
case lst: List[_] => print(lst.mkString(" "))
case lst: List[_] => lst --> mkString --> print
case other => throw ScratInvalidTypeError("expected a list but got " + other)
}

lazy val sprintln: FunctionVarArg = {
case lst: List[_] => println(lst.mkString(" "))
case lst: List[_] => lst --> mkString --> println
case other => throw ScratInvalidTypeError("expected a list but got " + other)
}

Expand Down

0 comments on commit 129e017

Please sign in to comment.