• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #ifndef _scanner_h
2 #define	_scanner_h
3 
4 #include <stdio.h>
5 #include "tools/re2c/token.h"
6 
7 typedef struct Scanner {
8     FILE		*in;
9     unsigned char	*bot, *tok, *ptr, *cur, *pos, *lim, *top, *eof;
10     unsigned int	tchar, tline, cline;
11 } Scanner;
12 
13 void Scanner_init(Scanner*, FILE *);
14 static Scanner *Scanner_new(FILE *);
15 
16 int Scanner_echo(Scanner*, FILE *);
17 int Scanner_scan(Scanner*);
18 void Scanner_fatal(Scanner*, const char*);
19 static SubStr Scanner_token(Scanner*);
20 static unsigned int Scanner_line(Scanner*);
21 
22 static SubStr
Scanner_token(Scanner * s)23 Scanner_token(Scanner *s)
24 {
25     SubStr r;
26     SubStr_init_u(&r, s->tok, s->cur - s->tok);
27     return r;
28 }
29 
30 static unsigned int
Scanner_line(Scanner * s)31 Scanner_line(Scanner *s)
32 {
33     return s->cline;
34 }
35 
36 static Scanner *
Scanner_new(FILE * i)37 Scanner_new(FILE *i)
38 {
39     Scanner *r = malloc(sizeof(Scanner));
40     Scanner_init(r, i);
41     return r;
42 }
43 
44 #endif
45