]> git.unchartedbackwaters.co.uk Git - francis/ofc.git/commitdiff
Pattern match ONETEP-specific initialisers.
authorFrancis Russell <francis@unchartedbackwaters.co.uk>
Tue, 3 Jan 2012 19:18:56 +0000 (19:18 +0000)
committerFrancis Russell <francis@unchartedbackwaters.co.uk>
Tue, 3 Jan 2012 19:18:56 +0000 (19:18 +0000)
src/ofc/generators/Onetep.scala
src/ofc/parser/Parser.scala
src/ofc/parser/Statement.scala

index d3744340fd48c59acec0936b629b01fca0aaf066..5ffe37b87e9d5826d3309211bc30227a4ebb2ff7 100644 (file)
@@ -36,16 +36,35 @@ class Onetep extends Generator {
     filterStatements[parser.DeclarationList](statements).flatMap(getMappings(_)).toMap
   }
 
-  def buildMatrix(id: parser.Identifier, call : Option[parser.FunctionCall]) = {
-    println(id + " " + call)
+  def buildMatrix(id: parser.Identifier, call : Option[parser.FunctionCall]) {
+    import parser._
+
+    call match {
+      case Some(FunctionCall(matType, params)) => (matType, params) match {
+        case (Identifier("SPAM3"), ParameterList(StringParameter(name))) => println(name)
+        case _ => throw new InvalidInputException("Unknown usage of type: "+matType.name)
+      }
+      case _ => throw new InvalidInputException("Undefined concrete type for matrix: "+id.name)
+    }
   }
 
-  def buildFunctionSet(id: parser.Identifier, call : Option[parser.FunctionCall]) = {
-    println(id + " " + call)
+  def buildFunctionSet(id: parser.Identifier, call : Option[parser.FunctionCall]) {
+    import parser._
+
+    call match {
+      case Some(FunctionCall(fSetType, params)) => (fSetType, params) match {
+        case (Identifier("PPDFunctionSet"), ParameterList(StringParameter(basis), StringParameter(data))) => println(basis)
+        case _ => throw new InvalidInputException("Unknown usage of type: "+fSetType.name)
+      }
+      case _ => throw new InvalidInputException("Undefined concrete type for function set: "+id.name)
+    }
   }
 
-  def buildIndex(id: parser.Identifier, call : Option[parser.FunctionCall]) = {
-    println(id + " " + call)
+  def buildIndex(id: parser.Identifier, call : Option[parser.FunctionCall]) {
+    call match {
+      case Some(_) => throw new InvalidInputException("Index "+id.name+" cannot have concrete type.")
+      case None => ()
+    }
   }
 
   def buildDictionary(statements : List[parser.Statement]) {
index b22ea74ee62514e18399a4c0775d85fa1ea1c157..2a7b2bd4e81268dcce5c271ed0889d8fab956022 100644 (file)
@@ -51,12 +51,12 @@ class Parser extends JavaTokenParsers {
   def target : Parser[Target] = "target"~!identifier ^^ (x => new Target(x._2))
   def specifics : Parser[TargetAssignment] = identifier~("is"~>functionCall) ^^ (x => new TargetAssignment(x._1, x._2))
   def functionCall : Parser[FunctionCall] = identifier~("("~>repsep(functionParameter, ",")<~")") ^^ 
-    (x => new FunctionCall(x._1, new ParameterList(x._2)))
+    (x => new FunctionCall(x._1, new ParameterList(x._2 : _*)))
   
   def functionParameter : Parser[Parameter] = stringParameter | numericParameter | parameterList
   def stringParameter : Parser[StringParameter] = stringLiteral ^^ (x => new StringParameter(x.slice(1, x.length-1)))
   def numericParameter : Parser[NumericParameter] = floatingPointNumber ^^ (x => new NumericParameter(x.toDouble))
-  def parameterList : Parser[ParameterList] = "["~>repsep(functionParameter, ",")<~"]" ^^ (x => new ParameterList(x))
+  def parameterList : Parser[ParameterList] = "["~>repsep(functionParameter, ",")<~"]" ^^ (x => new ParameterList(x : _*))
 
   def parseProgram(in: Reader) : List[Statement] =
     parseAll(program, in) match {
index 01a1fbbc2f725c780990ebfa803c7cc29aff4a49..d794c1f0a80d7ac15cced390c0284db4523c4759 100644 (file)
@@ -56,7 +56,7 @@ case class FunctionCall(name: Identifier, params: ParameterList) {
 }
 
 sealed abstract class Parameter
-case class ParameterList(params: List[Parameter]) extends Parameter {
+case class ParameterList(params: Parameter*) extends Parameter {
   override def toString : String = params.mkString("[", ", ", "]")
 }
 case class StringParameter(s: String)  extends Parameter {