From 062d3944ee86c273ad3919993185d5901768ef2d Mon Sep 17 00:00:00 2001 From: Scott Lawrence Date: Tue, 25 Jun 2024 21:11:01 -0700 Subject: Attempting to use sedlex (and maybe Menhir) --- agate.opam | 2 ++ bin/dune | 3 ++- bin/main.ml | 12 +++++++++++- dune-project | 2 +- 4 files changed, 16 insertions(+), 3 deletions(-) diff --git a/agate.opam b/agate.opam index fcd4bfe..c9cea14 100644 --- a/agate.opam +++ b/agate.opam @@ -12,6 +12,8 @@ bug-reports: "https://github.com/username/reponame/issues" depends: [ "ocaml" "dune" {>= "3.16"} + "sedlex" + "menhir" "odoc" {with-doc} ] build: [ diff --git a/bin/dune b/bin/dune index 33c70b5..edad4dc 100644 --- a/bin/dune +++ b/bin/dune @@ -1,4 +1,5 @@ (executable (public_name agate) (name main) - (libraries agate)) + (libraries agate sedlex) + (preprocess (pps sedlex.ppx))) diff --git a/bin/main.ml b/bin/main.ml index 7bf6048..de7cd87 100644 --- a/bin/main.ml +++ b/bin/main.ml @@ -1 +1,11 @@ -let () = print_endline "Hello, World!" +let rec token buf = + match%sedlex buf with + | white_space -> token buf + | "a" -> token buf + | "b" -> 2 + | eof -> 0 + | _ -> failwith "Unknown token" + +let () = + let lexbuf = Sedlexing.Utf8.from_string "ab" in + print_newline (print_int (token lexbuf)) diff --git a/dune-project b/dune-project index 41ac7cf..d636dc5 100644 --- a/dune-project +++ b/dune-project @@ -19,7 +19,7 @@ (name agate) (synopsis "A strongly typed concatenative language") (description "A strongly typed concatenative language") - (depends ocaml dune) + (depends ocaml dune sedlex) (tags (topics "to describe" your project))) -- cgit v1.2.3-54-g00ecf