50 lines
1 KiB
C++
50 lines
1 KiB
C++
#include <string>
|
|||
|
|||
#include <stdio.h>
|
|||
|
|||
#include <misc.h>
|
|||
#include <slog.h>
|
|||
#include <YMisc.h>
|
|||
|
|||
// TODO: this should be included from grammartest.tab.h automatically
|
|||
#include "include/grammartest.h"
|
|||
|
|||
#include "include/defs.h"
|
|||
#include "include/grammartest.tab.h"
|
|||
|
|||
|
grammar.py and friends: Implement config file support
Signed-off-by: Jan Lindemann <jan@janware.com>
|
extern int FB_SYM(debug);
|
||
|
|||
using namespace std;
|
|||
|
|||
int main(int argc, const char *argv[])
|
|||
{
|
|||
if (argc < 2) {
|
|||
fprintf(stderr, "usage: %s input-file\n", filenotdir(argv[0]));
|
|||
return 1;
|
|||
}
|
|||
|
|||
const char *path = argv[1];
|
|||
string content;
|
|||
if (YMisc::suck_in_file(path, content)<0) {
|
|||
slog(PRI_ERR, "failed to read [%s] (%s)", path, err());
|
|||
return 1;
|
|||
}
|
|||
|
|||
|
grammar.py and friends: Implement config file support
Signed-off-by: Jan Lindemann <jan@janware.com>
|
// TODO: Initialize this in a generated function
|
||
struct context context = {
|
|||
|
grammar.py and friends: Implement config file support
Signed-off-by: Jan Lindemann <jan@janware.com>
|
line: 1,
|
||
column: 0
|
|||
};
|
|||
|
|||
|
grammar.py and friends: Implement config file support
Signed-off-by: Jan Lindemann <jan@janware.com>
|
FB_SYM(debug) = 1;
|
||
|
|||
struct vp_scanner *scanner = FB_SYM(init_scanner)(content.c_str());
|
|||
int status = FB_SYM(parse)(&context, FB_SYM(scanner_get_data)(scanner));
|
|||
FB_SYM(cleanup_scanner)(scanner);
|
|||
if (status) {
|
|||
slog(PRI_ERR, "failed to parse [%s] (%s)", path, err());
|
|||
return -1;
|
|||
}
|
|||
|
|||
return 0;
|
|||
}
|