Add antlr docker image and setup to generate the parser
This commit is contained in:
parent
67cf700ff6
commit
7f1080964a
9
Makefile
9
Makefile
|
@ -1,5 +1,14 @@
|
||||||
THIS_DIR=$(dir $(realpath $(firstword $(MAKEFILE_LIST))))
|
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
|
.PHONY: lint
|
||||||
lint:
|
lint:
|
||||||
cd $(THIS_DIR)/bootstrap && cargo fmt -- --check
|
cd $(THIS_DIR)/bootstrap && cargo fmt -- --check
|
||||||
|
|
|
@ -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"]
|
|
@ -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') ;
|
Loading…
Reference in New Issue