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/09/18 20:18:00 UTC

[lucy-commits] svn commit: r1172313 - in /incubator/lucy/branches/clownfish_lemon/clownfish: buildlib/Clownfish/Build.pm src/CFCParseHeader.y src/CFCParser.c src/CFCParser.h

Author: marvin
Date: Sun Sep 18 18:18:00 2011
New Revision: 1172313

URL: http://svn.apache.org/viewvc?rev=1172313&view=rev
Log:
Add a stub Lemon-based Clownfish header parser.

Added:
    incubator/lucy/branches/clownfish_lemon/clownfish/src/CFCParseHeader.y
Modified:
    incubator/lucy/branches/clownfish_lemon/clownfish/buildlib/Clownfish/Build.pm
    incubator/lucy/branches/clownfish_lemon/clownfish/src/CFCParser.c
    incubator/lucy/branches/clownfish_lemon/clownfish/src/CFCParser.h

Modified: incubator/lucy/branches/clownfish_lemon/clownfish/buildlib/Clownfish/Build.pm
URL: http://svn.apache.org/viewvc/incubator/lucy/branches/clownfish_lemon/clownfish/buildlib/Clownfish/Build.pm?rev=1172313&r1=1172312&r2=1172313&view=diff
==============================================================================
--- incubator/lucy/branches/clownfish_lemon/clownfish/buildlib/Clownfish/Build.pm (original)
+++ incubator/lucy/branches/clownfish_lemon/clownfish/buildlib/Clownfish/Build.pm Sun Sep 18 18:18:00 2011
@@ -22,6 +22,8 @@ use base qw( Module::Build );
 use File::Spec::Functions qw( catfile );
 
 my $PPPORT_H_PATH = catfile(qw( include ppport.h ));
+my $LEMON_EXE_PATH = 'lemon';    # Don't bother compiling lemon for now.
+my $CFC_SOURCE_DIR = 'src';
 
 sub extra_ccflags {
     my $self = shift;
@@ -94,9 +96,26 @@ sub ACTION_ppport {
     }
 }
 
+# Run all .y files through lemon.
+sub ACTION_parsers {
+    my $self = shift;
+    # $self->dispatch('lemon');
+    my $y_files = $self->rscan_dir( $CFC_SOURCE_DIR, qr/\.y$/ );
+    for my $y_file (@$y_files) {
+        my $c_file = $y_file;
+        my $h_file = $y_file;
+        $c_file =~ s/\.y$/.c/ or die "no match";
+        $h_file =~ s/\.y$/.h/ or die "no match";
+        next if $self->up_to_date( $y_file, [ $c_file, $h_file ] );
+        $self->add_to_cleanup( $c_file, $h_file );
+        system( $LEMON_EXE_PATH, '-q', $y_file ) and die "lemon failed";
+    }
+}
+
 sub ACTION_code {
     my $self = shift;
     $self->dispatch('ppport');
+    $self->dispatch('parsers');
     $self->SUPER::ACTION_code;
 }
 

Added: 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=1172313&view=auto
==============================================================================
--- incubator/lucy/branches/clownfish_lemon/clownfish/src/CFCParseHeader.y (added)
+++ incubator/lucy/branches/clownfish_lemon/clownfish/src/CFCParseHeader.y Sun Sep 18 18:18:00 2011
@@ -0,0 +1,39 @@
+%name CFCParseHeader
+
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+%token_type { CFCBase* }
+%token_destructor { CFCBase_decref((CFCBase*)$$); }
+%token_prefix CFC_TOKENTYPE_
+
+%extra_argument { CFCParserState *state }
+
+%include {
+#include <stdio.h>
+#include <string.h>
+#include <assert.h>
+#include "CFC.h"
+}
+
+void_type(A) ::= void_type_specifier.
+{
+    int is_const = 0; /* FIXME get this from content. */
+    A = (CFCBase*)CFCType_new_void(is_const);
+}
+
+void_type_specifier ::= VOID.
+

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=1172313&r1=1172312&r2=1172313&view=diff
==============================================================================
--- incubator/lucy/branches/clownfish_lemon/clownfish/src/CFCParser.c (original)
+++ incubator/lucy/branches/clownfish_lemon/clownfish/src/CFCParser.c Sun Sep 18 18:18:00 2011
@@ -13,14 +13,28 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
+#include <stdio.h>
+#include <stdlib.h>
 
 #define CFC_NEED_BASE_STRUCT_DEF
 #include "CFCBase.h"
 #include "CFCParser.h"
 #include "CFCUtil.h"
 
+/* Routines generated by Lemon. */
+void*
+CFCParseHeaderAlloc(void * (*allocate)(size_t));
+void
+CFCParseHeader(void *header_parser, int token_type, CFCBase *value,
+               CFCParserState *state);
+void
+CFCParseHeaderFree(void *header_parser, void(*freemem)(void*));
+void
+CFCParseHeaderTrace(FILE *trace, char *line_prefix);
+
 struct CFCParser {
     CFCBase base;
+    void *header_parser;
 };
 
 CFCParser*
@@ -32,11 +46,16 @@ CFCParser_new(void) {
 
 CFCParser*
 CFCParser_init(CFCParser *self) {
+    self->header_parser = CFCParseHeaderAlloc(malloc);
+    if (self->header_parser == NULL) {
+        CFCUtil_die("Failed to allocate header parser");
+    }
     return self;
 }
 
 void
 CFCParser_destroy(CFCParser *self) {
+    CFCParseHeaderFree(self->header_parser, free);
     CFCBase_destroy((CFCBase*)self);
 }
 

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=1172313&r1=1172312&r2=1172313&view=diff
==============================================================================
--- incubator/lucy/branches/clownfish_lemon/clownfish/src/CFCParser.h (original)
+++ incubator/lucy/branches/clownfish_lemon/clownfish/src/CFCParser.h Sun Sep 18 18:18:00 2011
@@ -22,6 +22,14 @@ extern "C" {
 #endif
 
 typedef struct CFCParser CFCParser;
+struct CFCBase;
+
+struct CFCParserState 
+{
+    struct CFCBase *result;
+    int errors;
+};
+typedef struct CFCParserState CFCParserState;
 
 CFCParser*
 CFCParser_new(void);