forked from NeoFlock/noom
parser: variable attributes
This commit is contained in:
@@ -33,7 +33,7 @@ void print_node(noomP_Node* node, noom_uint_t depth) {
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
// uhh uhhh uhhhhh
|
||||
const char* code = "local a,b; a,b = test(), test2() test3()";
|
||||
const char* code = "local str <const>, test <close> = 5, 5;";
|
||||
noom_uint_t pos = 0;
|
||||
|
||||
printf("LEX OUTPUT:\n");
|
||||
|
||||
34
src/parser.c
34
src/parser.c
@@ -15,6 +15,8 @@ const char *noomP_formatNodeType(noomP_NodeType node_type) {
|
||||
return "while loop";
|
||||
case NOOMP_NODE_BLOCK:
|
||||
return "block";
|
||||
case NOOMP_NODE_ATTRIBUTE:
|
||||
return "attribute";
|
||||
case NOOMP_NODE_BREAK:
|
||||
return "break";
|
||||
case NOOMP_NODE_VARIABLE:
|
||||
@@ -590,6 +592,38 @@ noomP_Node* noomP_parseRawStatement(noomP_Parser* parser) {
|
||||
varname->type = NOOMP_NODE_VARNAME;
|
||||
varname->source_offset = token.offset;
|
||||
|
||||
if (parser->version >= NOOM_VERSION_54) {
|
||||
noomP_peek(parser, &token);
|
||||
|
||||
if (token.type == NOOML_TOKEN_SYMBOL && noom_streql(parser->code + token.offset, token.length, "<", 1)) {
|
||||
// attribute yay
|
||||
noomP_skip(parser, &token);
|
||||
|
||||
// the attribute is an identifier.
|
||||
noomP_peek(parser, &token);
|
||||
if (token.type != NOOML_TOKEN_IDENTIFIER) return 0; // unexpected
|
||||
noom_uint_t attr = token.offset;
|
||||
noomP_skip(parser, &token);
|
||||
|
||||
if (!noom_streql(parser->code + token.offset, token.length, "const", 5) && !noom_streql(parser->code + token.offset, token.length, "close", 5)) {
|
||||
return 0; // not a real attribute smh my head
|
||||
}
|
||||
|
||||
noomP_peek(parser, &token);
|
||||
if (token.type != NOOML_TOKEN_SYMBOL) return 0;
|
||||
if (!noom_streql(parser->code + token.offset, token.length, ">", 1)) return 0;
|
||||
noomP_skip(parser, &token);
|
||||
|
||||
noomP_Node* attrn = noomP_allocNode(parser);
|
||||
if (attr == 0) return 0;
|
||||
|
||||
attrn->type = NOOMP_NODE_ATTRIBUTE;
|
||||
attrn->source_offset = attr;
|
||||
|
||||
noomP_addSubnode(varname, attrn);
|
||||
}
|
||||
}
|
||||
|
||||
noomP_addSubnode(localNode, varname);
|
||||
|
||||
noomP_peek(parser, &token);
|
||||
|
||||
@@ -11,6 +11,8 @@ typedef enum noomP_NodeType {
|
||||
NOOMP_NODE_WHILELOOP,
|
||||
NOOMP_NODE_BLOCK,
|
||||
|
||||
NOOMP_NODE_ATTRIBUTE,
|
||||
|
||||
NOOMP_NODE_BREAK,
|
||||
|
||||
NOOMP_NODE_VARIABLE,
|
||||
|
||||
Reference in New Issue
Block a user