Skip to content
/ jflex Public
forked from jflex-de/jflex

Commit

Permalink
Merge branch 'master' into test-fileutil
Browse files Browse the repository at this point in the history
  • Loading branch information
regisd committed Oct 18, 2018
2 parents d4899d3 + d154372 commit ce7a037
Show file tree
Hide file tree
Showing 67 changed files with 764 additions and 255 deletions.
373 changes: 373 additions & 0 deletions .bazelrc

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions .travis.bazelrc → .ci.bazelrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import %workspace%/.bazelrc

# This is from Bazel's former travis setup, to avoid blowing up the RAM usage.
startup --host_jvm_args=-Xms2000m
startup --host_jvm_args=-Xmx3000m
Expand Down
12 changes: 12 additions & 0 deletions .cirrus.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Copyright 2018 Google LLC.
# SPDX-License-Identifier: Apache-2.0

container:
image: cirrusci/bazel:latest
task:
name: Bazel build and test
build_script:
- bazel --bazelrc=.ci.bazelrc info --remote_http_cache=http://$CIRRUS_HTTP_CACHE_HOST release
- bazel --bazelrc=.ci.bazelrc build --remote_http_cache=http://$CIRRUS_HTTP_CACHE_HOST //...
test_script:
- bazel --bazelrc=.ci.bazelrc test --remote_http_cache=http://$CIRRUS_HTTP_CACHE_HOST //...
4 changes: 3 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ matrix:
- scripts/test-unit.sh
- scripts/mvn-site.sh
- scripts/mvn-aggregate-srcs.sh
- scripts/preparare-deploy-source-code.sh
after_success: scripts/send-code-coverage.sh
env:
- PUBLISH_SOURCES=true
Expand Down Expand Up @@ -133,4 +134,5 @@ deploy:
- travis
condition:
- $PUBLISH_SOURCES
script: ./scripts/deploy-source-code.sh
script: scripts/deploy-aggregated-sources.sh

3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
<a href="https://travis-ci.org/jflex-de/jflex">
<img alt="Build status" src="https://travis-ci.org/jflex-de/jflex.svg?branch=master" height="20">
</a>
<a href="https://cirrus-ci.com/github/jflex-de/jflex/master">
<img alt="Bazel build status" src="https://api.cirrus-ci.com/github/jflex-de/jflex.svg" height="20">
</a>
<a href="https://search.maven.org/artifact/de.jflex/jflex/">
<img alt="Maven central" src="https://img.shields.io/maven-central/v/de.jflex/jflex.svg" height="20">
</a>
Expand Down
2 changes: 1 addition & 1 deletion WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository")

git_repository(
name = "jflex_rules",
branch = "stable",
tag = "v3",
remote = "https://github.com/jflex-de/bazel_rules.git",
)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package de.jflex.plugin.cup;
package jflex.maven.plugin.cup;

import static com.google.common.base.Preconditions.checkArgument;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package de.jflex.plugin.cup;
package jflex.maven.plugin.cup;

import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Optional;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package de.jflex.plugin.cup;
package jflex.maven.plugin.cup;

import com.google.common.base.Strings;
import java.io.File;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package de.jflex.plugin.cup;
package jflex.maven.plugin.cup;

import org.apache.maven.plugin.logging.Log;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package de.jflex.plugin.cup;
package jflex.maven.plugin.cup;

import static com.google.common.truth.Truth.assertThat;

import com.google.common.collect.ImmutableList;
import java.io.File;
import org.junit.Test;

/** Test for {@link CliCupInvoker}. */
/** Test for {@link jflex.maven.plugin.cup.CliCupInvoker}. */
public class CliCupInvokerTest {

@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package de.jflex.plugin.cup;
package jflex.maven.plugin.cup;

import static com.google.common.truth.Truth.assertThat;
import static com.google.common.truth.Truth.assertWithMessage;
Expand All @@ -9,7 +9,10 @@
import org.junit.Rule;
import org.junit.Test;

/** Integration test for {@link GenerateMojo} on {@code /jflex/cup/sample-project/pom.xml}. */
/**
* Integration test for {@link jflex.maven.plugin.cup.GenerateMojo} on {@code
* /jflex/cup/sample-project/pom.xml}.
*/
public class GenerateMojoIntegrationTest {

private MavenProject mavenTestProject;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package de.jflex.plugin.cup;
package jflex.maven.plugin.cup;

import static com.google.common.truth.Truth.assertThat;
import static org.mockito.ArgumentMatchers.endsWith;
Expand All @@ -17,7 +17,7 @@
import org.mockito.junit.MockitoJUnit;
import org.mockito.junit.MockitoRule;

/** Tests for {@link GenerateMojo}. */
/** Tests for {@link jflex.maven.plugin.cup.GenerateMojo}. */
public class GenerateMojoTest {

private GenerateMojo mojo;
Expand Down
14 changes: 0 additions & 14 deletions cup/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,6 @@ package(default_visibility = ["//visibility:public"])

licenses(["notice"]) # GPL-compatible

java_binary(
name = "cup_bin",
main_class = "java_cup.Main",
runtime_deps = [
":cup",
],
)

# This is the full Java CUP (with runtime)
java_import(
name = "cup",
jars = ["cup/java-cup-11b.jar"],
)

alias(
name = "cup_runtime",
actual = "//cup/cup_runtime",
Expand Down
5 changes: 4 additions & 1 deletion cup/cup_runtime/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,8 @@ licenses(["notice"]) # BSD-like
java_library(
name = "cup_runtime",
srcs = glob(["src/main/java/**/*.java"]),
visibility=["//visibility:public"]
visibility=["//visibility:public"],
javacopts=[
# Not our code, there is nothing we can do
"-XepDisableAllChecks"],
)
3 changes: 2 additions & 1 deletion cup/sample-project/BUILD
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
load("//cup:cup.bzl", "cup")
load("@jflex_rules//cup:cup.bzl", "cup")

cup(
name = "gen_parser",
src = "src/main/cup/calculator.cup",
cup_bin = "@jflex_rules//cup:cup_bin",
)
32 changes: 20 additions & 12 deletions docs/md/example.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,31 @@ A simple Example: How to work with JFlex {#Example}
========================================

To demonstrate how a lexical specification with JFlex looks like, this
section presents a part of the specification for the Java language. The
example does not describe the whole lexical structure of Java programs,
but only a small and simplified part of it (some keywords, some
operators, comments and only two kinds of literals). It also shows how
to interface with the LALR parser generator CUP [@CUP] and therefore uses
a class `sym` (generated by CUP), where integer constants for the
terminal tokens of the CUP grammar are declared. JFlex comes with a
directory `examples`, where you can find a small standalone scanner that
doesn’t need other tools like CUP to give you working example code without
dependencies.

The `examples` directory also contains a *complete* JFlex specification of the
section presents a part of the specification for the Java language.

The example does not describe the whole lexical structure of Java programs,
but only a small and simplified part of it:
- some keywords,
- some operators,
- comments
- and only two kinds of literals.

It also shows how to interface with the LALR parser generator CUP [@CUP]
and therefore uses a class `sym` (generated by CUP), where integer constants
for the terminal tokens of the CUP grammar are declared.

You can find this example in `examples/cup-java-simplified`.

The `examples/cup-java` directory also contains a *complete* JFlex specification of the
lexical structure of Java programs together with the CUP parser specification
for Java by C. Scott Ananian, obtained from the CUP [@CUP] web site (modified to
interface with the JFlex scanner). Both specifications adhere to the Java
Language Specification [@LangSpec].

In `examples/standalone`, you can find a small standalone scanner that
doesn’t need other dependencies or tools like CUP to give you working code.


```
/* JFlex example: partial Java language lexer specification */
import java_cup.runtime.*;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* License: BSD *
* *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
package de.jflex.plugin.maven;
package jflex.maven.plugin.jflex;

import com.google.common.base.Strings;
import java.io.File;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* License: BSD *
* *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
package de.jflex.plugin.maven;
package jflex.maven.plugin.jflex;

import static com.google.common.base.Strings.isNullOrEmpty;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* License: BSD *
* *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
package de.jflex.plugin.maven;
package jflex.maven.plugin.jflex;

import com.google.common.io.Files;
import java.io.File;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* License: BSD *
* *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
package de.jflex.plugin.maven;
package jflex.maven.plugin.jflex;

import static com.google.common.truth.Truth.assertThat;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* License: BSD *
* *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
package de.jflex.plugin.maven;
package jflex.maven.plugin.jflex;

import static com.google.common.truth.Truth.assertThat;
import static com.google.common.truth.Truth.assertWithMessage;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package de.jflex.plugin.maven;
package jflex.maven.plugin.jflex;

import static com.google.common.truth.Truth.assertThat;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package jflex;
package jflex.maven.plugin.unicode;

import java.io.IOException;
import java.io.InputStreamReader;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package jflex;
package jflex.maven.plugin.unicode;

import java.io.Reader;
import java.util.Map.Entry;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

package jflex;
package jflex.maven.plugin.unicode;

import java.io.File;
import java.io.IOException;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package jflex;
package jflex.maven.plugin.unicode;

import java.util.Objects;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package jflex;
package jflex.maven.plugin.unicode;

import java.util.ArrayList;
import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

package jflex;
package jflex.maven.plugin.unicode;

import java.io.BufferedReader;
import java.io.InputStreamReader;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

package jflex;
package jflex.maven.plugin.unicode;

import java.io.File;
import java.io.IOException;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package jflex;
package jflex.maven.plugin.unicode;

import java.util.SortedSet;
import java.util.TreeSet;
Expand Down Expand Up @@ -33,7 +33,7 @@ import java.util.TreeSet;
String propertyName = "Block";
int start;
int end;

public void addPropertyValueIntervals() {
int prevEnd = -1;
int prevStart = -1;
Expand All @@ -57,10 +57,10 @@ import java.util.TreeSet;

// Add final default property value interval, if necessary
if (prevEnd < unicodeVersion.maximumCodePoint) {
unicodeVersion.addInterval(propertyName, defaultPropertyValue,
unicodeVersion.addInterval(propertyName, defaultPropertyValue,
prevEnd + 1, unicodeVersion.maximumCodePoint);
}

// Add final named interval
unicodeVersion.addInterval(propertyName, prevValue, prevStart, prevEnd);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package jflex;
package jflex.maven.plugin.unicode;

import java.util.SortedSet;
import java.util.TreeSet;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package jflex;
package jflex.maven.plugin.unicode;

import java.util.SortedSet;
import java.util.TreeSet;
Expand Down Expand Up @@ -32,12 +32,12 @@ import java.util.Map;

%{
UnicodeVersion unicodeVersion;
Map<String, SortedSet<NamedRange>> properties
Map<String, SortedSet<NamedRange>> properties
= new HashMap<String, SortedSet<NamedRange>>();
String propertyName;
int start;
int end;

public void addPropertyIntervals() {
for (Map.Entry<String,SortedSet<NamedRange>> property : properties.entrySet()) {
String currentPropertyName = property.getKey();
Expand All @@ -57,7 +57,7 @@ import java.util.Map;
unicodeVersion.addInterval(currentPropertyName, prevStart, prevEnd);
}
}

public void addCurrentInterval() {
SortedSet<NamedRange> intervals = properties.get(propertyName);
if (null == intervals) {
Expand Down
Loading

0 comments on commit ce7a037

Please sign in to comment.