Skip to content
Go to file

Latest commit


Git stats


Failed to load latest commit information.
Latest commit message
Commit time

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


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:git.bzl", "git_repository")

        name = "jflex_rules",
        remote = "",
        branch = "stable",

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

    name = "maven",
    artifacts = JFLEX_ARTIFACTS,
    maven_install_json = "//:maven_install.json",
    repositories = [

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 mven_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")

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

    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

You can’t perform that action at this time.