Created
April 25, 2019 17:48
-
-
Save toots/c0a082da9e92ebdae0025da49bfb52d8 to your computer and use it in GitHub Desktop.
Reproduction files for https://github.com/ocaml-community/sedlex/issues/45.
This file contains hidden or 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
open Parser | |
let rec tokenizer lexbuf = | |
match%sedlex lexbuf with | |
| '\n' -> tokenizer lexbuf | |
| Plus('0'..'9') -> NUMBER (Sedlexing.Utf8.lexeme lexbuf) | |
| ';', ';' -> SEQSEQ | |
| eof -> EOF | |
| _ -> failwith "Parse error!" |
This file contains hidden or 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
let interactive = | |
MenhirLib.Convert.Simplified.traditional2revised Parser.interactive | |
let empty_p = { | |
Lexing. | |
pos_fname = ""; | |
pos_lnum = 1; | |
pos_bol = 0; | |
pos_cnum = 0; | |
} | |
let get_token lexbuf = | |
let tokenizer () = | |
(Lexer.tokenizer lexbuf, empty_p, empty_p) | |
in | |
interactive tokenizer | |
let () = | |
let lexbuf = Sedlexing.Utf8.from_channel stdin in | |
let rec f () = | |
Printf.printf "Got number from stdin: %d\n%!" (get_token lexbuf); | |
f () | |
in | |
f () |
This file contains hidden or 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
.PHONY: clean all | |
x := cmx | |
i := cmi | |
V := @ | |
OCAMLOPT := ocamlfind ocamlopt | |
OCAMLDEP := ocamlfind ocamldep | |
OCAMLFLAGS := -g -linkpkg -package sedlex -package sedlex.ppx -package menhirlib | |
SOURCES := parser.mli parser.ml lexer.ml main.ml | |
all: test | |
parser.mli parser.ml: parser.mly | |
menhir --explain $(<) | |
.depend: $(SOURCES) | |
$(V)echo OCAMLDEP | |
$(V)$(OCAMLDEP) $(^) > $(@) | |
%.$(i): %.mli | |
$(V)echo OCAMLOPT -c $(<) | |
$(V)$(OCAMLOPT) $(OCAMLFLAGS) -c $(<) | |
%.$(x): %.ml | |
$(V)echo OCAMLOPT -c $(<) | |
$(V)$(OCAMLOPT) $(OCAMLFLAGS) -c $(<) | |
test: $(SOURCES:.ml=.$(x)) | |
$(V)echo OCAMLOPT -o $(@) | |
$(V)$(OCAMLOPT) -linkpkg -o $(@) $(^) $(OCAMLFLAGS) | |
clean: | |
rm -f .depend parser.mli parser.ml test *.o *.conflicts *.cm* | |
-include .depend |
This file contains hidden or 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
%token <string> NUMBER | |
%token SEQSEQ EOF | |
%start interactive | |
%type <int> interactive | |
%% | |
exprs: | |
| NUMBER { int_of_string $1 } | |
interactive: | |
| exprs SEQSEQ { $1 } | |
| EOF { raise End_of_file } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment