Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F2922402
ast.h
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
1 KB
Referenced Files
None
Subscribers
None
ast.h
View Options
#ifndef ANT_AST_H
#define ANT_AST_H
#include
"ant.h"
#include
<yyjson.h>
#include
<stdbool.h>
enum
{
T_OBJ
,
T_PROP
,
T_STR
,
T_UNDEF
,
T_NULL
,
T_NUM
,
T_BOOL
,
T_FUNC
,
T_CODEREF
,
T_CFUNC
,
T_ERR
,
T_ARR
,
T_PROMISE
,
T_TYPEDARRAY
,
T_BIGINT
,
T_PROPREF
,
T_SYMBOL
,
T_GENERATOR
,
T_FFI
};
typedef
struct
ast_ctx
{
struct
js
*
js
;
yyjson_doc
*
doc
;
yyjson_val
*
root
;
}
ast_ctx_t
;
ast_ctx_t
*
ast_parse
(
struct
js
*
js
,
const
char
*
code
,
size_t
len
,
const
char
*
filename
);
void
ast_free
(
ast_ctx_t
*
ctx
);
jsval_t
ast_eval_program
(
struct
js
*
js
,
ast_ctx_t
*
ctx
);
jsval_t
ast_eval_node
(
struct
js
*
js
,
yyjson_val
*
node
);
jsval_t
ast_eval_stmt
(
struct
js
*
js
,
yyjson_val
*
node
);
jsval_t
ast_eval_expr
(
struct
js
*
js
,
yyjson_val
*
node
);
jsval_t
js_eval_ast
(
struct
js
*
js
,
const
char
*
code
,
size_t
len
,
const
char
*
filename
);
static
inline
const
char
*
ast_node_type
(
yyjson_val
*
node
)
{
if
(
!
node
||
!
yyjson_is_obj
(
node
))
return
NULL
;
yyjson_val
*
type
=
yyjson_obj_get
(
node
,
"type"
);
return
yyjson_get_str
(
type
);
}
static
inline
yyjson_val
*
ast_get
(
yyjson_val
*
node
,
const
char
*
key
)
{
if
(
!
node
||
!
yyjson_is_obj
(
node
))
return
NULL
;
return
yyjson_obj_get
(
node
,
key
);
}
static
inline
const
char
*
ast_get_str
(
yyjson_val
*
node
,
const
char
*
key
)
{
yyjson_val
*
val
=
ast_get
(
node
,
key
);
return
yyjson_get_str
(
val
);
}
static
inline
double
ast_get_num
(
yyjson_val
*
node
,
const
char
*
key
)
{
yyjson_val
*
val
=
ast_get
(
node
,
key
);
return
yyjson_get_real
(
val
);
}
static
inline
bool
ast_get_bool
(
yyjson_val
*
node
,
const
char
*
key
)
{
yyjson_val
*
val
=
ast_get
(
node
,
key
);
return
yyjson_get_bool
(
val
);
}
static
inline
bool
ast_is_null
(
yyjson_val
*
node
,
const
char
*
key
)
{
yyjson_val
*
val
=
ast_get
(
node
,
key
);
return
yyjson_is_null
(
val
);
}
#endif
File Metadata
Details
Attached
Mime Type
text/x-c
Expires
Fri, Mar 27, 1:01 PM (2 d)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
513083
Default Alt Text
ast.h (1 KB)
Attached To
Mode
rANT Ant
Attached
Detach File
Event Timeline
Log In to Comment