I'm trying to write a parser with ANTLR4 that should parse a very simple model file from hyperledger:
asset Car identified by id {
o String id
o String model
--> Owner owner
}
participant Owner identified by id {
o String id
o String name
}
transaction Auction {
--> Car asset
o String newValue
}
I'm having a problem within the transaction: I can't give the variable of type Car the name 'asset', which is valid in the language specification. The ANTLR parser doesn't expect that. I get an exception similar like that: mismatched input 'o' expecting {'[', IDENTIFIER}
I know the cause is the assetDeclaration in my grammar, which detects the asset keyword in the transaction as well.
Is there a way to ignore the asset within the transaction? Or can I make the declaration more specific, so that it is triggered when the asset is at the start and followed by letters?
This is my asset declaration:
assetDeclaration: ASSET IDENTIFIER
(EXTENDS typeType)?
IDENTIFIED
IDENTIFIER
classBody;
And my transaction declaration:
transactionDeclaration: TRANSACTION IDENTIFIER
classBody
;
Asset, Transaction and so on defined as:
ASSET: 'asset';
TRANSACTION: 'transaction';
IDENTIFIED: 'identified by';
PARTICIPANT: 'participant';
The rest of the grammar is similar to the JavaGrammar which is available at GitHub