Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit f223874

Browse files
authoredMar 13, 2024··
Merge pull request #137 from adobe/issues
Issues
2 parents c877f79 + 717b792 commit f223874

16 files changed

+633
-138
lines changed
 

‎dist/index.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,4 @@
3232
}
3333
.hidden {
3434
display:none;
35-
}</style><script defer="defer" src="tutorial.js"></script></head><body><table class="expressions"><caption>json-formula Testing</caption><thead><tr><th scope="col" class="data">Input JSON</th><th scope="col" class="expression">Expression</th><th scope="col" class="result">Result</th><th scope="col" class="debug">Debug Info</th></tr></thead><tbody><tr><td class="data"><textarea id="data" name="data"></textarea></td><td class="expression"><textarea id="expression" name="expression"></textarea></td><td class="result"><textarea id="result" name="result" readonly="readonly"></textarea></td><td class="debug"><textarea id="debug" name="debug" readonly="readonly"></textarea></td></tr><tr id="description-row" style="display:none;"><td id="description" colspan="4"></td></tr><tr id="mimic-fields"><td colspan="4"><label>mimic fields<input type="checkbox" id="use-fields"></label></td></tr><tr class="controls"><td colspan="4"><label for="canned">Select Expression</label> <select id="canned"><option label="&lt;none>"></option><option>address.street</option><option>substitute(address.street, "Oak", "Maple")</option><option>items[*]</option><option>items[? @.price > 2]</option><option>items[*].price</option><option>items[*].price * items[*].quantity</option><option>sum(items[*].price * items[*].quantity)</option><option>map(items, &price * quantity)</option><option>items[*].{subtotal: price * quantity}</option><option>items[*].merge(@, {subtotal: price*quantity})</option><option>sum(items[*].price * items[*].quantity) * tax</option><option>round(sum(items[*].price * items[*].quantity) * tax, 2)</option><option>address.phone | "(" & mid(@, 0, 3) & ")" & mid(@, 3, 3) & "-" & mid(@, 6, 4)</option></select></td></tr><tr class="controls"><td colspan="4"><button id="data-reset">Reset Data</button></td></tr></tbody></table><a class="controls" href="../doc/output/json-formula.rrd.html">Syntax Railroad Diagram</a><h3 class="controls">Antlr4 Grammar</h3><pre class="controls" id="grammar-out" style="border: thin solid black"></pre><script>document.getElementById("mimic-fields").style.display = location.host.startsWith("localhost:") ? "block" : "none"</script></body></html>
35+
}</style><script defer="defer" src="tutorial.js"></script></head><body><table class="expressions"><caption>json-formula Testing</caption><thead><tr><th scope="col" class="data">Input JSON</th><th scope="col" class="expression">Expression</th><th scope="col" class="result">Result</th><th scope="col" class="debug">Debug Info</th></tr></thead><tbody><tr><td class="data"><textarea id="data" name="data"></textarea></td><td class="expression"><textarea id="expression" name="expression"></textarea></td><td class="result"><textarea id="result" name="result" readonly="readonly"></textarea></td><td class="debug"><textarea id="debug" name="debug" readonly="readonly"></textarea></td></tr><tr id="description-row" style="display:none;"><td id="description" colspan="4"></td></tr><tr id="mimic-fields"><td colspan="4"><label>mimic fields<input type="checkbox" id="use-fields"></label></td></tr><tr class="controls"><td colspan="4"><label for="canned">Select Expression</label> <select id="canned"><option label="&lt;none>"></option><option>address.street</option><option>substitute(address.street, "Oak", "Maple")</option><option>items[*]</option><option>items[? @.price > 2]</option><option>items[*].price</option><option>items[*].price * items[*].quantity</option><option>sum(items[*].price * items[*].quantity)</option><option>map(items, &price * quantity)</option><option>items[*].{subtotal: price * quantity}</option><option>items[*].merge(@, {subtotal: price*quantity})</option><option>sum(items[*].price * items[*].quantity) * tax</option><option>round(sum(items[*].price * items[*].quantity) * tax, 2)</option><option>address.phone | "(" & mid(@, 0, 3) & ")" & mid(@, 3, 3) & "-" & mid(@, 6, 4)</option></select></td></tr><tr><td colspan="4"><button id="data-reset">Reset Data</button></td></tr></tbody></table><a class="controls" href="../doc/output/json-formula.rrd.html">Syntax Railroad Diagram</a><h3 class="controls">Antlr4 Grammar</h3><pre class="controls" id="grammar-out" style="border: thin solid black"></pre><script>document.getElementById("mimic-fields").style.display = location.host.startsWith("localhost:") ? "block" : "none"</script></body></html>

‎dist/tutorial.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎dist/tutorial.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎src/Lexer.js

+5-22
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,6 @@ const skipChars = {
9797
'\n': true,
9898
};
9999

100-
function isNumChar(ch) {
101-
return (ch >= '0' && ch <= '9') || (ch === '.');
102-
}
103-
104100
function isAlphaNum(ch) {
105101
return (ch >= 'a' && ch <= 'z')
106102
|| (ch >= 'A' && ch <= 'Z')
@@ -327,24 +323,11 @@ export default class Lexer {
327323

328324
_consumeNumber(stream) {
329325
const start = this._current;
330-
this._current += 1;
331-
const maxLength = stream.length;
332-
while (isNumChar(stream[this._current]) && this._current < maxLength) {
333-
this._current += 1;
334-
}
335-
// check again for exponent character
336-
if (stream[this._current] === 'e' || stream[this._current] === 'E') {
337-
this._current += 1;
338-
// check for + or - after exponent
339-
if (stream[this._current] === '-' || stream[this._current] === '+') {
340-
this._current += 1;
341-
}
342-
// consume digits after exponent
343-
while (isNumChar(stream[this._current]) && this._current < maxLength) {
344-
this._current += 1;
345-
}
346-
}
347-
const n = stream.slice(start, this._current);
326+
const num = stream.slice(start);
327+
const match = num.match(/^[0-9]*\.?[0-9]+(?:[eE][-+]?[0-9]+)?/);
328+
if (!match) throw syntaxError(`Invalid number: ${num}`);
329+
const n = match[0];
330+
this._current += n.length;
348331
let value;
349332
if (n.includes('.') || n.toLowerCase().includes('e')) {
350333
value = parseFloat(n);

0 commit comments

Comments
 (0)