package(default_visibility = ["//visibility:public"])

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

# The best practice is to define the rules in their respective directory in
# - src/main/java/org/example/foo/BUILD
# - src/main/jflex/BUILD
# - src/test/java/org/example/foo/BUILD
# - etc.
# However, this example is simple enough and we can define all rules here.

java_library(
    name = "minijava",
    # glob is not a best practice, but it's good enough for this example
    srcs = glob(["src/main/java/**/*.java"]) + [
        ":gen_lexer",
        ":gen_parser",
    ],
    deps = ["//third_party/java_cup:runtime"],
)

jflex(
    name = "gen_lexer",
    srcs = ["src/main/jflex/minijava.flex"],
    jflex_bin = "//jflex:jflex_bin",
    outputs = ["Lexer.java"],
)

cup(
    name = "gen_parser",
    src = "src/main/cup/minijava.cup",
    symbols = "sym",
)

# Tests
java_test(
    name = "LexerTest",
    srcs = ["src/test/java/jflex/examples/minijava/LexerTest.java"],
    deps = [
        ":minijava",
        "//third_party/com/google/truth",
        "//third_party/java_cup:runtime",
    ],
)
