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]) {
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 {
}
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 {