Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.sky.mattca.ccl3
- /**
- * Created by Matt on 22/02/14.
- */
- class SyntacticCategory(definition: SyntacticCategory*) {
- def this() {
- this()
- }
- }
- class OptionalSyntacticCategory(definition: SyntacticCategory*) extends SyntacticCategory(definition:_*) { }
- class MultipleSyntacticCategory(definition: SyntacticCategory*) extends SyntacticCategory(definition:_*) { }
- class OrSyntacticCategory(definition: SyntacticCategory*) extends SyntacticCategory(definition:_*) { }
- class LiteralSyntacticCategory(definition: String) extends SyntacticCategory() { }
- object SyntacticCategory {
- val Period = of(".")
- val Digit = of("1", "2", "3", "4", "5", "6", "7", "8", "9", "0")
- val UnaryMinus = of("-")
- val Integer = required(optional(UnaryMinus), Digit, multiple(Digit))
- val Decimal = required(optional(UnaryMinus), Digit, multiple(Digit), Period,
- Digit, multiple(Digit))
- def required(definition: SyntacticCategory*) = {
- new SyntacticCategory(definition:_*)
- }
- def optional(definition: SyntacticCategory*) = {
- new OptionalSyntacticCategory(definition:_*)
- }
- def multiple(definition: SyntacticCategory*) = {
- new MultipleSyntacticCategory(definition:_*)
- }
- def of(matches: String*) = {
- val literals = matches.map((literal) => {
- new LiteralSyntacticCategory(literal)
- })
- new OrSyntacticCategory(literals:_*)
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement