Skip to content

Commit

Permalink
Parse makefile in 2 steps (first step do nothing currently)
Browse files Browse the repository at this point in the history
  • Loading branch information
sgranjoux committed Oct 20, 2009
1 parent 68ff9fd commit fb2847b
Show file tree
Hide file tree
Showing 4 changed files with 199 additions and 55 deletions.
87 changes: 83 additions & 4 deletions libanjuta/anjuta-token.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ typedef struct _AnjutaTokenData AnjutaTokenData;

struct _AnjutaTokenData
{
AnjutaToken *token;
AnjutaToken *data;
AnjutaTokenType type;
gint flags;
gchar *pos;
Expand Down Expand Up @@ -242,6 +242,31 @@ anjuta_token_parent (AnjutaToken *token)
return token->parent;
}

AnjutaToken*
anjuta_token_lex (AnjutaToken *token)
{
for (; token != NULL;)
{
AnjutaTokenType type = anjuta_token_get_type (token);

switch (type)
{
case ANJUTA_TOKEN_COMMENT:
token = anjuta_token_next_sibling (token);
break;
default:
if (type < ANJUTA_TOKEN_FIRST)
{
return token;
}
token = anjuta_token_next (token);
break;
}
}

return NULL;
}

void
anjuta_token_set_type (AnjutaToken *token, gint type)
{
Expand Down Expand Up @@ -448,7 +473,7 @@ anjuta_token_copy (AnjutaToken *token)
data->length = org->length;

copy = (AnjutaToken *)g_node_new (data);
data->token = copy;
data->data = data;

last = NULL;
for (child = anjuta_token_next_child (token); child != NULL; child = anjuta_token_next_sibling (child))
Expand Down Expand Up @@ -594,6 +619,40 @@ AnjutaToken *anjuta_token_split (AnjutaToken *token, guint size)
}
}

AnjutaToken *anjuta_token_cut (AnjutaToken *token, guint pos, guint size)
{
AnjutaToken *copy;

copy = anjuta_token_copy (token);

if (pos >= ANJUTA_TOKEN_DATA (token)->length)
{
if (!(ANJUTA_TOKEN_DATA (copy)->flags & ANJUTA_TOKEN_STATIC))
{
g_free (ANJUTA_TOKEN_DATA (copy)->pos);
}
ANJUTA_TOKEN_DATA (copy)->pos = NULL;
ANJUTA_TOKEN_DATA (copy)->length = 0;
}
if ((pos + size) > ANJUTA_TOKEN_DATA (token)->length)
{
size = ANJUTA_TOKEN_DATA (token)->length - pos;
}

if (ANJUTA_TOKEN_DATA (copy)->flags & ANJUTA_TOKEN_STATIC)
{
ANJUTA_TOKEN_DATA (copy)->pos += pos;
}
else
{
memcpy(ANJUTA_TOKEN_DATA (copy)->pos, ANJUTA_TOKEN_DATA (copy)->pos + pos, size);
}
ANJUTA_TOKEN_DATA (copy)->length = size;

return copy;
}


AnjutaToken *anjuta_token_get_next_arg (AnjutaToken *arg, gchar ** value)
{
for (;arg != NULL;)
Expand All @@ -616,6 +675,26 @@ AnjutaToken *anjuta_token_get_next_arg (AnjutaToken *arg, gchar ** value)
return arg;
}

static void
anjuta_token_dump_child (AnjutaToken *group, gint indent)
{
for (; group != NULL; group = anjuta_token_next_sibling (group))
{
AnjutaToken *token = group->token;

fprintf (stdout, "%*s%p", indent, "", token);
fprintf (stdout, ": %d \"%.*s\"\n", anjuta_token_get_type (token), anjuta_token_get_length (token), anjuta_token_get_string (token));

anjuta_token_dump_child (anjuta_token_next_child (group), indent + 4);
}
}

void
anjuta_token_dump (AnjutaToken *token)
{
anjuta_token_dump_child (token, 0);
}

/* Constructor & Destructor
*---------------------------------------------------------------------------*/

Expand All @@ -638,7 +717,7 @@ AnjutaToken *anjuta_token_new_string (AnjutaTokenType type, const gchar *value)
data->length = strlen (value);

token = (AnjutaToken *)g_node_new (data);
data->token = token;
data->data = data;
}

return token;
Expand All @@ -657,7 +736,7 @@ anjuta_token_new_fragment (gint type, const gchar *pos, gsize length)
data->length = length;

token = (AnjutaToken *)g_node_new (data);
data->token = token;
data->data = data;

return token;
};
Expand Down
6 changes: 6 additions & 0 deletions libanjuta/anjuta-token.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ AnjutaToken *anjuta_token_new_group (AnjutaTokenType type, AnjutaToken* first);

AnjutaToken *anjuta_token_split (AnjutaToken *token, guint size);

AnjutaToken *anjuta_token_cut (AnjutaToken *token, guint pos, guint size);

AnjutaToken * anjuta_token_insert_child (AnjutaToken *parent, AnjutaToken *child);
AnjutaToken *anjuta_token_insert_after (AnjutaToken *token, AnjutaToken *sibling);
AnjutaToken *anjuta_token_insert_before (AnjutaToken *token, AnjutaToken *sibling);
Expand All @@ -146,6 +148,10 @@ gchar *anjuta_token_evaluate_range (AnjutaToken *start, AnjutaToken *end);
gchar *anjuta_token_evaluate (AnjutaToken *token);
gchar *anjuta_token_value (AnjutaToken *token);

AnjutaToken *anjuta_token_lex (AnjutaToken *token);

void anjuta_token_dump (AnjutaToken *token);

AnjutaToken *anjuta_token_next (AnjutaToken *token);
AnjutaToken *anjuta_token_next_after_children (AnjutaToken *token);
AnjutaToken *anjuta_token_next_sibling (AnjutaToken *token);
Expand Down
46 changes: 21 additions & 25 deletions src/mk-parser.y
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@
%token _SILENT
%token _EXPORT_ALL_VARIABLES
%token _NOTPARALLEL

%token FIRST_PASS
%token SECOND_PASS

%defines

Expand All @@ -73,6 +74,7 @@
/*%glr-parser*/

%parse-param {void* scanner}
%parse-param {AnjutaToken** last}
%lex-param {void* scanner}

%name-prefix="mkp_yy"
Expand All @@ -89,7 +91,7 @@

//mkp_yydebug = 1;

static void mkp_yyerror (YYLTYPE *loc, MkpScanner *scanner, char const *s);
static void mkp_yyerror (YYLTYPE *loc, MkpScanner *scanner, AnjutaToken **last, char const *s);
static void mkp_special_target (AnjutaToken *list);
static gint mkp_special_prerequisite (AnjutaToken *token);

Expand All @@ -99,8 +101,23 @@ static gint mkp_special_prerequisite (AnjutaToken *token);
%%

file:
FIRST_PASS first_pass
| SECOND_PASS second_pass
;

first_pass:
not_eol_token
| EOL
| first_pass not_eol_token
| first_pass EOL {
g_message ("EOL %p", $2);
*last = $2;
}
;

second_pass:
statement
| file statement
| second_pass statement
;

statement:
Expand Down Expand Up @@ -180,27 +197,6 @@ not_eol_list:
| not_eol_list not_eol_token
;

value_list:
/* empty */ {
$$ = anjuta_token_group_new (ANJUTA_TOKEN_VALUE, NULL);
}
| space
| optional_space value_list_body optional_space {
$$ = $2;
}
;

value_list_body:
value {
$$ = anjuta_token_group_new (ANJUTA_TOKEN_VALUE, NULL);
anjuta_token_group_append ($$, $1);
}
| value_list_body space value {
anjuta_token_group_append ($1, $2);
anjuta_token_group_append ($1, $3);
}
;

prerequisite_list:
/* empty */ {
$$ = anjuta_token_group_new (MK_TOKEN_PREREQUISITE, NULL);
Expand Down Expand Up @@ -444,7 +440,7 @@ equal_token:
%%

static void
mkp_yyerror (YYLTYPE *loc, MkpScanner *scanner, char const *s)
mkp_yyerror (YYLTYPE *loc, MkpScanner *scanner, AnjutaToken **last, char const *s)
{
const gchar *filename;

Expand Down
Loading

0 comments on commit fb2847b

Please sign in to comment.