public static LNode LLLPG_parser(LNode node, IMacroContext context) { return(LllpgMacro(node, context, _parser, parserCfg => { // Scan options in parser(...) node var helper = new GeneralCodeGenHelper(); if (parserCfg == null) { return helper; } foreach (var option in MacroContext.GetOptions(parserCfg.Args)) { LNode value = option.Value ?? LNode.Missing; string key = option.Key.Name.Name; switch (key.ToLowerInvariant()) { case "inputsource": helper.InputSource = value; break; case "inputclass": helper.InputClass = value; break; case "terminaltype": helper.TerminalType = value; break; case "settype": helper.SetType = value; break; case "listinitializer": helper.SetListInitializer(value); break; case "nocheckbydefault": SetOption <bool>(context, option.Key, value.Value, b => helper.NoCheckByDefault = b); break; case "allowswitch": SetOption <bool>(context, option.Key, value.Value, b => helper.AllowSwitch = b); break; case "castla": SetOption <bool>(context, option.Key, value.Value, b => helper.CastLA = b); break; case "latype": helper.LaType = value; break; case "matchtype": // alternate name case "matchcast": helper.MatchCast = value; break; default: context.Sink.Error(option.Key, "Unrecognized option '{0}'. Available options: " + "InputSource: variable, InputClass: type, TerminalType: type, SetType: type, " + "ListInitializer: var _ = new List<T>(), NoCheckByDefault: true, AllowSwitch: bool, " + "CastLA: bool, LAType: type, MatchCast: type", key); break; } } return helper; }, isDefault: true)); }
public static LNode LLLPG_parser(LNode node, IMacroContext context) { var p = context.GetArgsAndBody(true); var args = p.A; var body = p.B; LNode parserCfg = null; if (args.Count > 0) { if ((parserCfg = args[0]).Name != _parser || args.Count > 1) { return(null); } } // Scan options in parser(...) node var helper = new GeneralCodeGenHelper(); if (parserCfg != null) { foreach (var option in MacroContext.GetOptions(parserCfg.Args)) { LNode value = option.Value; string key = (option.Key ?? (Symbol)"??").Name; switch (key.ToLowerInvariant()) { case "inputsource": helper.InputSource = value; break; case "inputclass": helper.InputClass = value; break; case "terminaltype": helper.TerminalType = value; break; case "latype": helper.LaType = value; break; case "matchtype": // alternate name case "matchcast": helper.MatchCast = value; break; case "settype": helper.SetType = value; break; case "allowswitch": if (value.Value is bool) { helper.AllowSwitch = (bool)value.Value; } else { context.Write(Severity.Error, value, "AllowSwitch: expected literal boolean argument."); } break; case "castla": if (value.Value is bool) { helper.CastLA = (bool)value.Value; } else { context.Write(Severity.Error, value, "CastLA: expected literal boolean argument."); } break; case "listinitializer": helper.SetListInitializer(value); break; default: context.Write(Severity.Error, value, "Unrecognized option '{0}'. Available options: " + "inputSource: variable, inputClass: type, terminalType: type, laType: type, matchCast: type, setType: type, allowSwitch: bool, castLa: bool, listInitializer: var _ = new List<T>()", key); break; } } } return(node.WithTarget(_run_LLLPG).WithArgs(F.Literal(helper), F.Braces(body))); }
public static LNode LLLPG_parser(LNode node, IMacroContext context) { return(LllpgMacro(node, context, _parser, parserCfg => { // Scan options in parser(...) node var helper = new GeneralCodeGenHelper(); if (parserCfg == null) { return helper; } foreach (var option in MacroContext.GetOptions(parserCfg.Args)) { LNode value = option.Value; string key = (option.Key ?? (Symbol)"??").Name; switch (key.ToLowerInvariant()) { case "inputsource": helper.InputSource = value; break; case "inputclass": helper.InputClass = value; break; case "terminaltype": helper.TerminalType = value; break; case "settype": helper.SetType = value; break; case "listinitializer": helper.SetListInitializer(value); break; case "latype": helper.LaType = value; break; case "matchtype": // alternate name case "matchcast": helper.MatchCast = value; break; case "allowswitch": if (value.Value is bool) { helper.AllowSwitch = (bool)value.Value; } else { context.Write(Severity.Error, value, "AllowSwitch: expected literal boolean argument."); } break; case "castla": if (value.Value is bool) { helper.CastLA = (bool)value.Value; } else { context.Write(Severity.Error, value, "CastLA: expected literal boolean argument."); } break; default: context.Write(Severity.Error, value, "Unrecognized option '{0}'. Available options: " + "inputSource: variable, inputClass: type, terminalType: type, laType: type, matchCast: type, setType: type, allowSwitch: bool, castLa: bool, listInitializer: var _ = new List<T>()", key); break; } } return helper; }, isDefault: true)); }