Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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 77e62b9
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 4 deletions.
10 changes: 7 additions & 3 deletions src/core/qgsexpressionlexer.ll
Expand Up @@ -95,7 +95,9 @@ static QLocale cLocale("C");

%}

%s IN_COMMENT
%s BLOCK_COMMENT

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

white [ \t\r\n]+

Expand All @@ -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
Expand Down Expand Up @@ -195,6 +197,8 @@ string "'"{str_char}*"'"
{white} /* skip blanks and tabs */
{line_comment} /* skip line comments */
. { return Unknown_CHARACTER; }
Expand Down
24 changes: 23 additions & 1 deletion tests/src/python/test_qgsexpression.py
Expand Up @@ -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):
Expand All @@ -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.