Skip to content

Commit 69951ad

Browse files
committed
fix nested-expressions in the calc() function. fix #57
1 parent ba9a101 commit 69951ad

File tree

3 files changed

+17
-4
lines changed

3 files changed

+17
-4
lines changed

src/com/inet/lib/less/LessParser.java

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -897,11 +897,22 @@ private Expression parseExpression( char leftOperator ) {
897897
right = new Operation( reader, op.getOperands().get( 0 ), '~' );
898898
break;
899899
case "calc":
900-
ch = read();
901-
while( ch != ')' ) {
902-
builder.append( ch );
900+
int parenthesisCount = 0;
901+
CALC: do {
903902
ch = read();
904-
}
903+
switch( ch ) {
904+
case '(':
905+
parenthesisCount++;
906+
break;
907+
case ')':
908+
if( parenthesisCount == 0 ) {
909+
break CALC;
910+
}
911+
parenthesisCount--;
912+
break;
913+
}
914+
builder.append( ch );
915+
} while( true );
905916
op = new Operation( reader, new ValueExpression( reader, trim( builder ), Expression.STRING ), ';' );
906917
right = new FunctionExpression( reader, str, op );
907918
break;

test/com/inet/lib/less/samples/general/minus.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
calcWithSpace: calc(100% - 98px);
2626
calcCompact: calc(100%-98px);
2727
calcVariable: calc(90% -10px);
28+
calcNested: calc(100% - (2 * 2em));
2829
}
2930
:root {
3031
--main-bg-color: pink;

test/com/inet/lib/less/samples/general/minus.less

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
@a : 90%;
3030
@b : 10px;
3131
calcVariable: calc(@a -@b);
32+
calcNested: calc(100% - (2 * 2em));
3233
}
3334
:root {
3435
--main-bg-color: pink;

0 commit comments

Comments
 (0)