Permalink
Browse files

update README and calc sample

  • Loading branch information...
kulibali committed Mar 30, 2016
1 parent 4f8139f commit 28dea4764bbccb32390882ed9120e7db711cb816
Showing with 68 additions and 19 deletions.
  1. +4 −1 README.md
  2. +64 −18 Samples/Calc/Calc.g.cs
View
@@ -66,7 +66,7 @@ Although the most common use for IronMeta is to build parsers on streams of text
- Generated parsers are implemented as C# partial classes, allowing you to keep ancillary code in a separate file from your grammar.
- You can use anonymously-typed object literals in rules; they are matched by comparing their properties with the input objects'.
- Unrestricted use of C# in semantic conditions and match actions.
-- Higher-order rules: you can pass rules as parameters, and then use them in a pattern.
+- Higher-order rules: you can pass rules (or arbitrary patterns) as parameters, and then use them in a pattern.
- Pattern matching on rule arguments: you can apply different rule bodies depending on the number and types of parameters.
- Flexible variables: variables in an IronMeta rule may be used to:
- get the input of an expression they are bound to.
@@ -297,6 +297,9 @@ This rule demonstrates how to match parameters. The parameter part of a rule is
These rules show that you can pass rules as parameters to other rules. To match against them, just capture them in a variable in your parameter pattern, and then use the variable as an expression in your pattern. You can pass parameters as usual.
+## Patterns as Arguments
+
+You can also pass arbitrary patterns as arguments. Variables from the outer rule that you use in the argument pattern will be passed to the inner pattern when matching.
## List Folding
View
@@ -1,5 +1,5 @@
//
-// IronMeta Calc Parser; Generated 2015-06-01 04:42:57Z UTC
+// IronMeta Calc Parser; Generated 2016-03-30 04:36:58Z UTC
//
using System;
@@ -50,6 +50,9 @@ void _setTerminals()
public void Expression(_Calc_Memo _memo, int _index, _Calc_Args _args)
{
+ int _arg_index = 0;
+ int _arg_input_index = 0;
+
// CALLORVAR Additive
_Calc_Item _r0;
@@ -63,6 +66,9 @@ public void Expression(_Calc_Memo _memo, int _index, _Calc_Args _args)
public void Additive(_Calc_Memo _memo, int _index, _Calc_Args _args)
{
+ int _arg_index = 0;
+ int _arg_input_index = 0;
+
// OR 0
int _start_i0 = _index;
@@ -108,12 +114,17 @@ public void Additive(_Calc_Memo _memo, int _index, _Calc_Args _args)
public void Add(_Calc_Memo _memo, int _index, _Calc_Args _args)
{
+ int _arg_index = 0;
+ int _arg_input_index = 0;
+
// CALL BinaryOp
var _start_i1 = _index;
_Calc_Item _r1;
var _arg1_0 = '+';
- _r1 = _MemoCall(_memo, "BinaryOp", _index, BinaryOp, new _Calc_Item[] { new _Calc_Item(Additive), new _Calc_Item(_arg1_0), new _Calc_Item(Multiplicative) });
+ _Calc_Args _actual_args1 = new _Calc_Item[] { new _Calc_Item(Additive), new _Calc_Item(_arg1_0), new _Calc_Item(Multiplicative) };
+ if (_args != null) _actual_args1 = _actual_args1.Concat(_args.Skip(_arg_index));
+ _r1 = _MemoCall(_memo, "BinaryOp", _index, BinaryOp, _actual_args1);
if (_r1 != null) _index = _r1.NextIndex;
@@ -131,12 +142,17 @@ public void Add(_Calc_Memo _memo, int _index, _Calc_Args _args)
public void Sub(_Calc_Memo _memo, int _index, _Calc_Args _args)
{
+ int _arg_index = 0;
+ int _arg_input_index = 0;
+
// CALL BinaryOp
var _start_i1 = _index;
_Calc_Item _r1;
var _arg1_0 = '-';
- _r1 = _MemoCall(_memo, "BinaryOp", _index, BinaryOp, new _Calc_Item[] { new _Calc_Item(Additive), new _Calc_Item(_arg1_0), new _Calc_Item(Multiplicative) });
+ _Calc_Args _actual_args1 = new _Calc_Item[] { new _Calc_Item(Additive), new _Calc_Item(_arg1_0), new _Calc_Item(Multiplicative) };
+ if (_args != null) _actual_args1 = _actual_args1.Concat(_args.Skip(_arg_index));
+ _r1 = _MemoCall(_memo, "BinaryOp", _index, BinaryOp, _actual_args1);
if (_r1 != null) _index = _r1.NextIndex;
@@ -154,6 +170,9 @@ public void Sub(_Calc_Memo _memo, int _index, _Calc_Args _args)
public void Multiplicative(_Calc_Memo _memo, int _index, _Calc_Args _args)
{
+ int _arg_index = 0;
+ int _arg_input_index = 0;
+
// OR 0
int _start_i0 = _index;
@@ -187,7 +206,9 @@ public void Multiplicative(_Calc_Memo _memo, int _index, _Calc_Args _args)
var _start_i4 = _index;
_Calc_Item _r4;
- _r4 = _MemoCall(_memo, "Number", _index, Number, new _Calc_Item[] { new _Calc_Item(DecimalDigit) });
+ _Calc_Args _actual_args4 = new _Calc_Item[] { new _Calc_Item(DecimalDigit) };
+ if (_args != null) _actual_args4 = _actual_args4.Concat(_args.Skip(_arg_index));
+ _r4 = _MemoCall(_memo, "Number", _index, Number, _actual_args4);
if (_r4 != null) _index = _r4.NextIndex;
@@ -200,12 +221,17 @@ public void Multiplicative(_Calc_Memo _memo, int _index, _Calc_Args _args)
public void Multiply(_Calc_Memo _memo, int _index, _Calc_Args _args)
{
+ int _arg_index = 0;
+ int _arg_input_index = 0;
+
// CALL BinaryOp
var _start_i1 = _index;
_Calc_Item _r1;
var _arg1_0 = "*";
- _r1 = _MemoCall(_memo, "BinaryOp", _index, BinaryOp, new _Calc_Item[] { new _Calc_Item(Multiplicative), new _Calc_Item(_arg1_0), new _Calc_Item(Number), new _Calc_Item(DecimalDigit) });
+ _Calc_Args _actual_args1 = new _Calc_Item[] { new _Calc_Item(Multiplicative), new _Calc_Item(_arg1_0), new _Calc_Item(Number), new _Calc_Item(DecimalDigit) };
+ if (_args != null) _actual_args1 = _actual_args1.Concat(_args.Skip(_arg_index));
+ _r1 = _MemoCall(_memo, "BinaryOp", _index, BinaryOp, _actual_args1);
if (_r1 != null) _index = _r1.NextIndex;
@@ -223,12 +249,17 @@ public void Multiply(_Calc_Memo _memo, int _index, _Calc_Args _args)
public void Divide(_Calc_Memo _memo, int _index, _Calc_Args _args)
{
+ int _arg_index = 0;
+ int _arg_input_index = 0;
+
// CALL BinaryOp
var _start_i1 = _index;
_Calc_Item _r1;
var _arg1_0 = "/";
- _r1 = _MemoCall(_memo, "BinaryOp", _index, BinaryOp, new _Calc_Item[] { new _Calc_Item(Multiplicative), new _Calc_Item(_arg1_0), new _Calc_Item(Number), new _Calc_Item(DecimalDigit) });
+ _Calc_Args _actual_args1 = new _Calc_Item[] { new _Calc_Item(Multiplicative), new _Calc_Item(_arg1_0), new _Calc_Item(Number), new _Calc_Item(DecimalDigit) };
+ if (_args != null) _actual_args1 = _actual_args1.Concat(_args.Skip(_arg_index));
+ _r1 = _MemoCall(_memo, "BinaryOp", _index, BinaryOp, _actual_args1);
if (_r1 != null) _index = _r1.NextIndex;
@@ -364,8 +395,8 @@ public void BinaryOp(_Calc_Memo _memo, int _index, _Calc_Args _args)
if (first.Production != null)
{
- var _p17 = (System.Action<_Calc_Memo, int, IEnumerable<_Calc_Item>>)(object)first.Production; // what type safety?
- _r17 = _MemoCall(_memo, first.Production.Method.Name, _index, _p17, null);
+ var _p17 = (System.Action<_Calc_Memo, int, IEnumerable<_Calc_Item>>)(object)first.Production;
+ _r17 = _MemoCall(_memo, first.Production.Method.Name, _index, _p17, _args != null ? _args.Skip(_arg_index) : null);
}
else
{
@@ -384,7 +415,9 @@ public void BinaryOp(_Calc_Memo _memo, int _index, _Calc_Args _args)
var _start_i18 = _index;
_Calc_Item _r18;
- _r18 = _MemoCall(_memo, "KW", _index, KW, new _Calc_Item[] { op });
+ _Calc_Args _actual_args18 = new _Calc_Item[] { op };
+ if (_args != null) _actual_args18 = _actual_args18.Concat(_args.Skip(_arg_index));
+ _r18 = _MemoCall(_memo, "KW", _index, KW, _actual_args18);
if (_r18 != null) _index = _r18.NextIndex;
@@ -409,7 +442,9 @@ public void BinaryOp(_Calc_Memo _memo, int _index, _Calc_Args _args)
var _start_i20 = _index;
_Calc_Item _r20;
- _r20 = _MemoCall(_memo, second.ProductionName, _index, second.Production, new _Calc_Item[] { type });
+ _Calc_Args _actual_args20 = new _Calc_Item[] { type };
+ if (_args != null) _actual_args20 = _actual_args20.Concat(_args.Skip(_arg_index));
+ _r20 = _MemoCall(_memo, second.ProductionName, _index, second.Production, _actual_args20);
if (_r20 != null) _index = _r20.NextIndex;
@@ -476,7 +511,9 @@ public void Number(_Calc_Memo _memo, int _index, _Calc_Args _args)
var _start_i6 = _index;
_Calc_Item _r6;
- _r6 = _MemoCall(_memo, "Digits", _index, Digits, new _Calc_Item[] { type });
+ _Calc_Args _actual_args6 = new _Calc_Item[] { type };
+ if (_args != null) _actual_args6 = _actual_args6.Concat(_args.Skip(_arg_index));
+ _r6 = _MemoCall(_memo, "Digits", _index, Digits, _actual_args6);
if (_r6 != null) _index = _r6.NextIndex;
@@ -574,7 +611,9 @@ public void Digits(_Calc_Memo _memo, int _index, _Calc_Args _args)
var _start_i7 = _index;
_Calc_Item _r7;
- _r7 = _MemoCall(_memo, "Digits", _index, Digits, new _Calc_Item[] { type });
+ _Calc_Args _actual_args7 = new _Calc_Item[] { type };
+ if (_args != null) _actual_args7 = _actual_args7.Concat(_args.Skip(_arg_index));
+ _r7 = _MemoCall(_memo, "Digits", _index, Digits, _actual_args7);
if (_r7 != null) _index = _r7.NextIndex;
@@ -589,8 +628,8 @@ public void Digits(_Calc_Memo _memo, int _index, _Calc_Args _args)
if (type.Production != null)
{
- var _p9 = (System.Action<_Calc_Memo, int, IEnumerable<_Calc_Item>>)(object)type.Production; // what type safety?
- _r9 = _MemoCall(_memo, type.Production.Method.Name, _index, _p9, null);
+ var _p9 = (System.Action<_Calc_Memo, int, IEnumerable<_Calc_Item>>)(object)type.Production;
+ _r9 = _MemoCall(_memo, type.Production.Method.Name, _index, _p9, _args != null ? _args.Skip(_arg_index) : null);
}
else
{
@@ -651,8 +690,8 @@ public void Digits(_Calc_Memo _memo, int _index, _Calc_Args _args)
if (type.Production != null)
{
- var _p13 = (System.Action<_Calc_Memo, int, IEnumerable<_Calc_Item>>)(object)type.Production; // what type safety?
- _r13 = _MemoCall(_memo, type.Production.Method.Name, _index, _p13, null);
+ var _p13 = (System.Action<_Calc_Memo, int, IEnumerable<_Calc_Item>>)(object)type.Production;
+ _r13 = _MemoCall(_memo, type.Production.Method.Name, _index, _p13, _args != null ? _args.Skip(_arg_index) : null);
}
else
{
@@ -673,6 +712,9 @@ public void Digits(_Calc_Memo _memo, int _index, _Calc_Args _args)
public void DecimalDigit(_Calc_Memo _memo, int _index, _Calc_Args _args)
{
+ int _arg_index = 0;
+ int _arg_input_index = 0;
+
_Calc_Item c = null;
// INPUT CLASS
@@ -724,8 +766,8 @@ public void KW(_Calc_Memo _memo, int _index, _Calc_Args _args)
if (str.Production != null)
{
- var _p4 = (System.Action<_Calc_Memo, int, IEnumerable<_Calc_Item>>)(object)str.Production; // what type safety?
- _r4 = _MemoCall(_memo, str.Production.Method.Name, _index, _p4, null);
+ var _p4 = (System.Action<_Calc_Memo, int, IEnumerable<_Calc_Item>>)(object)str.Production;
+ _r4 = _MemoCall(_memo, str.Production.Method.Name, _index, _p4, _args != null ? _args.Skip(_arg_index) : null);
}
else
{
@@ -784,6 +826,9 @@ public void KW(_Calc_Memo _memo, int _index, _Calc_Args _args)
public void WS(_Calc_Memo _memo, int _index, _Calc_Args _args)
{
+ int _arg_index = 0;
+ int _arg_input_index = 0;
+
// OR 0
int _start_i0 = _index;
@@ -825,6 +870,7 @@ public void WS(_Calc_Memo _memo, int _index, _Calc_Args _args)
}
+
} // class Calc
} // namespace IronMeta.Samples.Calc

0 comments on commit 28dea47

Please sign in to comment.