Created
January 6, 2023 03:38
-
-
Save queercat/a3411e364ad1cf272078a5782d704d23 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using import struct | |
| using import enum | |
| using import Array | |
| using import Map | |
| using import String | |
| enum N : i32 | |
| N_STRING | |
| N_NUMBER | |
| N_OBJECT | |
| N_BOOL | |
| N_ARRAY | |
| N_INVALID | |
| N_NULL | |
| struct ASTNode | |
| kind : (typeof N.N_STRING) | |
| value-string = (" " as String) | |
| value-number : f64 | |
| value-bool : bool | |
| value-null : bool | |
| value-object : (Map String (mutable@ this-type)) | |
| value-array : (Array (mutable@ this-type)) | |
| invalid : bool | |
| inline... __typecall | |
| case (cls, value : String) | |
| super-type.__typecall cls | |
| kind = N.N_STRING | |
| value-string = value | |
| case (cls, value : f64) | |
| super-type.__typecall cls | |
| kind = N.N_NUMBER | |
| value-number = value | |
| case (cls, value : bool) | |
| super-type.__typecall cls | |
| kind = N.N_BOOL | |
| value-bool = value | |
| case (cls, value : (typeof null)) | |
| super-type.__typecall cls | |
| kind = N.N_NULL | |
| value-null = true | |
| # defaultish case assumes its an object or an array | |
| case (cls, kind : N) | |
| super-type.__typecall cls | |
| kind = kind | |
| fn... append | |
| case (self node) | |
| ('append self.value-array node) | |
| case (self key node) | |
| ('set self.value-object key node) | |
| fn get (self key) | |
| dupe ('getdefault self.value-object key (null as (mutable@ this-type))) | |
| local node = | |
| (ASTNode N.N_OBJECT) | |
| local child = | |
| (ASTNode ("i'm a child!" as String)) | |
| ('set node.value-object ("a" as String) &child) | |
| let res = | |
| ('get node ("a" as String)) | |
| 0:i32 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment