plum

#treesitter#compiler#wasm

git clone https://git.pyrossh.dev/plum

A statically typed, imperative programming language inspired by rust, python


plum-tooling/tree-sitter-plum/test/corpus/enum.txt
f997bee 1
================================================================================
f997bee 2
enum
f997bee 3
================================================================================
f997bee 4
5de508e 5
enum Bool =
f997bee 6
  | True
f997bee 7
  | False
f997bee 8
6b5d9db 9
  fun toStr() -> Str =
6b5d9db 10
    "Bool"
fd085d9 11
f997bee 12
--------------------------------------------------------------------------------
f997bee 13
f997bee 14
(source
f997bee 15
  (enum
f997bee 16
    (type_identifier)
5de508e 17
    (field
f997bee 18
      (type_identifier))
5de508e 19
    (field
c05610c 20
      (type_identifier))
6b5d9db 21
    (fn
6b5d9db 22
      (fn_identifier)
6b5d9db 23
      (type
6b5d9db 24
        (type_identifier))
6b5d9db 25
      (body
6b5d9db 26
        (expression
6b5d9db 27
          (primary_expression
6b5d9db 28
            (string
6b5d9db 29
              (string_start)
6b5d9db 30
              (string_content)
6b5d9db 31
              (string_end))))))))
c273ea5 32
c273ea5 33
================================================================================
c273ea5 34
enum - generic variant fields
c273ea5 35
================================================================================
c273ea5 36
c273ea5 37
enum Option =
287b97c 38
  | Some(T)
c273ea5 39
  | None
c273ea5 40
c273ea5 41
--------------------------------------------------------------------------------
c273ea5 42
c273ea5 43
(source
c273ea5 44
  (enum
c273ea5 45
    (type_identifier)
c273ea5 46
    (field
c273ea5 47
      (type_identifier)
a43f3af 48
      (type
a43f3af 49
        (generic)))
a43f3af 50
    (field
a43f3af 51
      (type_identifier))))
a43f3af 52
a43f3af 53
================================================================================
a43f3af 54
enum - nested generic variant field
a43f3af 55
================================================================================
a43f3af 56
a43f3af 57
enum Json =
287b97c 58
  | JsonList(List[Json])
a43f3af 59
  | JsonNull
a43f3af 60
a43f3af 61
--------------------------------------------------------------------------------
a43f3af 62
a43f3af 63
(source
a43f3af 64
  (enum
a43f3af 65
    (type_identifier)
a43f3af 66
    (field
a43f3af 67
      (type_identifier)
a43f3af 68
      (type
a43f3af 69
        (type_identifier)
a43f3af 70
        (type
a43f3af 71
          (type_identifier))))
c273ea5 72
    (field
c273ea5 73
      (type_identifier))))
f047082 74
f047082 75
================================================================================
f047082 76
enum - nested method declaration
f047082 77
================================================================================
f047082 78
f047082 79
enum Step =
f047082 80
  | ReadMin
f047082 81
  | ReadMax
f047082 82
f047082 83
  fun toNumber(self) -> Int =
f047082 84
    match self
f047082 85
      ReadMin => 0
f047082 86
      ReadMax => 1
f047082 87
f047082 88
--------------------------------------------------------------------------------
f047082 89
f047082 90
(source
f047082 91
  (enum
f047082 92
    (type_identifier)
f047082 93
    (field
f047082 94
      (type_identifier))
f047082 95
    (field
f047082 96
      (type_identifier))
f047082 97
    (fn
f047082 98
      (fn_identifier)
f047082 99
      (self)
f047082 100
      (type
f047082 101
        (type_identifier))
f047082 102
      (body
f047082 103
        (match
f047082 104
          (expression
f047082 105
            (primary_expression
f047082 106
              (self)))
f047082 107
          (case
f047082 108
            (case_pattern
f047082 109
              (type_identifier))
f047082 110
            (expression
f047082 111
              (primary_expression
f047082 112
                (integer))))
f047082 113
          (case
f047082 114
            (case_pattern
f047082 115
              (type_identifier))
f047082 116
            (expression
f047082 117
              (primary_expression
f047082 118
                (integer)))))))))
8554271 119
8554271 120
================================================================================
8554271 121
enum - discriminant values
8554271 122
================================================================================
8554271 123
8554271 124
enum Step(n: Int) =
8554271 125
  | ReadMin(0)
8554271 126
  | ReadMax(1)
8554271 127
8554271 128
--------------------------------------------------------------------------------
8554271 129
8554271 130
(source
8554271 131
  (enum
8554271 132
    (type_identifier)
8554271 133
    (enum_param
8554271 134
      (var_identifier)
8554271 135
      (type
8554271 136
        (type_identifier)))
8554271 137
    (field
8554271 138
      (type_identifier)
8554271 139
      (expression
8554271 140
        (primary_expression
8554271 141
          (integer))))
8554271 142
    (field
8554271 143
      (type_identifier)
8554271 144
      (expression
8554271 145
        (primary_expression
8554271 146
          (integer))))))
3a2119e 147
3a2119e 148
================================================================================
3a2119e 149
enum - named payload fields
3a2119e 150
================================================================================
3a2119e 151
3a2119e 152
enum Shape =
3a2119e 153
  | Circle(radius: Int)
3a2119e 154
  | Square(x: Int, y: Int)
3a2119e 155
3a2119e 156
--------------------------------------------------------------------------------
3a2119e 157
3a2119e 158
(source
3a2119e 159
  (enum
3a2119e 160
    (type_identifier)
3a2119e 161
    (field
3a2119e 162
      (type_identifier)
3a2119e 163
      (enum_named_field
3a2119e 164
        (var_identifier)
3a2119e 165
        (type
3a2119e 166
          (type_identifier))))
3a2119e 167
    (field
3a2119e 168
      (type_identifier)
3a2119e 169
      (enum_named_field
3a2119e 170
        (var_identifier)
3a2119e 171
        (type
3a2119e 172
          (type_identifier)))
3a2119e 173
      (enum_named_field
3a2119e 174
        (var_identifier)
3a2119e 175
        (type
3a2119e 176
          (type_identifier))))))