Single line commenting doesn't work.

Issue #23 new
Satish Chandra Prasad
created an issue

Hi, I am learning wheezy.template from the docs and, here is a portion of my code:

@if not isThisFirstPage:
    <a href="?tableName=@tableName&chunkSize=@str(chunkSize)&pageNum=@str(pageNum-1)">Previous</a>
@end
@if not isThisLastPage:
    <a href="?tableName=@tableName&chunkSize=@str(chunkSize)&pageNum=@str(pageNum+1)">Next</a>
@end

I get the following syntax error when I try to render it:

SyntaxError: if not isThisLastPage:
                ^

Note that the above template code is perfectly logical and valid, I overlook bad parsing and decide to modify my code.

I remove line number three, i.e. the first @end and now my code looks like:

@if not isThisFirstPage:
    <a href="?tableName=@tableName&chunkSize=@str(chunkSize)&pageNum=@str(pageNum-1)">Previous</a>
@if not isThisLastPage:
    <a href="?tableName=@tableName&chunkSize=@str(chunkSize)&pageNum=@str(pageNum+1)">Next</a>
@end

With the above code I get no errors. Although this whole incident (illustrated above) is technically incorrect, let us ignore it for the moment.

But could you please explain WHY does single line commented code throw errors:

@if not isThisFirstPage:
    <a href="?tableName=@tableName&chunkSize=@str(chunkSize)&pageNum=@str(pageNum-1)">Previous</a>
@#end --- THIS IS COMMENTED OUT AND STILL THIS LINE CAUSES ERROR
@if not isThisLastPage:
    <a href="?tableName=@tableName&chunkSize=@str(chunkSize)&pageNum=@str(pageNum+1)">Next</a>
@end

Comments (9)

  1. Andriy Kornatskyy repo owner

    test.json:

    {
        "isThisFirstPage": false,
        "isThisLastPage": false,
        "tableName": "x",
        "chunkSize": 10,
        "pageNum": 2
    }
    

    test.html:

    @require(isThisFirstPage, isThisLastPage, tableName, chunkSize, pageNum)
    @if not isThisFirstPage:
        <a href="?tableName=@tableName&chunkSize=@str(chunkSize)&pageNum=@str(pageNum-1)">Previous</a>
    @end
    @if not isThisLastPage:
        <a href="?tableName=@tableName&chunkSize=@str(chunkSize)&pageNum=@str(pageNum+1)">Next</a>
    @end
    

    result:

    $ env/bin/wheezy.template test.html test.json
        <a href="?tableName=x&chunkSize=10&pageNum=1">Previous</a>
        <a href="?tableName=x&chunkSize=10&pageNum=3">Next</a>
    
  2. Satish Chandra Prasad reporter

    Well it works in command line but not when I use it in browser (bottle.py is serving over localhost), here's the full error I get:

    Traceback (most recent call last):
      File "C:\Program Files\Python36-32\lib\site-packages\wheezy\template\engine.py", line 39, in get_template
        return self.templates[name]
    KeyError: 'displayTable.tpl'
    
    During handling of the above exception, another exception occurred:
    
    Traceback (most recent call last):
      File "C:\Program Files\Python36-32\lib\site-packages\bottle.py", line 862, in _handle
        return route.call(**args)
      File "C:\Program Files\Python36-32\lib\site-packages\bottle.py", line 1740, in wrapper
        rv = callback(*a, **ka)
      File "C:\Users\Admin\Coding\anyDBviewer\controller.py", line 48, in displayTable
        template = engine.get_template("displayTable.tpl")
      File "C:\Program Files\Python36-32\lib\site-packages\wheezy\template\engine.py", line 41, in get_template
        self.compile_template(name)
      File "C:\Program Files\Python36-32\lib\site-packages\wheezy\template\engine.py", line 89, in compile_template
        source, name)['render']
      File "C:\Program Files\Python36-32\lib\site-packages\wheezy\template\compiler.py", line 26, in compile_source
        source = adjust_source_lineno(source, name, self.source_lineno)
      File "C:\Program Files\Python36-32\lib\site-packages\wheezy\template\comp.py", line 21, in adjust_source_lineno
        source = compile(source, name, 'exec', ast.PyCF_ONLY_AST)
      File "displayTable.tpl", line 24
        w('\t'); if not isThisLastPage:
                  ^
    SyntaxError: invalid syntax
    
  3. Satish Chandra Prasad reporter

    Anyway Andriy how are you, why have you stopped writing on the blog. I saw the last post was in 2015 and I got worried whether or not to use wheezy.template in my project.

    Has the development stalled?

  4. Satish Chandra Prasad reporter

    Its nice to focus on speed but why don't you aim for usability (and a better parser please)? I can help with all the documentation and tutorial. If you improve it further.

    BTW, what are the things that make wheezy.template so so fast?

  5. Log in to comment