Пример #1
0
        public void ParseContextualMatches(Capture contextualMatchInput, Func <char, int> symbolRemapper)
        {
            var contextualMatchSection = contextualMatchInput.Value;
            var contextualMatch        = Regex.Match(contextualMatchSection, @"(?:(?<prefix>[^<>]+)\s*<\s*)?(?<target>[^<>]+)(?:\s*>(?<suffix>[^<>]+))?");

            if (!contextualMatch.Success || !contextualMatch.Groups["target"].Success)
            {
                throw new SyntaxException("Must specify a single target symbol", contextualMatchInput);
            }
            var targetSymbols = InputSymbolParser.ParseInputSymbols(contextualMatch.Groups["target"].Value, symbolRemapper);

            if (targetSymbols.Length != 1)
            {
                throw new SyntaxException("Multi match target symbols are not supported. Convert this rule into mutliple context-sensitive rules.", contextualMatch.Groups["target"]);
            }
            coreSymbol = targetSymbols[0];
            if (contextualMatch.Groups["prefix"].Success)
            {
                backwardsMatch = InputSymbolParser.ParseInputSymbols(contextualMatch.Groups["prefix"].Value, symbolRemapper);
            }
            else
            {
                backwardsMatch = new InputSymbol[0];
            }
            if (contextualMatch.Groups["suffix"].Success)
            {
                forwardsMatch = InputSymbolParser.ParseInputSymbols(contextualMatch.Groups["suffix"].Value, symbolRemapper);
            }
            else
            {
                forwardsMatch = new InputSymbol[0];
            }
        }
Пример #2
0
        public override int GetHashCode()
        {
            unchecked
            {
                var hashCode = InputState != null?InputState.GetHashCode() : 0;

                hashCode = (hashCode * 397) ^ (InputSymbol != null ? InputSymbol.GetHashCode() : 0);
                hashCode = (hashCode * 397) ^ (ResultStates != null ? ResultStates.GetHashCode() : 0);
                return(hashCode);
            }
        }
Пример #3
0
        private bool TryParseInputSymbol(string inputSymbol,
                                         out IdentifierNode identifier,
                                         out AssociativeNode defaultValue)
        {
            identifier   = null;
            defaultValue = null;

            // workaround: there is an issue in parsing "x:int" format unless
            // we create the other parser specially for it. We change it to
            // "x:int = dummy;" for parsing.
            var parseString = InputSymbol;

            // if it has default value, then append ';'
            if (InputSymbol.Contains("="))
            {
                parseString += ";";
            }
            else
            {
                String dummyExpression = "{0}=dummy;";
                parseString = string.Format(dummyExpression, parseString);
            }

            ParseParam parseParam = new ParseParam(this.GUID, parseString);

            if (EngineController.CompilationServices.PreCompileCodeBlock(ref parseParam) &&
                parseParam.ParsedNodes != null &&
                parseParam.ParsedNodes.Any())
            {
                var node = parseParam.ParsedNodes.First() as BinaryExpressionNode;
                Validity.Assert(node != null);

                if (node != null)
                {
                    identifier = node.LeftNode as IdentifierNode;
                    if (inputSymbol.Contains('='))
                    {
                        defaultValue = node.RightNode;
                    }

                    return(identifier != null);
                }
            }

            return(false);
        }