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/18 01:21:22 UTC

[lucy-commits] svn commit: r1185429 - in /incubator/lucy/branches/clownfish_lemon/clownfish: src/CFCLexHeader.l src/CFCParseHeader.y t/401-c_block.t

Author: marvin
Date: Mon Oct 17 23:21:22 2011
New Revision: 1185429

URL: http://svn.apache.org/viewvc?rev=1185429&view=rev
Log:
Add support for embedded C code to Lemon-based parser.

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/401-c_block.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=1185429&r1=1185428&r2=1185429&view=diff
==============================================================================
--- incubator/lucy/branches/clownfish_lemon/clownfish/src/CFCLexHeader.l (original)
+++ incubator/lucy/branches/clownfish_lemon/clownfish/src/CFCLexHeader.l Mon Oct 17 23:21:22 2011
@@ -48,6 +48,8 @@ CLASS_NAME_COMPONENT    [A-Z]+[A-Z0-9]*[
 %option nodefault
 %option yylineno
 
+%x CBLOCK
+
 %%
 const       { PARSE(CFC_TOKENTYPE_CONST); }
 nullable    { PARSE(CFC_TOKENTYPE_NULLABLE); } 
@@ -103,13 +105,17 @@ parcel     { PARSE(CFC_TOKENTYPE_PARCEL)
 \"([^\"\\]|\\.)*\"     { SAVE_AND_PARSE(CFC_TOKENTYPE_STRING_LITERAL); }
 
 [a-zA-Z_][a-zA-Z0-9_]* { SAVE_AND_PARSE(CFC_TOKENTYPE_IDENTIFIER); }
+
+__C__[[:space:]]*    { BEGIN(CBLOCK);  PARSE(CFC_TOKENTYPE_CBLOCK_START); }
+<CBLOCK>__END_C__    { BEGIN(INITIAL); PARSE(CFC_TOKENTYPE_CBLOCK_CLOSE); }
+<CBLOCK>(__END_C_[^_]|[^_])+   { SAVE_AND_PARSE(CFC_TOKENTYPE_BLOB); }
            
     /* Parse docucomments, but skip ordinary comments */
 "/**"([^*]|"*"[^/])*"*/" { SAVE_AND_PARSE(CFC_TOKENTYPE_DOCUCOMMENT); }
 "/*"([^*]|"*"[^/])*"*/"
 
 [ \t\r\n]  /* Skip whitespace. */
-.          { 
+<*>.       { 
                 printf("Bad input character '%s' at line %d\n", yytext, yylineno);
                 yyterminate();
            }

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=1185429&r1=1185428&r2=1185429&view=diff
==============================================================================
--- incubator/lucy/branches/clownfish_lemon/clownfish/src/CFCParseHeader.y (original)
+++ incubator/lucy/branches/clownfish_lemon/clownfish/src/CFCParseHeader.y Mon Oct 17 23:21:22 2011
@@ -70,6 +70,7 @@ result ::= param_list(A).             { 
 result ::= param_variable(A).         { state->result = A; }
 result ::= docucomment(A).            { state->result = A; }
 result ::= parcel_definition(A).      { state->result = A; }
+result ::= cblock(A).                 { state->result = A; }
 
 parcel_definition(A) ::= PARCEL class_name(B) SEMICOLON.
 {
@@ -130,6 +131,7 @@ void_type(A) ::= void_type_specifier.
 %type declarator                    {char*}
 %type class_name                    {char*}
 %type cnick                         {char*}
+%type blob                          {char*}
 %destructor float_type_specifier        { }
 %destructor integer_type_specifier      { }
 %destructor object_type_specifier       { FREEMEM($$); }
@@ -146,6 +148,7 @@ void_type(A) ::= void_type_specifier.
 %destructor declarator                  { FREEMEM($$); }
 %destructor class_name                  { FREEMEM($$); }
 %destructor cnick                       { FREEMEM($$); }
+%destructor blob                        { FREEMEM($$); }
 
 void_type_specifier ::= VOID.
 va_list_specifier         ::= VA_LIST.
@@ -345,3 +348,12 @@ cnick(A) ::= CNICK CLASS_NAME_COMPONENT.
     A = CFCUtil_strdup(CFCParser_current_state->text);
 }
 
+cblock(A) ::= CBLOCK_START blob(B) CBLOCK_CLOSE.
+{
+    A = (CFCBase*)CFCCBlock_new(B);
+}
+
+blob(A) ::= BLOB.
+{
+    A = CFCUtil_strdup(CFCParser_current_state->text);
+}

Modified: incubator/lucy/branches/clownfish_lemon/clownfish/t/401-c_block.t
URL: http://svn.apache.org/viewvc/incubator/lucy/branches/clownfish_lemon/clownfish/t/401-c_block.t?rev=1185429&r1=1185428&r2=1185429&view=diff
==============================================================================
--- incubator/lucy/branches/clownfish_lemon/clownfish/t/401-c_block.t (original)
+++ incubator/lucy/branches/clownfish_lemon/clownfish/t/401-c_block.t Mon Oct 17 23:21:22 2011
@@ -29,7 +29,7 @@ is( $block->get_contents, 'int foo;', "g
 eval { Clownfish::CBlock->new };
 like( $@, qr/contents/, "content required" );
 
-$block = $parser->embed_c(qq| __C__\n#define FOO 1\n__END_C__  |);
+$block = $parser->parse(qq| __C__\n#define FOO 1\n__END_C__  |);
 
 isa_ok( $block, "Clownfish::CBlock" );
 is( $block->get_contents, "#define FOO 1\n", "parse embed_c" );