Skip to content

Commit

Permalink
Remove use of AnjutaTokenGroup in am parser
Browse files Browse the repository at this point in the history
  • Loading branch information
sgranjoux committed Nov 17, 2009
1 parent b5d053b commit fd8104e
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 73 deletions.
95 changes: 46 additions & 49 deletions src/am-parser.y
Original file line number Diff line number Diff line change
Expand Up @@ -31,48 +31,37 @@
%}


%union {
AnjutaToken *token;
AnjutaTokenGroup* group;
}

%token <token> EOL '\n'
%token <token> SPACE
%token <token> TAB '\t'
%token <token> MACRO
%token <token> VARIABLE
%token <token> COLON ':'
%token <token> DOUBLE_COLON "::"
%token <token> ORDER '|'
%token <token> SEMI_COLON ';'
%token <token> EQUAL '='
%token <token> IMMEDIATE_EQUAL ":="
%token <token> CONDITIONAL_EQUAL "?="
%token <token> APPEND "+="
%token <token> CHARACTER
%token <token> NAME
%token <token> AM_VARIABLE

%token <token> SUBDIRS
%token <token> DIST_SUBDIRS
%token <token> _DATA
%token <token> _HEADERS
%token <token> _LIBRARIES
%token <token> _LISP
%token <token> _LTLIBRARIES
%token <token> _MANS
%token <token> _PROGRAMS
%token <token> _PYTHON
%token <token> _JAVA
%token <token> _SCRIPTS
%token <token> _SOURCES
%token <token> _TEXINFOS

%type <token> space_token automake_token value_token target_token equal_token rule_token head_token
%type <token> space optional_space

%type <group> 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

Expand Down Expand Up @@ -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);
}
;

Expand All @@ -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);
}
Expand Down
32 changes: 16 additions & 16 deletions src/am-project.c
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ typedef struct _AmpSourceData AmpSourceData;

struct _AmpSourceData {
AnjutaProjectSourceData base;
AnjutaTokenGroup* token;
AnjutaToken* token;
};

typedef struct _AmpConfigFile AmpConfigFile;
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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 */
Expand Down Expand Up @@ -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;
Expand All @@ -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);
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion src/am-scanner.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ G_BEGIN_DECLS

//#define YYSTYPE AnjutaToken*
#define YYLTYPE AnjutaToken*
#define YYSTYPE AnjutaToken*

typedef struct _AmpAmScanner AmpAmScanner;

Expand All @@ -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);

Expand Down
21 changes: 14 additions & 7 deletions src/am-scanner.l
Original file line number Diff line number Diff line change
Expand Up @@ -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

%}
Expand Down Expand Up @@ -148,6 +148,8 @@ struct _AmpAmBuffer
AnjutaToken *start;
gsize begin;

AnjutaToken *end; /* Last token */

/* Next data read buffer */
AnjutaToken *next;
gsize pos;
Expand Down Expand Up @@ -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;
}
}
Expand All @@ -258,17 +260,20 @@ 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);

if ((anjuta_token_get_type (scanner->buffer->next) >= ANJUTA_TOKEN_PARSED) || (scanner->buffer->pos >= length))
{
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
{
Expand Down Expand Up @@ -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);
}
Expand All @@ -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)
{
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit fd8104e

Please sign in to comment.