コード例 #1
0
        public override int ConvertTokens(IEnumerable <RPToken> tokens)
        {
            string regex = tokens.First().Value;

            if (!Options.ContainsKey(typeof(RPScanTypes).Name))
            {
                throw new Exception("ScanTypes not defined.");
            }

            if (!Enum.TryParse(Options[typeof(RPScanTypes).Name], true, out RPScanTypes scanType))
            {
                throw new Exception("Invalid ScanType");
            }

            Element = new RPRegexElement(RPRegexFactory.Create(regex), scanType);

            return(base.ConvertTokens(tokens.Skip(1)) + 1);
        }
コード例 #2
0
        public override int ConvertTokens(IEnumerable <RPToken> tokens)
        {
            if (Element == null || !(Element is RPSyntaxKindElement syntaxKindElement))
            {
                throw new Exception("An RPSyntaxKindRegexPairTokenType must be preceeded by an RPSyntaxKindTokenType.");
            }

            RPToken token = tokens.ElementAtOrDefault(1);

            if (token == null || !(token.TokenType == typeof(RPRegexTokenType)))
            {
                throw new Exception("The RPSyntaxKindRegexPairTokenType must be followed by an RPRegexTokenType.");
            }

            string regex = token.Value;

            Element = new RPSyntaxKindRegexPairElement(syntaxKindElement.SyntaxKind, RPRegexFactory.Create(regex), syntaxKindElement.ScanType);

            return(base.ConvertTokens(tokens.Skip(2)) + 2);
        }