-
Notifications
You must be signed in to change notification settings - Fork 0
/
Semacrolon.idr
51 lines (40 loc) · 1.76 KB
/
Semacrolon.idr
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
module Semacrolon
import Nope
%access public export
%default total
--data SemacrolonToken : Type where
-- STMacro : SemacrolonToken
-- STEq : SemacrolonToken
-- STMacroName : String -> SemacrolonToken
-- STTerm : Term String -> SemacrolonToken
data SemacrolonExpr : Type where
MacroAppl : String -> List SemacrolonExpr -> SemacrolonExpr
NopeAppl : Term String -> SemacrolonExpr -> List SemacrolonExpr -> SemacrolonExpr
SemacrolonTerm : Term String -> SemacrolonExpr
data SemacrolonAst : Type where
MacroDef : String -> List SemacrolonExpr -> NopeAst -> SemacrolonAst
MacroExpr : SemacrolonExpr -> SemacrolonAst
mutual
-- This is necessary for totality
unwrapQuotedIds_ : List NopeAst -> List NopeAst
unwrapQuotedIds_ [] = []
unwrapQuotedIds_ (ast :: asts) = unwrapQuotedIds ast :: unwrapQuotedIds_ asts
unwrapQuotedIds : NopeAst -> NopeAst
unwrapQuotedIds (TermAst (Raw '#' y)) = TermAst (Id y)
unwrapQuotedIds (TermAst term@(Raw _ _)) = TermAst term
unwrapQuotedIds (TermAst term@(Id _)) = TermAst term
unwrapQuotedIds (Appl ast ast_ asts) =
Appl (unwrapQuotedIds ast) (unwrapQuotedIds ast_) (unwrapQuotedIds_ asts)
parseMacroExpr : NopeAst -> Maybe SemacrolonExpr
parseMacroExpr (TermAst term@(Raw _ _)) = Just $ SemacrolonTerm term
parseMacroExpr (TermAst (Id x)) =
case unpack x of
('#' :: _) => Nothing
(';' :: _) => Just $ MacroAppl x []
_ => Just $ SemacrolonTerm $ Id x
parseMacroExpr (Appl (TermAst x) ast2 xs) = ?parseMacroExpr_rhs_1
parseMacroExpr (Appl (Appl ast ast_ ys) ast2 xs) = ?parseMacroExpr_rhs_3
parseMacro : NopeAst -> Maybe SemacrolonAst
execMacro : SemacrolonAst -> NopeAst
execMacro (MacroDef x xs ast) = ?execMacro_rhs_1
execMacro (MacroExpr x) = ?execMacro_rhs_2