Skip to content
Permalink
Browse files

Add line comments to QgsExpression

Delimited by double-minus and EOL/EOF

Example:
  $id -- This is the feature id
  • Loading branch information
m-kuhn committed Nov 30, 2014
1 parent a92d1a6 commit 77e62b97c13d949a311ffbfb49beee8bba0d1f4f
Showing with 30 additions and 4 deletions.
  1. +7 −3 src/core/qgsexpressionlexer.ll
  2. +23 −1 tests/src/python/test_qgsexpression.py
@@ -95,7 +95,9 @@ static QLocale cLocale("C");

%}

%s IN_COMMENT
%s BLOCK_COMMENT

line_comment \-\-[^\r\n]*[\r\n]?

white [ \t\r\n]+

@@ -120,9 +122,9 @@ string "'"{str_char}*"'"
%%
<INITIAL>{
"/*" BEGIN(IN_COMMENT);
"/*" BEGIN(BLOCK_COMMENT);
}
<IN_COMMENT>{
<BLOCK_COMMENT>{
"*/" BEGIN(INITIAL);
[^*\n]+ // eat comment in chunks
"*" // eat the lone star
@@ -195,6 +197,8 @@ string "'"{str_char}*"'"
{white} /* skip blanks and tabs */
{line_comment} /* skip line comments */
. { return Unknown_CHARACTER; }
@@ -84,7 +84,14 @@ def testCantOverrideBuiltinsWithUnregister(self):
self.assertFalse(success)

def testDump(self):
for txt in ["id", u"idä", "\"id abc\"", "\"id abc\""]:
for txt in [
"id",
u"idä",
"\"id abc\"",
"\"id abc\"",
" abc ",
" /* co */ da ",
]:
self.assertEqual( txt, QgsExpression(txt).expression() )

def testBlockComment(self):
@@ -109,5 +116,20 @@ def testBlockComment(self):
result = exp.evaluate()
self.assertEqual(exp_res, result)


def testComment(self):
expressions = {
"'test' -- comment\n": 'test',
"'test--'\n": 'test--',
"'--test'\n": '--test',
"'test' -- comment": 'test',
"'test--'": 'test--',
"'--test'": '--test',
}
for e, exp_res in expressions.iteritems():
exp = QgsExpression(e)
result = exp.evaluate()
self.assertEqual(exp_res, result)

if __name__ == "__main__":
unittest.main()

0 comments on commit 77e62b9

Please sign in to comment.
You can’t perform that action at this time.