"""ushyph_format.py

A Martel format usable to parse TeX hyphenation table.

Formats:
pattern_format
format

"""
from Martel import *


spaces = Rep(Str(" "))

comment = Str("%") + Re(r"[^\R]*")
optcomment = Opt(spaces + comment)
comment_line = spaces + comment + AnyEol()
comment_block = Rep(comment_line)


pattern_heading = Str("\\patterns{") + optcomment + ToEol()
pattern = Group("patterns", Re(r"[a-z0-9\.]+"))
pattern_line = pattern + optcomment + AnyEol()
pattern_footer = Str("}") + optcomment + AnyEol()
pattern_block = pattern_heading + \
                Rep(Alt(pattern_line, comment_line)) + \
                pattern_footer


hyphenation_heading = Str("\\hyphenation{") + optcomment + ToEol()
hyphenation = Group("hyphenation", Re(r"[a-z-]+"))
hyphenation_line = hyphenation + optcomment + AnyEol()
hyphenation_footer = Str("}") + optcomment + AnyEol()
hyphenation_block = hyphenation_heading + \
                    Rep(Alt(hyphenation_line, comment_line)) + \
                    hyphenation_footer


format = Opt(comment_block) + \
         pattern_block + \
         Opt(comment_block) + \
         hyphenation_block + \
         Opt(comment_block)



score = Re(r"[0-9]")
syllable = Re(r"[\.a-z]+")
pattern_format = Rep1(Alt(score, syllable))
