Copied from old documentation. Removed all Gedcom_val details.
[gedcom-parse.git] / gedcom / gedcom_1byte.lex
index a4a5659df39a24977b2a067da5bffea39a304a50..69d6d15a4fccd4c847588063f97eaa49cf26dfbe 100644 (file)
@@ -1,17 +1,29 @@
-/*  This program is free software; you can redistribute it and/or modify  *
- *  it under the terms of the GNU General Public License as published by  *
- *  the Free Software Foundation; either version 2 of the License, or     *
- *  (at your option) any later version.                                   *
+/* Lexer for 1-byte encoding of Gedcom.
+   Copyright (C) 2001 The Genes Development Team
+   This file is part of the Gedcom parser library.
+   Contributed by Peter Verthez <Peter.Verthez@advalvas.be>, 2001.
 
- (C) 2001 by The Genes Development Team
- Original author: Peter Verthez (Peter.Verthez@advalvas.be)
-*/
+   The Gedcom parser library is free software; you can redistribute it
+   and/or modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The Gedcom parser library is distributed in the hope that it will be
+   useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the Gedcom parser library; if not, write to the
+   Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+   02111-1307 USA.  */
 
 /* $Id$ */
 /* $Name$ */
 
 %{
-#undef IN_LEX    /* include only a specific part of the following file */
+#define LEX_SECTION 1  /* include only a specific part of the following file */
+#define yymyinit gedcom_1byte_myinit
 #include "gedcom_lex_common.c"
 
 static size_t encoding_width = 1;
@@ -26,6 +38,7 @@ delim        " "
 tab          [\t]
 hash         #
 literal_at   @@
+normal_at    @
 otherchar    [\x21-\x22\x24-\x2F\x3A-\x3F\x5B-\x5E\x60\x7B-\x7E\x80-\xFE]
 terminator   \x0D|\x0A|\x0D\x0A|\x0A\x0D
 
@@ -36,12 +49,13 @@ alphanum     {alpha}|{digit}
 gen_delim    {delim}|{tab}
 
 escape       @#{any_char}+@
-pointer      @{alphanum}{non_at}+@
+pointer      @{alphanum}{non_at}*@
 
 %%
 
 %{
-#define IN_LEX    /* include only a specific part of the following file */
+#undef LEX_SECTION
+#define LEX_SECTION 2  /* include only a specific part of the following file */
 #include "gedcom_lex_common.c"
 
 ACTION_BEFORE_REGEXPS
@@ -198,13 +212,49 @@ ACTION_BEFORE_REGEXPS
 
 <<EOF>>                   ACTION_EOF
 
+{normal_at}               ACTION_NORMAL_AT
+
+{tab}                     ACTION_TAB
+
 .                         ACTION_UNEXPECTED
 
 %%
+#undef LEX_SECTION
+#define LEX_SECTION 3  /* include only a specific part of the following file */
+#include "gedcom_lex_common.c"
 
-int yywrap()
+int gedcom_check_token(const char* str, ParseState state, int check_token)
 {
-  return 1;
+  int result = 0;
+  int token;
+  YY_BUFFER_STATE buffer;
+
+  yy_delete_buffer(YY_CURRENT_BUFFER);
+  buffer = yy_scan_string(str);
+
+  INIT_LINE_LEN;
+  if (state == STATE_NORMAL)
+    BEGIN(NORMAL);
+  else if (state == STATE_INITIAL)
+    BEGIN(INITIAL);
+  else if (state == STATE_EXPECT_TAG)
+    BEGIN(EXPECT_TAG);
+
+  /* Input is UTF-8 coming from the application, so bypass iconv */
+  dummy_conv = 1;
+  token = yylex();
+  if (token != check_token)
+    result = 1;
+  
+  if (token != 0) {
+    token = yylex();
+    if (token != 0)
+      result = 1;
+  }
+  dummy_conv = 0;
+  
+  yy_delete_buffer(buffer);
+  return result;
 }
 
 #ifdef LEXER_TEST