LIMA
Libre Multilingual Analyzer — C++ API
Loading...
Searching...
No Matches
LimaTokenizerParser.cpp
Go to the documentation of this file.
1// Copyright 2002-2013 CEA LIST
2// SPDX-FileCopyrightText: 2022 CEA LIST <gael.de-chalendar@cea.fr>
3//
4// SPDX-License-Identifier: MIT
5
7
8#include <iostream>
9#include <fstream>
10
11void readStream(std::istream &is,std::string &dest)
12{
13 while (is.good() && !is.eof())
14 {
15 const int bufferSize = 10240;
16 char buffer[bufferSize];
17 is.read(buffer,bufferSize);
18 const int size = is.gcount();
19 if (size>0)
20 dest.insert(dest.end(),buffer,buffer+size);
21 }
22}
23
24int main(int argc, char* argv[])
25{
26 if (argc != 2)
27 {
28 std::cerr << "Needs exactly one argument" << std::endl;
29 return 1;
30 }
31 namespace qi = boost::spirit::qi;
32 namespace ascii = boost::spirit::ascii;
33 using ascii::space;
34 typedef std::string::const_iterator iterator_type;
36
37 // @ERROR DOES NOT WORK ON WINDOWS PORT
38 tokenizer tokenizer_parser;
39 std::string str;
40 std::ifstream file(argv[1], std::ifstream::binary);
41 readStream(file, str);
42
43 std::string::const_iterator iter = str.begin();
44 std::string::const_iterator end = str.end();
45
46 tokenizer_automaton automaton;
47 bool r = false;
48 // @ERROR DOES NOT WORK ON WINDOWS PORT
49 r = phrase_parse(iter, end, tokenizer_parser, skipper, automaton);
50
51 if (r && iter == end)
52 {
53 std::cout << "Parsing succeeded: "<<automaton.size()<<" states" << std::endl;
54 }
55 else
56 {
57 std::string rest(iter, end);
58 std::cout << "Parsing failed. Stopped at: \": " << rest << "\"\n";
59 }
60
61 return 0;
62}
int main(int argc, char *argv[])
void readStream(std::istream &is, std::string &dest)
#define skipper
std::vector< tokenizer_state > tokenizer_automaton