Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor AST into standalone library #69

Merged
merged 1 commit into from
Aug 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .ocamlformat
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version=0.26.1
version=0.26.2
3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ RUN sudo apt-get update \
RUN sudo ln -f /usr/bin/opam-2.1 /usr/bin/opam
USER 1000:1000
RUN cd ~/opam-repository && git pull origin -q master && git reset --hard 3505e93828fa76861e82d09d92a37a6272d46da5 && opam update
COPY --chown=opam shark.opam /src/
COPY --chown=opam shark.opam shark-ast.opam /src/
WORKDIR /src
RUN opam pin . -yn
RUN opam install -y --deps-only --with-test .
ADD --chown=opam . .
RUN opam exec -- dune build @runtest @install @check
Expand Down
39 changes: 39 additions & 0 deletions shark-ast.opam
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# This file is generated by dune, edit dune-project instead
opam-version: "2.0"
homepage:"https://github.com/RyanGibb/shark"
bug-reports:"https://github.com/RyanGibb/shark/issues"
synopsis:"Shhhhhark!"
authors:[
"Ryan Gibb"
"Patrick Ferris"
"Michael Dales"
]
# Didn't want to burden you @Ryan!
maintainer:"[email protected]"
depends: [
"dune" {>= "3.3"}
"ocaml"
"obuilder-spec"
"yaml"

"digestif"

"patdiff" {with-test}
"mdx" {with-test}
"alcotest" {with-test}
]
build: [
["dune" "subst"] {dev}
[
"dune"
"build"
"-p"
name
"-j"
jobs
"@install"
"@runtest" {with-test}
"@doc" {with-doc}
]
]

2 changes: 2 additions & 0 deletions shark.opam
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ maintainer:"[email protected]"
depends: [
"dune" {>= "3.3"}
"ocaml"

"shark-ast"
# "obuilder"
"obuilder-spec"
"cmarkit"
Expand Down
1 change: 1 addition & 0 deletions src/bin/dune
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
(executable
(name main)
(public_name shark)
(package shark)
(libraries
eio_posix
shark
Expand Down
23 changes: 13 additions & 10 deletions src/bin/main.ml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
open Shark_ast

let ( / ) = Filename.concat

module Sandbox = Obuilder.Native_sandbox
Expand Down Expand Up @@ -142,7 +144,7 @@ let md ~fs ~net ~domain_mgr ~proc () no_run store conf file port fetcher jobs
let file_path = Eio.Path.(fs / file) in
let template_markdown = Eio.Path.load file_path in
let ast, markdown =
Shark.Ast.of_sharkdown ~concrete_paths:import_map template_markdown
Shark.Md_to_ast.of_sharkdown ~concrete_paths:import_map template_markdown
in

let doc = Cmarkit.Doc.of_string markdown in
Expand All @@ -154,7 +156,7 @@ let md ~fs ~net ~domain_mgr ~proc () no_run store conf file port fetcher jobs
let f ~build_cache code_block block =
if no_run then (code_block, `Continue)
else
match Shark.Block.kind block with
match Ast.Block.Raw.kind block with
| `Import -> (
(* First we translate the import statement to a build block *)
let uid = string_of_int !import_uid in
Expand All @@ -164,11 +166,12 @@ let md ~fs ~net ~domain_mgr ~proc () no_run store conf file port fetcher jobs
(* Now we build the block *)
(* Import block digests need to be mapped to this build hash *)
let hb =
match Shark.Ast.find_ast_block_from_shark_block ast block with
match Ast.find_block_from_raw_block ast block with
| Some hb -> hb
| None ->
Logs.info (fun f ->
f "Failed to find the astblock for %a" Shark.Block.pp block);
f "Failed to find the astblock for %a" Ast.Block.Raw.pp
block);
failwith "Block not found"
in
let res =
Expand All @@ -181,9 +184,9 @@ let md ~fs ~net ~domain_mgr ~proc () no_run store conf file port fetcher jobs
| `Stop msg -> Error (msg, cb)
| `Continue ->
Ok
( Shark.Block.alias blk,
( Ast.Block.Raw.alias blk,
option_get ~msg:"Block hash for import"
(Shark.Block.hash blk),
(Ast.Block.Raw.hash blk),
cb )
in
match res with
Expand All @@ -205,9 +208,9 @@ let md ~fs ~net ~domain_mgr ~proc () no_run store conf file port fetcher jobs
| `Stop msg -> Error (msg, cb)
| `Continue ->
Ok
( Shark.Block.alias blk,
( Ast.Block.Raw.alias blk,
option_get ~msg:"Block hash for build"
(Shark.Block.hash blk),
(Ast.Block.Raw.hash blk),
cb )
in
match res with
Expand Down Expand Up @@ -266,8 +269,8 @@ let dot ~fs () file =
run_eventloop @@ fun () ->
let file_path = Eio.Path.(fs / file) in
let template_markdown = Eio.Path.load file_path in
let s = Shark.Dotrenderer.render ~template_markdown in
Format.pp_print_string Format.std_formatter s;
let ast, _ = Shark.Md_to_ast.of_sharkdown template_markdown in
Shark_ast.Ast.pp_dot Fmt.stdout ast;
Ok ()

open Cmdliner
Expand Down
Loading
Loading