Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions yarn-project/circuits.js/src/scripts/constants.in.ts
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ function parseNoirFile(fileContent: string): ParsedContent {
}

{
const [, name, _type, value, end] = line.match(/global\s+(\w+)(\s*:\s*\w+)?\s*=\s*([^;]+)(;)?/) || [];
const [, name, _type, value, end] = line.match(/global\s+(\w+)(\s*:\s*\w+)?\s*=\s*([^;]*)(;)?/) || [];
if (name && value) {
const [, indexName] = name.match(/GENERATOR_INDEX__(\w+)/) || [];
if (indexName) {
Expand All @@ -336,6 +336,10 @@ function parseNoirFile(fileContent: string): ParsedContent {
expression = { name, content: [value] };
}
return;
} else if (name) {
// This case happens if we have only a name, with the value being on the next line
expression = { name, content: [] };
return;
}
}

Expand Down Expand Up @@ -389,8 +393,11 @@ function evaluateExpressions(expressions: [string, string][]): { [key: string]:
// We make some space around the parentheses, so that constant numbers are still split.
.replace(/\(/g, '( ')
.replace(/\)/g, ' )')
// We also make some space around common operators
.replace(/\+/g, ' + ')
.replace(/(?<!\/)\*(?!\/)/, ' * ')
// We split the expression into terms...
.split(' ')
.split(/\s+/)
// ...and then we convert each term to a BigInt if it is a number.
.map(term => (isNaN(+term) ? term : `BigInt('${term}')`))
// .. also, we convert the known bigints to BigInts.
Expand Down