kivy/kivy — pull request #1919 by matham (2014-02-27 20:01:40+00:00)
Title: Updates lang to allow comments on same line as code.

This implements https://github.com/kivy/kivy/issues/1541.

There is one change which might be unexpected. Previously, although if the following code was put in a .kv file it was invalid, but if done through load_string it worked:

Builder.load_string("""
adapter:
sla.SimpleListAdapter(
data=["Item #{0}".format(i) for i in range(100)],
cls=label.Label)
""")

However, now, when tokenizing, python chokes on it because there's no new line escape (even with new line escape it would still not have worked in .kv though). The solution I did was making the code generate an exception if it happens, and to fix it in the test case where it happened by adding escaping.

Another solution would be to raise no error and simply ignore it, but then python is unable to parse that part for comments, and the following code might not work:

Builder.load_string("""
adapter:
sla.SimpleListAdapter(
data=["Item #{0}".format(i) for i in range(100)],
cls=label.Label) # comment not removed
""")