Skip to content

Instantly share code, notes, and snippets.

@NN---
Created November 15, 2012 14:09
Show Gist options
  • Save NN---/4078790 to your computer and use it in GitHub Desktop.
Save NN---/4078790 to your computer and use it in GitHub Desktop.
// Calculator.CalcParser
private mutable mutable __GENERATED_PEG__Memeoize_Pos__start__ : int
// Calculator.CalcParser
private mutable mutable __GENERATED_PEG__Memeoize_End__start__ : int
// Calculator.CalcParser
private mutable mutable __GENERATED_PEG__Memeoize_Res__start__ : int
// Calculator.CalcParser
private mutable mutable __GENERATED_PEG__MaxRollback___start__ : int
// Calculator.CalcParser
private __GENERATED_PEG__RULE__start__(pos : int, text : string, result : ref int) : int
{
unchecked
{
mutable (c : char);
_ = c;
{
_ = "CaptureH[start](CaptureA[(Void, int)](CaptureA[(Void, int)](CaptureA[Void](spaces) CaptureA[int](mainRule) !any)))";
{
mutable token_1;
if (__GENERATED_PEG__Memeoize_Pos__start__ == pos)
{
when (__GENERATED_PEG__Memeoize_End__start__ >= 0) result = __GENERATED_PEG__Memeoize_Res__start__;
__GENERATED_PEG__Memeoize_End__start__
}; else
{
def newPos =
{
_ = "CaptureA[(Void, int)](CaptureA[Void](spaces) CaptureA[int](mainRule) !any)";
(res :
{
_ = "CaptureA[Void](spaces) CaptureA[int](mainRule) !any";
{
def pos =
{
_ = "spaces";
__GENERATED_PEG__RULE__spaces__(pos, text)
};
if (pos >= 0)
{
def pos =
{
_ = "mainRule";
__GENERATED_PEG__RULE__mainRule__(pos, text, ref token_1)
};
if (pos >= 0)
{
_ = "!any";
{
def newPos =
{
_ = "any";
__GENERATED_PEG__RULE__any__(pos, text)
};
if (newPos < 0) pos; else -1
}
}; else -1
}; else -1
}
})
};
__GENERATED_PEG__Memeoize_Pos__start__ = pos;
__GENERATED_PEG__Memeoize_End__start__ = newPos;
if (newPos >= 0)
{
result = start(token_1);
();
__GENERATED_PEG__Memeoize_Res__start__ = result
}; else when (__GENERATED_PEG__MaxRollback___start__ < pos) __GENERATED_PEG__MaxRollback___start__ = pos;
newPos
}
}
}
}
}
// Calculator.CalcParser
private __GENERATED_PEG__RULE__any__(pos : int, text : string) : int
{
unchecked
{
mutable (c : char);
_ = c;
{
_ = "['\\0'.. char.MaxValue]";
(res :
{
_ = "['\\0'.. char.MaxValue]";
{
_ = "['\\0'.. char.MaxValue]";
if (pos < text.Length) pos + 1; else -1
}
})
}
}
}
// Calculator.CalcParser
private mutable mutable __GENERATED_PEG__Memeoize_Pos__mainRule__ : int
// Calculator.CalcParser
private mutable mutable __GENERATED_PEG__Memeoize_End__mainRule__ : int
// Calculator.CalcParser
private mutable mutable __GENERATED_PEG__Memeoize_Res__mainRule__ : int
// Calculator.CalcParser
private mutable mutable __GENERATED_PEG__MaxRollback___mainRule__ : int
// Calculator.CalcParser
private __GENERATED_PEG__RULE__mainRule__(pos : int, text : string, result : ref int) : int
{
unchecked
{
mutable (c : char);
_ = c;
{
_ = "CaptureH[mainRule](CaptureA[(int, int?)](CaptureA[(int, int?)](CaptureA[int](sumOrSub) CaptureA[int?](CaptureA[int](inputError)?))))";
{
mutable token_1;
mutable token_2;
if (__GENERATED_PEG__Memeoize_Pos__mainRule__ == pos)
{
when (__GENERATED_PEG__Memeoize_End__mainRule__ >= 0) result = __GENERATED_PEG__Memeoize_Res__mainRule__;
__GENERATED_PEG__Memeoize_End__mainRule__
}; else
{
def newPos =
{
_ = "CaptureA[(int, int?)](CaptureA[int](sumOrSub) CaptureA[int?](CaptureA[int](inputError)?))";
(res :
{
_ = "CaptureA[int](sumOrSub) CaptureA[int?](CaptureA[int](inputError)?)";
{
def pos =
{
_ = "sumOrSub";
__GENERATED_PEG__RULE__sumOrSub__(pos, text, ref token_1)
};
if (pos >= 0)
{
_ = "CaptureA[int](inputError)?";
{
();
mutable token_3;
def newPos =
{
_ = "inputError";
__GENERATED_PEG__RULE__inputError__(pos, text, ref token_3)
};
if (newPos >= 0)
{
token_2 = Some(token_3);
newPos
}; else
{
token_2 = None();
pos
}
}
}; else -1
}
})
};
__GENERATED_PEG__Memeoize_Pos__mainRule__ = pos;
__GENERATED_PEG__Memeoize_End__mainRule__ = newPos;
if (newPos >= 0)
{
result = mainRule(token_1, token_2);
();
__GENERATED_PEG__Memeoize_Res__mainRule__ = result
}; else when (__GENERATED_PEG__MaxRollback___mainRule__ < pos) __GENERATED_PEG__MaxRollback___mainRule__ = pos;
newPos
}
}
}
}
}
// Calculator.CalcParser
private mutable mutable __GENERATED_PEG__Memeoize_Pos__inputError__ : int
// Calculator.CalcParser
private mutable mutable __GENERATED_PEG__Memeoize_End__inputError__ : int
// Calculator.CalcParser
private mutable mutable __GENERATED_PEG__Memeoize_Res__inputError__ : int
// Calculator.CalcParser
private mutable mutable __GENERATED_PEG__MaxRollback___inputError__ : int
// Calculator.CalcParser
private __GENERATED_PEG__RULE__inputError__(pos : int, text : string, result : ref int) : int
{
unchecked
{
mutable (c : char);
_ = c;
{
_ = "CaptureH[inputError](CaptureA[Chars](any))";
{
mutable token_1;
if (__GENERATED_PEG__Memeoize_Pos__inputError__ == pos)
{
when (__GENERATED_PEG__Memeoize_End__inputError__ >= 0) result = __GENERATED_PEG__Memeoize_Res__inputError__;
__GENERATED_PEG__Memeoize_End__inputError__
}; else
{
def newPos =
{
def newPos =
{
_ = "any";
(res :
{
_ = "any";
__GENERATED_PEG__RULE__any__(pos, text)
})
};
when (newPos >= 0) token_1 = Nemerle.Peg.NToken(pos, newPos);
newPos
};
__GENERATED_PEG__Memeoize_Pos__inputError__ = pos;
__GENERATED_PEG__Memeoize_End__inputError__ = newPos;
if (newPos >= 0)
{
result = inputError(token_1);
();
__GENERATED_PEG__Memeoize_Res__inputError__ = result
}; else when (__GENERATED_PEG__MaxRollback___inputError__ < pos) __GENERATED_PEG__MaxRollback___inputError__ = pos;
newPos
}
}
}
}
}
// Calculator.CalcParser
private mutable mutable __GENERATED_PEG__Memeoize_Pos__sumOrSub__ : int
// Calculator.CalcParser
private mutable mutable __GENERATED_PEG__Memeoize_End__sumOrSub__ : int
// Calculator.CalcParser
private mutable mutable __GENERATED_PEG__Memeoize_Res__sumOrSub__ : int
// Calculator.CalcParser
private mutable mutable __GENERATED_PEG__MaxRollback___sumOrSub__ : int
// Calculator.CalcParser
private __GENERATED_PEG__RULE__sumOrSub__(pos : int, text : string, result : ref int) : int
{
unchecked
{
mutable (c : char);
_ = c;
{
_ = "CaptureH[sumOrSub](CaptureA[(int, List[(Chars, Void, int)])](CaptureA[(int, List[(Chars, Void, int)])](CaptureA[int](mulOrDiv) CaptureA[List[(Chars, Void, int)]](CaptureA[(Chars, Void, int)](CaptureA[(Chars, Void, int)](CaptureA[Chars]('+' / '-') CaptureA[Void](spaces) CaptureA[int](mulOrDiv)))*))))";
{
mutable token_1;
mutable token_2;
if (__GENERATED_PEG__Memeoize_Pos__sumOrSub__ == pos)
{
when (__GENERATED_PEG__Memeoize_End__sumOrSub__ >= 0) result = __GENERATED_PEG__Memeoize_Res__sumOrSub__;
__GENERATED_PEG__Memeoize_End__sumOrSub__
}; else
{
def newPos =
{
_ = "CaptureA[(int, List[(Chars, Void, int)])](CaptureA[int](mulOrDiv) CaptureA[List[(Chars, Void, int)]](CaptureA[(Chars, Void, int)](CaptureA[(Chars, Void, int)](CaptureA[Chars]('+' / '-') CaptureA[Void](spaces) CaptureA[int](mulOrDiv)))*))";
(res :
{
_ = "CaptureA[int](mulOrDiv) CaptureA[List[(Chars, Void, int)]](CaptureA[(Chars, Void, int)](CaptureA[(Chars, Void, int)](CaptureA[Chars]('+' / '-') CaptureA[Void](spaces) CaptureA[int](mulOrDiv)))*)";
{
def pos =
{
_ = "mulOrDiv";
__GENERATED_PEG__RULE__mulOrDiv__(pos, text, ref token_1)
};
if (pos >= 0)
{
_ = "CaptureA[(Chars, Void, int)](CaptureA[(Chars, Void, int)](CaptureA[Chars]('+' / '-') CaptureA[Void](spaces) CaptureA[int](mulOrDiv)))*";
{
token_2 = SCG.List();
mutable token_3;
mutable token_4;
def rep (pos : int)
{
def newPos =
{
_ = "CaptureA[(Chars, Void, int)](CaptureA[Chars]('+' / '-') CaptureA[Void](spaces) CaptureA[int](mulOrDiv))";
(res :
{
_ = "CaptureA[Chars]('+' / '-') CaptureA[Void](spaces) CaptureA[int](mulOrDiv)";
{
def pos =
{
def newPos =
{
_ = "'+' / '-'";
(res :
{
def newPos =
{
_ = "'+'";
if (pos < text.Length)
{
c = text[pos];
if (c == '+') pos + 1; else -1
}; else -1
};
when (newPos >= 0) res(newPos);
_ = "'-'";
if (pos < text.Length)
{
c = text[pos];
if (c == '-') pos + 1; else -1
}; else -1
})
};
when (newPos >= 0) token_3 = Nemerle.Peg.NToken(pos, newPos);
newPos
};
if (pos >= 0)
{
def pos =
{
_ = "spaces";
__GENERATED_PEG__RULE__spaces__(pos, text)
};
if (pos >= 0)
{
_ = "mulOrDiv";
__GENERATED_PEG__RULE__mulOrDiv__(pos, text, ref token_4)
}; else -1
}; else -1
}
})
};
if (newPos >= 0)
{
token_2.Add(token_3, token_4);
rep(newPos)
}; else pos
};
rep(pos)
}
}; else -1
}
})
};
__GENERATED_PEG__Memeoize_Pos__sumOrSub__ = pos;
__GENERATED_PEG__Memeoize_End__sumOrSub__ = newPos;
if (newPos >= 0)
{
result = sumOrSub(token_1, token_2);
();
__GENERATED_PEG__Memeoize_Res__sumOrSub__ = result
}; else when (__GENERATED_PEG__MaxRollback___sumOrSub__ < pos) __GENERATED_PEG__MaxRollback___sumOrSub__ = pos;
newPos
}
}
}
}
}
// Calculator.CalcParser
private mutable mutable __GENERATED_PEG__Memeoize_Pos__mulOrDiv__ : int
// Calculator.CalcParser
private mutable mutable __GENERATED_PEG__Memeoize_End__mulOrDiv__ : int
// Calculator.CalcParser
private mutable mutable __GENERATED_PEG__Memeoize_Res__mulOrDiv__ : int
// Calculator.CalcParser
private mutable mutable __GENERATED_PEG__MaxRollback___mulOrDiv__ : int
// Calculator.CalcParser
private __GENERATED_PEG__RULE__mulOrDiv__(pos : int, text : string, result : ref int) : int
{
unchecked
{
mutable (c : char);
_ = c;
{
_ = "CaptureH[mulOrDiv](CaptureA[(int, List[(Chars, Void, int)])](CaptureA[(int, List[(Chars, Void, int)])](CaptureA[int](simplExpr) CaptureA[List[(Chars, Void, int)]](CaptureA[(Chars, Void, int)](CaptureA[(Chars, Void, int)](CaptureA[Chars]('*' / '/') CaptureA[Void](spaces) CaptureA[int](simplExpr)))*))))";
{
mutable token_1;
mutable token_2;
if (__GENERATED_PEG__Memeoize_Pos__mulOrDiv__ == pos)
{
when (__GENERATED_PEG__Memeoize_End__mulOrDiv__ >= 0) result = __GENERATED_PEG__Memeoize_Res__mulOrDiv__;
__GENERATED_PEG__Memeoize_End__mulOrDiv__
}; else
{
def newPos =
{
_ = "CaptureA[(int, List[(Chars, Void, int)])](CaptureA[int](simplExpr) CaptureA[List[(Chars, Void, int)]](CaptureA[(Chars, Void, int)](CaptureA[(Chars, Void, int)](CaptureA[Chars]('*' / '/') CaptureA[Void](spaces) CaptureA[int](simplExpr)))*))";
(res :
{
_ = "CaptureA[int](simplExpr) CaptureA[List[(Chars, Void, int)]](CaptureA[(Chars, Void, int)](CaptureA[(Chars, Void, int)](CaptureA[Chars]('*' / '/') CaptureA[Void](spaces) CaptureA[int](simplExpr)))*)";
{
def pos =
{
_ = "simplExpr";
__GENERATED_PEG__RULE__simplExpr__(pos, text, ref token_1)
};
if (pos >= 0)
{
_ = "CaptureA[(Chars, Void, int)](CaptureA[(Chars, Void, int)](CaptureA[Chars]('*' / '/') CaptureA[Void](spaces) CaptureA[int](simplExpr)))*";
{
token_2 = SCG.List();
mutable token_3;
mutable token_4;
def rep (pos : int)
{
def newPos =
{
_ = "CaptureA[(Chars, Void, int)](CaptureA[Chars]('*' / '/') CaptureA[Void](spaces) CaptureA[int](simplExpr))";
(res :
{
_ = "CaptureA[Chars]('*' / '/') CaptureA[Void](spaces) CaptureA[int](simplExpr)";
{
def pos =
{
def newPos =
{
_ = "'*' / '/'";
(res :
{
def newPos =
{
_ = "'*'";
if (pos < text.Length)
{
c = text[pos];
if (c == '*') pos + 1; else -1
}; else -1
};
when (newPos >= 0) res(newPos);
_ = "'/'";
if (pos < text.Length)
{
c = text[pos];
if (c == '/') pos + 1; else -1
}; else -1
})
};
when (newPos >= 0) token_3 = Nemerle.Peg.NToken(pos, newPos);
newPos
};
if (pos >= 0)
{
def pos =
{
_ = "spaces";
__GENERATED_PEG__RULE__spaces__(pos, text)
};
if (pos >= 0)
{
_ = "simplExpr";
__GENERATED_PEG__RULE__simplExpr__(pos, text, ref token_4)
}; else -1
}; else -1
}
})
};
if (newPos >= 0)
{
token_2.Add(token_3, token_4);
rep(newPos)
}; else pos
};
rep(pos)
}
}; else -1
}
})
};
__GENERATED_PEG__Memeoize_Pos__mulOrDiv__ = pos;
__GENERATED_PEG__Memeoize_End__mulOrDiv__ = newPos;
if (newPos >= 0)
{
result = mulOrDiv(token_1, token_2);
();
__GENERATED_PEG__Memeoize_Res__mulOrDiv__ = result
}; else when (__GENERATED_PEG__MaxRollback___mulOrDiv__ < pos) __GENERATED_PEG__MaxRollback___mulOrDiv__ = pos;
newPos
}
}
}
}
}
// Calculator.CalcParser
private mutable mutable __GENERATED_PEG__Memeoize_Pos__simplExpr__ : int
// Calculator.CalcParser
private mutable mutable __GENERATED_PEG__Memeoize_End__simplExpr__ : int
// Calculator.CalcParser
private mutable mutable __GENERATED_PEG__Memeoize_Res__simplExpr__ : int
// Calculator.CalcParser
private mutable mutable __GENERATED_PEG__MaxRollback___simplExpr__ : int
// Calculator.CalcParser
private __GENERATED_PEG__RULE__simplExpr__(pos : int, text : string, result : ref int) : int
{
unchecked
{
mutable (c : char);
_ = c;
{
_ = "CaptureH[simplExpr](CaptureA[int](CaptureA[int](num) / CaptureA[int](parenthesesExpr) / CaptureA[int](unaryMinus) / CaptureA[int](parenthesesExprError) / CaptureA[int](simplExprError)))";
{
mutable token_1;
if (__GENERATED_PEG__Memeoize_Pos__simplExpr__ == pos)
{
when (__GENERATED_PEG__Memeoize_End__simplExpr__ >= 0) result = __GENERATED_PEG__Memeoize_Res__simplExpr__;
__GENERATED_PEG__Memeoize_End__simplExpr__
}; else
{
def newPos =
{
_ = "CaptureA[int](num) / CaptureA[int](parenthesesExpr) / CaptureA[int](unaryMinus) / CaptureA[int](parenthesesExprError) / CaptureA[int](simplExprError)";
(res :
{
def newPos =
{
_ = "num";
__GENERATED_PEG__RULE__num__(pos, text, ref token_1)
};
when (newPos >= 0) res(newPos);
def newPos =
{
_ = "parenthesesExpr";
__GENERATED_PEG__RULE__parenthesesExpr__(pos, text, ref token_1)
};
when (newPos >= 0) res(newPos);
def newPos =
{
_ = "unaryMinus";
__GENERATED_PEG__RULE__unaryMinus__(pos, text, ref token_1)
};
when (newPos >= 0) res(newPos);
def newPos =
{
_ = "parenthesesExprError";
__GENERATED_PEG__RULE__parenthesesExprError__(pos, text, ref token_1)
};
when (newPos >= 0) res(newPos);
_ = "simplExprError";
__GENERATED_PEG__RULE__simplExprError__(pos, text, ref token_1)
})
};
__GENERATED_PEG__Memeoize_Pos__simplExpr__ = pos;
__GENERATED_PEG__Memeoize_End__simplExpr__ = newPos;
if (newPos >= 0)
{
result = simplExpr(token_1);
();
__GENERATED_PEG__Memeoize_Res__simplExpr__ = result
}; else when (__GENERATED_PEG__MaxRollback___simplExpr__ < pos) __GENERATED_PEG__MaxRollback___simplExpr__ = pos;
newPos
}
}
}
}
}
// Calculator.CalcParser
private mutable mutable __GENERATED_PEG__Memeoize_Pos__simplExprError__ : int
// Calculator.CalcParser
private mutable mutable __GENERATED_PEG__Memeoize_End__simplExprError__ : int
// Calculator.CalcParser
private mutable mutable __GENERATED_PEG__Memeoize_Res__simplExprError__ : int
// Calculator.CalcParser
private mutable mutable __GENERATED_PEG__MaxRollback___simplExprError__ : int
// Calculator.CalcParser
private __GENERATED_PEG__RULE__simplExprError__(pos : int, text : string, result : ref int) : int
{
unchecked
{
mutable (c : char);
_ = c;
{
_ = "CaptureH[simplExprError](CaptureA[Chars](any))";
{
mutable token_1;
if (__GENERATED_PEG__Memeoize_Pos__simplExprError__ == pos)
{
when (__GENERATED_PEG__Memeoize_End__simplExprError__ >= 0) result = __GENERATED_PEG__Memeoize_Res__simplExprError__;
__GENERATED_PEG__Memeoize_End__simplExprError__
}; else
{
def newPos =
{
def newPos =
{
_ = "any";
(res :
{
_ = "any";
__GENERATED_PEG__RULE__any__(pos, text)
})
};
when (newPos >= 0) token_1 = Nemerle.Peg.NToken(pos, newPos);
newPos
};
__GENERATED_PEG__Memeoize_Pos__simplExprError__ = pos;
__GENERATED_PEG__Memeoize_End__simplExprError__ = newPos;
if (newPos >= 0)
{
result = simplExprError(token_1);
();
__GENERATED_PEG__Memeoize_Res__simplExprError__ = result
}; else when (__GENERATED_PEG__MaxRollback___simplExprError__ < pos) __GENERATED_PEG__MaxRollback___simplExprError__ = pos;
newPos
}
}
}
}
}
// Calculator.CalcParser
private mutable mutable __GENERATED_PEG__Memeoize_Pos__parenthesesExprError__ : int
// Calculator.CalcParser
private mutable mutable __GENERATED_PEG__Memeoize_End__parenthesesExprError__ : int
// Calculator.CalcParser
private mutable mutable __GENERATED_PEG__Memeoize_Res__parenthesesExprError__ : int
// Calculator.CalcParser
private mutable mutable __GENERATED_PEG__MaxRollback___parenthesesExprError__ : int
// Calculator.CalcParser
private __GENERATED_PEG__RULE__parenthesesExprError__(pos : int, text : string, result : ref int) : int
{
unchecked
{
mutable (c : char);
_ = c;
{
_ = "CaptureH[parenthesesExprError](CaptureA[(Chars, Void, int)](CaptureA[(Chars, Void, int)](CaptureA[Chars]('(') CaptureA[Void](spaces) CaptureA[int](sumOrSub) CaptureA[None](&any / !any))))";
{
mutable token_1;
mutable token_2;
if (__GENERATED_PEG__Memeoize_Pos__parenthesesExprError__ == pos)
{
when (__GENERATED_PEG__Memeoize_End__parenthesesExprError__ >= 0) result = __GENERATED_PEG__Memeoize_Res__parenthesesExprError__;
__GENERATED_PEG__Memeoize_End__parenthesesExprError__
}; else
{
def newPos =
{
_ = "CaptureA[(Chars, Void, int)](CaptureA[Chars]('(') CaptureA[Void](spaces) CaptureA[int](sumOrSub) CaptureA[None](&any / !any))";
(res :
{
_ = "CaptureA[Chars]('(') CaptureA[Void](spaces) CaptureA[int](sumOrSub) CaptureA[None](&any / !any)";
{
def pos =
{
def newPos =
{
_ = "'('";
if (pos < text.Length)
{
c = text[pos];
if (c == '(') pos + 1; else -1
}; else -1
};
when (newPos >= 0) token_1 = Nemerle.Peg.NToken(pos, newPos);
newPos
};
if (pos >= 0)
{
def pos =
{
_ = "spaces";
__GENERATED_PEG__RULE__spaces__(pos, text)
};
if (pos >= 0)
{
def pos =
{
_ = "sumOrSub";
__GENERATED_PEG__RULE__sumOrSub__(pos, text, ref token_2)
};
if (pos >= 0)
{
_ = "&any / !any";
(res :
{
def newPos =
{
_ = "&any";
{
def newPos =
{
_ = "any";
__GENERATED_PEG__RULE__any__(pos, text)
};
if (newPos >= 0) pos; else -1
}
};
when (newPos >= 0) res(newPos);
_ = "!any";
{
def newPos =
{
_ = "any";
__GENERATED_PEG__RULE__any__(pos, text)
};
if (newPos < 0) pos; else -1
}
})
}; else -1
}; else -1
}; else -1
}
})
};
__GENERATED_PEG__Memeoize_Pos__parenthesesExprError__ = pos;
__GENERATED_PEG__Memeoize_End__parenthesesExprError__ = newPos;
if (newPos >= 0)
{
result = parenthesesExprError(token_1, token_2);
();
__GENERATED_PEG__Memeoize_Res__parenthesesExprError__ = result
}; else when (__GENERATED_PEG__MaxRollback___parenthesesExprError__ < pos) __GENERATED_PEG__MaxRollback___parenthesesExprError__ = pos;
newPos
}
}
}
}
}
// Calculator.CalcParser
private mutable mutable __GENERATED_PEG__Memeoize_Pos__unaryMinus__ : int
// Calculator.CalcParser
private mutable mutable __GENERATED_PEG__Memeoize_End__unaryMinus__ : int
// Calculator.CalcParser
private mutable mutable __GENERATED_PEG__Memeoize_Res__unaryMinus__ : int
// Calculator.CalcParser
private mutable mutable __GENERATED_PEG__MaxRollback___unaryMinus__ : int
// Calculator.CalcParser
private __GENERATED_PEG__RULE__unaryMinus__(pos : int, text : string, result : ref int) : int
{
unchecked
{
mutable (c : char);
_ = c;
{
_ = "CaptureH[unaryMinus](CaptureA[(Chars, Void, int)](CaptureA[(Chars, Void, int)](CaptureA[Chars]('-') CaptureA[Void](spaces) CaptureA[int](simplExpr))))";
{
mutable token_1;
mutable token_2;
if (__GENERATED_PEG__Memeoize_Pos__unaryMinus__ == pos)
{
when (__GENERATED_PEG__Memeoize_End__unaryMinus__ >= 0) result = __GENERATED_PEG__Memeoize_Res__unaryMinus__;
__GENERATED_PEG__Memeoize_End__unaryMinus__
}; else
{
def newPos =
{
_ = "CaptureA[(Chars, Void, int)](CaptureA[Chars]('-') CaptureA[Void](spaces) CaptureA[int](simplExpr))";
(res :
{
_ = "CaptureA[Chars]('-') CaptureA[Void](spaces) CaptureA[int](simplExpr)";
{
def pos =
{
def newPos =
{
_ = "'-'";
if (pos < text.Length)
{
c = text[pos];
if (c == '-') pos + 1; else -1
}; else -1
};
when (newPos >= 0) token_1 = Nemerle.Peg.NToken(pos, newPos);
newPos
};
if (pos >= 0)
{
def pos =
{
_ = "spaces";
__GENERATED_PEG__RULE__spaces__(pos, text)
};
if (pos >= 0)
{
_ = "simplExpr";
__GENERATED_PEG__RULE__simplExpr__(pos, text, ref token_2)
}; else -1
}; else -1
}
})
};
__GENERATED_PEG__Memeoize_Pos__unaryMinus__ = pos;
__GENERATED_PEG__Memeoize_End__unaryMinus__ = newPos;
if (newPos >= 0)
{
result = unaryMinus(token_1, token_2);
();
__GENERATED_PEG__Memeoize_Res__unaryMinus__ = result
}; else when (__GENERATED_PEG__MaxRollback___unaryMinus__ < pos) __GENERATED_PEG__MaxRollback___unaryMinus__ = pos;
newPos
}
}
}
}
}
// Calculator.CalcParser
private mutable mutable __GENERATED_PEG__Memeoize_Pos__parenthesesExpr__ : int
// Calculator.CalcParser
private mutable mutable __GENERATED_PEG__Memeoize_End__parenthesesExpr__ : int
// Calculator.CalcParser
private mutable mutable __GENERATED_PEG__Memeoize_Res__parenthesesExpr__ : int
// Calculator.CalcParser
private mutable mutable __GENERATED_PEG__MaxRollback___parenthesesExpr__ : int
// Calculator.CalcParser
private __GENERATED_PEG__RULE__parenthesesExpr__(pos : int, text : string, result : ref int) : int
{
unchecked
{
mutable (c : char);
_ = c;
{
_ = "CaptureH[parenthesesExpr](CaptureA[(Chars, Void, int, Chars, Void)](CaptureA[(Chars, Void, int, Chars, Void)](CaptureA[Chars]('(') CaptureA[Void](spaces) CaptureA[int](sumOrSub) CaptureA[Chars](')') CaptureA[Void](spaces))))";
{
mutable token_1;
mutable token_2;
mutable token_3;
if (__GENERATED_PEG__Memeoize_Pos__parenthesesExpr__ == pos)
{
when (__GENERATED_PEG__Memeoize_End__parenthesesExpr__ >= 0) result = __GENERATED_PEG__Memeoize_Res__parenthesesExpr__;
__GENERATED_PEG__Memeoize_End__parenthesesExpr__
}; else
{
def newPos =
{
_ = "CaptureA[(Chars, Void, int, Chars, Void)](CaptureA[Chars]('(') CaptureA[Void](spaces) CaptureA[int](sumOrSub) CaptureA[Chars](')') CaptureA[Void](spaces))";
(res :
{
_ = "CaptureA[Chars]('(') CaptureA[Void](spaces) CaptureA[int](sumOrSub) CaptureA[Chars](')') CaptureA[Void](spaces)";
{
def pos =
{
def newPos =
{
_ = "'('";
if (pos < text.Length)
{
c = text[pos];
if (c == '(') pos + 1; else -1
}; else -1
};
when (newPos >= 0) token_1 = Nemerle.Peg.NToken(pos, newPos);
newPos
};
if (pos >= 0)
{
def pos =
{
_ = "spaces";
__GENERATED_PEG__RULE__spaces__(pos, text)
};
if (pos >= 0)
{
def pos =
{
_ = "sumOrSub";
__GENERATED_PEG__RULE__sumOrSub__(pos, text, ref token_2)
};
if (pos >= 0)
{
def pos =
{
def newPos =
{
_ = "')'";
if (pos < text.Length)
{
c = text[pos];
if (c == ')') pos + 1; else -1
}; else -1
};
when (newPos >= 0) token_3 = Nemerle.Peg.NToken(pos, newPos);
newPos
};
if (pos >= 0)
{
_ = "spaces";
__GENERATED_PEG__RULE__spaces__(pos, text)
}; else -1
}; else -1
}; else -1
}; else -1
}
})
};
__GENERATED_PEG__Memeoize_Pos__parenthesesExpr__ = pos;
__GENERATED_PEG__Memeoize_End__parenthesesExpr__ = newPos;
if (newPos >= 0)
{
result = parenthesesExpr(token_1, token_2, token_3);
();
__GENERATED_PEG__Memeoize_Res__parenthesesExpr__ = result
}; else when (__GENERATED_PEG__MaxRollback___parenthesesExpr__ < pos) __GENERATED_PEG__MaxRollback___parenthesesExpr__ = pos;
newPos
}
}
}
}
}
// Calculator.CalcParser
private mutable mutable __GENERATED_PEG__Memeoize_Pos__num__ : int
// Calculator.CalcParser
private mutable mutable __GENERATED_PEG__Memeoize_End__num__ : int
// Calculator.CalcParser
private mutable mutable __GENERATED_PEG__Memeoize_Res__num__ : int
// Calculator.CalcParser
private mutable mutable __GENERATED_PEG__MaxRollback___num__ : int
// Calculator.CalcParser
private __GENERATED_PEG__RULE__num__(pos : int, text : string, result : ref int) : int
{
unchecked
{
mutable (c : char);
_ = c;
{
_ = "CaptureH[num](CaptureA[(Chars, Void)](CaptureA[(Chars, Void)](CaptureA[Chars](digit) CaptureA[Void](spaces))))";
{
mutable token_1;
if (__GENERATED_PEG__Memeoize_Pos__num__ == pos)
{
when (__GENERATED_PEG__Memeoize_End__num__ >= 0) result = __GENERATED_PEG__Memeoize_Res__num__;
__GENERATED_PEG__Memeoize_End__num__
}; else
{
def newPos =
{
_ = "CaptureA[(Chars, Void)](CaptureA[Chars](digit) CaptureA[Void](spaces))";
(res :
{
_ = "CaptureA[Chars](digit) CaptureA[Void](spaces)";
{
def pos =
{
def newPos =
{
_ = "digit";
__GENERATED_PEG__RULE__digit__(pos, text)
};
when (newPos >= 0) token_1 = Nemerle.Peg.NToken(pos, newPos);
newPos
};
if (pos >= 0)
{
_ = "spaces";
__GENERATED_PEG__RULE__spaces__(pos, text)
}; else -1
}
})
};
__GENERATED_PEG__Memeoize_Pos__num__ = pos;
__GENERATED_PEG__Memeoize_End__num__ = newPos;
if (newPos >= 0)
{
result = num(token_1);
();
__GENERATED_PEG__Memeoize_Res__num__ = result
}; else when (__GENERATED_PEG__MaxRollback___num__ < pos) __GENERATED_PEG__MaxRollback___num__ = pos;
newPos
}
}
}
}
}
// Calculator.CalcParser
private __GENERATED_PEG__RULE__digit__(pos : int, text : string) : int
{
unchecked
{
mutable (c : char);
_ = c;
{
_ = "['0'..'9']+";
(res :
{
_ = "['0'..'9']+";
{
_ = "['0'..'9']+";
{
def rep (count, pos)
{
def newPos =
{
_ = "['0'..'9']";
if (pos < text.Length)
{
c = text[pos];
if ('0' <= c && c <= '9') pos + 1; else -1
}; else -1
};
if (newPos >= 0)
{
();
rep(count + 1, newPos)
}; else if (count >= 1) pos; else -1
};
rep(0, pos)
}
}
})
}
}
}
// Calculator.CalcParser
private __GENERATED_PEG__RULE__spaces__(pos : int, text : string) : int
{
unchecked
{
mutable (c : char);
_ = c;
{
_ = "' '*";
(res :
{
_ = "' '*";
{
def rep (pos : int)
{
def newPos =
{
_ = "' '";
if (pos < text.Length)
{
c = text[pos];
if (c == ' ') pos + 1; else -1
}; else -1
};
if (newPos >= 0)
{
();
rep(newPos)
}; else pos
};
rep(pos)
}
})
}
}
}
// Calculator.CalcParser
public GetMaxRollbackPosAndIds() : int * System.Collections.Generic.List[int]
{
def ids = System.Collections.Generic.List(42);
mutable max = -1;
{
{
when (max < __GENERATED_PEG__MaxRollback___start__)
{
max = __GENERATED_PEG__MaxRollback___start__;
ids.Clear()
};
when (__GENERATED_PEG__MaxRollback___start__ > 0 && max == __GENERATED_PEG__MaxRollback___start__) ids.Add(13)
};
{
when (max < __GENERATED_PEG__MaxRollback___mainRule__)
{
max = __GENERATED_PEG__MaxRollback___mainRule__;
ids.Clear()
};
when (__GENERATED_PEG__MaxRollback___mainRule__ > 0 && max == __GENERATED_PEG__MaxRollback___mainRule__) ids.Add(12)
};
{
when (max < __GENERATED_PEG__MaxRollback___inputError__)
{
max = __GENERATED_PEG__MaxRollback___inputError__;
ids.Clear()
};
when (__GENERATED_PEG__MaxRollback___inputError__ > 0 && max == __GENERATED_PEG__MaxRollback___inputError__) ids.Add(9)
};
{
when (max < __GENERATED_PEG__MaxRollback___sumOrSub__)
{
max = __GENERATED_PEG__MaxRollback___sumOrSub__;
ids.Clear()
};
when (__GENERATED_PEG__MaxRollback___sumOrSub__ > 0 && max == __GENERATED_PEG__MaxRollback___sumOrSub__) ids.Add(11)
};
{
when (max < __GENERATED_PEG__MaxRollback___mulOrDiv__)
{
max = __GENERATED_PEG__MaxRollback___mulOrDiv__;
ids.Clear()
};
when (__GENERATED_PEG__MaxRollback___mulOrDiv__ > 0 && max == __GENERATED_PEG__MaxRollback___mulOrDiv__) ids.Add(10)
};
{
when (max < __GENERATED_PEG__MaxRollback___simplExpr__)
{
max = __GENERATED_PEG__MaxRollback___simplExpr__;
ids.Clear()
};
when (__GENERATED_PEG__MaxRollback___simplExpr__ > 0 && max == __GENERATED_PEG__MaxRollback___simplExpr__) ids.Add(7)
};
{
when (max < __GENERATED_PEG__MaxRollback___simplExprError__)
{
max = __GENERATED_PEG__MaxRollback___simplExprError__;
ids.Clear()
};
when (__GENERATED_PEG__MaxRollback___simplExprError__ > 0 && max == __GENERATED_PEG__MaxRollback___simplExprError__) ids.Add(8)
};
{
when (max < __GENERATED_PEG__MaxRollback___parenthesesExprError__)
{
max = __GENERATED_PEG__MaxRollback___parenthesesExprError__;
ids.Clear()
};
when (__GENERATED_PEG__MaxRollback___parenthesesExprError__ > 0 && max == __GENERATED_PEG__MaxRollback___parenthesesExprError__) ids.Add(6)
};
{
when (max < __GENERATED_PEG__MaxRollback___unaryMinus__)
{
max = __GENERATED_PEG__MaxRollback___unaryMinus__;
ids.Clear()
};
when (__GENERATED_PEG__MaxRollback___unaryMinus__ > 0 && max == __GENERATED_PEG__MaxRollback___unaryMinus__) ids.Add(4)
};
{
when (max < __GENERATED_PEG__MaxRollback___parenthesesExpr__)
{
max = __GENERATED_PEG__MaxRollback___parenthesesExpr__;
ids.Clear()
};
when (__GENERATED_PEG__MaxRollback___parenthesesExpr__ > 0 && max == __GENERATED_PEG__MaxRollback___parenthesesExpr__) ids.Add(5)
};
{
when (max < __GENERATED_PEG__MaxRollback___num__)
{
max = __GENERATED_PEG__MaxRollback___num__;
ids.Clear()
};
when (__GENERATED_PEG__MaxRollback___num__ > 0 && max == __GENERATED_PEG__MaxRollback___num__) ids.Add(3)
}
};
(max, ids)
}
// Calculator.CalcParser
public GetMaxRollbackPosAndNames() : int * System.Collections.Generic.List[string]
{
def (max, ids) = GetMaxRollbackPosAndIds();
def names = System.Collections.Generic.List(ids.Count);
foreach (id in ids) names.Add(GetRuleName(id));
(max, names)
}
// Calculator.CalcParser
public GetRuleName(id : int) : string
{
match (id)
{
| 0 =>
"any"
| 1 =>
"digit"
| 9 =>
"inputError"
| 12 =>
"mainRule"
| 10 =>
"mulOrDiv"
| 3 =>
"num"
| 5 =>
"parenthesesExpr"
| 6 =>
"parenthesesExprError"
| 7 =>
"simplExpr"
| 8 =>
"simplExprError"
| 2 =>
"spaces"
| 13 =>
"start"
| 11 =>
"sumOrSub"
| 4 =>
"unaryMinus"
| _ =>
"Unknown rule id."
}
}
// Calculator.CalcParser
private ResetMaxRollbackPos() : void
{
__GENERATED_PEG__MaxRollback___start__ = -1;
__GENERATED_PEG__MaxRollback___mainRule__ = -1;
__GENERATED_PEG__MaxRollback___inputError__ = -1;
__GENERATED_PEG__MaxRollback___sumOrSub__ = -1;
__GENERATED_PEG__MaxRollback___mulOrDiv__ = -1;
__GENERATED_PEG__MaxRollback___simplExpr__ = -1;
__GENERATED_PEG__MaxRollback___simplExprError__ = -1;
__GENERATED_PEG__MaxRollback___parenthesesExprError__ = -1;
__GENERATED_PEG__MaxRollback___unaryMinus__ = -1;
__GENERATED_PEG__MaxRollback___parenthesesExpr__ = -1;
__GENERATED_PEG__MaxRollback___num__ = -1
}
// Calculator.CalcParser
private ResetMemoization() : void
{
__GENERATED_PEG__Memeoize_Pos__start__ = -1;
__GENERATED_PEG__Memeoize_End__start__ = -1;
__GENERATED_PEG__Memeoize_Res__start__ = DEFAULT;
__GENERATED_PEG__Memeoize_Pos__mainRule__ = -1;
__GENERATED_PEG__Memeoize_End__mainRule__ = -1;
__GENERATED_PEG__Memeoize_Res__mainRule__ = DEFAULT;
__GENERATED_PEG__Memeoize_Pos__inputError__ = -1;
__GENERATED_PEG__Memeoize_End__inputError__ = -1;
__GENERATED_PEG__Memeoize_Res__inputError__ = DEFAULT;
__GENERATED_PEG__Memeoize_Pos__sumOrSub__ = -1;
__GENERATED_PEG__Memeoize_End__sumOrSub__ = -1;
__GENERATED_PEG__Memeoize_Res__sumOrSub__ = DEFAULT;
__GENERATED_PEG__Memeoize_Pos__mulOrDiv__ = -1;
__GENERATED_PEG__Memeoize_End__mulOrDiv__ = -1;
__GENERATED_PEG__Memeoize_Res__mulOrDiv__ = DEFAULT;
__GENERATED_PEG__Memeoize_Pos__simplExpr__ = -1;
__GENERATED_PEG__Memeoize_End__simplExpr__ = -1;
__GENERATED_PEG__Memeoize_Res__simplExpr__ = DEFAULT;
__GENERATED_PEG__Memeoize_Pos__simplExprError__ = -1;
__GENERATED_PEG__Memeoize_End__simplExprError__ = -1;
__GENERATED_PEG__Memeoize_Res__simplExprError__ = DEFAULT;
__GENERATED_PEG__Memeoize_Pos__parenthesesExprError__ = -1;
__GENERATED_PEG__Memeoize_End__parenthesesExprError__ = -1;
__GENERATED_PEG__Memeoize_Res__parenthesesExprError__ = DEFAULT;
__GENERATED_PEG__Memeoize_Pos__unaryMinus__ = -1;
__GENERATED_PEG__Memeoize_End__unaryMinus__ = -1;
__GENERATED_PEG__Memeoize_Res__unaryMinus__ = DEFAULT;
__GENERATED_PEG__Memeoize_Pos__parenthesesExpr__ = -1;
__GENERATED_PEG__Memeoize_End__parenthesesExpr__ = -1;
__GENERATED_PEG__Memeoize_Res__parenthesesExpr__ = DEFAULT;
__GENERATED_PEG__Memeoize_Pos__num__ = -1;
__GENERATED_PEG__Memeoize_End__num__ = -1;
__GENERATED_PEG__Memeoize_Res__num__ = DEFAULT
}
// Calculator.CalcParser
public Parse(text : string) : option[int]
{
def (pos, res) = TryParse(text);
if (pos < 0) None(); else Some(res)
}
// Calculator.CalcParser
public ParseSource(source : Nemerle.Peg.SourceSnapshot) : option[int]
{
def (pos, res) = TryParseSource(source);
if (pos < 0) None(); else Some(res)
}
// Calculator.CalcParser
public TryParse(text : string) : int * int
{
TryParseSource(Nemerle.Peg.SourceSnapshot(text, text, 0, "", Nemerle.Peg.SourceSnapshot("", "", 0, "", null).MakeLineIndexes(text)))
}
// Calculator.CalcParser
public TryParseSource(source : Nemerle.Peg.SourceSnapshot) : int * int
{
ResetMemoization();
ResetMaxRollbackPos();
_parsingSource = source;
mutable result;
def pos = __GENERATED_PEG__RULE__start__(0, _parsingSource.Text, ref result);
(pos, result)
}
// Calculator.CalcParser
protected GetText(tok : Nemerle.Peg.NToken) : string
{
_parsingSource.OriginalText.Substring(tok.StartPos, tok.EndPos - tok.StartPos)
}
// Calculator.CalcParser
protected GetLocation(tok : Nemerle.Peg.NToken) : Nemerle.Peg.Location
{
Nemerle.Peg.Location(_parsingSource, tok.StartPos, tok.EndPos)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment