Skip to content

jflex-de/bazel_rules

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
cup
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Bazel rules for JFlex & Cup

This repository offers two rules for projects using the Bazel build system:

  • Rule to generate java source files from a lexer specification, with JFlex

  • Rule to generate java source files from a parser specification, with CUP

Project health

Status of the master branch: Build status

Disclaimer

This is not an officially supported Google product.

Prepare your Bazel workspace

Add a dependency on rules_jvm_external

See bazelbuild/rules_jvm_external.

Load the jflex rule

Load the bazel_rules in your WORKSPACE file and add JFLEX_ARTIFACTS in your maven_install rule:

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
load("@rules_jvm_external//:defs.bzl", "maven_install")

http_archive(
    name = "jflex_rules",
    sha256 = "c4d68bde12f47af86b6f80a34dd55c67e82cf77b7ff2317cb472c07b1d09a6da",
    strip_prefix = "bazel_rules-1.9.1",
    url = "https://github.com/jflex-de/bazel_rules/archive/v1.9.1.tar.gz",
)

load("@jflex_rules//jflex:deps.bzl", "JFLEX_ARTIFACTS")

maven_install(
    name = "maven",
    artifacts = JFLEX_ARTIFACTS,
    maven_install_json = "//:maven_install.json",
    repositories = [
        "https://jcenter.bintray.com/",
        "https://maven.google.com",
        "https://repo1.maven.org/maven2",
    ],
)

If this is the first time you use maven_install, you need to generate the maven_install.json with

bazel run @maven//:pin

If you already used maven_install before, you need to update the pinned artifacts with:

bazel run @unpinned_maven//:pin

Usage in BUILD files

load("@jflex_rules//jflex:jflex.bzl", "jflex")
load("@jflex_rules//cup:cup.bzl", "cup")

jflex(
    name = "",           # Choose a rule name
    srcs = [],           # A list of flex specifications
    outputs = [],        # List of expected generated files
)

cup(
    name = "",           # Choose a rule name
    src = "",            # Grammar specification
)

As usual, these rules can be used as one of the srcs of another rules, such as a java_library.

For more details, see cup and jflex.

Directory layout

├── assets                 → assets for the web site
├── cup                    → contains the `cup.bzl` Skylark extension
├── java                   → main Java source code
│   └── jflex
│       └── examples       → examples
│           ├── calculator → integration of JFlex and CUP
│           └── helloworld → simple lexer
├── javatests              → tests of the examples
├── jflex                  → contains the `jflex.bzl` Skylark extension
└── third_party            → Aliases for third-party libraries