• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #include "UserTestTraits.hpp"
2 #include "t001lexer.hpp"
3 
4 #include <sys/types.h>
5 
6 #include <iostream>
7 #include <sstream>
8 #include <fstream>
9 
10 using namespace Antlr3Test;
11 using namespace std;
12 
13 int testValid(string const& data);
14 int testIteratorInterface(string const& data);
15 int testMalformedInput(string const& data);
16 
17 static    t001lexer*		    lxr;
18 
main(int argc,char * argv[])19 int main (int argc, char *argv[])
20 {
21 	testValid("0");
22 	testIteratorInterface("0");
23 	testMalformedInput("1");
24 	return 0;
25 }
26 
testValid(string const & data)27 int testValid(string const& data)
28 {
29 	t001lexerTraits::InputStreamType* input	= new t001lexerTraits::InputStreamType((const ANTLR_UINT8 *)data.c_str(),
30 										       ANTLR_ENC_8BIT,
31 										       data.length(), //strlen(data.c_str()),
32 										       (ANTLR_UINT8*)"t001");
33 	if (lxr == NULL)
34 		lxr = new t001lexer(input);
35 	else
36 		lxr->setCharStream(input);
37 
38 	std::cout << "testValid: \"" << data << '"' <<std::endl;
39 
40 	t001lexerTraits::CommonTokenType *token0 = lxr->nextToken();
41 	t001lexerTraits::CommonTokenType *token1 = lxr->nextToken();
42 
43 	std::cout << token0->getText() << std::endl;
44 	std::cout << token1->getText() << std::endl;
45 
46 	delete lxr; lxr = NULL;
47 	delete input;
48 	return 0;
49 }
50 
testIteratorInterface(string const & data)51 int testIteratorInterface(string const& data)
52 {
53 	t001lexerTraits::InputStreamType* input	= new t001lexerTraits::InputStreamType((const ANTLR_UINT8 *)data.c_str(),
54 										       ANTLR_ENC_8BIT,
55 										       data.length(), //strlen(data.c_str()),
56 										       (ANTLR_UINT8*)"t001");
57 	if (lxr == NULL)
58 		lxr = new t001lexer(input);
59 	else
60 		lxr->setCharStream(input);
61 
62 	std::cout << "testIteratorInterface: \"" << data << '"' <<std::endl;
63 
64 	t001lexerTraits::TokenStreamType *tstream = new t001lexerTraits::TokenStreamType(ANTLR_SIZE_HINT, lxr->get_tokSource());
65 	t001lexerTraits::CommonTokenType const *token0 = tstream->_LT(1);
66 	t001lexerTraits::CommonTokenType const *token1 = tstream->_LT(2);
67 
68 	std::cout << token0->getText() << std::endl;
69 	std::cout << token1->getText() << std::endl;
70 
71 	delete tstream;
72 	delete lxr; lxr = NULL;
73 	delete input;
74 	return 0;
75 }
76 
testMalformedInput(string const & data)77 int testMalformedInput(string const& data)
78 {
79 	t001lexerTraits::InputStreamType* input	= new t001lexerTraits::InputStreamType((const ANTLR_UINT8 *)data.c_str(),
80 										       ANTLR_ENC_8BIT,
81 										       data.length(), //strlen(data.c_str()),
82 										       (ANTLR_UINT8*)"t001");
83 	if (lxr == NULL)
84 		lxr = new t001lexer(input);
85 	else
86 		lxr->setCharStream(input);
87 
88 	std::cout << "testMalformedInput: \"" << data << '"' <<std::endl;
89 
90 	t001lexerTraits::CommonTokenType *token0 = lxr->nextToken();
91 	std::cout << token0->getText() << std::endl;
92 
93 	delete lxr; lxr = NULL;
94 	delete input;
95 	return 0;
96 }
97