public CommandToken(Command command, LocatedString locatedName, LocatedString locatedArguments, Action <Combo> action) { _command = command; LocatedName = locatedName; LocatedArguments = locatedArguments; Action = action; }
public void AddToInjectorStream <T>(IInjectorStream <T> injectorStream, LocatedString locatedString) { if (Flags.HasFlag(InputReaderFlags.AllowKeywordAny)) { throw new InvalidOperationException(); } _injectorStream = (IInjectorStream <object>)injectorStream; new MyCharReader(this, locatedString, false).Run(); }
private static Regex CreateRegex(LocatedString argument, RegexOptions regexOptions) { try { return(Helper.GetRegex(argument.Value, regexOptions, fullMatchIfLiteral: true)); } catch (Exception ex) when(ex is ArgumentException) { throw new ParseException(argument.Location, ex); } }
protected CharReader(LocatedString locatedString) { var text = locatedString.Value; if (text.Contains('\t')) { throw new ParseException("Tab character(s) found in input. Please use spaces only."); } Helper.ForbidCarriageReturn(ref text); _text = text; Location = locatedString.Location; }
public Chord CreateChord(LocatedString locatedString) { if ((Flags & (InputReaderFlags.AllowCustomCharacter | InputReaderFlags.AllowHoldRelease | InputReaderFlags.AllowMultiplier | InputReaderFlags.AllowDynamicHotkey)) != 0) { throw new InvalidOperationException(); } _combos.Clear(); new MyCharReader(this, locatedString, true).Run(); var chord = new Chord(_combos); _combos.Clear(); return(chord); }
private void RunInner() { while (!EndOfStream) { _locatedString = new LocatedString(Current.ToString(), Location); if (!_parseLiteral && At(TokenRegex)) { HandleToken(); } else { Add(Read().ToString()); } } if (_multiplier != 1 || _modifiers != Modifiers.None || _pressType != PressType.None) { ForbidEndOfStream(); } }
private Action <Combo> GetAction(Command command, LocatedString locatedName, LocatedString locatedArguments) { var parameters = new List <ParameterInfo>(command.MethodInfo.GetParameters()); var arguments = new List <object>(); var insertTrigger = false; if (command.CommandTypes.HasFlag(CommandTypes.ExecuteAtParseTime) && parameters.Count > 0 && parameters[0].ParameterType == typeof(ExecuteAtParseTimeData)) { arguments.Add(new ExecuteAtParseTimeData(_parserOutput, _sections.Peek(), _chord, locatedName)); parameters.RemoveAt(0); } if (!command.CommandTypes.HasFlag(CommandTypes.ExecuteAtParseTime) && parameters.Count > 0 && parameters[0].ParameterType == typeof(HotkeyTrigger)) { insertTrigger = true; parameters.RemoveAt(0); } arguments.AddRange(locatedArguments.ReadArguments(parameters)); return(CreateAction(command.Actor, command.MethodInfo, arguments.ToArray(), insertTrigger)); }
private Section CreateSection(LocatedString type, LocatedString argument) { if (type.Value == nameof(RegexSectionType.Process) || type.Value == nameof(RegexSectionType.Window)) { var sectionType = (RegexSectionType)Enum.Parse(typeof(RegexSectionType), type.Value); var regexOptions = sectionType == RegexSectionType.Process ? RegexOptions.IgnoreCase : RegexOptions.None; return(new RegexSection((StandardSection)_sections.Peek(), CreateRegex(argument, regexOptions), sectionType)); } if (type.Value == Constants.FlagSectionIdentifier) { return(new FlagSection((StandardSection)_sections.Peek(), argument.Value)); } if (type.Value == Constants.InputModeSectionIdentifier) { return(new Mode(argument.Value, false)); } if (type.Value == Constants.ComposeModeSectionIdentifier) { return(new Mode(argument.Value, true)); } throw new ParseException(type.Location, $"Unrecognized section type '{type.Value}'."); }
private void HandleToken() { _locatedString = ReadToken(out var text); if (text[0] >= '0' && text[0] <= '9') { HandleMultiplier(text); } else if (Enum.TryParse(text, out Modifiers modifiers) && modifiers != Modifiers.None) { HandleModifiers(modifiers); } else if (Enum.TryParse(text, out Input input) && input != Input.None) { Add(input); } else if (Env.Config.TryGetCustomInput(text, out input)) { Add(input); } else if (Env.Config.TryGetCustomCombo(text, out var combo)) { HandleModifiers(combo.Modifiers); Add(combo.Input); } else if (Enum.TryParse(text, out PressType pressType) && pressType != PressType.None) { HandleHoldRelease(pressType); } else if (Env.Parser.IsDynamicHotkey(text)) { HandleDynamicHotkey(text); } else { throw CreateException("Unrecognized token."); } }
public ParseException(LocatedString locatedString, string message, Exception innerException = null) : base(locatedString + ": " + message, innerException) { HasLocation = true; }
public ParseException(LocatedString locatedString, Exception innerException = null) : base(locatedString.ToString(), innerException) { HasLocation = true; }
public MyCharReader(InputReader inputReader, LocatedString locatedString, bool createChord) : base(locatedString) { _inputReader = inputReader; _createChord = createChord; _parseLiteral = inputReader.Flags.HasFlag(InputReaderFlags.ParseLiteral); }
public MyCharReader(LocatedString text, ParserOutput parserOutput) : base(text) { _parserOutput = parserOutput; }