MCPcopy Create free account
hub / github.com/GoogleChrome/samples / parse

Method parse

examplescript-to-wasm/parser.js:2–20  ·  view source on GitHub ↗
(input)

Source from the content-addressed store, hash-verified

1export default class Parser {
2 parse(input) {
3 input = input.split(/\n/);
4 input = input.filter(line => line.trim());
5 if (!input.every((line) => /\d+\s*[\+\-\*\/]\s*\d+\s*/gm.test(line))) {
6 throw new Error('Parse error');
7 }
8
9 return input.map((line) => {
10 const { groups } =
11 /(?<first_operand>\d+)\s*(?<operator>[\+\-\*\/])\s*(?<second_operand>\d+)/gm.exec(
12 line
13 );
14 return {
15 firstOperand: Number(groups.first_operand),
16 operator: groups.operator,
17 secondOperand: Number(groups.second_operand),
18 };
19 });
20 }
21}

Callers 15

sqlite3.jsFile · 0.45
script.jsFile · 0.45
readLSManifestFunction · 0.45
readLSManifestFunction · 0.45
readLSManifestFunction · 0.45
readLSManifestFunction · 0.45
server.mjsFile · 0.45
qMethod · 0.45
tryParseMethod · 0.45

Calls

no outgoing calls

Tested by

no test coverage detected