Created
December 9, 2011 07:38
-
-
Save eiennohito/1450635 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package org.eiennohito.scot.epwing.simple.gaiji | |
import util.parsing.combinator.RegexParsers | |
/** | |
* @author eiennohito | |
* @since 09.12.11 | |
*/ | |
abstract class Literal { | |
def process(g: GaijiDict): String | |
} | |
case class StringLiteral(s: String) extends Literal { | |
def process(g: GaijiDict) = s | |
} | |
case class Gaiji(v: String) extends Literal { | |
def process(g: GaijiDict) = { | |
g(v) match { | |
case Some(va) => va | |
case None => "_" | |
} | |
} | |
} | |
class GaijiParser extends RegexParsers { | |
def word = "[^\\[]+".r ^^ { StringLiteral(_) } | |
def gaiji = "[GAIJI=" <~ ".[0-9a-fA-F]".r ~> "]" ^^ { Gaiji(_) } | |
def article = word ~ (gaiji ~ word).* ^^ { | |
case w ~ l => w :: l.flatMap { | |
case gaiji ~ word=> gaiji :: word :: Nil | |
} | |
} | |
def parse(s: String) = parseAll(article, s) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment