static internal ParseManager Create(string source, TextWriter tw, IList <Pair <string, string> > settings = null) { var cp = new ColourParser(); var gamedef = new GameDef(); gamedef.Scripts = ScriptManager.Create(gamedef); gamedef.Palette = cp.GetPalette(); var gp = new ParseManager { _sourcename = source, _out = tw, _gamedef = gamedef, SettingsParser = new SettingsParser { GameDef = gamedef, Colour = cp }, ColourParser = cp, }; if (settings != null) { foreach (var setting in settings) { gp.SettingsParser.Parse(setting.Item1, setting.Item2); } } gp.PegParser = PuzzLangParser.Create(tw, gp); gp._rulebuilder = RuleBuilder.Create(gp); return(gp); }
static internal ScriptFunctionCall Create(ScriptManager manager, ParseManager parser, string ident, IList <string> args) { return(new ScriptFunctionCall { _name = ident, _arguments = args, _manager = manager, _parser = parser, }); }
internal static PuzzLangParser Create(TextWriter tw, ParseManager manager) { return(new PuzzLangParser { Tracer = new Tracer { Out = tw }, _manager = manager, }); }
internal void AddScript(ParseManager parser, IList <string> lines) { Script script = new Script(); try { _vartable = new Table(script); script.Globals["state"] = _vartable; var prog = String.Join("\n", lines.ToArray()); script.DoString(prog, null, "lua script"); } catch (SyntaxErrorException ex) { parser.CompileError(ex.DecoratedMessage); } scriptMain = script; }
void Compile(TextReader reader) { _parser = ParseManager.Create(SourceName, Out, Settings); var program = reader.ReadToEnd() + "\r\n"; // just too hard to parse missing EOL try { _parser.PegParser.Parse(program); _parser.CheckData(); } catch (FormatException e) { if (e.Data.Contains("cursor")) { var state = e.Data["cursor"] as Cursor; var offset = Math.Max(0, state.Location - 30); var source = (program.Substring(offset, state.Location - offset) + "(^)" + program.Substring(state.Location)) .Replace("\r", "").Replace("\n", ";"); Message = "{0}\n*** '{1}' at {2},{3}: parse error: {4}".Fmt(source.Shorten(78), SourceName, state.Line, state.Column, e.Message); Out.WriteLine(Message); ++_parser.ErrorCount; } else { Out.WriteLine($"*** '{SourceName}': unexpected exception: {e.ToString()}"); ++_parser.ErrorCount; } } catch (DOLEException e) { Message = e.Message; Out.WriteLine(Message); ++_parser.ErrorCount; } var fmt = _parser.ErrorCount > 0 ? "Compiled '{0}' with errors, count: {1} warnings: {2}." : _parser.WarningCount > 0 ? "Compiled '{0}' with warnings, count: {2}." : "Compiled '{0}' with no errors, {3} rules."; Out.WriteLine(fmt, SourceName, _parser.ErrorCount, _parser.WarningCount, _parser.RuleCount); }
internal static RuleBuilder Create(ParseManager parser) { return(new RuleBuilder { _parser = parser, }); }
internal ScriptFunctionCall CreateFunctionCall(ParseManager parser, string ident, IList <string> args) { return(ScriptFunctionCall.Create(this, parser, ident, args)); }