File: rawy.y

package info (click to toggle)
squizz 0.99d%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 6,772 kB
  • sloc: sh: 4,799; ansic: 2,640; lex: 1,992; yacc: 1,650; makefile: 123
file content (85 lines) | stat: -rw-r--r-- 1,412 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/* rawy.y - RAW sequence parser */

%{
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif

#include <stdlib.h>

#include "sequence.h"
#include "sequence/parse.h"
#include "sequence/rawy.h"

void rawset_in(FILE *);
int rawlex(YYSTYPE *);
int rawlex_destroy(void);

static void yyerror(sequence_t *seq, const char *);

int rawy_check(FILE *);
sequence_t *rawy_parse(FILE *);
%}

%expect 0
%pure-parser
%parse-param { sequence_t *seq }

%union { char *str; }
%destructor { free($$); } <str>

%token ERR NUL
%token <str> BAS

%%

raw : sequence end                     { return 0;  /*NOTREACHED*/ }
    | NUL                              { return -1; /*NOTREACHED*/ }
    ;

sequence : sequence BAS                              { parse_stradd(seq, $2); }
         | BAS                                       { parse_stradd(seq, $1); }
         ;

end : NUL ;

%%


/* Checks RAW sequence */
int rawy_check(FILE *f) {
  int i;

  rawset_in(f);

  i = yyparse(NULL);
  if (i == 0) { return i; }

  rawlex_destroy();

  return i; }


/* Parse RAW sequence */
sequence_t *rawy_parse(FILE *f) {
  int i;
  sequence_t *seq;

  seq = sequence_new();
  if (seq == NULL) { return (seq); }
  rawset_in(f);

  i = yyparse((void *)seq);
  if (i == 0) {
    return seq; }

  rawlex_destroy();
  sequence_free(seq);

  return NULL; }


/* Helpers ... */

/*ARGSUSED*/
static void yyerror(sequence_t *seq, const char *s) { return; }