diff --git a/Makefile b/Makefile index cbecf97..45c422f 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,14 @@ THIS_DIR=$(dir $(realpath $(firstword $(MAKEFILE_LIST)))) + +.PHONY: build-antlr-image +build-antlr-image: + cd $(PWD)/bootstrap/grammar/ && docker build -t serene-antlr:latest . + +.PHONY: gen-parser-go +gen-parser-go: + docker run -it --rm --user $(shell id -u):$(shell id -g) -v $(PWD):/serene serene-antlr:latest -Dlanguage=Go -o /serene/bootstrap/pkg/parser/ /serene/bootstrap/grammar/Serene.g4 + .PHONY: lint lint: cd $(THIS_DIR)/bootstrap && cargo fmt -- --check diff --git a/bootstrap/grammar/Dockerfile b/bootstrap/grammar/Dockerfile new file mode 100644 index 0000000..2c72e88 --- /dev/null +++ b/bootstrap/grammar/Dockerfile @@ -0,0 +1,5 @@ +FROM openjdk:16-jdk-alpine3.12 + +WORKDIR / +RUN wget https://www.antlr.org/download/antlr-4.8-complete.jar +ENTRYPOINT ["java", "-jar", "/antlr-4.8-complete.jar"] diff --git a/bootstrap/grammar/Serene.g4 b/bootstrap/grammar/Serene.g4 new file mode 100644 index 0000000..236fa6c --- /dev/null +++ b/bootstrap/grammar/Serene.g4 @@ -0,0 +1,27 @@ +grammar Serene; +/*------------------------------------------------------------------ + * PARSER RULES + *------------------------------------------------------------------*/ +program : expression* EOF ; +expression: OP SYMBOL (SYMBOL | STRING | NUMBER | expression)* CP; + +/*------------------------------------------------------------------ + * LEXER RULES + *------------------------------------------------------------------*/ +SYMBOL : (LETTER (LETTER | DIGIT)*) ; + +OP : '('; +CP : ')'; + +STRING : '"' (LETTER | DIGIT)+ '"'; + +NUMBER : (DIGIT)+ ; + +WHITESPACE : [ \r\n\t] + -> channel (HIDDEN); + +DIGIT : '0'..'9'; + +LETTER : LOWER | UPPER ; + +LOWER : ('a'..'z') ; +UPPER : ('A'..'Z') ;