Skip to content

Commit

Permalink
Completed basic version of updated parser. Tested CircomTemplateInput…
Browse files Browse the repository at this point in the history
…sVisitor
  • Loading branch information
KyrylR committed Oct 31, 2024
1 parent fb435e0 commit c81eef1
Show file tree
Hide file tree
Showing 15 changed files with 969 additions and 474 deletions.
2 changes: 1 addition & 1 deletion circom-g4-grammar
136 changes: 68 additions & 68 deletions src/generated/CircomParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1865,74 +1865,74 @@ export default class CircomParser extends Parser {
this._errHandler.sync(this);
switch (this._interp.adaptivePredict(this._input, 39, this._ctx)) {
case 1:
localctx = new SubsLeftAssignmetContext(this, localctx);
localctx = new SubsLeftAssignmentContext(this, localctx);
this.enterOuterAlt(localctx, 1);
{
this.state = 392;
(localctx as SubsLeftAssignmetContext)._lhs = this.expression(0);
(localctx as SubsLeftAssignmentContext)._lhs = this.expression(0);
this.state = 393;
(localctx as SubsLeftAssignmetContext)._op = this._input.LT(1);
(localctx as SubsLeftAssignmentContext)._op = this._input.LT(1);
_la = this._input.LA(1);
if (
!(
((_la - 40) & ~0x1f) === 0 &&
((1 << (_la - 40)) & 134217731) !== 0
)
) {
(localctx as SubsLeftAssignmetContext)._op =
(localctx as SubsLeftAssignmentContext)._op =
this._errHandler.recoverInline(this);
} else {
this._errHandler.reportMatch(this);
this.consume();
}
this.state = 394;
(localctx as SubsLeftAssignmetContext)._rhs = this.expression(0);
(localctx as SubsLeftAssignmentContext)._rhs = this.expression(0);
}
break;
case 2:
localctx = new SubsRightSimpleAssignmetContext(this, localctx);
localctx = new SubsRightSimpleAssignmentContext(this, localctx);
this.enterOuterAlt(localctx, 2);
{
this.state = 396;
(localctx as SubsRightSimpleAssignmetContext)._lhs =
(localctx as SubsRightSimpleAssignmentContext)._lhs =
this.expression(0);
this.state = 397;
(localctx as SubsRightSimpleAssignmetContext)._op = this.match(
(localctx as SubsRightSimpleAssignmentContext)._op = this.match(
CircomParser.RIGHT_ASSIGNMENT,
);
this.state = 398;
(localctx as SubsRightSimpleAssignmetContext)._variable =
(localctx as SubsRightSimpleAssignmentContext)._variable =
this.expression(0);
}
break;
case 3:
localctx = new SubsRightConstrAssignmetContext(this, localctx);
localctx = new SubsRightConstrAssignmentContext(this, localctx);
this.enterOuterAlt(localctx, 3);
{
this.state = 400;
(localctx as SubsRightConstrAssignmetContext)._lhs =
(localctx as SubsRightConstrAssignmentContext)._lhs =
this.expression(0);
this.state = 401;
(localctx as SubsRightConstrAssignmetContext)._op = this.match(
(localctx as SubsRightConstrAssignmentContext)._op = this.match(
CircomParser.RIGHT_CONSTRAINT,
);
this.state = 402;
(localctx as SubsRightConstrAssignmetContext)._variable =
(localctx as SubsRightConstrAssignmentContext)._variable =
this.expression(0);
}
break;
case 4:
localctx = new SubsAssignmetWithOperationContext(this, localctx);
localctx = new SubsAssignmentWithOperationContext(this, localctx);
this.enterOuterAlt(localctx, 4);
{
this.state = 404;
this.identifierStatement();
this.state = 405;
(localctx as SubsAssignmetWithOperationContext)._op = this.match(
(localctx as SubsAssignmentWithOperationContext)._op = this.match(
CircomParser.ASSIGNMENT_WITH_OP,
);
this.state = 406;
(localctx as SubsAssignmetWithOperationContext)._rhs =
(localctx as SubsAssignmentWithOperationContext)._rhs =
this.expression(0);
}
break;
Expand Down Expand Up @@ -5416,7 +5416,7 @@ export class SubstitutionsContext extends ParserRuleContext {
super.copyFrom(ctx);
}
}
export class SubsLeftAssignmetContext extends SubstitutionsContext {
export class SubsLeftAssignmentContext extends SubstitutionsContext {
public _lhs!: ExpressionContext;
public _op!: Token;
public _rhs!: ExpressionContext;
Expand All @@ -5440,25 +5440,25 @@ export class SubsLeftAssignmetContext extends SubstitutionsContext {
return this.getToken(CircomParser.LEFT_CONSTRAINT, 0);
}
public enterRule(listener: CircomParserListener): void {
if (listener.enterSubsLeftAssignmet) {
listener.enterSubsLeftAssignmet(this);
if (listener.enterSubsLeftAssignment) {
listener.enterSubsLeftAssignment(this);
}
}
public exitRule(listener: CircomParserListener): void {
if (listener.exitSubsLeftAssignmet) {
listener.exitSubsLeftAssignmet(this);
if (listener.exitSubsLeftAssignment) {
listener.exitSubsLeftAssignment(this);
}
}
// @Override
public accept<Result>(visitor: CircomParserVisitor<Result>): Result {
if (visitor.visitSubsLeftAssignmet) {
return visitor.visitSubsLeftAssignmet(this);
if (visitor.visitSubsLeftAssignment) {
return visitor.visitSubsLeftAssignment(this);
} else {
return visitor.visitChildren(this);
}
}
}
export class SubsRightConstrAssignmetContext extends SubstitutionsContext {
export class SubsRightConstrAssignmentContext extends SubstitutionsContext {
public _lhs!: ExpressionContext;
public _op!: Token;
public _variable!: ExpressionContext;
Expand All @@ -5476,94 +5476,94 @@ export class SubsRightConstrAssignmetContext extends SubstitutionsContext {
return this.getToken(CircomParser.RIGHT_CONSTRAINT, 0);
}
public enterRule(listener: CircomParserListener): void {
if (listener.enterSubsRightConstrAssignmet) {
listener.enterSubsRightConstrAssignmet(this);
if (listener.enterSubsRightConstrAssignment) {
listener.enterSubsRightConstrAssignment(this);
}
}
public exitRule(listener: CircomParserListener): void {
if (listener.exitSubsRightConstrAssignmet) {
listener.exitSubsRightConstrAssignmet(this);
if (listener.exitSubsRightConstrAssignment) {
listener.exitSubsRightConstrAssignment(this);
}
}
// @Override
public accept<Result>(visitor: CircomParserVisitor<Result>): Result {
if (visitor.visitSubsRightConstrAssignmet) {
return visitor.visitSubsRightConstrAssignmet(this);
if (visitor.visitSubsRightConstrAssignment) {
return visitor.visitSubsRightConstrAssignment(this);
} else {
return visitor.visitChildren(this);
}
}
}
export class SubsInvalidIcnDecOperationContext extends SubstitutionsContext {
export class SubsRightSimpleAssignmentContext extends SubstitutionsContext {
public _lhs!: ExpressionContext;
public _op!: Token;
public _variable!: ExpressionContext;
constructor(parser: CircomParser, ctx: SubstitutionsContext) {
super(parser, ctx.parentCtx, ctx.invokingState);
super.copyFrom(ctx);
}
public SELF_OP(): TerminalNode {
return this.getToken(CircomParser.SELF_OP, 0);
public expression_list(): ExpressionContext[] {
return this.getTypedRuleContexts(ExpressionContext) as ExpressionContext[];
}
public identifierStatement(): IdentifierStatementContext {
return this.getTypedRuleContext(
IdentifierStatementContext,
0,
) as IdentifierStatementContext;
public expression(i: number): ExpressionContext {
return this.getTypedRuleContext(ExpressionContext, i) as ExpressionContext;
}
public RIGHT_ASSIGNMENT(): TerminalNode {
return this.getToken(CircomParser.RIGHT_ASSIGNMENT, 0);
}
public enterRule(listener: CircomParserListener): void {
if (listener.enterSubsInvalidIcnDecOperation) {
listener.enterSubsInvalidIcnDecOperation(this);
if (listener.enterSubsRightSimpleAssignment) {
listener.enterSubsRightSimpleAssignment(this);
}
}
public exitRule(listener: CircomParserListener): void {
if (listener.exitSubsInvalidIcnDecOperation) {
listener.exitSubsInvalidIcnDecOperation(this);
if (listener.exitSubsRightSimpleAssignment) {
listener.exitSubsRightSimpleAssignment(this);
}
}
// @Override
public accept<Result>(visitor: CircomParserVisitor<Result>): Result {
if (visitor.visitSubsInvalidIcnDecOperation) {
return visitor.visitSubsInvalidIcnDecOperation(this);
if (visitor.visitSubsRightSimpleAssignment) {
return visitor.visitSubsRightSimpleAssignment(this);
} else {
return visitor.visitChildren(this);
}
}
}
export class SubsRightSimpleAssignmetContext extends SubstitutionsContext {
public _lhs!: ExpressionContext;
public _op!: Token;
public _variable!: ExpressionContext;
export class SubsInvalidIcnDecOperationContext extends SubstitutionsContext {
constructor(parser: CircomParser, ctx: SubstitutionsContext) {
super(parser, ctx.parentCtx, ctx.invokingState);
super.copyFrom(ctx);
}
public expression_list(): ExpressionContext[] {
return this.getTypedRuleContexts(ExpressionContext) as ExpressionContext[];
}
public expression(i: number): ExpressionContext {
return this.getTypedRuleContext(ExpressionContext, i) as ExpressionContext;
public SELF_OP(): TerminalNode {
return this.getToken(CircomParser.SELF_OP, 0);
}
public RIGHT_ASSIGNMENT(): TerminalNode {
return this.getToken(CircomParser.RIGHT_ASSIGNMENT, 0);
public identifierStatement(): IdentifierStatementContext {
return this.getTypedRuleContext(
IdentifierStatementContext,
0,
) as IdentifierStatementContext;
}
public enterRule(listener: CircomParserListener): void {
if (listener.enterSubsRightSimpleAssignmet) {
listener.enterSubsRightSimpleAssignmet(this);
if (listener.enterSubsInvalidIcnDecOperation) {
listener.enterSubsInvalidIcnDecOperation(this);
}
}
public exitRule(listener: CircomParserListener): void {
if (listener.exitSubsRightSimpleAssignmet) {
listener.exitSubsRightSimpleAssignmet(this);
if (listener.exitSubsInvalidIcnDecOperation) {
listener.exitSubsInvalidIcnDecOperation(this);
}
}
// @Override
public accept<Result>(visitor: CircomParserVisitor<Result>): Result {
if (visitor.visitSubsRightSimpleAssignmet) {
return visitor.visitSubsRightSimpleAssignmet(this);
if (visitor.visitSubsInvalidIcnDecOperation) {
return visitor.visitSubsInvalidIcnDecOperation(this);
} else {
return visitor.visitChildren(this);
}
}
}
export class SubsAssignmetWithOperationContext extends SubstitutionsContext {
export class SubsAssignmentWithOperationContext extends SubstitutionsContext {
public _op!: Token;
public _rhs!: ExpressionContext;
constructor(parser: CircomParser, ctx: SubstitutionsContext) {
Expand All @@ -5583,19 +5583,19 @@ export class SubsAssignmetWithOperationContext extends SubstitutionsContext {
return this.getTypedRuleContext(ExpressionContext, 0) as ExpressionContext;
}
public enterRule(listener: CircomParserListener): void {
if (listener.enterSubsAssignmetWithOperation) {
listener.enterSubsAssignmetWithOperation(this);
if (listener.enterSubsAssignmentWithOperation) {
listener.enterSubsAssignmentWithOperation(this);
}
}
public exitRule(listener: CircomParserListener): void {
if (listener.exitSubsAssignmetWithOperation) {
listener.exitSubsAssignmetWithOperation(this);
if (listener.exitSubsAssignmentWithOperation) {
listener.exitSubsAssignmentWithOperation(this);
}
}
// @Override
public accept<Result>(visitor: CircomParserVisitor<Result>): Result {
if (visitor.visitSubsAssignmetWithOperation) {
return visitor.visitSubsAssignmetWithOperation(this);
if (visitor.visitSubsAssignmentWithOperation) {
return visitor.visitSubsAssignmentWithOperation(this);
} else {
return visitor.visitChildren(this);
}
Expand Down
52 changes: 28 additions & 24 deletions src/generated/CircomParserListener.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ import { RStatementReturnContext } from "./CircomParser";
import { CycleForWithDeclarationContext } from "./CircomParser";
import { CycleForWithoutDeclarationContext } from "./CircomParser";
import { CycleWhileContext } from "./CircomParser";
import { SubsLeftAssignmetContext } from "./CircomParser";
import { SubsRightSimpleAssignmetContext } from "./CircomParser";
import { SubsRightConstrAssignmetContext } from "./CircomParser";
import { SubsAssignmetWithOperationContext } from "./CircomParser";
import { SubsLeftAssignmentContext } from "./CircomParser";
import { SubsRightSimpleAssignmentContext } from "./CircomParser";
import { SubsRightConstrAssignmentContext } from "./CircomParser";
import { SubsAssignmentWithOperationContext } from "./CircomParser";
import { SubsIcnDecOperationContext } from "./CircomParser";
import { SubsInvalidIcnDecOperationContext } from "./CircomParser";
import { ExpressionListContext } from "./CircomParser";
Expand Down Expand Up @@ -479,60 +479,64 @@ export default class CircomParserListener extends ParseTreeListener {
*/
exitCycleWhile?: (ctx: CycleWhileContext) => void;
/**
* Enter a parse tree produced by the `SubsLeftAssignmet`
* Enter a parse tree produced by the `SubsLeftAssignment`
* labeled alternative in `CircomParser.substitutions`.
* @param ctx the parse tree
*/
enterSubsLeftAssignmet?: (ctx: SubsLeftAssignmetContext) => void;
enterSubsLeftAssignment?: (ctx: SubsLeftAssignmentContext) => void;
/**
* Exit a parse tree produced by the `SubsLeftAssignmet`
* Exit a parse tree produced by the `SubsLeftAssignment`
* labeled alternative in `CircomParser.substitutions`.
* @param ctx the parse tree
*/
exitSubsLeftAssignmet?: (ctx: SubsLeftAssignmetContext) => void;
exitSubsLeftAssignment?: (ctx: SubsLeftAssignmentContext) => void;
/**
* Enter a parse tree produced by the `SubsRightSimpleAssignmet`
* Enter a parse tree produced by the `SubsRightSimpleAssignment`
* labeled alternative in `CircomParser.substitutions`.
* @param ctx the parse tree
*/
enterSubsRightSimpleAssignmet?: (
ctx: SubsRightSimpleAssignmetContext,
enterSubsRightSimpleAssignment?: (
ctx: SubsRightSimpleAssignmentContext,
) => void;
/**
* Exit a parse tree produced by the `SubsRightSimpleAssignmet`
* Exit a parse tree produced by the `SubsRightSimpleAssignment`
* labeled alternative in `CircomParser.substitutions`.
* @param ctx the parse tree
*/
exitSubsRightSimpleAssignmet?: (ctx: SubsRightSimpleAssignmetContext) => void;
exitSubsRightSimpleAssignment?: (
ctx: SubsRightSimpleAssignmentContext,
) => void;
/**
* Enter a parse tree produced by the `SubsRightConstrAssignmet`
* Enter a parse tree produced by the `SubsRightConstrAssignment`
* labeled alternative in `CircomParser.substitutions`.
* @param ctx the parse tree
*/
enterSubsRightConstrAssignmet?: (
ctx: SubsRightConstrAssignmetContext,
enterSubsRightConstrAssignment?: (
ctx: SubsRightConstrAssignmentContext,
) => void;
/**
* Exit a parse tree produced by the `SubsRightConstrAssignmet`
* Exit a parse tree produced by the `SubsRightConstrAssignment`
* labeled alternative in `CircomParser.substitutions`.
* @param ctx the parse tree
*/
exitSubsRightConstrAssignmet?: (ctx: SubsRightConstrAssignmetContext) => void;
exitSubsRightConstrAssignment?: (
ctx: SubsRightConstrAssignmentContext,
) => void;
/**
* Enter a parse tree produced by the `SubsAssignmetWithOperation`
* Enter a parse tree produced by the `SubsAssignmentWithOperation`
* labeled alternative in `CircomParser.substitutions`.
* @param ctx the parse tree
*/
enterSubsAssignmetWithOperation?: (
ctx: SubsAssignmetWithOperationContext,
enterSubsAssignmentWithOperation?: (
ctx: SubsAssignmentWithOperationContext,
) => void;
/**
* Exit a parse tree produced by the `SubsAssignmetWithOperation`
* Exit a parse tree produced by the `SubsAssignmentWithOperation`
* labeled alternative in `CircomParser.substitutions`.
* @param ctx the parse tree
*/
exitSubsAssignmetWithOperation?: (
ctx: SubsAssignmetWithOperationContext,
exitSubsAssignmentWithOperation?: (
ctx: SubsAssignmentWithOperationContext,
) => void;
/**
* Enter a parse tree produced by the `SubsIcnDecOperation`
Expand Down
Loading

0 comments on commit c81eef1

Please sign in to comment.