1
- import { getCircomParser , ParserError , BigIntOrNestedArray } from "@distributedlab/circom-parser" ;
1
+ import { CircomValueType , getCircomParser , ParserError } from "@distributedlab/circom-parser" ;
2
2
3
3
import { CircomFilesVisitor } from "./CircomFilesVisitor" ;
4
4
import { CircomTemplateInputsVisitor } from "./CircomTemplateInputsVisitor" ;
5
5
import { CircuitsCompileCache } from "../../../cache" ;
6
6
import { Reporter } from "../../../reporter" ;
7
7
8
- import { InputData , ResolvedFileData } from "../../../types/core" ;
8
+ import { VisitorError } from "../parser/VisitorError" ;
9
+ import { CircomResolvedFile , ErrorType , InputData , ResolvedFileData } from "../../../types/core" ;
9
10
10
11
/**
11
12
* A parser class for handling Circom files and extracting relevant data.
@@ -48,7 +49,7 @@ export class CircomFilesParser {
48
49
49
50
const parser = getCircomParser ( fileContent ) ;
50
51
51
- const circomFilesVisitor = new CircomFilesVisitor ( ) ;
52
+ const circomFilesVisitor = new CircomFilesVisitor ( absolutePath ) ;
52
53
53
54
Reporter ! . verboseLog ( "circom-files-parser" , "Parsing '%s' file" , [ absolutePath ] ) ;
54
55
@@ -60,6 +61,17 @@ export class CircomFilesParser {
60
61
61
62
circomFilesVisitor . visit ( context ) ;
62
63
64
+ const visitorErrors = circomFilesVisitor . errors . filter (
65
+ ( error ) =>
66
+ error . type === ErrorType . InvalidPragmaVersion ||
67
+ error . type === ErrorType . TemplateAlreadyUsed ||
68
+ error . type === ErrorType . FailedToResolveMainComponentParameter ,
69
+ ) ;
70
+
71
+ if ( visitorErrors . length > 0 ) {
72
+ throw new VisitorError ( visitorErrors ) ;
73
+ }
74
+
63
75
this . _cache . set ( contentHash , { parsedFileData : circomFilesVisitor . fileData } ) ;
64
76
65
77
return { parsedFileData : circomFilesVisitor . fileData } ;
@@ -73,29 +85,33 @@ export class CircomFilesParser {
73
85
* parsing errors and throws a `ParserError` if any issues are encountered.
74
86
* The structured input data associated with the specified template is then returned.
75
87
*
76
- * @param absolutePath The absolute path to the Circom file containing the template
88
+ * @param circomResolvedFile The resolved Circom file data containing the template to parse
77
89
* @param templateName The name of the template whose inputs are being parsed
78
90
* @param parameterValues A record of parameter values used for template input resolution
79
91
* @returns A structured record of input data for the specified template
80
92
* @throws ParserError If any parsing issues occur while processing the template inputs
81
93
*/
82
94
public parseTemplateInputs (
83
- absolutePath : string ,
95
+ circomResolvedFile : CircomResolvedFile ,
84
96
templateName : string ,
85
- parameterValues : Record < string , BigIntOrNestedArray > ,
97
+ parameterValues : Record < string , CircomValueType > ,
86
98
) : Record < string , InputData > {
87
- const parser = getCircomParser ( absolutePath ) ;
99
+ const circomTemplateInputsVisitor = new CircomTemplateInputsVisitor (
100
+ circomResolvedFile . absolutePath ,
101
+ circomResolvedFile . fileData . parsedFileData . templates [ templateName ] . context ,
102
+ parameterValues ,
103
+ ) ;
88
104
89
- const circomTemplateInputsVisitor = new CircomTemplateInputsVisitor ( templateName , parameterValues ) ;
105
+ circomTemplateInputsVisitor . startParse ( ) ;
90
106
91
- const context = parser . circuit ( ) ;
107
+ const visitorErrors = circomTemplateInputsVisitor . errors . filter (
108
+ ( error ) => error . type === ErrorType . SignalDimensionResolution ,
109
+ ) ;
92
110
93
- if ( parser . hasAnyErrors ( ) ) {
94
- throw new ParserError ( parser . getAllErrors ( ) ) ;
111
+ if ( visitorErrors . length > 0 ) {
112
+ throw new VisitorError ( visitorErrors ) ;
95
113
}
96
114
97
- circomTemplateInputsVisitor . visit ( context ) ;
98
-
99
115
return circomTemplateInputsVisitor . templateInputs ;
100
116
}
101
117
0 commit comments