Skip to content

Commit

Permalink
Add option to specify functionName for compiled regex circuit
Browse files Browse the repository at this point in the history
  • Loading branch information
Shigoto-dev19 committed Jul 20, 2024
1 parent c428904 commit a41bdb2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
14 changes: 13 additions & 1 deletion src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,17 @@ program
'Partial state transitions to reveal'
)
.option('-s, --revealSubpatterns <values...>', 'Regex subpatterns to reveal')
.option(
'-n, --functionName <name>',
'Function name to give to the regex circuit'
)
.action((rawRegex, options) => {
// Extract and set the options
const countEnabled = options.count || false;
let revealEnabled = false;
const functionName = options.functionName
? 'function ' + options.functionName
: '';

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

Expand Down Expand Up @@ -48,7 +55,12 @@ program
}

// Print the regex circuit based on the options
compiler.printRegexCircuit(countEnabled, revealEnabled, revealInput);
compiler.printRegexCircuit(
countEnabled,
revealEnabled,
revealInput,
functionName
);
});

// Parse the command-line arguments
Expand Down
5 changes: 3 additions & 2 deletions src/compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,8 @@ export class RegexCompiler {
printRegexCircuit(
countEnabled: boolean,
revealEnabled: boolean,
transitionInput?: string[] | [number, number][][]
transitionInput?: string[] | [number, number][][],
functionName?: string
) {
let circuitLines: string[] = [];
circuitLines = this.writeDeclarationLines()
Expand All @@ -503,7 +504,7 @@ export class RegexCompiler {
.concat(this.writeAcceptLines(countEnabled));

const stringRegexCircuit =
'\n(input: UInt8[]) {\n' +
`\n${functionName}(input: UInt8[]) {\n` +
circuitLines.join('\n\t') +
this.writeRevealLines(revealEnabled, transitionInput) +
'\n}';
Expand Down

0 comments on commit a41bdb2

Please sign in to comment.