diff --git a/src/am-parser.y b/src/am-parser.y index c9582b8..cfa6eeb 100644 --- a/src/am-parser.y +++ b/src/am-parser.y @@ -31,48 +31,37 @@ %} -%union { - AnjutaToken *token; - AnjutaTokenGroup* group; -} - -%token EOL '\n' -%token SPACE -%token TAB '\t' -%token MACRO -%token VARIABLE -%token COLON ':' -%token DOUBLE_COLON "::" -%token ORDER '|' -%token SEMI_COLON ';' -%token EQUAL '=' -%token IMMEDIATE_EQUAL ":=" -%token CONDITIONAL_EQUAL "?=" -%token APPEND "+=" -%token CHARACTER -%token NAME -%token AM_VARIABLE - -%token SUBDIRS -%token DIST_SUBDIRS -%token _DATA -%token _HEADERS -%token _LIBRARIES -%token _LISP -%token _LTLIBRARIES -%token _MANS -%token _PROGRAMS -%token _PYTHON -%token _JAVA -%token _SCRIPTS -%token _SOURCES -%token _TEXINFOS - -%type space_token automake_token value_token target_token equal_token rule_token head_token -%type space optional_space - -%type space_list_value value_list strip_value_list value - +%token EOL '\n' +%token SPACE +%token TAB '\t' +%token MACRO +%token VARIABLE +%token COLON ':' +%token DOUBLE_COLON "::" +%token ORDER '|' +%token SEMI_COLON ';' +%token EQUAL '=' +%token IMMEDIATE_EQUAL ":=" +%token CONDITIONAL_EQUAL "?=" +%token APPEND "+=" +%token CHARACTER +%token NAME +%token AM_VARIABLE + +%token SUBDIRS +%token DIST_SUBDIRS +%token _DATA +%token _HEADERS +%token _LIBRARIES +%token _LISP +%token _LTLIBRARIES +%token _MANS +%token _PROGRAMS +%token _PYTHON +%token _JAVA +%token _SCRIPTS +%token _SOURCES +%token _TEXINFOS %defines @@ -150,16 +139,22 @@ space_list_value: optional_space equal_token value_list { value_list: optional_space strip_value_list optional_space { + if ($1 != NULL) anjuta_token_set_type ($1, ANJUTA_TOKEN_START); + if ($3 != NULL) anjuta_token_set_type ($3, ANJUTA_TOKEN_LAST); + anjuta_token_merge_previous ($2, $1); + anjuta_token_merge ($2, $3); $$ = $2; } strip_value_list: value { - $$ = anjuta_token_group_new (ANJUTA_TOKEN_LIST, NULL); - anjuta_token_group_append ($$, $1); + $$ = anjuta_token_new_static (ANJUTA_TOKEN_LIST, NULL); + anjuta_token_merge ($$, $1); } | strip_value_list space value { - anjuta_token_group_append ($$, $3); + anjuta_token_set_type ($2, ANJUTA_TOKEN_NEXT); + anjuta_token_merge ($1, $2); + anjuta_token_merge ($1, $3); } ; @@ -172,16 +167,18 @@ optional_space: value: value_token { - $$ = anjuta_token_group_new (ANJUTA_TOKEN_ARGUMENT, NULL); - anjuta_token_group_append_token ($$, $1); + $$ = anjuta_token_new_static (ANJUTA_TOKEN_ARGUMENT, NULL); + anjuta_token_merge ($$, $1); } | value value_token { - anjuta_token_group_append_token ($1, $2); + anjuta_token_merge ($1, $2); } ; space: - space_token {anjuta_token_set_type ($1, ANJUTA_TOKEN_SPACE);} + space_token { + $$ = anjuta_token_new_static (ANJUTA_TOKEN_SPACE, NULL); + anjuta_token_merge ($$, $1);} | space space_token { anjuta_token_merge ($1, $2); } diff --git a/src/am-project.c b/src/am-project.c index 6686f9f..7544a35 100644 --- a/src/am-project.c +++ b/src/am-project.c @@ -118,7 +118,7 @@ typedef struct _AmpSourceData AmpSourceData; struct _AmpSourceData { AnjutaProjectSourceData base; - AnjutaTokenGroup* token; + AnjutaToken* token; }; typedef struct _AmpConfigFile AmpConfigFile; @@ -744,7 +744,7 @@ amp_group_free (AmpGroup *node) *---------------------------------------------------------------------------*/ static void -amp_target_add_token (AmpGroup *node, AnjutaTokenGroup *token) +amp_target_add_token (AmpGroup *node, AnjutaToken *token) { AmpTargetData *target; @@ -1163,9 +1163,9 @@ find_canonical_target (AnjutaProjectTarget *node, gpointer data) } static AnjutaToken* -project_load_target (AmpProject *project, AnjutaToken *name, AnjutaTokenGroup *list, AnjutaProjectGroup *parent, GHashTable *orphan_sources) +project_load_target (AmpProject *project, AnjutaToken *name, AnjutaToken *list, AnjutaProjectGroup *parent, GHashTable *orphan_sources) { - AnjutaTokenGroup *arg; + AnjutaToken *arg; AnjutaProjectTargetType type = NULL; gchar *install; gchar *value; @@ -1189,7 +1189,7 @@ project_load_target (AmpProject *project, AnjutaToken *name, AnjutaTokenGroup *l amp_group_add_token (parent, name, AM_GROUP_TARGET); - for (arg = anjuta_token_group_first (list); arg != NULL; arg = anjuta_token_group_next (arg)) + for (arg = anjuta_token_first_item (list); arg != NULL; arg = anjuta_token_next_item (arg)) { gchar *value; gchar *canon_id; @@ -1198,7 +1198,7 @@ project_load_target (AmpProject *project, AnjutaToken *name, AnjutaTokenGroup *l gchar *orig_key; gpointer find; - value = anjuta_token_group_evaluate (arg); + value = anjuta_token_evaluate (arg); canon_id = canonicalize_automake_variable (value); /* Check if target already exists */ @@ -1241,9 +1241,9 @@ project_load_target (AmpProject *project, AnjutaToken *name, AnjutaTokenGroup *l } static AnjutaToken* -project_load_sources (AmpProject *project, AnjutaToken *name, AnjutaTokenGroup *list, AnjutaProjectGroup *parent, GHashTable *orphan_sources) +project_load_sources (AmpProject *project, AnjutaToken *name, AnjutaToken *list, AnjutaProjectGroup *parent, GHashTable *orphan_sources) { - AnjutaTokenGroup *arg; + AnjutaToken *arg; AmpGroupData *group = AMP_GROUP_DATA (parent); GFile *parent_file = g_object_ref (group->base.directory); gchar *target_id = NULL; @@ -1268,13 +1268,13 @@ project_load_sources (AmpProject *project, AnjutaToken *name, AnjutaTokenGroup * anjuta_project_node_children_foreach (parent, find_canonical_target, &find); parent = (gchar *)find != target_id ? (AnjutaProjectTarget *)find : NULL; - for (arg = anjuta_token_group_first (list); arg != NULL; arg = anjuta_token_group_next (arg)) + for (arg = anjuta_token_first_item (list); arg != NULL; arg = anjuta_token_next_item (arg)) { gchar *value; AmpSource *source; GFile *src_file; - value = anjuta_token_group_evaluate (arg); + value = anjuta_token_evaluate (arg); /* Create source */ src_file = g_file_get_child (parent_file, value); @@ -1324,15 +1324,15 @@ project_load_sources (AmpProject *project, AnjutaToken *name, AnjutaTokenGroup * static AmpGroup* project_load_makefile (AmpProject *project, GFile *file, AmpGroup *parent, gboolean dist_only); static void -project_load_subdirs (AmpProject *project, AnjutaTokenGroup *list, AmpGroup *parent, gboolean dist_only) +project_load_subdirs (AmpProject *project, AnjutaToken *list, AmpGroup *parent, gboolean dist_only) { - AnjutaTokenGroup *arg; + AnjutaToken *arg; - for (arg = anjuta_token_group_first (list); arg != NULL; arg = anjuta_token_group_next (arg)) + for (arg = anjuta_token_first_item (list); arg != NULL; arg = anjuta_token_next_item (arg)) { gchar *value; - value = anjuta_token_group_evaluate (arg); + value = anjuta_token_evaluate (arg); /* Skip ., it is a special case, used to defined build order */ if (strcmp (value, ".") != 0) @@ -1440,14 +1440,14 @@ project_load_makefile (AmpProject *project, GFile *file, AnjutaProjectGroup *par g_object_add_toggle_ref (G_OBJECT (tfile), remove_config_file, project); scanner = amp_am_scanner_new (project, group); arg = anjuta_token_file_load (tfile, NULL); - arg = amp_am_scanner_parse_token (scanner, anjuta_token_next_child (arg), NULL); + arg = amp_am_scanner_parse_token (scanner, arg, NULL); amp_am_scanner_free (scanner); return group; } void -amp_project_set_am_variable (AmpProject* project, AmpGroup* group, AnjutaTokenType variable, AnjutaToken *name, AnjutaTokenGroup *list, GHashTable *orphan_sources) +amp_project_set_am_variable (AmpProject* project, AmpGroup* group, AnjutaTokenType variable, AnjutaToken *name, AnjutaToken *list, GHashTable *orphan_sources) { switch (variable) diff --git a/src/am-scanner.h b/src/am-scanner.h index 1510cda..55640a5 100644 --- a/src/am-scanner.h +++ b/src/am-scanner.h @@ -32,6 +32,7 @@ G_BEGIN_DECLS //#define YYSTYPE AnjutaToken* #define YYLTYPE AnjutaToken* +#define YYSTYPE AnjutaToken* typedef struct _AmpAmScanner AmpAmScanner; @@ -40,7 +41,7 @@ void amp_am_scanner_free (AmpAmScanner *scanner); AnjutaToken *amp_am_scanner_parse_token (AmpAmScanner *scanner, AnjutaToken *token, GError **error); -void amp_am_scanner_set_am_variable (AmpAmScanner *scanner, AnjutaTokenType variable, AnjutaToken *name, AnjutaTokenGroup *list); +void amp_am_scanner_set_am_variable (AmpAmScanner *scanner, AnjutaTokenType variable, AnjutaToken *name, AnjutaToken *list); void amp_am_yyerror (YYLTYPE *loc, AmpAmScanner *scanner, char const *s); diff --git a/src/am-scanner.l b/src/am-scanner.l index 2c6af40..72f4fbb 100644 --- a/src/am-scanner.l +++ b/src/am-scanner.l @@ -40,7 +40,7 @@ static AnjutaToken* amp_am_scanner_append_lex_token (AmpAmScanner *scanner, gint static gint amp_am_scanner_input (AmpAmScanner *scanner, gchar *buffer, gsize max_size); static int amp_am_scanner_parse_end (AmpAmScanner *scanner); -#define RETURN(tok) yylval->token = amp_am_scanner_append_lex_token (yyextra, tok); \ +#define RETURN(tok) *yylval = amp_am_scanner_append_lex_token (yyextra, tok); \ return tok %} @@ -148,6 +148,8 @@ struct _AmpAmBuffer AnjutaToken *start; gsize begin; + AnjutaToken *end; /* Last token */ + /* Next data read buffer */ AnjutaToken *next; gsize pos; @@ -243,7 +245,7 @@ amp_am_scanner_append_lex_token (AmpAmScanner *scanner, gint token) } else { - end = anjuta_token_next_sibling (end); + end = anjuta_token_next (end); scanner->buffer->begin = 0; } } @@ -258,7 +260,7 @@ amp_am_scanner_input (AmpAmScanner *scanner, gchar *buffer, gsize max_size) { gint result = YY_NULL; - if (scanner->buffer->next) + if (scanner->buffer->next != NULL) { gsize length = anjuta_token_get_length (scanner->buffer->next); @@ -266,9 +268,12 @@ amp_am_scanner_input (AmpAmScanner *scanner, gchar *buffer, gsize max_size) { for (;;) { + /* Last token */ + if (scanner->buffer->next == scanner->buffer->end) return 0; + if (anjuta_token_get_type (scanner->buffer->next) >= ANJUTA_TOKEN_PARSED) { - scanner->buffer->next = anjuta_token_next_sibling (scanner->buffer->next); + scanner->buffer->next = anjuta_token_next (scanner->buffer->next); } else { @@ -346,7 +351,7 @@ amp_am_yyerror (YYLTYPE *loc, AmpAmScanner *scanner, char const *s) } void -amp_am_scanner_set_am_variable (AmpAmScanner *scanner, AnjutaTokenType variable, AnjutaToken *name, AnjutaTokenGroup *list) +amp_am_scanner_set_am_variable (AmpAmScanner *scanner, AnjutaTokenType variable, AnjutaToken *name, AnjutaToken *list) { amp_project_set_am_variable (scanner->project, scanner->group, variable, name, list, scanner->orphan_sources); } @@ -365,8 +370,10 @@ amp_am_scanner_parse_token (AmpAmScanner *scanner, AnjutaToken *token, GError ** buffer->begin = 0; buffer->parent = NULL; - buffer->next = token; + buffer->next = anjuta_token_next (token); buffer->start = buffer->next; + buffer->end = anjuta_token_last (token); + if (buffer->end == token) buffer->end = NULL; if (scanner->buffer != NULL) { @@ -404,7 +411,7 @@ amp_am_scanner_parse_token (AmpAmScanner *scanner, AnjutaToken *token, GError ** { gint yychar = am_yylex (&yylval_param, &yylloc_param, scanner->scanner); - yylloc_param = yylval_param.token; + yylloc_param = yylval_param; status = amp_am_yypush_parse (ps, yychar, &yylval_param, &yylloc_param, scanner); } while (status == YYPUSH_MORE);