2016-04-08 6 views
0

私は、次のソースを解析したいと思います:Instaparseでオプションの部品を扱うにはどうすればいいですか?

​​

問題は用途のリストがつくれなくなければならないことを、です。私は[用途]への使用を変更しようとしましたが、たとえ存在していたとしても、それは私にemtpyの使用リストを与えるでしょう。

ところで:

[:S 
[:unit-decl "unit" [:identifier "SystemGeneralAR"]] 
[:interface 
    [:uses 
    [:uses_list 
    [:uses_element [:identifier "AbstractRecord"]] 
    [:uses_element [:identifier "OracleData"]] 
    [:uses_element [:identifier "systemgeneral_auto_gen"]]]]] 
[:implementation 
    [:impl_body [:uses [:uses_list [:uses_element [:identifier "testa"]] [:uses_element [:identifier "testb"]]]]]]] 
:ちょうどそれがどのように見える使用して

[:S [:unit-decl "unit" [:identifier "SystemGeneralAR"]] [:interface] 
[:implementation [:impl_body]]] 

S = unit-decl interface<any>*implementation<any>*<'.'> 

unit-decl = 'unit'<space>*identifier<space>*<';'> 
unit-name = identifier 

interface = <interface_dec> uses 
interface_dec = <space>*'interface'<space>* 

implementation = <'implementation'>impl_body 
impl_body = uses 

uses = <space>*<'uses'><space>*uses_list 
uses_list = (uses_element<','>)*(uses_element<';'>) 
uses_element = <space>*identifier<space>* 

identifier = #'[A-Za-z|_]+' 
space = #' ' 
any = #'[A-Za-z|_| |,|;|=|(|)|:]' 

結果の解析ツリー、用途*はこのようになりますと:私の文法は次のようになります

+0

ユーザが0以上のカーディナリティを持つようにする(例: 'uses *') –

+0

usesを使用するように変更した場合、ソルーズコードに1があってもuses_listは空です* – rogergl

+0

あなたの質問には、 ? –

答えて

0

ロジャー

有効な、テスト済みのユースケース文法です。私はあなたが持っているものを使ってみましたが、それは失敗しており、完全には見えません。これは二つの例条件が存在する場合は、オプションの外観を実証するため、次のとおりです。

;input 1 = "a b" 
;produces 

=> [:S [:A "a"] [:B "b"]] 

input 2 = "a b c" 
;produces 

=> [:S [:A "a"] [:B "b"] [:optC [:C "c"]]] 

あなたの文法で:ここで

S = A <space> B [<space> optC] 

A = "a" 

B = "b" 

C = "c" 

optC = C 

space = #' ' 

すると、2つの出力があります。私が言ったように、それは完全に定義されて表示されますが、一般的に言っていないとして、私は問題を抱えた:

(* If you change this *) 

interface = <interface_dec> uses 

(* to this, you should get similar results *) 

interface = <interface_dec> [uses] 

問題が解決しない場合は、あなたのように与えられた入力サンプルで動作する文法を提供する必要があります彼らは同期していないようです。

+0

ありがとう、私は今問題の文法を理解しようとしています。端末記号と非終端記号の配置。 – rogergl

関連する問題