This particular section in example_code.renpy
init python hide:
import os.path
import re
# A list of files we will be scanning.
files = [ ]
for i in os.listdir(config.gamedir):
if i.endswith(".rpy"):
files.append(os.path.join(config.gamedir, i))
for fn in files:
fn = fn.replace("\\","/")
f = renpy.open_file(fn)
open_examples = set()
for l in f:
l = l.decode("utf-8")
l = l.rstrip()
m = re.match("\s*#begin (\w+)", l)
if m:
example = m.group(1)
if example in examples:
raise Exception("Example %r is defined in two places.", example)
open_examples.add(example)
examples[example] = [ ]
continue
m = re.match("\s*#end (\w+)", l)
if m:
example = m.group(1)
if example not in open_examples:
raise Exception("Example %r is not open.", example)
open_examples.remove(example)
continue
for i in open_examples:
examples[i].append(l)
if open_examples:
raise Exception("Examples %r remain open at the end of %r" % (open_examples, fn))
f.close()