Skip to content

Commit

Permalink
Start work on Hmc.Grammar
Browse files Browse the repository at this point in the history
  • Loading branch information
Jason Evans committed Sep 29, 2024
1 parent 1508526 commit a750f4f
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 0 deletions.
89 changes: 89 additions & 0 deletions bootstrap/src/hmc/Grammar.hmh
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
open Basis
open! Basis.Rudiments

type token = {source: Source.Slice.t}

type nonterm_sep =
| SepSemi of token
| SepLineDelim of token
type nonterm_rec =
| Rec
| RecNon
type nonterm_type_param =
| TypeParam
type nonterm_type_params =
| TypeParams
type nonterm_type_args =
| TypeArgs
type nonterm_c_module_def =
| CModuleDef
type nonterm_expr =
| ExprUnit
type nonterm_c_module_item =
| CModuleItem
type nonterm_c_module_items =
| CModuleItems
type nonterm_hm =
| Hm

include hocc
token AND "and" of token
token REC "rec" of token
token TYPE "type" of token
token TICK "'" of token
token CARAT "^" of token
token EQ "=" of token
token GT ">" of token
token LCURLY "{" of token
token RCURLY "}" of token
token LPAREN "(" of token
token RPAREN ")" of token
token LINE_DELIM of token
token COLON ":" of token
token SEMI ";" of token
token UIDENT of token
token CIDENT of token
token EOI of token

nonterm Sep of nonterm_sep ::=
| {source}:";" -> SepSemi {source}
| {source}:LINE_DELIM -> SepLineDelim {source}

nonterm Rec of nonterm_rec ::=
| "rec" -> Rec
| epsilon -> RecNon

nonterm TypeParam of nonterm_type_param ::=
| "'" UIDENT
| "^" UIDENT
| ">" UIDENT
-> TypeParam

nonterm TypeParams of nonterm_type_params ::=
| TypeParam TypeParams
| epsilon
-> TypeParams

nonterm TypeArgs of nonterm_type_args ::=
| epsilon
-> TypeArgs

nonterm CModuleDef of nonterm_c_module_def ::=
| "type" Rec CIDENT TypeParams ":" CIDENT TypeArgs "=" "{" (* XXX *) "}"
| CIDENT
-> CModuleDef

nonterm Expr of nonterm_expr ::=
| "(" ")" -> ExprUnit

nonterm CModuleItem of nonterm_c_module_item ::=
| CModuleDef
| Expr
-> CModuleItem

nonterm CModuleItems of nonterm_c_module_items ::=
| CModuleItem Sep CModuleItems -> CModuleItems
| epsilon -> CModuleItems

start Hm of nonterm_hm ::=
| CModuleItems EOI -> Hm
10 changes: 10 additions & 0 deletions bootstrap/src/hmc/dune
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,13 @@
(libraries Basis)
(synopsis "Hemlock bootstrap compiler library")
)

; This rule calls an out-of-tree `hocc`, because the in-tree one depends on `Hmc`.
(rule
(deps
(glob_files Grammar.hmh*))
(targets Grammar.ml)
(action
(with-accepted-exit-codes
(or 0 1)
(system "hocc -v -txt -a ielr1 -ml -s Grammar"))))

0 comments on commit a750f4f

Please sign in to comment.