Updated from branch dev
authorThadeu Lima de Souza Cascardo <cascardo@dcc.ufmg.br>
Wed, 26 Oct 2005 12:43:18 +0000 (12:43 +0000)
committerThadeu Lima de Souza Cascardo <cascardo@dcc.ufmg.br>
Wed, 26 Oct 2005 12:43:18 +0000 (12:43 +0000)
Patches applied:

 * cascardo@tlscascardo--private/libgrammatic--dev--0.1--patch-22
   Added scanner module and fixed BNF dependency on it

git-archimport-id: cascardo@tlscascardo--private/libgrammatic--nogobject-lr1--0.1--patch-8

bnf.c
scanner.c [new file with mode: 0644]
scanner.h [new file with mode: 0644]

diff --git a/bnf.c b/bnf.c
index 44cc72e..92d385f 100644 (file)
--- a/bnf.c
+++ b/bnf.c
@@ -6,7 +6,16 @@
 #include <unistd.h>
 #include <stdlib.h>
 
-static gint scanner_next (scanner_t* scanner, GString** val)
+typedef enum
+  {
+    NONE = 0,
+    EQUAL = 1,
+    ID = 2,
+    STRING = 3,
+    EOL = 4
+  } token_t;
+
+static gint bnf_scanner_next (scanner_t* scanner, GString** val)
 {
 
   int state;
@@ -250,7 +259,7 @@ grammar_t* grammar_load (char* filename)
   scanner = scanner_new (read, fd);
 
   grammar = grammar_new ();
-  parser = rdp_new (scanner_next, scanner, BNF_GRAMMAR, grammar);
+  parser = rdp_new (bnf_scanner_next, scanner, BNF_GRAMMAR, grammar);
 
   rule = grammar_rule_new (grammar, symbol_new (FALSE, BNF_GRAMMAR));
   rule_append (rule, symbol_new (FALSE, BNF_RULES));
diff --git a/scanner.c b/scanner.c
new file mode 100644 (file)
index 0000000..1307bca
--- /dev/null
+++ b/scanner.c
@@ -0,0 +1,31 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <scanner.h>
+
+static void string_free (gpointer data)
+{
+  g_string_free ((GString*) data, TRUE);
+}
+
+scanner_t* scanner_new (readcb cb, gpointer data)
+{
+
+  scanner_t* scanner;
+
+  scanner = g_malloc (sizeof (scanner_t));
+  scanner->cb = cb;
+  scanner->data = data;
+  scanner->buffer = g_string_sized_new (256);
+  scanner->reserved = g_hash_table_new_full (g_string_hash, g_string_equal,
+                                            string_free, NULL);
+
+  return scanner;
+
+}
+
+void scanner_delete (scanner_t* scanner)
+{
+  g_hash_table_destroy (scanner->reserved);
+  g_string_free (scanner->buffer, TRUE);
+  g_free (scanner);
+}
diff --git a/scanner.h b/scanner.h
new file mode 100644 (file)
index 0000000..514d9a0
--- /dev/null
+++ b/scanner.h
@@ -0,0 +1,19 @@
+#ifndef SCANNER_H
+#define SCANNER_H
+
+#include <glib.h>
+
+typedef gint (*readcb) (gpointer, gchar*, gint);
+
+typedef struct
+{
+  readcb cb;
+  gpointer data;
+  GString* buffer;
+  GHashTable* reserved;
+} scanner_t;
+
+scanner_t* scanner_new (readcb, gpointer);
+void scanner_delete (scanner_t*);
+
+#endif