Add some tooling to bring in Antlr4 for eventually parsing .otto files
The thoughts are still swirling around in my head a bit, but given the current targets that Antlr4 supports, I fear that .otto file parsing will need to be handled in JavaScript or C++.
This commit is contained in:
parent
a3b5b0d6cf
commit
7020e1a509
|
@ -0,0 +1,42 @@
|
||||||
|
|
||||||
|
|
||||||
|
ANTLR_BIN=antlr-4.7.2-complete.jar
|
||||||
|
ANTLR=contrib/$(ANTLR_BIN)
|
||||||
|
GRAMMAR=Otto.g4
|
||||||
|
################################################################################
|
||||||
|
## Phony targets
|
||||||
|
all: help
|
||||||
|
|
||||||
|
check: ## Run validation tests
|
||||||
|
|
||||||
|
depends: prereqs $(ANTLR) ## Download all dependencies
|
||||||
|
|
||||||
|
prereqs: scripts/prereqs.sh ## Check that this system has the necessary tools to build otto
|
||||||
|
@sh scripts/prereqs.sh
|
||||||
|
|
||||||
|
clean: ## Clean all temporary/working files
|
||||||
|
rm -f $(ANTLR)
|
||||||
|
|
||||||
|
|
||||||
|
parser: depends $(GRAMMAR) ## Generate the parser code
|
||||||
|
@for target in JavaScript Go Cpp; do \
|
||||||
|
java -cp $(ANTLR) org.antlr.v4.Tool \
|
||||||
|
-Dlanguage=$$target \
|
||||||
|
-o build/$$target \
|
||||||
|
$(GRAMMAR); \
|
||||||
|
echo "--> Generated $$target stubs"; \
|
||||||
|
done;
|
||||||
|
|
||||||
|
################################################################################
|
||||||
|
## Non-phony targets
|
||||||
|
$(ANTLR): ## Download the latest ANTLR4 binary
|
||||||
|
(cd contrib && wget https://www.antlr.org/download/$(ANTLR_BIN))
|
||||||
|
|
||||||
|
################################################################################
|
||||||
|
|
||||||
|
# Cute hack thanks to:
|
||||||
|
# https://marmelab.com/blog/2016/02/29/auto-documented-makefile.html
|
||||||
|
help: ## Display this help text
|
||||||
|
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
|
||||||
|
|
||||||
|
.PHONY: all check clean depends
|
|
@ -0,0 +1,4 @@
|
||||||
|
grammar Otto;
|
||||||
|
r : 'hello' ID ; // match keyword hello followed by an identifier
|
||||||
|
ID : [a-z]+ ; // match lower-case identifiers
|
||||||
|
WS : [ \t\r\n]+ -> skip ; // skip spaces, tabs, newlines
|
|
@ -0,0 +1 @@
|
||||||
|
*
|
|
@ -0,0 +1 @@
|
||||||
|
*.jar
|
|
@ -0,0 +1,29 @@
|
||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
err() {
|
||||||
|
printf '\e[48;5;%dm' 196
|
||||||
|
echo -n ">> ${1}"
|
||||||
|
printf '\e[0m \n'
|
||||||
|
}
|
||||||
|
ok() {
|
||||||
|
printf '\e[48;5;%dm' 034
|
||||||
|
echo -n ">> ${1}"
|
||||||
|
printf '\e[0m \n'
|
||||||
|
}
|
||||||
|
|
||||||
|
which wget &> /dev/null
|
||||||
|
if [ $? -ne 0 ]; then
|
||||||
|
err "Please ensure that \`wget\` is in your PATH"
|
||||||
|
exit 1;
|
||||||
|
else
|
||||||
|
ok "wget is present"
|
||||||
|
fi;
|
||||||
|
|
||||||
|
which java &> /dev/null
|
||||||
|
if [ $? -ne 0 ]; then
|
||||||
|
err "Please ensure that \`java\` is in your PATH"
|
||||||
|
exit 1;
|
||||||
|
else
|
||||||
|
ok "Java is present"
|
||||||
|
fi;
|
||||||
|
|
Loading…
Reference in New Issue