public Statement Parse(ParserArgument args) { var m = Regex.Match(args.Text, $@"^{Formats.RegisterEx}\s*\=\s*{_meta.Operator}\s*{Formats.RegisterEx}$", RegexOptions.IgnoreCase); if (m.Success) return Activator.CreateInstance(_meta.StatementType, args.Formatter.GetRegEx(m.Groups[1].Value, true), args.Formatter.GetRegEx(m.Groups[2].Value, false)) as Statement; return null; }
public Statement Parse(ParserArgument args) { var m = Regex.Match(args.Text, $@"^{_meta.KeyWord}\s+{Formats.Register}$", RegexOptions.IgnoreCase); if (m.Success) return Activator.CreateInstance(_meta.StatementType, args.Formatter.GetReg(m.Groups[1].Value, _lhs)) as Statement; return null; }
private static Statement KeyParse(ParserArgument args) { NintendoSwitch.ECKey key; var m = Regex.Match(args.Text, @"^([a-z]+)$", RegexOptions.IgnoreCase); if (m.Success && (key = NSKeys.Get(m.Groups[1].Value)) != null) { return(new KeyPress(key)); } m = Regex.Match(args.Text, $@"^([a-z]+)\s+{Formats.ValueEx}$", RegexOptions.IgnoreCase); if (m.Success && (key = NSKeys.Get(m.Groups[1].Value)) != null) { return(new KeyPress(key, args.Formatter.GetValueEx(m.Groups[2].Value))); } m = Regex.Match(args.Text, @"^([a-z]+)\s+down$", RegexOptions.IgnoreCase); if (m.Success && (key = NSKeys.Get(m.Groups[1].Value)) != null) { return(new KeyDown(key)); } m = Regex.Match(args.Text, @"^([a-z]+)\s+up$", RegexOptions.IgnoreCase); if (m.Success && (key = NSKeys.Get(m.Groups[1].Value)) != null) { return(new KeyUp(key)); } // stick return(StickParse(args)); }
private static Statement LoopControlParse(ParserArgument args) { // break if (args.Text.Equals("break", StringComparison.OrdinalIgnoreCase)) { return(new Break()); } var m = Regex.Match(args.Text, $@"^break\s+{Formats.Instant}$", RegexOptions.IgnoreCase); if (m.Success) { return(new Break(args.Formatter.GetInstant(m.Groups[1].Value, true))); } // continue if (args.Text.Equals("continue", StringComparison.OrdinalIgnoreCase)) { return(new Continue()); } m = Regex.Match(args.Text, $@"^continue\s+{Formats.Instant}$", RegexOptions.IgnoreCase); if (m.Success) { return(new Continue(args.Formatter.GetInstant(m.Groups[1].Value, true))); } return(null); }
private static Statement EndParse(ParserArgument args) { if (args.Text.Equals("endif", StringComparison.OrdinalIgnoreCase)) { return(new EndIf()); } return(null); }
public static Statement Parse(ParserArgument args) { if (args.Text.Equals("next", StringComparison.OrdinalIgnoreCase)) { return(new Next()); } return(null); }
public static Statement Parse(ParserArgument args) { if (args.Text.Length == 0) { return(new Empty()); } return(null); }
private static Statement ElseParse(ParserArgument args) { if (args.Text.Equals("else", StringComparison.OrdinalIgnoreCase)) { return(new Else()); } return(EndParse(args)); }
private static Statement NextParse(ParserArgument args) { if (args.Text.Equals("next", StringComparison.OrdinalIgnoreCase)) { return(new Next()); } // loop-control return(LoopControlParse(args)); }
public Statement Parse(ParserArgument args) { var m = Regex.Match(args.Text, $@"^{Formats.RegisterEx}\s*\{_meta.Operator}\s*{(_meta.OnlyInstant ? Formats.Instant : Formats.ValueEx)}$", RegexOptions.IgnoreCase); if (m.Success) { return(Activator.CreateInstance(_meta.StatementType, FormatterUtil.GetRegEx(m.Groups[1].Value, true), args.Formatter.GetValueEx(m.Groups[2].Value)) as Statement); } return(null); }
Statement?IStatementParser.Parse(ParserArgument args) { // empty if (args.Text.Length == 0) { return(new Empty()); } // key return(KeyParse(args)); }
public static Statement Parse(ParserArgument args) { var m = Regex.Match(args.Text, $@"^{Formats.RegisterEx}\s*=\s*{Formats.ValueEx}$", RegexOptions.IgnoreCase); if (m.Success) { return(new Mov(args.Formatter.GetRegEx(m.Groups[1].Value, true), args.Formatter.GetValueEx(m.Groups[2].Value))); } return(null); }
private static Statement TimestampParse(ParserArgument args) { var m = Regex.Match(args.Text, $@"^TIME\s+{Formats.RegisterEx}$", RegexOptions.IgnoreCase); if (m.Success) { return(new TimeStamp(FormatterUtil.GetRegEx(m.Groups[1].Value))); } return(null); }
Statement?IStatementParser.Parse(ParserArgument args) { var m = Regex.Match(args.Text, $@"^{Formats.Constant}\s*=\s*{Formats.Instant}$", RegexOptions.IgnoreCase); if (m.Success) { var val = args.Formatter.GetInstant(m.Groups[2].Value); args.Formatter.SetConstantTable(m.Groups[1].Value, val.Val); return(new Statements.Empty($"{m.Groups[1].Value} = {m.Groups[2].Value}")); } return(null); }
public static Statement Parse(ParserArgument args) { foreach (var op in CompareOperator.All) { var m = Regex.Match(args.Text, $@"^if\s+{Formats.RegisterEx}\s*{op.Operator}\s*{Formats.ValueEx}$", RegexOptions.IgnoreCase); if (m.Success) { return(new If(op, args.Formatter.GetRegEx(m.Groups[1].Value), args.Formatter.GetValueEx(m.Groups[2].Value))); } } return(null); }
Statement?IStatementParser.Parse(ParserArgument args) { if (args.Text.Equals("PUSHALL", StringComparison.OrdinalIgnoreCase)) { return(new PushAll()); } if (args.Text.Equals("POPALL", StringComparison.OrdinalIgnoreCase)) { return(new PopAll()); } return(null); }
Statement?IStatementParser.Parse(ParserArgument args) { Statement st = null; foreach (var p in AsmParser()) { st = p.Parse(args); if (st != null) { return(st); } } return(st); }
private static Statement WaitParse(ParserArgument args) { if (int.TryParse(args.Text, out int duration)) { return(new Wait(duration, true)); } var m = Regex.Match(args.Text, $@"^wait\s+{Formats.ValueEx}$", RegexOptions.IgnoreCase); if (m.Success) { return(new Wait(args.Formatter.GetValueEx(m.Groups[1].Value))); } return(FuncParse(args)); }
public static Statement Parse(ParserArgument args) { Match m; if (args.Text.Equals("continue", StringComparison.OrdinalIgnoreCase)) { return(new Continue()); } m = Regex.Match(args.Text, $@"^continue\s+{Formats.Instant}$", RegexOptions.IgnoreCase); if (m.Success) { return(new Continue(args.Formatter.GetInstant(m.Groups[1].Value, true))); } return(null); }
Statement?IStatementParser.Parse(ParserArgument args) { var m = Regex.Match(args.Text, @"^sprint\s+(\d+)$", RegexOptions.IgnoreCase); if (m.Success) { return(new SerialPrint(uint.Parse(m.Groups[1].Value), false)); } m = Regex.Match(args.Text, @"^smem\s+(\d+)$", RegexOptions.IgnoreCase); if (m.Success) { return(new SerialPrint(uint.Parse(m.Groups[1].Value), true)); } return(null); }
private static Statement PrintParse(ParserArgument args) { if (args.Text.Equals("print", StringComparison.OrdinalIgnoreCase)) { return(new Print(Array.Empty <Content>(), false)); } var m = Regex.Match(args.Text, @"^print\s+(.*)$", RegexOptions.IgnoreCase); if (m.Success) { var strs = m.Groups[1].Value.Split('&'); var contents = new List <Content>(); var cancellinebreak = false; for (int i = 0; i < strs.Length; i++) { var s = strs[i].Trim(); if (i == strs.Length - 1 && s == "\\") { contents.Add(new TextContent("", "\\")); cancellinebreak = true; continue; } if (s.Length == 0 && strs.Length > 1) { contents.Add(new TextContent(" ", "")); continue; } m = Regex.Match(s, Formats.RegisterEx_F); if (m.Success) { contents.Add(new RegContent(FormatterUtil.GetRegEx(s))); continue; } m = Regex.Match(s, Formats.Constant_F); if (m.Success) { var v = args.Formatter.GetConstant(s); contents.Add(new TextContent(v.Val.ToString(), s)); continue; } contents.Add(new TextContent(s)); } return(new Print(contents.ToArray(), cancellinebreak)); } return(null); }
Statement?IStatementParser.Parse(ParserArgument args) { foreach (var op in CompareOperator.All) { var m = Regex.Match(args.Text, $@"^if\s+{Formats.VariableEx}\s*{op.Operator}\s*{Formats.ValueEx}$", RegexOptions.IgnoreCase); if (m.Success) { return(new If(op, args.Formatter.GetVar(m.Groups[1].Value), args.Formatter.GetValueEx(m.Groups[2].Value))); } // else if m = Regex.Match(args.Text, $@"^elif\s+{Formats.VariableEx}\s*{op.Operator}\s*{Formats.ValueEx}$", RegexOptions.IgnoreCase); if (m.Success) { return(new ElseIf(op, args.Formatter.GetVar(m.Groups[1].Value), args.Formatter.GetValueEx(m.Groups[2].Value))); } } return(ElseParse(args)); }
private static Statement StickParse(ParserArgument args) { Match m; m = Regex.Match(args.Text, @"^([lr]s)\s+(reset)$", RegexOptions.IgnoreCase); if (m.Success) { var keyname = m.Groups[1].Value; var key = ScripterUtil.GetKey(keyname); if (key == null) { return(null); } return(new StickUp(key, keyname)); } m = Regex.Match(args.Text, @"^([lr]s{1,2})\s+([a-z0-9]+)$", RegexOptions.IgnoreCase); if (m.Success) { var keyname = m.Groups[1].Value; var direction = m.Groups[2].Value; var key = ScripterUtil.GetKey(keyname, direction); if (key == null) { return(null); } return(new StickDown(key, keyname, direction)); } m = Regex.Match(args.Text, $@"^([lr]s{{1,2}})\s+([a-z0-9]+)\s*,\s*({Formats.ValueEx})$", RegexOptions.IgnoreCase); if (m.Success) { var keyname = m.Groups[1].Value; var direction = m.Groups[2].Value; var duration = m.Groups[3].Value; var key = ScripterUtil.GetKey(keyname, direction); if (key == null) { return(null); } return(new StickPress(key, keyname, direction, args.Formatter.GetValueEx(duration))); } // mov return(MovParse(args)); }
private static Statement FuncParse(ParserArgument args) { var m = Regex.Match(args.Text, @"^func\s+(\D[\d\p{L}_]+)$", RegexOptions.IgnoreCase); if (m.Success) { return(new Function(m.Groups[1].Value)); } m = Regex.Match(args.Text, @"^call\s+(\D[\d\p{L}_]+)$", RegexOptions.IgnoreCase); if (m.Success) { return(new CallStat(m.Groups[1].Value)); } if (args.Text.Equals("ret", StringComparison.OrdinalIgnoreCase)) { return(new ReturnStat()); } return(TimestampParse(args)); }
public static Statement Parse(ParserArgument args) { Match m; if (args.Text.Equals("for", StringComparison.OrdinalIgnoreCase)) { return(new For_Infinite()); } m = Regex.Match(args.Text, $@"^for\s+{Formats.ValueEx}$", RegexOptions.IgnoreCase); if (m.Success) { return(new For_Static(args.Formatter.GetValueEx(m.Groups[1].Value))); } m = Regex.Match(args.Text, $@"^for\s+{Formats.RegisterEx}\s*=\s*{Formats.ValueEx}\s*to\s*{Formats.ValueEx}$", RegexOptions.IgnoreCase); if (m.Success) { return(new For_Full(args.Formatter.GetRegEx(m.Groups[1].Value, true), args.Formatter.GetValueEx(m.Groups[2].Value), args.Formatter.GetValueEx(m.Groups[3].Value))); } return(null); }
Statement?IStatementParser.Parse(ParserArgument args) { return(AlertParse(args)); }