-
Notifications
You must be signed in to change notification settings - Fork 173
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
184 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
#include "utils.hpp" | ||
#include "ATestTraits.hpp" | ||
#include "a006Lexer.hpp" | ||
#include "a006Parser.hpp" | ||
|
||
#include <iostream> | ||
#include <sstream> | ||
#include <fstream> | ||
|
||
using namespace Antlr3Test; | ||
using namespace std; | ||
|
||
void test1(const char* input); | ||
void test2(const char* input); | ||
void test3(const char* input); | ||
|
||
int | ||
main (int argc, char *argv[]) | ||
{ | ||
test1("ABC"); | ||
test1("(ABC)"); | ||
test1("ABC AS 5"); | ||
test1("ABC AS(1,2,3,4,5,6)"); | ||
test1("(ABC,ABD,ABE,ABF)AS(1,2,3,4,5,6)"); | ||
|
||
test2("ABC"); | ||
test2("(ABC)"); | ||
test2("ABC AS 5"); | ||
test2("ABC AS(1,2,3,4,5,6)"); | ||
test2("(ABC,ABD,ABE,ABF)AS(1,2,3,4,5,6)"); | ||
|
||
test3("SAMPLE (4)"); | ||
test3("SAMPLE BLOCK(4,5)"); | ||
|
||
printf("finished parsing OK\n"); // Finnish parking is pretty good - I think it is all the snow | ||
|
||
return 0; | ||
} | ||
|
||
void test1(const char* input) | ||
{ | ||
a006LexerTraits::InputStreamType* istream = new a006LexerTraits::InputStreamType((const ANTLR_UINT8 *)input | ||
, ANTLR_ENC_8BIT | ||
, strlen(input) | ||
, (ANTLR_UINT8*)"test1"); | ||
istream->setUcaseLA(true); | ||
|
||
a006Lexer* lxr = new a006Lexer(istream); | ||
a006LexerTraits::TokenStreamType* tstream = new a006LexerTraits::TokenStreamType(ANTLR_SIZE_HINT, lxr->get_tokSource()); | ||
a006Parser* psr = new a006Parser(tstream); | ||
{ | ||
auto r1 = psr->test1(); | ||
std::cout << r1.tree->toStringTree() << std::endl; | ||
} | ||
|
||
delete psr; | ||
delete tstream; | ||
delete lxr; | ||
delete istream; | ||
} | ||
|
||
void test2(const char* input) | ||
{ | ||
a006LexerTraits::InputStreamType* istream = new a006LexerTraits::InputStreamType((const ANTLR_UINT8 *)input | ||
, ANTLR_ENC_8BIT | ||
, strlen(input) | ||
, (ANTLR_UINT8*)"test2"); | ||
istream->setUcaseLA(true); | ||
|
||
a006Lexer* lxr = new a006Lexer(istream); | ||
a006LexerTraits::TokenStreamType* tstream = new a006LexerTraits::TokenStreamType(ANTLR_SIZE_HINT, lxr->get_tokSource()); | ||
a006Parser* psr = new a006Parser(tstream); | ||
{ | ||
auto r1 = psr->test2(); | ||
std::cout << r1.tree->toStringTree() << std::endl; | ||
} | ||
|
||
delete psr; | ||
delete tstream; | ||
delete lxr; | ||
delete istream; | ||
} | ||
|
||
void test3(const char* input) | ||
{ | ||
a006LexerTraits::InputStreamType* istream = new a006LexerTraits::InputStreamType((const ANTLR_UINT8 *)input | ||
, ANTLR_ENC_8BIT | ||
, strlen(input) | ||
, (ANTLR_UINT8*)"test3"); | ||
istream->setUcaseLA(true); | ||
|
||
a006Lexer* lxr = new a006Lexer(istream); | ||
a006LexerTraits::TokenStreamType* tstream = new a006LexerTraits::TokenStreamType(ANTLR_SIZE_HINT, lxr->get_tokSource()); | ||
a006Parser* psr = new a006Parser(tstream); | ||
{ | ||
auto r1 = psr->test3(); | ||
std::cout << r1.tree->toStringTree() << std::endl; | ||
} | ||
|
||
delete psr; | ||
delete tstream; | ||
delete lxr; | ||
delete istream; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
grammar a006; | ||
|
||
options { | ||
language=Cpp; | ||
output=AST; | ||
} | ||
|
||
tokens { | ||
T_A = 'token A'; | ||
P_R = 'token pivot root'; | ||
S_R = 'token sample root'; | ||
E_R = 'token expression root'; | ||
} | ||
|
||
@lexer::includes | ||
{ | ||
#include "ATestTraits.hpp" | ||
} | ||
@lexer::namespace | ||
{ Antlr3Test } | ||
|
||
@parser::includes { | ||
#include "ATestTraits.hpp" | ||
#include "a006Lexer.hpp" | ||
} | ||
@parser::namespace | ||
{ Antlr3Test } | ||
|
||
test1 // see unpivot_in_elements | ||
: ( column_name | ||
| '(' column_name (',' column_name)* ')' | ||
) | ||
( 'AS' | ||
( constant | ||
| ('(')=> '(' constant (',' constant)* ')' | ||
) | ||
)? | ||
-> column_name+ ^(P_R constant*) | ||
; | ||
|
||
test2 // see unpivot_in_elements | ||
: ( column_name | ||
| '(' column_name (',' column_name)* ')' | ||
) | ||
( 'AS' | ||
( constant | ||
| ('(')=> '(' constant (',' constant)* ')' | ||
) | ||
)? | ||
-> column_name+ ^(P_R constant)* | ||
; | ||
|
||
|
||
test3 //sample_clause | ||
: s='SAMPLE' 'BLOCK'? | ||
'(' c1=constant (',' c2=constant)? ')' | ||
-> ^(S_R[$s] 'BLOCK'? ^(E_R $c1) ^(E_R $c2)?) | ||
; | ||
|
||
column_name | ||
: T_COLUMN_NAME; | ||
|
||
constant | ||
: T_CONSTANT; | ||
|
||
T_COLUMN_NAME | ||
: ('A'..'Z')+; | ||
|
||
T_CONSTANT | ||
: ('0'..'9')+; | ||
|
||
WS | ||
: ' '+ { $channel = HIDDEN; }; |