Exemple #1
0
 public CommandToken(Command command, LocatedString locatedName, LocatedString locatedArguments, Action <Combo> action)
 {
     _command         = command;
     LocatedName      = locatedName;
     LocatedArguments = locatedArguments;
     Action           = action;
 }
Exemple #2
0
 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();
 }
Exemple #3
0
 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);
     }
 }
Exemple #4
0
        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;
        }
Exemple #5
0
        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);
        }
Exemple #6
0
 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();
     }
 }
Exemple #7
0
            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));
            }
Exemple #8
0
 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}'.");
 }
Exemple #9
0
 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.");
     }
 }
Exemple #10
0
 public ParseException(LocatedString locatedString, string message, Exception innerException = null) :
     base(locatedString + ": " + message, innerException)
 {
     HasLocation = true;
 }
Exemple #11
0
 public ParseException(LocatedString locatedString, Exception innerException = null) : base(locatedString.ToString(), innerException)
 {
     HasLocation = true;
 }
Exemple #12
0
 public MyCharReader(InputReader inputReader, LocatedString locatedString, bool createChord) : base(locatedString)
 {
     _inputReader  = inputReader;
     _createChord  = createChord;
     _parseLiteral = inputReader.Flags.HasFlag(InputReaderFlags.ParseLiteral);
 }
Exemple #13
0
 public MyCharReader(LocatedString text, ParserOutput parserOutput) : base(text)
 {
     _parserOutput = parserOutput;
 }