Skip to content

Commit

Permalink
WIP: Add scope capture behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
josephmcl committed Aug 21, 2024
1 parent 7e98bb6 commit a86854a
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 6 deletions.
36 changes: 30 additions & 6 deletions grammar.y
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@
%token RANGLE
%token LBRACKET
%token RBRACKET
%token AT_SIGN
%token AMPERSAND

%token EN_IN
%token EN_NOT
Expand Down Expand Up @@ -131,7 +133,7 @@ scope_name
$$ = s; }
;
scope_context
: LANGLE u_inherited_scope_names RANGLE { $$ = NULL; }
: LANGLE u_inherited_scope_names RANGLE { $$ = $2; }
;

function
Expand All @@ -144,13 +146,35 @@ function
$$ = s; }
;
u_inherited_scope_names
: { }
| inherited_scope_names {}
| EQUAL {}
: { $$ = NULL; }
| inherited_scope_names {
syntax_store *s = Syntax.push();
s->type = ast_inherited_context;
s->size = 1;
s->content = malloc(sizeof(syntax_store *));
s->content[0] = (syntax_store *) $1;
$$ = s; }
| EQUAL {
syntax_store *s = Syntax.push();
s->type = ast_inherited_context;
s->token_index = TheIndex;
$$ = s; }
| AT_SIGN {
syntax_store *s = Syntax.push();
s->type = ast_inherited_context;
s->token_index = TheIndex;
$$ = s; }
| AMPERSAND {
syntax_store *s = Syntax.push();
s->type = ast_inherited_context;
s->token_index = TheIndex;
$$ = s; }
;
inherited_scope_names
: inherited_scope_name {}
| inherited_scope_names COMMA inherited_scope_name {}
: inherited_scope_name {
$$ = NULL; }
| inherited_scope_names COMMA inherited_scope_name {
$$ = NULL; }
;
inherited_scope_name
: IDENTIFIER {}
Expand Down
3 changes: 3 additions & 0 deletions include/token.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ typedef enum {
TOKEN_RANGLE = SINGLE_BYTE_TOKENS + 7, // > [Extended]
TOKEN_LBRACKET = SINGLE_BYTE_TOKENS + 8, // [ [Extended]
TOKEN_RBRACKET = SINGLE_BYTE_TOKENS + 9, // ] [Extended]
TOKEN_AT_SIGN = SINGLE_BYTE_TOKENS + 9, // @ [Extended]
TOKEN_AMPERSAND = SINGLE_BYTE_TOKENS + 9, // & [Extended]


TOKEN_EN_IN = KEYWORD_TOKENS, // in [1.2.5]
TOKEN_EN_NOT = KEYWORD_TOKENS + 1, // not [1.2.6]
Expand Down
2 changes: 2 additions & 0 deletions source/token.c
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,8 @@ lexical_token single_byte_token(uint8_t c) {
case '.': return TOKEN_PERIOD;
case '<': return TOKEN_LANGLE;
case '>': return TOKEN_RANGLE;
case '@': return TOKEN_AT_SIGN;
case '&': return TOKEN_AMPERSAND;
default: return TOKEN_UNKNOWN;
}
}

0 comments on commit a86854a

Please sign in to comment.