Parsing DNS Zone files -or- paranthesis can be freely inserted
[email protected] (Guido Roeskens)
| Newsgroups | perl.recdescent |
|---|---|
| Message-ID | <[email protected]> |
Hello,
I try do write a parser for DNS (Bind) Zone files
using Parse::RecDescent.
In Bind zone files you can put parantheses almost everywhere
(although you see them very rare if ever, expect in SOA records)
If parantheses are used, a statement ``line'' can span
multiple lines, otherwise not. Moreover each line can
end with a comment ( m{\s*\;[^\n]*\n}x )
See also examples 1 and 5.
I don't want to write a rule like
ARecord : lparen(?) ( space ¦ name ) rparen(?) lparen(?) 'IN' rparen(?)
lparen(?) 'A' rparen(?) lparen(?) ipaddr rparen(?) comment(?) rparen(?)
which is obviously wrong
- no newlines allowed
- only one comment at the end
- a construct like 'bla IN )( A 1.2.3.4' would pass
- single paranthese (left or right) possible
- nesting possible
What would be the best solution for the problem?
I don't know if I could use a <skip: > construct,
but I would like to keep the parantheses to be able to
fully reconstruct the data except for whitespace ( /\s+/ )
Summary:
- each can end with a comment
- a record spans a ``line''
- the record items can be freely paranthesized
- a record with parantheses can span multiple lines
(line feeds in parantheses are ignored)
Any ideas are welcome.
Regards, Guido Roeskens
lousy Perl programmer
Some data examples (these get loaded in a Bind 9 zone file)
; most people just use this kind of entries
standard IN A 10.0.0.1 ; single line
; example 1
test IN ( A ; a comment is allowed on every line
172.16.50.1 ; we can span multiple lines
)
IN A 192.168.100.1
; example 2
test2 IN ( A 172.16.50.102 )
; example 3
test3 (IN A) 172.16.50.103
; example 4
test4 IN A (172.16.50.102)
; example 5
(
test5 IN A
) 172.16.50.103
; example 6
; NOT ALLOWED : parantheses span two A record definitions
test3 IN ( A
172.16.50.103
test101 IN A 192.168.100.101 )