wasteScanner.h
Go to the documentation of this file.
1 /* -*- Mode: C++; coding: utf-8; c-basic-offset: 2; -*- */
2 /*
3  libmoot : moot part-of-speech tagging library
4  Copyright (C) 2013-2017 by Bryan Jurish <moocow@cpan.org> and Kay-Michael Würzner
5 
6  This library is free software; you can redistribute it and/or
7  modify it under the terms of the GNU Lesser General Public
8  License as published by the Free Software Foundation; either
9  version 3 of the License, or (at your option) any later version.
10 
11  This library is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  Lesser General Public License for more details.
15 
16  You should have received a copy of the GNU Lesser General Public
17  License along with this library; if not, write to the Free Software
18  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20 
35 #ifndef _WASTE_SCANNER_H
36 #define _WASTE_SCANNER_H
37 
38 #include <mootTokenIO.h> //-- includes TokenLexer -> GenericLexer -> BufferIO -> Utils -> CIO -> IO
39 
40 namespace moot
41 {
42 
43  /*============================================================================
44  * wasteScanner
45  */
49  class wasteScanner : public GenericLexer
50  {
51  public:
52  /*--------------------------------------------------------------------
53  * mootWasteScanner: Data
54  */
55  /*------------------------------------------------------------*/
58  char* yybuffer;
59  char* yycursor;
60  char* yylimit;
61  char* yytoken;
62  char* yymarker;
63  size_t buffer_size;
65 
66  /*--------------------------------------------------------------------
67  * mootWasteScanner: Methods
68  */
69  /*------------------------------------------------------------*/
73  wasteScanner(const std::string &myname="wasteScanner",
74  size_t line=0,
75  size_t column=0,
76  mootio::ByteOffset byte=0,
77  size_t init_bufsize=GenericLexer::MGL_DEFAULT_BUFFER_SIZE
78  );
79 
81  virtual ~wasteScanner();
83 
84  /*------------------------------------------------------------*/
87 
89  virtual void *mgl_yy_create_buffer(int size, FILE *unused=stdin)
90  {
91  yycarp("API method mgl_yy_create_buffer() not implemented in wasteScanner!");
92  abort();
93  };
94 
96  virtual void mgl_yy_switch_to_buffer(void *buf)
97  {
98  yycarp("API method mgl_yy_switch_to_buffer() not implemented in wasteScanner!");
99  abort();
100  };
101 
103  virtual void mgl_yy_init_buffer(void *buf, FILE *unused=stdin)
104  {
105  yycarp("API method mgl_yy_init_buffer() not implemented in wasteScanner!");
106  abort();
107  };
109 
110  /*------------------------------------------------------------*/
113 
115  int yylex ();
116 
118  inline std::string yytext ()
119  {
120  return std::string ( yytoken, yytoken + yyleng () );
121  }
124  inline int yyleng ()
125  {
126  return ( yycursor - yytoken );
127  }
130  bool fill ( size_t n );
131 
133  virtual void reset ();
134 
136  virtual void from_mstream (mootio::mistream *in);
138  };
139 
140  /*============================================================================
141  * wasteTokenScanner
142  */
144  class wasteTokenScanner : public TokenReader {
145  public:
146  /*----------------------------------------
147  * TokenScanner: Data
148  */
150  wasteScanner scanner;
151 
153  mootToken wts_token;
156  mootSentence wts_sentence;
158  public:
159  //------------------------------------------------------------
169  wasteTokenScanner(int fmt =tiofText,
170  const std::string &name ="wasteTokenScanner");
171 
173  virtual ~wasteTokenScanner(void);
175 
176  /*------------------------------------------------------------
177  * TokenReader: Input Selection
178  */
181 
183  virtual void from_mstream(mootio::mistream *mistreamp);
184 
189  virtual void close(void);
191 
192  /*------------------------------------------------------------
193  * TokenReader: Token-Level Access
194  */
201  virtual mootTokenType get_token(void);
202 
208  virtual mootTokenType get_sentence(void);
210 
211  /*------------------------------------------------------------
212  * TokenReader: Diagnostics
213  */
216 
218  virtual size_t line_number(void) { return scanner.theLine; };
219 
221  virtual size_t line_number(size_t n) { return scanner.theLine = n; };
224  virtual size_t column_number(void) { return scanner.theColumn; };
227  virtual size_t column_number(size_t n) { return scanner.theColumn = n; };
230  virtual mootio::ByteOffset byte_number(void) { return scanner.theByte; };
233  virtual mootio::ByteOffset byte_number(size_t n) { return scanner.theByte = n; };
235  };
236 
238 } // namespace moot
239 
240 
241 #endif /* _WASTE_SCANNER_H */
Definition: mootAssocVector.h:39
size_t theColumn
Definition: mootGenericLexer.h:103
std::string yytext()
Definition: wasteScanner.h:122
Abstract base class for Flex++ lexers.
Definition: mootGenericLexer.h:77
virtual void * mgl_yy_create_buffer(int size, FILE *unused=stdin)
Definition: wasteScanner.h:89
char * yycursor
Definition: wasteScanner.h:59
wasteScanner(const std::string &myname="wasteScanner", size_t line=0, size_t column=0, mootio::ByteOffset byte=0, size_t init_bufsize=GenericLexer::MGL_DEFAULT_BUFFER_SIZE)
int yyleng()
Definition: wasteScanner.h:128
Abstract class for token input.
Definition: mootTokenIO.h:208
High-level token information object.
Definition: mootToken.h:96
literal token text included
Definition: mootTokenIO.h:57
virtual void yycarp(const char *fmt,...)
char * yybuffer
Definition: wasteScanner.h:58
char * yytoken
Definition: wasteScanner.h:61
moot::OffsetT ByteOffset
typedef for (byte) offsets (may be unsigned)
Definition: mootIO.h:55
char * yylimit
Definition: wasteScanner.h:60
Low-level class for raw text scanning.
Definition: wasteScanner.h:49
list< mootToken > mootSentence
Definition: mootToken.h:630
virtual void from_mstream(mootio::mistream *in)
mootTokenTypeE
Definition: mootToken.h:71
Abstract and native classes for I/O of moot::mootToken objects.
Raw text scanner class returning mootToken; wraps wasteScanner.
Definition: wasteScanner.h:148
char * yymarker
Definition: wasteScanner.h:62
virtual void mgl_yy_init_buffer(void *buf, FILE *unused=stdin)
Definition: wasteScanner.h:105
virtual ~wasteScanner()
size_t theLine
Definition: mootGenericLexer.h:102
bool fill(size_t n)
mootio::ByteOffset theByte
Definition: mootGenericLexer.h:104
size_t buffer_size
Definition: wasteScanner.h:63
virtual void mgl_yy_switch_to_buffer(void *buf)
Definition: wasteScanner.h:98
Abstract base class for input stream wrappers.
Definition: mootIO.h:129
static const int MGL_DEFAULT_BUFFER_SIZE
Definition: mootGenericLexer.h:83
virtual void reset()