OILS / mycpp / mycpp.asdl View on Github | oilshell.org

121 lines, 43 significant
1# Is this Yaks? Well there is no CST / S-expression layer?
2#
3# Or should we call this "Pea" or "Tea"?
4
5module mycpp
6{
7 # Should these be Python types, or C++ types?
8 #
9 # Python: mops.BigInt, C++ mops::BigInt
10 # Python: float, C++: double
11
12 mtype = Foo()
13
14 yaks_type =
15 NoneType # -> None
16 | NoReturn # -> NoReturn
17
18 # Are we using typing.IO?
19 | IOError_OSError # Special thing for exceptions?
20
21 # Builtin types
22 # MyPy Float is C++ double
23 | Bool | Int | Float | Str
24
25 # e.g. state::Mem, mops::BigInt
26 | Class(List[str] mod_parts, str name)
27 | Callable(List[yaks_type] args, yaks_type return_) # Callable[[float, float], float]
28
29 # Parameterized types
30
31 | Dict_(yaks_type k, yaks_type v) # Dict[K, V]
32 | List_(yaks_type t) # List[T]
33 | Iterator(yaks_type t) # Iterator[T]
34
35 # Will be turns into Tuple2, Tuple3, Tuple4<A, B, C, D>
36 | Tuple(List[yaks_type] children)
37 | Optional(yaks_type child) # Optional[T]
38
39 | Alias(yaks_type child)
40
41
42 # Using names that are like MyPy
43 # Compare with Python.asdl, which has Num(object n) and Str(string s)
44
45 # This is the language we accept
46
47 yaks_expr =
48 BoolExpr(bool value)
49 | IntExpr(int value) # constant expression can't be big?
50 | FloatExpr(float value)
51 | StrExpr(str value)
52 # Disambiguate . and -> and ::
53 | MemberExpr()
54 | CallExpr()
55
56 | Cast()
57
58 yaks_stmt =
59 PassStmt()
60
61 # Should this just be a function call?
62 # Well there is also Yield
63 # But yeah we don't translate it, so it might be good to clamp down on it?
64
65 # log()
66 # probe()
67
68 | ExpressionStmt()
69
70 # This could be translated first? del mylist[:]
71 | DelStmt()
72 | RaiseStmt()
73
74 # Python assignment, no separation between var and setvar
75 # we remove __all__
76 # we also have d = NewDict()
77 # a = [x for x in other]
78 | AssignmentStmt()
79
80 # remove if __name__
81 # top level is STATIC
82 | IfStmt()
83
84 # xrange()
85 # reversed()
86 # enumerate()
87 # iteritems()
88 # tuple unpacking
89 # over dict, and over list
90 | ForStmt()
91 | WhileStmt()
92
93 # When there are zero args
94 | Break
95 | Continue
96 | Return(yaks_expr val)
97
98 # context manager
99 # 3 kinds of switches
100 | WithStmt()
101
102 | TryStmt()
103
104 # Constructor __init__
105 # __exit__
106 # method
107 # free function
108 | FuncDef(str name)
109
110 | ClassDef(str name)
111
112 | ImportFrom()
113
114 # TODO: revive this, at least for Python
115 # attributes (int lineno, int col_offset)
116
117 yaks_file = (str name, List[yaks_stmt] defs)
118}
119
120# vim: sw=2
121