]> git.draconx.ca Git - cdecl99.git/blobdiff - src/parse-decl.c
Start on a facility to translate error codes into strings.
[cdecl99.git] / src / parse-decl.c
index bce0afe186644d5f8968630ef830cbdf362f11e1..0d26b9d9dbdf07ed00719cb1d66916c4a6e4f326 100644 (file)
@@ -15,6 +15,7 @@
  *  You should have received a copy of the GNU General Public License
  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
+#include <config.h>
 #include <stdio.h>
 #include <assert.h>
 #include <stdbool.h>
@@ -23,6 +24,7 @@
 #include "typemap.h"
 #include "parse.h"
 #include "scan.h"
+#include "i18n.h"
 
 /*
  * Determine if a declarator declares an identifier (other than a function
@@ -391,14 +393,16 @@ struct cdecl *cdecl_parse_decl(const char *declstr)
        struct cdecl *decl;
        int rc;
 
-       rc = yylex_init(&scanner);
+       cdecl__init_i18n();
+
+       rc = cdecl__yylex_init(&scanner);
        if (rc != 0)
                return NULL;
 
-       state = yy_scan_string(declstr, scanner);
-       rc = yyparse(scanner, &decl);
-       yy_delete_buffer(state, scanner);
-       yylex_destroy(scanner);
+       state = cdecl__yy_scan_string(declstr, scanner);
+       rc = cdecl__yyparse(scanner, &decl);
+       cdecl__yy_delete_buffer(state, scanner);
+       cdecl__yylex_destroy(scanner);
 
        if (rc != 0)
                return NULL;
@@ -429,3 +433,42 @@ err:
        cdecl_free(decl);
        return NULL;
 }
+
+struct cdecl *cdecl_parse_english(const char *english)
+{
+       YY_BUFFER_STATE state;
+       yyscan_t scanner;
+       struct cdecl *decl;
+       int rc;
+
+       cdecl__init_i18n();
+
+       rc = cdecl__yylex_init_extra(true, &scanner);
+       if (rc != 0)
+               return NULL;
+
+       state = cdecl__yy_scan_string(english, scanner);
+       rc = cdecl__yyparse(scanner, &decl);
+       cdecl__yy_delete_buffer(state, scanner);
+       cdecl__yylex_destroy(scanner);
+
+       if (rc != 0)
+               return NULL;
+
+       for (struct cdecl *i = decl; i; i = i->next) {
+               if (!forall_declarators(i, check_parameters))
+                       goto err;
+               if (!forall_declarators(i, check_rettypes))
+                       goto err;
+               if (!forall_declarators(i, check_arrays))
+                       goto err;
+
+               if (!valid_declspecs(i, true))
+                       goto err;
+       }
+
+       return decl;
+err:
+       cdecl_free(decl);
+       return NULL;
+}