Skip to content

Commit a41bdb2

Browse files
committed
Add option to specify functionName for compiled regex circuit
1 parent c428904 commit a41bdb2

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

src/cli.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,17 @@ program
1515
'Partial state transitions to reveal'
1616
)
1717
.option('-s, --revealSubpatterns <values...>', 'Regex subpatterns to reveal')
18+
.option(
19+
'-n, --functionName <name>',
20+
'Function name to give to the regex circuit'
21+
)
1822
.action((rawRegex, options) => {
1923
// Extract and set the options
2024
const countEnabled = options.count || false;
2125
let revealEnabled = false;
26+
const functionName = options.functionName
27+
? 'function ' + options.functionName
28+
: '';
2229

2330
let revealInput: string[] | [number, number][][] | undefined = undefined;
2431

@@ -48,7 +55,12 @@ program
4855
}
4956

5057
// Print the regex circuit based on the options
51-
compiler.printRegexCircuit(countEnabled, revealEnabled, revealInput);
58+
compiler.printRegexCircuit(
59+
countEnabled,
60+
revealEnabled,
61+
revealInput,
62+
functionName
63+
);
5264
});
5365

5466
// Parse the command-line arguments

src/compiler.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,8 @@ export class RegexCompiler {
494494
printRegexCircuit(
495495
countEnabled: boolean,
496496
revealEnabled: boolean,
497-
transitionInput?: string[] | [number, number][][]
497+
transitionInput?: string[] | [number, number][][],
498+
functionName?: string
498499
) {
499500
let circuitLines: string[] = [];
500501
circuitLines = this.writeDeclarationLines()
@@ -503,7 +504,7 @@ export class RegexCompiler {
503504
.concat(this.writeAcceptLines(countEnabled));
504505

505506
const stringRegexCircuit =
506-
'\n(input: UInt8[]) {\n' +
507+
`\n${functionName}(input: UInt8[]) {\n` +
507508
circuitLines.join('\n\t') +
508509
this.writeRevealLines(revealEnabled, transitionInput) +
509510
'\n}';

0 commit comments

Comments
 (0)