Skip to content

Commit

Permalink
Config example parser
Browse files Browse the repository at this point in the history
  • Loading branch information
djspiewak committed Jul 1, 2009
1 parent f182db9 commit 7c9569b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
6 changes: 5 additions & 1 deletion examples/buildfile
Expand Up @@ -28,7 +28,7 @@ define 'examples', :layout => layout do
trace cp

start = Time.now
system JAVA_HOME + '/bin/java', '-cp', cp, classname, *Dir.glob("input/#{name.downcase}/*")
sh JAVA_HOME + '/bin/java', '-cp', cp, classname, *Dir.glob("input/#{name.downcase}/*")

puts "Total run time: #{Time.now - start} seconds"
puts '---------------------------------------'
Expand All @@ -51,5 +51,9 @@ define 'examples', :layout => layout do
run_eg.call 'Paren'
end

task :conf => :compile do
run_eg.call 'Config'
end

task :run => [:arithmetic, :miniml, :lambdacalc, :paren]
end
@@ -1,4 +1,4 @@
package conf
package config

import scala.io.Source
import edu.uwm.cs.gll._
Expand All @@ -10,7 +10,7 @@ import edu.uwm.cs.gll._
* possible results into a single map. This illustrates a practical
* advantage to ambiguous parsing.
*/
object ConfigParser extends RegexParsers {
object ConfigParser extends common.Example[Map[String, String]] with RegexParsers {

class ConfigException(failures: List[Failure]) extends RuntimeException("Failed to parse config file")

Expand Down Expand Up @@ -43,6 +43,12 @@ object ConfigParser extends RegexParsers {
}
}

def handleSuccesses(forest: List[Map[String, String]]) {
for ((key, value) <- forest.foldLeft(Map[String, String]()) { _ ++ _ }) {
println(" " + key + " -> " + value)
}
}

// %%

override val whitespace = """[ \t]+"""r // process newlines separately
Expand Down

0 comments on commit 7c9569b

Please sign in to comment.