/* $Name$ */
%{
-#include "gedcom.tab.h"
-#include "gedcom.h"
-#include "multilex.h"
-#include "encoding.h"
-
-#define YY_NO_UNPUT
+#undef IN_LEX /* include only a specific part of the following file */
+#include "gedcom_lex_common.c"
%}
%s NORMAL
escape @#{any_char}+@
pointer @{alphanum}{non_at}+@
-%{
-static int current_level=-1;
-static int level_diff=MAXGEDCLEVEL;
-
-#ifdef LEXER_TEST
-YYSTYPE gedcom_lval;
-int line_no = 1;
-#endif
-
-%}
-
%%
%{
+#define IN_LEX /* include only a specific part of the following file */
#include "gedcom_lex_common.c"
ACTION_BEFORE_REGEXPS
}
#ifdef LEXER_TEST
+int gedcom_lex()
+{
+ return gedcom_1byte_lex();
+}
+
int main()
{
- int tok, res;
- init_encodings();
- set_encoding_width(ONE_BYTE);
- res = open_conv_to_internal("ASCII");
- if (!res) {
- gedcom_error("Unable to open conversion context: %s",
- strerror(errno));
- return 1;
- }
- tok = gedcom_1byte_lex();
- while (tok) {
- switch(tok) {
- case BADTOKEN: printf("BADTOKEN "); break;
- case OPEN: printf("OPEN(%d) ", gedcom_lval.level); break;
- case CLOSE: printf("CLOSE "); break;
- case ESCAPE: printf("ESCAPE(%s) ", gedcom_lval.string); break;
- case DELIM: printf("DELIM "); break;
- case ANYCHAR: printf("%s ", gedcom_lval.string); break;
- case POINTER: printf("POINTER(%s) ", gedcom_lval.pointer); break;
- case USERTAG: printf("USERTAG(%s) ", gedcom_lval.tag); break;
- default: printf("TAG(%s) ", gedcom_lval.tag); break;
- }
- tok = gedcom_1byte_lex();
- }
- printf("\n");
- close_conv_to_internal();
- return 0;
+ return test_loop(ONE_BYTE, "ASCII");
}
#endif
/* i.e. this is utf-16-be */
%{
-#include "gedcom.tab.h"
-#include "gedcom.h"
-#include "multilex.h"
-#include "encoding.h"
-
-#define YY_NO_UNPUT
+#undef IN_LEX /* include only a specific part of the following file */
+#include "gedcom_lex_common.c"
%}
%s NORMAL
escape \x00@\x00#{any_char}+\x00@
pointer \x00@{alphanum}{non_at}+\x00@
-%{
-static int current_level=-1;
-static int level_diff=MAXGEDCLEVEL;
-
-#ifdef LEXER_TEST
-YYSTYPE gedcom_lval;
-int line_no = 1;
-#endif
-%}
-
%%
%{
+#define IN_LEX /* include only a specific part of the following file */
#include "gedcom_lex_common.c"
ACTION_BEFORE_REGEXPS
}
#ifdef LEXER_TEST
+int gedcom_lex()
+{
+ return gedcom_hilo_lex();
+}
int main()
{
- int tok, res;
- init_encodings();
- set_encoding_width(TWO_BYTE_HILO);
- res = open_conv_to_internal("UNICODE");
- if (!res) {
- gedcom_error("Unable to open conversion context: %s",
- strerror(errno));
- return 1;
- }
- tok = gedcom_hilo_lex();
- while (tok) {
- switch(tok) {
- case BADTOKEN: printf("BADTOKEN "); break;
- case OPEN: printf("OPEN(%d) ", gedcom_lval.level); break;
- case CLOSE: printf("CLOSE "); break;
- case ESCAPE: printf("ESCAPE(%s) ", gedcom_lval.string); break;
- case DELIM: printf("DELIM "); break;
- case ANYCHAR: printf("%s ", gedcom_lval.string); break;
- case POINTER: printf("POINTER(%s) ", gedcom_lval.pointer); break;
- case USERTAG: printf("USERTAG(%s) ", gedcom_lval.tag); break;
- default: printf("TAG(%s) ", gedcom_lval.tag); break;
- }
- tok = gedcom_hilo_lex();
- }
- printf("\n");
- close_conv_to_internal();
- return 0;
+ return test_loop(TWO_BYTE_HILO, "UNICODE");
}
#endif
/* $Id$ */
/* $Name$ */
+#ifndef IN_LEX
+
+#include "gedcom.tab.h"
+#include "gedcom.h"
+#include "multilex.h"
+#include "encoding.h"
+
+#define YY_NO_UNPUT
+
+static int current_level=-1;
+static int level_diff=MAXGEDCLEVEL;
+
+#ifdef LEXER_TEST
+YYSTYPE gedcom_lval;
+int line_no = 1;
+
+int gedcom_lex();
+
+int test_loop(ENCODING enc, char* code)
+{
+ int tok, res;
+ init_encodings();
+ set_encoding_width(enc);
+ res = open_conv_to_internal(code);
+ if (!res) {
+ gedcom_error("Unable to open conversion context: %s",
+ strerror(errno));
+ return 1;
+ }
+ tok = gedcom_lex();
+ while (tok) {
+ switch(tok) {
+ case BADTOKEN: printf("BADTOKEN "); break;
+ case OPEN: printf("OPEN(%d) ", gedcom_lval.level); break;
+ case CLOSE: printf("CLOSE "); break;
+ case ESCAPE: printf("ESCAPE(%s) ", gedcom_lval.string); break;
+ case DELIM: printf("DELIM "); break;
+ case ANYCHAR: printf("%s ", gedcom_lval.string); break;
+ case POINTER: printf("POINTER(%s) ", gedcom_lval.pointer); break;
+ case USERTAG: printf("USERTAG(%s) ", gedcom_lval.tag); break;
+ default: printf("TAG(%s) ", gedcom_lval.tag); break;
+ }
+ tok = gedcom_lex();
+ }
+ printf("\n");
+ close_conv_to_internal();
+ return 0;
+}
+
+#endif /* of #ifdef LEXER_TEST */
+
+#else /* of #ifndef IN_LEX */
+
char string_buf[MAXGEDCLINELEN+1];
#define TO_INTERNAL(str) to_internal(str, yyleng)
-#define MKTAGACTION(the_tag) \
- { gedcom_lval.tag = TO_INTERNAL(yytext); \
- BEGIN(NORMAL); \
- return TAG_##the_tag; }
+#define MKTAGACTION(the_tag) \
+ { gedcom_lval.tag = TO_INTERNAL(yytext); \
+ BEGIN(NORMAL); \
+ return TAG_##the_tag; \
+ }
/* The GEDCOM level number is converted into a sequence of opening
yytext, yytext[0]); \
return BADTOKEN; \
}
+
+#endif /* IN_LEX */
/* i.e. this is utf-16-le */
%{
-#include "gedcom.tab.h"
-#include "gedcom.h"
-#include "multilex.h"
-#include "encoding.h"
-
-#define YY_NO_UNPUT
+#undef IN_LEX /* include only a specific part of the following file */
+#include "gedcom_lex_common.c"
%}
%s NORMAL
escape @\x00#\x00{any_char}+@\x00
pointer @\x00{alphanum}{non_at}+@\x00
-%{
-static int current_level=-1;
-static int level_diff=MAXGEDCLEVEL;
-
-#ifdef LEXER_TEST
-YYSTYPE gedcom_lval;
-int line_no = 1;
-#endif
-%}
-
%%
%{
+#define IN_LEX /* include only a specific part of the following file */
#include "gedcom_lex_common.c"
ACTION_BEFORE_REGEXPS
}
#ifdef LEXER_TEST
+int gedcom_lex()
+{
+ return gedcom_lohi_lex();
+}
int main()
{
- int tok, res;
- init_encodings();
- set_encoding_width(TWO_BYTE_LOHI);
- res = open_conv_to_internal("UNICODE");
- if (!res) {
- gedcom_error("Unable to open conversion context: %s",
- strerror(errno));
- return 1;
- }
- tok = gedcom_lohi_lex();
- while (tok) {
- switch(tok) {
- case BADTOKEN: printf("BADTOKEN "); break;
- case OPEN: printf("OPEN(%d) ", gedcom_lval.level); break;
- case CLOSE: printf("CLOSE "); break;
- case ESCAPE: printf("ESCAPE(%s) ", gedcom_lval.string); break;
- case DELIM: printf("DELIM "); break;
- case ANYCHAR: printf("%s ", gedcom_lval.string); break;
- case POINTER: printf("POINTER(%s) ", gedcom_lval.pointer); break;
- case USERTAG: printf("USERTAG(%s) ", gedcom_lval.tag); break;
- default: printf("TAG(%s) ", gedcom_lval.tag); break;
- }
- tok = gedcom_lohi_lex();
- }
- printf("\n");
- close_conv_to_internal();
- return 0;
+ return test_loop(TWO_BYTE_LOHI, "UNICODE");
}
#endif