in reply to TNSNAMES.ORA and Recdescent

First some general advise. I personally prefer alternations instead of multiple rule definitions, if only for the fact that it makes the grammar look more BNF-ish (which is easy for me to read) Thus:

Address : '(' /address/i '=' AddressTCP ')' Address : '(' /address/i '=' AddressIPC ')' Address : '(' /address/i '=' AddressSPX ')' Address : '(' /address/i '=' AddressPipe ')'

Would become:

Address: '(' /address/i '=' (AddressTCP | AddressIPC | AddressSPX | Ad +dressPipe ) ')'

Or better yet:

Address: '(' /address/i '=' AddressProtocol ')' AddressProtocol: AddressTCP | AddressIPC | AddressSPX | AddressPipe

Also:

TNSEntry : NetServiceName '=' Description TNSEntry : NetServiceName '=' DescriptionList

Would become:

TNSEntry: NetServiceName '=' (Description | DescriptionList)

Note: In this last example order can matter in some situtations, you'll just have to play with it.

Now as far as:
The second problem is tied to the order of the clauses to be matched. If I take the following line:
AddressTCP : Community(?) ProtocolTCP Host Port
It will match the code only if they come in that exact order. There are no rules stating that Community needs to be first and Protocol needs to be second ... The obvious solution is to create create every permutation of this line. My question is "Is there an easier way?" What could be a relatively small program could otherwise become quite unwieldly.

I guess I don't understand what you are talking about here. The rule that you have states: AddressTCP by definition is: An optional Community followed by required Protocol, Host, and Port. So yes order does matter here. The rule does require that if a community appears, it must come before the protocol. I don't know enough about the TNSNAMES.ORA file to divine the intended meaning. A clearer description of the exact syntax of this line may help.

Also are you parsing each line individually just so you can report which lines contain errors? If so you can accomplish the same thing by letting Parse::RecDescent parse the entire input for you. There's no need to parse the document before you "parse" the document. Anyway that's just my $.02 I could be wrong.

Replies are listed 'Best First'.
Re: Re: TNSNAMES.ORA and Recdescent
by jmr4096 (Acolyte) on Feb 23, 2004 at 18:36 UTC

    Sorry, didn't realize the ambiguity in my question. What I am trying to do is check the syntax of tnsnames.ora entries. This file contains information about how to connect to an oracle database.

    The code: AddressTCP : Community(?) ProtocolTCP Host Port defines the particular order which the entry must follow for it to match. BUT that is not the action I am trying to achieve. The entry could come in any order so I would need to include the following to match every possible order.

    AddressTCP : Community(?) ProtocolTCP Host Port AddressTCP : Community(?) ProtocolTCP Port Host AddressTCP : Community(?) Host ProtocolTCP Port AddressTCP : Community(?) Port ProtocolTCP Host AddressTCP : Community(?) Host ProtocolTCP Port AddressTCP : Community(?) Host Port ProtocolTCP AddressTCP : Community(?) Port Host ProtocolTCP .... Would include every combination of each of these four fields.

    I picked AddressTCP as an example for the question but most of the fields on the parser could have this problem. All of a sudden this problem becomes unmanagle.Thanks for the help so far.

    Here is a sample TNSNAMES.ORA entry

    PRDSAP01 = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = mercury.empire.com)(PORT = 15 +21)) ) (CONNECT_DATA = (SERVICE_NAME = PRDSAP01) ) )