include "constants.bnf"

// Usage: nelly -v path=. examples/html.bnf

<%pre
    import base64
    $path
%>

HTML_START(start)
    : "<html>" CRLF HEAD CRLF BODYTAG CRLF "</html>"
    ;

HEAD
    : "<head>" CRLF "<title>" TITLE "</title>" CRLF "</head>"
    ;

TITLE
    : RANDCHAR{5,10}
    ;

BODYTAG
    : "<body>" CRLF BODY CRLF "</body>"
    ;

BODY
    : WORD ' => ' $ENCODER SP %str(%len(\WORD)) ' bytes'
    ;

$ENCODER
    : \WORD <% $* = base64.b64encode($$) %>
    ;

<%post
    fullPath = os.path.join($path, 'test.html')

    print fullPath
    print
    print $$
    print

    #fp = open(fullPath, 'wb')
    #fp.write($$)
    #fp.close()
%>
