Skip to content

Instantly share code, notes, and snippets.

@adridadou
Created June 5, 2016 10:28
Show Gist options
  • Save adridadou/07eb7cf0040f18ee266c57819564e198 to your computer and use it in GitHub Desktop.
Save adridadou/07eb7cf0040f18ee266c57819564e198 to your computer and use it in GitHub Desktop.
class ClauseParser (val input: ParserInput, val parameters:Map[String,ContractField]) extends Parser with StringBuilding{
val openS = "{{"
val closeS = "}}"
def clause: Rule1[Clause] = rule { Parameters ~ Text ~ EOI ~> ((parameters, text) => Clause(text, parameters))}
def Parameter:Rule1[(String,ContractField)] = rule {
ID ~ ':' ~ ID ~> (createParameterPair(_,_))
}
def Parameters: Rule1[Map[String,ContractField]] = rule {
oneOrMore(Parameter).separatedBy('\n') ~ "###" ~> (_.toMap)
}
def ID:Rule1[String] = rule {
oneOrMore(CharPredicate.AlphaNum) ~ push(sb.toString)
}
def Text: Rule1[String] = rule {
oneOrMore(CharPredicate.All) ~push(sb.toString)
}
private def createParameterPair(name:String, parameterType:String):(String,ContractField) = name -> toParameterType(parameterType)
private def toParameterType(name:String):ContractField = name match {
case "FullName" => FullName
case "Address" => Address
case "Date" => ContractDate
case _ => Unknown(name)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment