You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucy.apache.org by ma...@apache.org on 2011/10/24 03:49:01 UTC
[lucy-commits] svn commit: r1188011 - in
/incubator/lucy/branches/clownfish_lemon/clownfish: lib/Clownfish.xs
src/CFCClass.c src/CFCParseHeader.y src/CFCParser.c src/CFCParser.h
t/403-file.t
Author: marvin
Date: Mon Oct 24 01:49:01 2011
New Revision: 1188011
URL: http://svn.apache.org/viewvc?rev=1188011&view=rev
Log:
Add support for parsing "files", i.e. CFCFiles.
Modified:
incubator/lucy/branches/clownfish_lemon/clownfish/lib/Clownfish.xs
incubator/lucy/branches/clownfish_lemon/clownfish/src/CFCClass.c
incubator/lucy/branches/clownfish_lemon/clownfish/src/CFCParseHeader.y
incubator/lucy/branches/clownfish_lemon/clownfish/src/CFCParser.c
incubator/lucy/branches/clownfish_lemon/clownfish/src/CFCParser.h
incubator/lucy/branches/clownfish_lemon/clownfish/t/403-file.t
Modified: incubator/lucy/branches/clownfish_lemon/clownfish/lib/Clownfish.xs
URL: http://svn.apache.org/viewvc/incubator/lucy/branches/clownfish_lemon/clownfish/lib/Clownfish.xs?rev=1188011&r1=1188010&r2=1188011&view=diff
==============================================================================
--- incubator/lucy/branches/clownfish_lemon/clownfish/lib/Clownfish.xs (original)
+++ incubator/lucy/branches/clownfish_lemon/clownfish/lib/Clownfish.xs Mon Oct 24 01:49:01 2011
@@ -2071,6 +2071,16 @@ CODE:
RETVAL = S_cfcbase_to_perlref(got);
OUTPUT: RETVAL
+SV*
+_parse_file(self, string, source_class)
+ CFCParser *self;
+ const char *string;
+ const char *source_class;
+CODE:
+ CFCBase *got = CFCParser_parse_file(self, string, source_class);
+ RETVAL = S_cfcbase_to_perlref(got);
+OUTPUT: RETVAL
+
void
set_parcel(unused, parcel)
SV *unused;
Modified: incubator/lucy/branches/clownfish_lemon/clownfish/src/CFCClass.c
URL: http://svn.apache.org/viewvc/incubator/lucy/branches/clownfish_lemon/clownfish/src/CFCClass.c?rev=1188011&r1=1188010&r2=1188011&view=diff
==============================================================================
--- incubator/lucy/branches/clownfish_lemon/clownfish/src/CFCClass.c (original)
+++ incubator/lucy/branches/clownfish_lemon/clownfish/src/CFCClass.c Mon Oct 24 01:49:01 2011
@@ -128,6 +128,7 @@ CFCClass_do_create(CFCClass *self, struc
CFCUTIL_NULL_CHECK(class_name);
exposure = exposure ? exposure : "parcel";
micro_sym = micro_sym ? micro_sym : "class";
+ parcel = parcel ? parcel : CFCParcel_singleton(NULL, NULL);
CFCSymbol_init((CFCSymbol*)self, parcel, exposure, class_name, cnick,
micro_sym);
self->parent = NULL;
Modified: incubator/lucy/branches/clownfish_lemon/clownfish/src/CFCParseHeader.y
URL: http://svn.apache.org/viewvc/incubator/lucy/branches/clownfish_lemon/clownfish/src/CFCParseHeader.y?rev=1188011&r1=1188010&r2=1188011&view=diff
==============================================================================
--- incubator/lucy/branches/clownfish_lemon/clownfish/src/CFCParseHeader.y (original)
+++ incubator/lucy/branches/clownfish_lemon/clownfish/src/CFCParseHeader.y Mon Oct 24 01:49:01 2011
@@ -227,6 +227,21 @@ result ::= cblock(A).
result ::= var_declaration_statement(A). { CFCParser_set_result(state, A); }
result ::= subroutine_declaration_statement(A). { CFCParser_set_result(state, A); }
result ::= class_declaration(A). { CFCParser_set_result(state, A); }
+result ::= file(A). { CFCParser_set_result(state, A); }
+
+file(A) ::= FILE_START. /* Pseudo token, not passed by lexer. */
+{
+ A = (CFCBase*)CFCFile_new(CFCParser_get_source_class(state));
+}
+file(A) ::= file(B) major_block(C).
+{
+ A = B;
+ CFCFile_add_block((CFCFile*)A, C);
+}
+
+major_block(A) ::= class_declaration(B). { A = B; }
+major_block(A) ::= cblock(B). { A = B; }
+major_block(A) ::= parcel_definition(B). { A = B; }
parcel_definition(A) ::= exposure_specifier(B) qualified_id(C) SEMICOLON.
{
Modified: incubator/lucy/branches/clownfish_lemon/clownfish/src/CFCParser.c
URL: http://svn.apache.org/viewvc/incubator/lucy/branches/clownfish_lemon/clownfish/src/CFCParser.c?rev=1188011&r1=1188010&r2=1188011&view=diff
==============================================================================
--- incubator/lucy/branches/clownfish_lemon/clownfish/src/CFCParser.c (original)
+++ incubator/lucy/branches/clownfish_lemon/clownfish/src/CFCParser.c Mon Oct 24 01:49:01 2011
@@ -50,6 +50,7 @@ struct CFCParser {
size_t cap;
char *class_name;
char *class_cnick;
+ char *source_class;
};
CFCParser*
@@ -71,6 +72,7 @@ CFCParser_init(CFCParser *self) {
self->cap = 0;
self->class_name = NULL;
self->class_cnick = NULL;
+ self->source_class = NULL;
return self;
}
@@ -109,6 +111,17 @@ CFCParser_parse(CFCParser *self, const c
return self->result;
}
+CFCBase*
+CFCParser_parse_file(CFCParser *self, const char *string,
+ const char *source_class) {
+ CFCParser_set_parcel(NULL);
+ self->source_class = CFCUtil_strdup(source_class);
+ CFCParseHeader(self->header_parser, CFC_TOKENTYPE_FILE_START, NULL, self);
+ CFCBase *result = CFCParser_parse(self, string);
+ FREEMEM(self->source_class);
+ self->source_class = NULL;
+ return result;
+}
void
CFCParser_set_result(CFCParser *self, CFCBase *result)
{
@@ -188,3 +201,19 @@ CFCParser_get_class_cnick(CFCParser *sel
return self->class_cnick;
}
+void
+CFCParser_set_source_class(CFCParser *self, const char *source_class) {
+ FREEMEM(self->source_class);
+ if (source_class) {
+ self->source_class = CFCUtil_strdup(source_class);
+ }
+ else {
+ self->source_class = NULL;
+ }
+}
+
+const char*
+CFCParser_get_source_class(CFCParser *self) {
+ return self->source_class;
+}
+
Modified: incubator/lucy/branches/clownfish_lemon/clownfish/src/CFCParser.h
URL: http://svn.apache.org/viewvc/incubator/lucy/branches/clownfish_lemon/clownfish/src/CFCParser.h?rev=1188011&r1=1188010&r2=1188011&view=diff
==============================================================================
--- incubator/lucy/branches/clownfish_lemon/clownfish/src/CFCParser.h (original)
+++ incubator/lucy/branches/clownfish_lemon/clownfish/src/CFCParser.h Mon Oct 24 01:49:01 2011
@@ -40,6 +40,10 @@ CFCParser_destroy(CFCParser *self);
struct CFCBase*
CFCParser_parse(CFCParser *self, const char *string);
+struct CFCBase*
+CFCParser_parse_file(CFCParser *self, const char *string,
+ const char *source_class);
+
void
CFCParser_set_result(CFCParser *self, struct CFCBase *result);
@@ -70,6 +74,12 @@ CFCParser_set_class_cnick(CFCParser *sel
const char*
CFCParser_get_class_cnick(CFCParser *self);
+void
+CFCParser_set_source_class(CFCParser *self, const char *source_class);
+
+const char*
+CFCParser_get_source_class(CFCParser *self);
+
#ifdef __cplusplus
}
#endif
Modified: incubator/lucy/branches/clownfish_lemon/clownfish/t/403-file.t
URL: http://svn.apache.org/viewvc/incubator/lucy/branches/clownfish_lemon/clownfish/t/403-file.t?rev=1188011&r1=1188010&r2=1188011&view=diff
==============================================================================
--- incubator/lucy/branches/clownfish_lemon/clownfish/t/403-file.t (original)
+++ incubator/lucy/branches/clownfish_lemon/clownfish/t/403-file.t Mon Oct 24 01:49:01 2011
@@ -32,8 +32,9 @@ my $class_content = qq|
|;
my $c_block = "__C__\nint foo;\n__END_C__\n";
-my $file = $parser->file( "$parcel_declaration\n$class_content\n$c_block",
- 0, source_class => 'Stuff::Thing' );
+my $file
+ = $parser->_parse_file( "$parcel_declaration\n$class_content\n$c_block",
+ 'Stuff::Thing' );
is( $file->get_source_class, "Stuff::Thing", "get_source_class" );
@@ -67,7 +68,7 @@ isa_ok( $blocks->[0], "Clownfish::Parcel
isa_ok( $blocks->[1], "Clownfish::Class" );
isa_ok( $blocks->[2], "Clownfish::CBlock" );
-$file = $parser->file( $class_content, 0, source_class => 'Stuff::Thing' );
+$file = $parser->_parse_file( $class_content, 'Stuff::Thing' );
($class) = @{ $file->classes };
( $foo, $bar ) = @{ $class->member_vars };
is( $foo->get_type->get_specifier, 'Foo', 'file production resets parcel' );