Named.conf logical blocks

Phil Mayers p.mayers at
Tue Jun 28 18:58:55 UTC 2011

On 06/28/2011 05:53 PM, Stefan Certic wrote:
> Hi Guys,
> Does anyone have a sample grammar for pharsing named.conf into a data
> structure? Perl or PHP are preffered, but anything would be fine just to get a
> clear picture about grammar and logical blocks.

The only think I ever wrote was a quick python hack that used a big 
regexp and an "eat" block function. Maybe it'll be of some interest, but 
beware - regexp engines are not parsers, as jwz once famously pointed 
out: "You have a problem, and you decide to solve it with regexps. Now 
you have two problems." ;o)

Anyway, break the regexp up and it's fairly obvious what it's doing. You 
can get better results with a proper state-machine based parser.


import re
import sys
import pprint

token_re = 

def eat(toklist):
	all = []
	v = []
	while toklist:
		t = toklist.pop(0)
		if t=='{':
			inner = eat(toklist)
		elif t=='}' and toklist and toklist[0]==';':
		elif t==';':
			v = []
	return all

data =
tokens = token_re.findall(data)

More information about the bind-users mailing list