-
Notifications
You must be signed in to change notification settings - Fork 116
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add a genrule for cup - Update readme for cup - Fix sample
- Loading branch information
Showing
4 changed files
with
50 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
"""Bazel rules for cup. """ | ||
|
||
# CUP can only read from stdin, which Skylark rules don't support. Use a genrule for now. | ||
def cup(name, src, parser = "Parser", symbols = "Symbols", interface = False): | ||
"""Generate a parser with CUP. | ||
Args: | ||
name: name of the rule | ||
srcs: list of cup specifications | ||
parser: name of the generated parser class | ||
symbols: name of the generated symbols class | ||
interface: whether to generate an interface | ||
""" | ||
opts = "-parser {parser} -symbols {symbols}".format(parser = parser, symbols = symbols) | ||
if interface: | ||
opts = opts + " -interface" | ||
cmd = ("$(location //cup:cup_bin) -destdir $(@D) " + opts + " < $<") | ||
native.genrule( | ||
name = name, | ||
srcs = [src], | ||
tools = ["//cup:cup_bin"], | ||
outs = [parser + ".java", symbols + ".java"], | ||
cmd = cmd, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
load("//cup:cup.bzl", "cup") | ||
|
||
cup( | ||
name = "gen_parser", | ||
src = "src/main/cup/calculator.cup", | ||
) |