-
-
Save rightfold/699259d17c33fc9c244b to your computer and use it in GitHub Desktop.
This file contains 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 sexy.rightfold.millc.parse | |
import scala.util.parsing.combinator.{Parsers, RegexParsers} | |
import scala.util.parsing.input.CharSequenceReader | |
sealed abstract class Token | |
case class Identifier(name: String) extends Token | |
object lex extends Parsers with RegexParsers { | |
override def skipWhitespace = false | |
def lexeme[T](p: Parser[T]) = p <~ space.* | |
def space = elem("space", " \n".toSet) | |
def token = lexeme("""[a-zA-Z][a-zA-Z0-9_-]*[!?]?""".r ^^ Identifier) | |
def apply(text: String): Seq[Token] = { | |
val parser = space.* ~> token.* | |
val Success(result, rest) = parser(new CharSequenceReader(text)) | |
if (!rest.atEnd) { | |
throw new Exception("fuck") | |
} | |
result | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment