Skip to content

Commit

Permalink
Merge pull request #47 from dhis2/DHIS2-15035
Browse files Browse the repository at this point in the history
feat: Add support for comments in expression
  • Loading branch information
zubaira authored Apr 29, 2023
2 parents 0068ce8 + a9edade commit 1291a8f
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:

artifact:
name: Publish - Nexus
runs-on: ubuntu-18.04
runs-on: ubuntu-latest
needs: unit-test

steps:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/master.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:

artifact:
name: Publish - Nexus
runs-on: ubuntu-18.04
runs-on: ubuntu-latest
needs: unit-test

steps:
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<packaging>jar</packaging>
<name>DHIS Antlr Expression Parser</name>
<groupId>org.hisp.dhis.parser</groupId>
<version>1.0.33</version>
<version>1.0.34-SNAPSHOT</version>

<description>Antlr Expression Parser</description>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ expr
| numericLiteral
| stringLiteral
| booleanLiteral
| comments
;

programVariable // (alphabtical)
Expand Down Expand Up @@ -241,6 +242,10 @@ programRuleVariablePart
| '.'
;

comments
: COMMENT
;

// -----------------------------------------------------------------------------
// Assign token names to parser symbols
// -----------------------------------------------------------------------------
Expand Down Expand Up @@ -498,6 +503,12 @@ EMPTY
WS : [ \t\n\r]+
;

// Comments

COMMENT
: ('/*' .*? '*/') -> skip
;

// Lexer fragments

fragment Exponent
Expand Down
6 changes: 6 additions & 0 deletions src/test/java/org/hisp/dhis/antlr/ValidExpressionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@ public void testExpressionWithValidSyntaxAndNotSupportedVariable()
evaluate( "2 > V{not_supported}" );
}

@Test
public void testMultiLineComments()
{
assertEquals( true, evaluate( "true and true || 1 /* this is multi \n line comment \r */" ) );
}

@Test(expected = ParserExceptionWithoutContext.class)
public void testExpressionWithValidSyntaxAndNotSupportedAttribute()
{
Expand Down

0 comments on commit 1291a8f

Please sign in to comment.