Пример #1
0
        bool ParseNumber(ParsePosition position, ref int number)
        {
            var position1 = (ParsePosition)position.Clone();
            var num       = 1;

            if (position1.CurrentChar == '+' || position1.CurrentChar == '-')
            {
                num = position1.CurrentChar == '+' ? 1 : -1;
                position1.MoveNext();
            }

            var digit = 0;

            if (!ParseDigit(position: position1, digit: out digit))
            {
                return(false);
            }
            number = digit;
            position.Skip(count: position1.CurrentIndex);
            while (ParseDigit(position: position, digit: out digit))
            {
                number = 10 * number + digit;
            }
            number *= num;
            return(true);
        }
Пример #2
0
        bool ParseCurly(ParsePosition position, List <IInputAction> inputs)
        {
            if (position.CurrentChar != '{')
            {
                return(false);
            }
            var position1 = (ParsePosition)position.Clone();

            position1.MoveNext();
            var pressInputs   = new List <IInputAction>();
            var releaseInputs = new List <IInputAction>();

            if (!ParseSpecialChar(position: position1, pressInputs: pressInputs) && !ParseNonPrintable(position: position1, pressInputs: pressInputs, releaseInputs: releaseInputs) && !ParsePrintable(position: position1, pressInputs: pressInputs, releaseInputs: releaseInputs))
            {
                return(false);
            }
            var repetitionCount = 1;
            var keyAction       = KeyAction.PressAndRelease;

            if (ParseWhitespaces(position: position1) && !ParseCurlyPostfix(position: position1, repetitionCount: ref repetitionCount, keyAction: ref keyAction) || position1.CurrentChar != '}')
            {
                return(false);
            }
            position1.MoveNext();
            position.Skip(count: position1.CurrentIndex);
            for (var index = 0; index < repetitionCount; ++index)
            {
                switch (keyAction)
                {
                case KeyAction.Press:
                    inputs.AddRange(collection: pressInputs);
                    break;

                case KeyAction.Release:
                    inputs.AddRange(collection: releaseInputs);
                    break;

                case KeyAction.PressAndRelease:
                    inputs.AddRange(collection: pressInputs);
                    inputs.AddRange(collection: releaseInputs);
                    break;
                }
            }

            return(true);
        }
Пример #3
0
        bool ParseBlock(ParsePosition position, List <IInputAction> inputs)
        {
            if (position.CurrentChar != '(')
            {
                return(false);
            }
            var position1 = (ParsePosition)position.Clone();

            position1.MoveNext();
            var inputs1 = new List <IInputAction>();

            ParseInnerText(position: position1, inputs: inputs1);
            if (position1.CurrentChar != ')')
            {
                return(false);
            }
            position1.MoveNext();
            position.Skip(count: position1.CurrentIndex);
            inputs.AddRange(collection: inputs1);
            return(true);
        }
Пример #4
0
        bool ParseModifiers(ParsePosition position, List <IInputAction> inputs)
        {
            var position1       = (ParsePosition)position.Clone();
            var inputActionList = new List <IInputAction>();
            var releaseInputs   = new List <IInputAction>();

            if (!ParseModifier(position: position1, pressInputs: inputActionList, releaseInputs: releaseInputs))
            {
                return(false);
            }
            position.Skip(count: position1.CurrentIndex);
            do
            {
                ;
            } while (ParseModifier(position: position, pressInputs: inputActionList, releaseInputs: releaseInputs));

            if (!ParsePrintable(position: position, pressInputs: inputActionList, releaseInputs: releaseInputs) && !ParseCurly(position: position, inputs: inputActionList))
            {
                ParseBlock(position: position, inputs: inputActionList);
            }
            inputs.AddRange(collection: inputActionList);
            inputs.AddRange(collection: releaseInputs);
            return(true);
        }