Skip to content

Commit

Permalink
fix: handle unusual spacing in conditions
Browse files Browse the repository at this point in the history
  • Loading branch information
DinoChiesa committed Feb 27, 2024
1 parent d42f3bf commit e8f3a84
Show file tree
Hide file tree
Showing 5 changed files with 199 additions and 125 deletions.
252 changes: 135 additions & 117 deletions build/ConditionParser.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions lib/package/plugins/CC007-ConditionSyntax.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2019-2023 Google LLC
Copyright 2019-2024 Google LLC
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -31,7 +31,7 @@ const plugin = {
const onCondition = function (condition, cb) {
debug(`onCondition (${condition.getExpression()})`);
let flagged = false;
const expr = condition.getExpression();
const expr = condition.getExpression().trim();
try {
parser.parse(expr);
} catch (e) {
Expand Down
8 changes: 4 additions & 4 deletions lib/peggy/Apigee-Condition.pegjs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ start
= boolean_stmt1

boolean_stmt1
= left:boolean_stmt2 ws+ op1:op_boolean ws+ right:boolean_stmt1 { return {operator:op1, operands:[left, right] } }
= left:boolean_stmt2 ws* op1:op_boolean ws* right:boolean_stmt1 { return {operator:op1, operands:[left, right] } }
/ boolean_stmt2

boolean_stmt2
Expand All @@ -78,20 +78,20 @@ factor
/ primary

primary
= "(" ws* t1:token ws+ op1:op_accepts_literal ws+ v1:value ws* ")" {
= ws* "(" ws* t1:token ws+ op1:op_accepts_literal ws+ v1:value ws* ")" ws* {
return parseBinaryOp(t1,op1,v1,error);
}
/ t1:token ws+ op1:op_accepts_literal ws+ v1:value {
return parseBinaryOp(t1,op1,v1,error);
}
/ "(" ws* t1:token ws+ op1:op_accepts_variable ws+ t2:token ws* ")" {
/ ws* "(" ws* t1:token ws+ op1:op_accepts_variable ws+ t2:token ws* ")" ws* {
return { operator:op1, operands:[t1, t2]};
}
/ t1:token ws+ op1:op_accepts_variable ws+ t2:token {
return { operator:op1, operands:[t1, t2]};
}
/ token1:token { return token1; }
/ "(" token1:token ")" { return token1; }
/ "(" ws* token1:token ws* ")" { return token1; }
/ "(" stmt1:boolean_stmt1 ")" { return stmt1; }

op_boolean
Expand Down
Loading

0 comments on commit e8f3a84

Please sign in to comment.