我只是用ANTLR開始,試圖解析一些模式出來一個日誌文件使用ANTLR來分析日誌文件
例如:日誌文件:
7114422 2009-07- 16 15:43:07078 [LOGTHREAD] INFO StatusLog - 任務0 輸入: uk.project.Evaluation.Input.Function1(選擇= [ 「紅色」, 「黃色」]){}
7114437 2009- 07-16 15:43:07,093 [LOGTHREAD]信息狀態日誌 - 任務0 輸出: uk.org.project.Evaluation.Output.Function2(選擇= [ 「火箭」]){}
7114422 2009-07-16 15:43:07078 [LOGTHREAD] INFO StatusLog - 任務0 輸入: uk.project.Evaluation.Input.Function3(選擇= [ 「藍色」, 「黃色」]){}
7114437 2009-07-16 15:43:07093 [LOGTHREAD] INFO StatusLog - 任務0 輸出: uk.org.project.Evaluation.Output.Function4(選擇= [ 「語音」]){}
現在我必須解析這個文件才能找到'Evaluation.Input.Function1',它的值是'red'和'yellow'以及'Evaluation.Output.Function2'和'Rocket'的值,並忽略其他所有內容, 2下面的輸入輸出功能3,4。有許多這樣的輸入和輸出功能,我必須找到這樣的輸入/輸出功能集。這是我嘗試過的語法,它不起作用。任何幫助,將不勝感激。是我在寫作的語法和ANTLR的第一次嘗試它變得相當艱鉅現在..
grammar test;
tag : inputtag+ outputtag+ ;
//Input tag consists of atleast one inputfunction with one or more values
inputtag: INPUTFUNCTIONS INPUTVALUES+;
//output tag consists of atleast one ontput function with one or more output values
outputtag : OUTPUTFUNCTIONS OUTPUTVALUES+;
INPUTFUNCTIONS
: INFUNCTION1 | INFUNCTION2;
OUTPUTFUNCTIONS
:OUTFUNCTION1 | OUTFUNCTION2;
// Possible input functions in the log file
fragment INFUNCTION1
:'Evaluation.Input.Function1';
fragment INFUNCTION2
:'Evaluation.Input.Function3';
//Possible values in the input functions
INPUTVALUES
: 'red' | 'yellow' | 'blue';
// Possible output functions in the log file
fragment OUTFUNCTION1
:'Evaluation.Output.Function2';
fragment OUTFUNCTION2
:'Evaluation.Output.Function4';
//Possible ouput values in the output functions
fragment OUTPUTVALUES
: 'Rocket' | 'Speech';
很好的例子,但犯規作品=/ –
@arkilus,如果「它」不起作用,那麼它就不是一個好例子,我會假設......但它確實有效。事實上,它不適用於你是一個完全不同的故事:) –
對不起巴特,你的例子實際上完美的作品,問題是與我的構建路徑...順便謝謝你的美妙的幫助與ANTLR在所以:) –