Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2014
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scala 1.39 KB | None | 0 0
  1. package com.sky.mattca.ccl3
  2.  
  3. /**
  4.  * Created by Matt on 22/02/14.
  5.  */
  6. class SyntacticCategory(definition: SyntacticCategory*) {
  7.  
  8.   def this() {
  9.     this()
  10.   }
  11.  
  12. }
  13.  
  14. class OptionalSyntacticCategory(definition: SyntacticCategory*) extends SyntacticCategory(definition:_*) { }
  15.  
  16. class MultipleSyntacticCategory(definition: SyntacticCategory*) extends SyntacticCategory(definition:_*) { }
  17.  
  18. class OrSyntacticCategory(definition: SyntacticCategory*) extends SyntacticCategory(definition:_*) { }
  19.  
  20. class LiteralSyntacticCategory(definition: String) extends SyntacticCategory() { }
  21.  
  22. object SyntacticCategory {
  23.  
  24.   val Period = of(".")
  25.   val Digit = of("1", "2", "3", "4", "5", "6", "7", "8", "9", "0")
  26.   val UnaryMinus = of("-")
  27.  
  28.   val Integer = required(optional(UnaryMinus), Digit, multiple(Digit))
  29.   val Decimal = required(optional(UnaryMinus), Digit, multiple(Digit), Period,
  30.     Digit, multiple(Digit))
  31.  
  32.   def required(definition: SyntacticCategory*) = {
  33.     new SyntacticCategory(definition:_*)
  34.   }
  35.  
  36.   def optional(definition: SyntacticCategory*) = {
  37.     new OptionalSyntacticCategory(definition:_*)
  38.   }
  39.  
  40.   def multiple(definition: SyntacticCategory*) = {
  41.     new MultipleSyntacticCategory(definition:_*)
  42.   }
  43.  
  44.   def of(matches: String*) = {
  45.     val literals = matches.map((literal) => {
  46.       new LiteralSyntacticCategory(literal)
  47.     })
  48.     new OrSyntacticCategory(literals:_*)
  49.   }
  50.  
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement