Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 1ece49c

Browse files
Merge pull request #115 from gourlaysama/merge-1.0.x-master
Merge 1.0.x to master (i.e. 1.1.x)
2 parents 2324d69 + 5a972f2 commit 1ece49c

File tree

12 files changed

+285
-69
lines changed

12 files changed

+285
-69
lines changed

‎.travis.yml‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ addons:
88
hosts:
99
- myshorthost
1010
hostname: myshorthost
11+
apt:
12+
packages:
13+
- graphviz
1114

1215
env:
1316
global:
@@ -28,3 +31,12 @@ notifications:
2831
email:
2932
- adriaan.moors@typesafe.com
3033
- antoine@gourlay.fr
34+
35+
before_cache:
36+
- find $HOME/.sbt -name "*.lock" | xargs rm
37+
- find $HOME/.ivy2/cache -name "ivydata-*.properties" | xargs rm
38+
cache:
39+
directories:
40+
- $HOME/.ivy2/cache
41+
- $HOME/.sbt/boot
42+
- $HOME/.sbt/launchers

‎README.md‎

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,60 @@ As of Scala 2.11, this library is a separate jar that can be omitted from Scala
99

1010
## Documentation
1111

12-
* [Latest version](http://www.scala-lang.org/files/archive/api/2.11.x/scala-parser-combinators/)
13-
* [Previous versions](http://scala-lang.org/documentation/api.html) (included in the API docs for the Scala library until Scala 2.11)
12+
* [Current API](https://javadoc.io/page/org.scala-lang.modules/scala-parser-combinators_2.12/latest/scala/util/parsing/combinator/index.html)
13+
* The [Getting Started](docs/Getting_Started.md) guide
14+
* A more complicated example, [Building a lexer and parser with Scala's Parser Combinators](https://enear.github.io/2016/03/31/parser-combinators/)
15+
* "Combinator Parsing", chapter 33 of [_Programming in Scala, Third Edition_](http://www.artima.com/shop/programming_in_scala), shows how to use this library to parse arithmetic expressions and JSON. The second half of the chapter examines how the library is implemented.
1416

1517
## Adding an SBT dependency
1618
To depend on scala-parser-combinators in SBT, add something like this to your build.sbt:
1719

1820
```
19-
libraryDependencies += "org.scala-lang.modules" %% "scala-parser-combinators" % "1.0.4"
21+
libraryDependencies += "org.scala-lang.modules" %% "scala-parser-combinators" % "1.0.6"
2022
```
2123

2224
(Assuming you're using a `scalaVersion` for which a scala-parser-combinators is published. The first 2.11 milestone for which this is true is 2.11.0-M4.)
2325

2426
To support multiple Scala versions, see the example in https://github.com/scala/scala-module-dependency-sample.
2527

28+
## Example
29+
30+
```scala
31+
import scala.util.parsing.combinator._
32+
33+
case class WordFreq(word: String, count: Int) {
34+
override def toString = "Word <" + word + "> " +
35+
"occurs with frequency " + count
36+
}
37+
38+
class SimpleParser extends RegexParsers {
39+
def word: Parser[String] = """[a-z]+""".r ^^ { _.toString }
40+
def number: Parser[Int] = """(0|[1-9]\d*)""".r ^^ { _.toInt }
41+
def freq: Parser[WordFreq] = word ~ number ^^ { case wd ~ fr => WordFreq(wd,fr) }
42+
}
43+
44+
object TestSimpleParser extends SimpleParser {
45+
def main(args: Array[String]) = {
46+
parse(freq, "johnny 121") match {
47+
case Success(matched,_) => println(matched)
48+
case Failure(msg,_) => println("FAILURE: " + msg)
49+
case Error(msg,_) => println("ERROR: " + msg)
50+
}
51+
}
52+
}
53+
```
54+
55+
For a detailed unpacking of this example see
56+
[Getting Started](docs/Getting_Started.md).
57+
58+
## ScalaJS support
59+
60+
Scala-parser-combinators directly supports scala-js 0.6+, starting with v1.0.5:
61+
62+
```
63+
libraryDependencies += "org.scala-lang.modules" %%% "scala-parser-combinators" % "1.0.6"
64+
```
65+
2666
## Contributing
2767

2868
* See the [Scala Developer Guidelines](https://github.com/scala/scala/blob/2.12.x/CONTRIBUTING.md) for general contributing guidelines

‎admin/README.md‎

Lines changed: 40 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
## Tag Driven Releasing
22

3-
Copied from https://github.com/scala/scala-java8-compat/commit/4a6cfc97cd95227b86650410e1b632e5ff79335b.
4-
53
### Background Reading
64

75
- http://docs.travis-ci.com/user/environment-variables/
@@ -14,47 +12,61 @@ To configure tag driven releases from Travis CI.
1412

1513
1. Generate a key pair for this repository with `./admin/genKeyPair.sh`.
1614
Edit `.travis.yml` and `admin/build.sh` as prompted.
17-
2. Publish the public key to https://pgp.mit.edu
18-
3. Store other secrets as encrypted environment variables with `admin/encryptEnvVars.sh`.
15+
1. Publish the public key to https://pgp.mit.edu
16+
1. Store other secrets as encrypted environment variables with `admin/encryptEnvVars.sh`.
1917
Edit `.travis.yml` as prompted.
20-
4. Edit `.travis.yml` to use `./admin/build.sh` as the build script,
18+
1. Edit `.travis.yml` to use `./admin/build.sh` as the build script,
2119
and edit that script to use the tasks required for this project.
22-
5. Edit `build.sbt` to select which JDK will be used for publishing.
20+
1. Edit `build.sbt`'s `scalaVersionsByJvm in ThisBuild` to select Scala and JVM version
21+
combinations that will be used for publishing.
2322

24-
It is important to add comments in .travis.yml to identify the name
23+
It is important to add comments in `.travis.yml` to identify the name
2524
of each environment variable encoded in a `:secure` section.
2625

27-
After all of these steps, your .travis.yml should contain config of the
28-
form:
26+
After these steps, your `.travis.yml` should contain config of the form:
27+
28+
```
29+
language: scala
30+
31+
env:
32+
global:
33+
# PGP_PASSPHRASE
34+
- secure: "XXXXXX"
35+
# SONA_USER
36+
- secure: "XXXXXX"
37+
# SONA_PASS
38+
- secure: "XXXXXX"
39+
40+
script: admin/build.sh
2941
30-
language: scala
31-
env:
32-
global:
33-
# PGP_PASSPHRASE
34-
- secure: "XXXXXX"
35-
# SONA_USER
36-
- secure: "XXXXXX"
37-
# SONA_PASS
38-
- secure: "XXXXXX"
39-
script: admin/build.sh
42+
jdk:
43+
- openjdk6
44+
- oraclejdk8
45+
46+
notifications:
47+
email:
48+
- a@b.com
49+
```
4050

4151
If Sonatype credentials change in the future, step 3 can be repeated
4252
without generating a new key.
4353

44-
Be sure to use SBT 0.13.7 or higher to avoid [#1430](https://github.com/sbt/sbt/issues/1430)!
45-
4654
### Testing
4755

48-
1. Follow the release process below to create a dummy release (e.g. 0.1.0-TEST1).
56+
1. Follow the release process below to create a dummy release (e.g., `v0.1.0-TEST1`).
4957
Confirm that the release was staged to Sonatype but do not release it to Maven
5058
central. Instead, drop the staging repository.
5159

5260
### Performing a release
5361

54-
1. Create a GitHub "Release" (with a corresponding tag) via the GitHub
62+
1. Create a GitHub "Release" with a corresponding tag (e.g., `v0.1.1`) via the GitHub
5563
web interface.
56-
2. Travis CI will schedule a build for this release. Review the build logs.
57-
3. Log into https://oss.sonatype.org/ and identify the staging repository.
58-
4. Sanity check its contents
59-
5. Release staging repository to Maven and send out release announcement.
60-
64+
1. The release will be published using the Scala and JVM version combinations specified
65+
in `scalaVersionsByJvm` in `build.sbt`.
66+
- If you need to release against a different Scala version, include the Scala version
67+
and the JVM version to use in the tag name, separated by `#`s (e.g., `v0.1.1#2.13.0-M1#8`).
68+
Note that the JVM version needs to be listed in `.travis.yml` for the build to run.
69+
1. Travis CI will schedule a build for this release. Review the build logs.
70+
1. Log into https://oss.sonatype.org/ and identify the staging repository.
71+
1. Sanity check its contents.
72+
1. Release staging repository to Maven and send out release announcement.

‎admin/build.sh‎

Lines changed: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,43 @@
22

33
set -e
44

5-
# prep environment for publish to sonatype staging if the HEAD commit is tagged
5+
# Builds of tagged revisions are published to sonatype staging.
66

7-
# git on travis does not fetch tags, but we have TRAVIS_TAG
8-
# headTag=$(git describe --exact-match ||:)
7+
# Travis runs a build on new revisions and on new tags, so a tagged revision is built twice.
8+
# Builds for a tag have TRAVIS_TAG defined, which we use for identifying tagged builds.
9+
# Checking the local git clone would not work because git on travis does not fetch tags.
10+
11+
# The version number to be published is extracted from the tag, e.g., v1.2.3 publishes
12+
# version 1.2.3 using all Scala versions in build.sbt's `crossScalaVersions`.
13+
14+
# When a new, binary incompatible Scala version becomes available, a previously released version
15+
# can be released using that new Scala version by creating a new tag containing the Scala and the
16+
# JVM version after hashes, e.g., v1.2.3#2.13.0-M1#8. The JVM version needs to be listed in
17+
# `.travis.yml`, otherwise the required build doesn't run.
18+
19+
verPat="[0-9]+\.[0-9]+\.[0-9]+(-[A-Za-z0-9-]+)?"
20+
tagPat="^v$verPat(#$verPat#[0-9]+)?$"
21+
22+
if [[ "$TRAVIS_TAG" =~ $tagPat ]]; then
23+
currentJvmVer=$(java -version 2>&1 | awk -F '"' '/version/ {print 2ドル}' | sed 's/^1\.//' | sed 's/[^0-9].*//')
24+
25+
tagVer=$(echo $TRAVIS_TAG | sed s/#.*// | sed s/^v//)
26+
publishVersion='set every version := "'$tagVer'"'
27+
28+
scalaAndJvmVer=$(echo $TRAVIS_TAG | sed s/[^#]*// | sed s/^#//)
29+
if [ "$scalaAndJvmVer" != "" ]; then
30+
scalaVer=$(echo $scalaAndJvmVer | sed s/#.*//)
31+
jvmVer=$(echo $scalaAndJvmVer | sed s/[^#]*// | sed s/^#//)
32+
if [ "$jvmVer" != "$currentJvmVer" ]; then
33+
echo "Not publishing $TRAVIS_TAG on Java version $currentJvmVer."
34+
exit 0
35+
fi
36+
publishScalaVersion='set every ScalaModulePlugin.scalaVersionsByJvm := Map('$jvmVer' -> List("'$scalaVer'" -> true))'
37+
echo "Releasing $tagVer using Scala $scalaVer on Java version $jvmVer."
38+
else
39+
echo "Releasing $tagVer on Java version $currentJvmVer according to 'scalaVersionsByJvm' in build.sbt."
40+
fi
941
10-
if [[ "$TRAVIS_TAG" =~ ^v[0-9]+\.[0-9]+\.[0-9]+(-[A-Za-z0-9-]+)? ]]; then
11-
echo "Going to release from tag $TRAVIS_TAG!"
12-
myVer=$(echo $TRAVIS_TAG | sed -e s/^v//)
13-
publishVersion='set every version := "'$myVer'"'
1442
extraTarget="+publish-signed"
1543
cat admin/gpg.sbt >> project/plugins.sbt
1644
cp admin/publish-settings.sbt .
@@ -22,4 +50,4 @@ if [[ "$TRAVIS_TAG" =~ ^v[0-9]+\.[0-9]+\.[0-9]+(-[A-Za-z0-9-]+)? ]]; then
2250
openssl aes-256-cbc -K $K -iv $IV -in admin/secring.asc.enc -out admin/secring.asc -d
2351
fi
2452
25-
sbt "$publishVersion" clean update +test +publishLocal $extraTarget
53+
sbt "$publishVersion" "$publishScalaVersion"clean update +test +publishLocal $extraTarget

‎build.sbt‎

Lines changed: 30 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,39 @@
1-
scalaVersion in ThisBuild:= crossScalaVersions.value.head
1+
importScalaModulePlugin._
22

3-
crossScalaVersions in ThisBuild := {
4-
val v211 = List("2.11.8")
5-
val v212 = List("2.12.0-RC1")
3+
scalaVersionsByJvm in ThisBuild := {
4+
val v211 = "2.11.11"
5+
val v212 = "2.12.2"
6+
val v213 = "2.13.0-M1"
67

7-
val javaVersion = System.getProperty("java.version")
8-
val isTravisPublishing = !util.Properties.envOrElse("TRAVIS_TAG", "").trim.isEmpty
9-
10-
if (isTravisPublishing) {
11-
if (javaVersion.startsWith("1.6.")) v211
12-
else if (javaVersion.startsWith("1.8.")) v212
13-
else Nil
14-
} else if (javaVersion.startsWith("1.6.") || javaVersion.startsWith("1.7.")) {
15-
v211
16-
} else if (javaVersion.startsWith("1.8.") || javaVersion.startsWith("9")) {
17-
v211 ++ v212
18-
} else {
19-
sys.error(s"Unsupported java version: $javaVersion.")
20-
}
8+
Map(
9+
6 -> List(v211 -> true),
10+
7 -> List(v211 -> false),
11+
8 -> List(v212 -> true, v213 -> true, v211 -> false),
12+
9 -> List(v212 -> false, v213 -> false, v211 -> false)
13+
)
2114
}
2215

16+
lazy val root = project.in(file("."))
17+
.aggregate(`scala-parser-combinatorsJS`, `scala-parser-combinatorsJVM`)
18+
.settings(disablePublishing)
19+
2320
lazy val `scala-parser-combinators` = crossProject.in(file(".")).
2421
settings(scalaModuleSettings: _*).
2522
settings(
26-
name := "scala-parser-combinators-root"
23+
name := "scala-parser-combinators-root",
24+
apiMappings += (scalaInstance.value.libraryJar ->
25+
url(s"https://www.scala-lang.org/api/${scalaVersion.value}/")),
26+
scalacOptions in (Compile, doc) ++= Seq(
27+
"-diagrams",
28+
"-doc-source-url",
29+
s"https://github.com/scala/scala-parser-combinators/tree/v${version.value}€{FILE_PATH}.scala",
30+
"-sourcepath",
31+
(baseDirectory in LocalRootProject).value.absolutePath,
32+
"-doc-title",
33+
"Scala Parser Combinators",
34+
"-doc-version",
35+
version.value
36+
)
2737
).
2838
jvmSettings(
2939
// Mima uses the name of the jvm project in the artifactId
@@ -38,14 +48,7 @@ lazy val `scala-parser-combinators` = crossProject.in(file(".")).
3848
version := "1.1.0-SNAPSHOT"
3949
).
4050
jvmSettings(
41-
// important!! must come here (why?)
42-
scalaModuleOsgiSettings: _*
43-
).
44-
jvmSettings(
45-
OsgiKeys.exportPackage := Seq(s"scala.util.parsing.*;version=${version.value}"),
46-
47-
// needed to fix classloader issues (see scala-xml#20)
48-
fork in Test := true
51+
OsgiKeys.exportPackage := Seq(s"scala.util.parsing.*;version=${version.value}")
4952
).
5053
jsSettings(
5154
// Scala.js cannot run forked tests

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /