scala-parser-combinators

基于组合器的简单解析Scala。 以前是Scala标准库的一部分,现在是一个单独的社区维护模块。(simple combinator-based parsing for Scala. formerly part of the Scala standard library, now a separate community-maintained module)

Github星跟蹤圖

scala-parser-combinators




Scala Standard Parser Combinator Library

This library is now community-maintained. If you are interested in helping please contact @Philippus or @SethTisue.

As of Scala 2.11, this library is a separate jar that can be omitted from Scala projects that do not use Parser Combinators.

Documentation

Adding an sbt dependency

To depend on scala-parser-combinators in sbt, add something like this to your build.sbt:

libraryDependencies += "org.scala-lang.modules" %% "scala-parser-combinators" % "1.1.2"

To support multiple Scala versions, see the example in scala/scala-module-dependency-sample.

Scala.js and Scala Native

Scala-parser-combinators is also available for Scala.js 0.6+ and Scala Native:

libraryDependencies += "org.scala-lang.modules" %%% "scala-parser-combinators" % "1.1.2"

Example

import scala.util.parsing.combinator._

case class WordFreq(word: String, count: Int) {
  override def toString = s"Word <$word> occurs with frequency $count"
}

class SimpleParser extends RegexParsers {
  def word: Parser[String]   = """[a-z]+""".r       ^^ { _.toString }
  def number: Parser[Int]    = """(0, [1-9]\d*)""".r ^^ { _.toInt }
  def freq: Parser[WordFreq] = word ~ number        ^^ { case wd ~ fr => WordFreq(wd,fr) }
}

object TestSimpleParser extends SimpleParser {
  def main(args: Array[String]) = {
    parse(freq, "johnny 121") match {
      case Success(matched,_) => println(matched)
      case Failure(msg,_) => println(s"FAILURE: $msg")
      case Error(msg,_) => println(s"ERROR: $msg")
    }
  }
}

For a detailed unpacking of this example see
Getting Started.

Issues

Many old issues from the Scala JIRA issue tracker have been migrated
here, but not all of them. Community assistance identifying and
migrating still-relevant issues is welcome. See this
page
for
details.

Contributing

主要指標

概覽
名稱與所有者scala/scala-parser-combinators
主編程語言Scala
編程語言Scala (語言數: 1)
平台Linux, Mac, Windows
許可證Apache License 2.0
所有者活动
創建於2013-08-15 18:35:18
推送於2025-03-18 06:56:42
最后一次提交
發布數44
最新版本名稱v2.4.0 (發布於 )
第一版名稱v1.0-RC1 (發布於 2013-08-15 17:02:03)
用户参与
星數663
關注者數32
派生數131
提交數1.1k
已啟用問題?
問題數121
打開的問題數22
拉請求數412
打開的拉請求數2
關閉的拉請求數46
项目设置
已啟用Wiki?
已存檔?
是復刻?
已鎖定?
是鏡像?
是私有?