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/17 02:06:49 UTC
[lucy-commits] svn commit: r1184960 - in
/incubator/lucy/branches/clownfish_lemon/clownfish: src/CFCLexHeader.l
src/CFCParseHeader.y t/200-function.t t/201-method.t
t/202-overridden_method.t t/203-final_method.t t/301-param_list.t
t/400-class.t t/600-parser.t
Author: marvin
Date: Mon Oct 17 00:06:48 2011
New Revision: 1184960
URL: http://svn.apache.org/viewvc?rev=1184960&view=rev
Log:
Add support for param lists to Lemon-based parser.
Additionally, add support for several scalar constants: string literals, float
literals, hex literals, true, false and NULL.
Modified:
incubator/lucy/branches/clownfish_lemon/clownfish/src/CFCLexHeader.l
incubator/lucy/branches/clownfish_lemon/clownfish/src/CFCParseHeader.y
incubator/lucy/branches/clownfish_lemon/clownfish/t/200-function.t
incubator/lucy/branches/clownfish_lemon/clownfish/t/201-method.t
incubator/lucy/branches/clownfish_lemon/clownfish/t/202-overridden_method.t
incubator/lucy/branches/clownfish_lemon/clownfish/t/203-final_method.t
incubator/lucy/branches/clownfish_lemon/clownfish/t/301-param_list.t
incubator/lucy/branches/clownfish_lemon/clownfish/t/400-class.t
incubator/lucy/branches/clownfish_lemon/clownfish/t/600-parser.t
Modified: incubator/lucy/branches/clownfish_lemon/clownfish/src/CFCLexHeader.l
URL: http://svn.apache.org/viewvc/incubator/lucy/branches/clownfish_lemon/clownfish/src/CFCLexHeader.l?rev=1184960&r1=1184959&r2=1184960&view=diff
==============================================================================
--- incubator/lucy/branches/clownfish_lemon/clownfish/src/CFCLexHeader.l (original)
+++ incubator/lucy/branches/clownfish_lemon/clownfish/src/CFCLexHeader.l Mon Oct 17 00:06:48 2011
@@ -65,6 +65,9 @@ long { PARSE(CFC_TOKENTYPE_LONG, N
size_t { PARSE(CFC_TOKENTYPE_SIZE_T, NULL); }
bool_t { PARSE(CFC_TOKENTYPE_BOOL_T, NULL); }
va_list { PARSE(CFC_TOKENTYPE_VA_LIST, NULL); }
+true { PARSE(CFC_TOKENTYPE_TRUE, NULL); }
+false { PARSE(CFC_TOKENTYPE_FALSE, NULL); }
+NULL { PARSE(CFC_TOKENTYPE_NULL, NULL); }
[A-Za-z0-9_]+_t {
S_save_yytext();
PARSE(CFC_TOKENTYPE_ARBITRARY, NULL);
@@ -76,10 +79,27 @@ va_list { PARSE(CFC_TOKENTYPE_VA_LIST
[*] { PARSE(CFC_TOKENTYPE_ASTERISK, NULL); }
[\[] { PARSE(CFC_TOKENTYPE_LEFT_SQUARE_BRACKET, NULL); }
[\]] { PARSE(CFC_TOKENTYPE_RIGHT_SQUARE_BRACKET, NULL); }
+[\(] { PARSE(CFC_TOKENTYPE_LEFT_PAREN, NULL); }
+[\)] { PARSE(CFC_TOKENTYPE_RIGHT_PAREN, NULL); }
+\.\.\. { PARSE(CFC_TOKENTYPE_ELLIPSIS, NULL); }
+, { PARSE(CFC_TOKENTYPE_COMMA, NULL); }
+= { PARSE(CFC_TOKENTYPE_EQUALS, NULL); }
+-?0x[0-9A-Fa-f]+ {
+ S_save_yytext();
+ PARSE(CFC_TOKENTYPE_HEX_LITERAL, NULL);
+ }
-?[0-9]+ {
S_save_yytext();
PARSE(CFC_TOKENTYPE_INTEGER_LITERAL, NULL);
}
+-?[ ]*[0-9+].[0-9]+ {
+ S_save_yytext();
+ PARSE(CFC_TOKENTYPE_FLOAT_LITERAL, NULL);
+ }
+\"([^\"\\]|\\.)*\" {
+ S_save_yytext();
+ PARSE(CFC_TOKENTYPE_STRING_LITERAL, NULL);
+ }
[a-zA-Z_][a-zA-Z0-9_]* {
S_save_yytext();
PARSE(CFC_TOKENTYPE_IDENTIFIER, 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=1184960&r1=1184959&r2=1184960&view=diff
==============================================================================
--- incubator/lucy/branches/clownfish_lemon/clownfish/src/CFCParseHeader.y (original)
+++ incubator/lucy/branches/clownfish_lemon/clownfish/src/CFCParseHeader.y Mon Oct 17 00:06:48 2011
@@ -64,14 +64,13 @@ static const char KW_DOUBLE[] = "doubl
state->cap = 0;
}
-result ::= type(A).
-{
- state->result = A;
-}
+/* Temporary. */
+result ::= type(A). { state->result = A; }
+result ::= param_list(A). { state->result = A; }
+result ::= param_variable(A). { state->result = A; }
type(A) ::= simple_type(B). { A = B; }
type(A) ::= composite_type(B). { A = B; }
-type(A) ::= param_variable(B). { A = B; } /* temporary */
composite_type(A) ::= simple_type(B) asterisk_postfix(C).
{
@@ -106,7 +105,11 @@ void_type(A) ::= void_type_specifier.
%type object_type_specifier {char*}
%type type_qualifier {int}
%type type_qualifier_list {int}
-%type integer_literal {long}
+%type scalar_constant {char*}
+%type integer_literal {char*}
+%type float_literal {char*}
+%type hex_literal {char*}
+%type string_literal {char*}
%type asterisk_postfix {char*}
%type array_postfix {char*}
%type array_postfix_elem {char*}
@@ -116,6 +119,11 @@ void_type(A) ::= void_type_specifier.
%destructor object_type_specifier { FREEMEM($$); }
%destructor type_qualifier { }
%destructor type_qualifier_list { }
+%destructor scalar_constant { FREEMEM($$); }
+%destructor integer_literal { FREEMEM($$); }
+%destructor float_literal { FREEMEM($$); }
+%destructor hex_literal { FREEMEM($$); }
+%destructor string_literal { FREEMEM($$); }
%destructor asterisk_postfix { FREEMEM($$); }
%destructor array_postfix { FREEMEM($$); }
%destructor array_postfix_elem { FREEMEM($$); }
@@ -212,9 +220,7 @@ array_postfix_elem(A) ::= LEFT_SQUARE_BR
}
array_postfix_elem(A) ::= LEFT_SQUARE_BRACKET integer_literal(B) RIGHT_SQUARE_BRACKET.
{
- char buffer[30];
- sprintf(buffer, "%ld", B);
- A = CFCUtil_cat(CFCUtil_strdup(""), "[", buffer, "]", NULL);
+ A = CFCUtil_cat(CFCUtil_strdup(""), "[", B, "]", NULL);
}
array_postfix(A) ::= array_postfix_elem(B).
@@ -226,9 +232,29 @@ array_postfix(A) ::= array_postfix(B) ar
A = CFCUtil_cat(B, C, NULL);
}
+scalar_constant(A) ::= hex_literal(B). { A = B; }
+scalar_constant(A) ::= float_literal(B). { A = B; }
+scalar_constant(A) ::= integer_literal(B). { A = B; }
+scalar_constant(A) ::= string_literal(B). { A = B; }
+scalar_constant(A) ::= TRUE. { A = CFCUtil_strdup("true"); }
+scalar_constant(A) ::= FALSE. { A = CFCUtil_strdup("false"); }
+scalar_constant(A) ::= NULL. { A = CFCUtil_strdup("NULL"); }
+
integer_literal(A) ::= INTEGER_LITERAL.
{
- A = strtol(CFCParser_current_state->text, NULL, 10);
+ A = CFCUtil_strdup(CFCParser_current_state->text);
+}
+float_literal(A) ::= FLOAT_LITERAL.
+{
+ A = CFCUtil_strdup(CFCParser_current_state->text);
+}
+hex_literal(A) ::= HEX_LITERAL.
+{
+ A = CFCUtil_strdup(CFCParser_current_state->text);
+}
+string_literal(A) ::= STRING_LITERAL.
+{
+ A = CFCUtil_strdup(CFCParser_current_state->text);
}
declarator(A) ::= IDENTIFIER.
@@ -241,3 +267,37 @@ param_variable(A) ::= type(B) declarator
A = (CFCBase*)CFCVariable_new(NULL, NULL, NULL, NULL, C, (CFCType*)B);
}
+param_list(A) ::= LEFT_PAREN RIGHT_PAREN.
+{
+ A = (CFCBase*)CFCParamList_new(false);
+}
+param_list(A) ::= LEFT_PAREN param_list_elems(B) RIGHT_PAREN.
+{
+ A = B;
+}
+param_list(A) ::= LEFT_PAREN param_list_elems(B) COMMA ELLIPSIS RIGHT_PAREN.
+{
+ A = B;
+ CFCParamList_set_variadic((CFCParamList*)A, true);
+}
+param_list_elems(A) ::= param_list_elems(B) COMMA param_variable(C).
+{
+ A = B;
+ CFCParamList_add_param((CFCParamList*)A, (CFCVariable*)C, NULL);
+}
+param_list_elems(A) ::= param_list_elems(B) COMMA param_variable(C) EQUALS scalar_constant(D).
+{
+ A = B;
+ CFCParamList_add_param((CFCParamList*)A, (CFCVariable*)C, D);
+}
+param_list_elems(A) ::= param_variable(B).
+{
+ A = (CFCBase*)CFCParamList_new(false);
+ CFCParamList_add_param((CFCParamList*)A, (CFCVariable*)B, NULL);
+}
+param_list_elems(A) ::= param_variable(B) EQUALS scalar_constant(C).
+{
+ A = (CFCBase*)CFCParamList_new(false);
+ CFCParamList_add_param((CFCParamList*)A, (CFCVariable*)B, C);
+}
+
Modified: incubator/lucy/branches/clownfish_lemon/clownfish/t/200-function.t
URL: http://svn.apache.org/viewvc/incubator/lucy/branches/clownfish_lemon/clownfish/t/200-function.t?rev=1184960&r1=1184959&r2=1184960&view=diff
==============================================================================
--- incubator/lucy/branches/clownfish_lemon/clownfish/t/200-function.t (original)
+++ incubator/lucy/branches/clownfish_lemon/clownfish/t/200-function.t Mon Oct 17 00:06:48 2011
@@ -31,7 +31,7 @@ my %args = (
return_type => $parser->type('Obj*'),
class_name => 'Neato::Foo',
class_cnick => 'Foo',
- param_list => $parser->param_list('(int32_t some_num)'),
+ param_list => $parser->parse('(int32_t some_num)'),
micro_sym => 'return_an_obj',
);
Modified: incubator/lucy/branches/clownfish_lemon/clownfish/t/201-method.t
URL: http://svn.apache.org/viewvc/incubator/lucy/branches/clownfish_lemon/clownfish/t/201-method.t?rev=1184960&r1=1184959&r2=1184960&view=diff
==============================================================================
--- incubator/lucy/branches/clownfish_lemon/clownfish/t/201-method.t (original)
+++ incubator/lucy/branches/clownfish_lemon/clownfish/t/201-method.t Mon Oct 17 00:06:48 2011
@@ -30,7 +30,7 @@ my %args = (
return_type => $parser->type('Obj*'),
class_name => 'Neato::Foo',
class_cnick => 'Foo',
- param_list => $parser->param_list('(Foo *self, int32_t count = 0)'),
+ param_list => $parser->parse('(Foo *self, int32_t count = 0)'),
macro_sym => 'Return_An_Obj',
);
@@ -56,35 +56,35 @@ ok( !$macro_sym_differs->compatible($met
my $extra_param = Clownfish::Method->new( %args,
param_list =>
- $parser->param_list('(Foo *self, int32_t count = 0, int b)'), );
+ $parser->parse('(Foo *self, int32_t count = 0, int b)'), );
ok( !$method->compatible($macro_sym_differs),
"extra param spoils compatible()"
);
ok( !$extra_param->compatible($method), "... reversed" );
my $default_differs = Clownfish::Method->new( %args,
- param_list => $parser->param_list('(Foo *self, int32_t count = 1)'), );
+ param_list => $parser->parse('(Foo *self, int32_t count = 1)'), );
ok( !$method->compatible($default_differs),
"different initial_value spoils compatible()"
);
ok( !$default_differs->compatible($method), "... reversed" );
my $missing_default = Clownfish::Method->new( %args,
- param_list => $parser->param_list('(Foo *self, int32_t count)'), );
+ param_list => $parser->parse('(Foo *self, int32_t count)'), );
ok( !$method->compatible($missing_default),
"missing initial_value spoils compatible()"
);
ok( !$missing_default->compatible($method), "... reversed" );
my $param_name_differs = Clownfish::Method->new( %args,
- param_list => $parser->param_list('(Foo *self, int32_t countess)'), );
+ param_list => $parser->parse('(Foo *self, int32_t countess)'), );
ok( !$method->compatible($param_name_differs),
"different param name spoils compatible()"
);
ok( !$param_name_differs->compatible($method), "... reversed" );
my $param_type_differs = Clownfish::Method->new( %args,
- param_list => $parser->param_list('(Foo *self, uint32_t count)'), );
+ param_list => $parser->parse('(Foo *self, uint32_t count)'), );
ok( !$method->compatible($param_type_differs),
"different param type spoils compatible()"
);
@@ -94,7 +94,7 @@ my $self_type_differs = Clownfish::Metho
%args,
class_name => 'Neato::Bar',
class_cnick => 'Bar',
- param_list => $parser->param_list('(Bar *self, int32_t count = 0)'),
+ param_list => $parser->parse('(Bar *self, int32_t count = 0)'),
);
ok( $method->compatible($self_type_differs),
"different self type still compatible(), since can't test inheritance" );
Modified: incubator/lucy/branches/clownfish_lemon/clownfish/t/202-overridden_method.t
URL: http://svn.apache.org/viewvc/incubator/lucy/branches/clownfish_lemon/clownfish/t/202-overridden_method.t?rev=1184960&r1=1184959&r2=1184960&view=diff
==============================================================================
--- incubator/lucy/branches/clownfish_lemon/clownfish/t/202-overridden_method.t (original)
+++ incubator/lucy/branches/clownfish_lemon/clownfish/t/202-overridden_method.t Mon Oct 17 00:06:48 2011
@@ -29,7 +29,7 @@ my %args = (
return_type => $parser->type('Obj*'),
class_name => 'Neato::Foo',
class_cnick => 'Foo',
- param_list => $parser->param_list('(Foo *self)'),
+ param_list => $parser->parse('(Foo *self)'),
macro_sym => 'Return_An_Obj',
parcel => 'Neato',
);
@@ -37,7 +37,7 @@ my %args = (
my $orig = Clownfish::Method->new(%args);
my $overrider = Clownfish::Method->new(
%args,
- param_list => $parser->param_list('(FooJr *self)'),
+ param_list => $parser->parse('(FooJr *self)'),
class_name => 'Neato::Foo::FooJr',
class_cnick => 'FooJr'
);
Modified: incubator/lucy/branches/clownfish_lemon/clownfish/t/203-final_method.t
URL: http://svn.apache.org/viewvc/incubator/lucy/branches/clownfish_lemon/clownfish/t/203-final_method.t?rev=1184960&r1=1184959&r2=1184960&view=diff
==============================================================================
--- incubator/lucy/branches/clownfish_lemon/clownfish/t/203-final_method.t (original)
+++ incubator/lucy/branches/clownfish_lemon/clownfish/t/203-final_method.t Mon Oct 17 00:06:48 2011
@@ -28,7 +28,7 @@ my %args = (
return_type => $parser->type('Obj*'),
class_name => 'Neato::Foo',
class_cnick => 'Foo',
- param_list => $parser->param_list('(Foo* self)'),
+ param_list => $parser->parse('(Foo* self)'),
macro_sym => 'Return_An_Obj',
parcel => 'Neato',
);
Modified: incubator/lucy/branches/clownfish_lemon/clownfish/t/301-param_list.t
URL: http://svn.apache.org/viewvc/incubator/lucy/branches/clownfish_lemon/clownfish/t/301-param_list.t?rev=1184960&r1=1184959&r2=1184960&view=diff
==============================================================================
--- incubator/lucy/branches/clownfish_lemon/clownfish/t/301-param_list.t (original)
+++ incubator/lucy/branches/clownfish_lemon/clownfish/t/301-param_list.t Mon Oct 17 00:06:48 2011
@@ -30,13 +30,13 @@ isa_ok( $parser->parse($_),
"Clownfish::Variable", "param_variable: $_" )
for ( 'uint32_t baz', 'CharBuf *stuff', 'float **ptr', );
-my $param_list = $parser->param_list("(Obj *self, int num)");
+my $param_list = $parser->parse("(Obj *self, int num)");
isa_ok( $param_list, "Clownfish::ParamList" );
ok( !$param_list->variadic, "not variadic" );
is( $param_list->to_c, 'neato_Obj* self, int num', "to_c" );
is( $param_list->name_list, 'self, num', "name_list" );
-$param_list = $parser->param_list("(Obj *self=NULL, int num, ...)");
+$param_list = $parser->parse("(Obj *self=NULL, int num, ...)");
ok( $param_list->variadic, "variadic" );
is_deeply(
$param_list->get_initial_values,
Modified: incubator/lucy/branches/clownfish_lemon/clownfish/t/400-class.t
URL: http://svn.apache.org/viewvc/incubator/lucy/branches/clownfish_lemon/clownfish/t/400-class.t?rev=1184960&r1=1184959&r2=1184960&view=diff
==============================================================================
--- incubator/lucy/branches/clownfish_lemon/clownfish/t/400-class.t (original)
+++ incubator/lucy/branches/clownfish_lemon/clownfish/t/400-class.t Mon Oct 17 00:06:48 2011
@@ -38,7 +38,7 @@ my $tread_water = Clownfish::Function->n
class_name => 'Foo',
return_type => $parser->type('void'),
micro_sym => 'tread_water',
- param_list => $parser->param_list('()'),
+ param_list => $parser->parse('()'),
);
my %foo_create_args = (
parcel => 'Neato',
Modified: incubator/lucy/branches/clownfish_lemon/clownfish/t/600-parser.t
URL: http://svn.apache.org/viewvc/incubator/lucy/branches/clownfish_lemon/clownfish/t/600-parser.t?rev=1184960&r1=1184959&r2=1184960&view=diff
==============================================================================
--- incubator/lucy/branches/clownfish_lemon/clownfish/t/600-parser.t (original)
+++ incubator/lucy/branches/clownfish_lemon/clownfish/t/600-parser.t Mon Oct 17 00:06:48 2011
@@ -108,11 +108,11 @@ my %param_lists = (
'()' => 0,
);
while ( my ( $param_list, $num_params ) = each %param_lists ) {
- my $parsed = $parser->param_list($param_list);
+ my $parsed = $parser->parse($param_list);
isa_ok( $parsed, "Clownfish::ParamList", "param_list: $param_list" );
}
-ok( $parser->param_list("(int foo, ...)")->variadic, "variadic param list" );
-my $param_list = $parser->param_list(q|(int foo = 0xFF, char *bar ="blah")|);
+ok( $parser->parse("(int foo, ...)")->variadic, "variadic param list" );
+my $param_list = $parser->parse(q|(int foo = 0xFF, char *bar ="blah")|);
is_deeply(
$param_list->get_initial_values,
[ '0xFF', '"blah"' ],