Skip to content
Open
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
13 changes: 12 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
.PHONY: ceptre
.PHONY: ceptre syn

ceptre:
mlton -output ceptre src/sources.mlb


syn: src/ceptre.cmlex.sml src/ceptre.cmyacc.sml

%.cmlex.sml : %.cmlex
cmlex $< -o $@

%.cmyacc.sml : %.cmyacc
cmyacc $< -o $@


12 changes: 9 additions & 3 deletions ceptre.vim
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,21 @@ syn clear
set iskeyword+=\",~,@,!,#-',*-45,47-57,59-90,94-122,\|,^:

syn keyword ceptrePercentKey #mode #interactive #trace #builtin
syn keyword ceptreType type pred bwd stage context
syn keyword ceptreType type pred action bwd stage context
syn match ceptrePunct ":\|\.\|="
syn match ceptreFVar "\<[A-Z_]\k*\>"
syn keyword ceptreSymbol -> <- -o o- *
syn match ceptreDecl "^\s*[^()A-Z_]\k*\s*:" contains=ceptrePunct

syn match ceptreNumber "0\|[1-9]\d*"
syn match ceptreEsc "\\."
syn region ceptreString start="\"" end="\"" contains=ceptreEsc

syn match ceptreCurly "{\|}" contained
syn match ceptreSquare "\[\|\]" contained
syn match ceptreBindDecl "[^A-Z_{\[]\k*\s*:" contains=ceptrePunct contained
syn region ceptrePiBind start="{" end="}" keepend transparent contains=ceptreCurly,ceptrePunct,ceptreFVar,ceptreSymbol,ceptreType,ceptreBindDecl,ceptreComment
syn region ceptreLamBind start="\[" end="\]" keepend transparent contains=ceptreSquare,ceptrePunct,ceptreFVar,ceptreSymbol,ceptreType,ceptreBindDecl,ceptreComment
syn region ceptrePiBind start="{" end="}" keepend transparent contains=ceptreCurly,ceptrePunct,ceptreFVar,ceptreSymbol,ceptreType,ceptreBindDecl,ceptreComment,ceptreNumber,ceptreString
syn region ceptreLamBind start="\[" end="\]" keepend transparent contains=ceptreSquare,ceptrePunct,ceptreFVar,ceptreSymbol,ceptreType,ceptreBindDecl,ceptreComment,ceptreNumber,ceptreString

syn match ceptreParen "(\|)" contained
syn region ceptreParens start="(" end=")" transparent contains=ALL
Expand All @@ -38,6 +41,9 @@ hi link ceptreSymbol Operator
hi link ceptreDecl Identifier
hi link ceptreBindDecl ceptreDeclarationFace
hi link ceptreFVar Identifier
hi link ceptreNumber Number
hi link ceptreEsc SpecialChar
hi link ceptreString String

" Indentation
setlocal foldmethod=syntax
Expand Down
32 changes: 32 additions & 0 deletions examples/write.cep
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
nat : type. #builtin NAT nat.
z : nat. #builtin NAT_ZERO z.
s nat : nat. #builtin NAT_SUCC s.

plus nat nat nat : bwd.
plus/z : plus z N N.
plus/s : plus (s N) M (s P) <- plus N M P.

go nat nat : pred.

str : type. #builtin STRING str.
write/str str : action. #builtin WRITE write/str.
write/nat nat : action. #builtin WRITE write/nat.
write/res str nat str nat str nat str : action. #builtin WRITE write/res.

stage rules {
name: go N M * plus N M P -o

write/res "The result of " N " + " M " is " P ".\n"

* write/str "THe result of "
* write/nat N
* write/str " + "
* write/nat M
* write/str " is "
* write/nat P
* write/str ".\n".
}

context init = { go 99 12 }.

#trace _ rules init.
5 changes: 5 additions & 0 deletions src/ceptre.cmlex
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ regexp ident = (seq id_start (* id_cont))
regexp ws = (+ white)
regexp number = (| '0 (seq posdigit (* digit)))

set nonesc = (~ (| '\ '"))
regexp esc = (seq '\ notnewln)
regexp string = (seq '" (* (| nonesc esc)) '")

function lexmain: t =
eos => eof
"pred" => pred
Expand Down Expand Up @@ -39,6 +43,7 @@ function lexmain: t =
"o-" => llolli
"-o" => rlolli
number => num
string => str
ident => ident
any => error
epsilon => error
Loading