Ejemplo n.º 1
0
        public override Match <IParseNode> Match(List <Lexeme> lexemes)
        {
            Match <IParseNode> match = Rule.Match(lexemes);

            if (match.Success)
            {
                return(new Match <IParseNode>(match.Result, false));
            }
            else
            {
                return(new Match <IParseNode>(null, true));
            }
        }
Ejemplo n.º 2
0
        public override Match <IParseNode> Match(List <Lexeme> lexemes)
        {
            Match <IParseNode> match = Rule.Match(lexemes);

            IParseNode[] results = match.Success ? new[] { match.Result } : new IParseNode[0];
            if (match.Success)
            {
                return(new Match <IParseNode>(new BranchParseNode(this, match.Result.StartIndex, new[] { match.Result }), true));
            }
            else
            {
                return(new Match <IParseNode>(new BranchParseNode(this, lexemes.FirstOrDefault()?.StartIndex ?? -1, new IParseNode[0]), false));
            }
        }
Ejemplo n.º 3
0
        public override Match <IParseNode> Match(List <Lexeme> lexemes)
        {
            Super.ReportHypothesis(this, lexemes.FirstOrDefault()?.StartIndex);

            var match = Rule.Match(lexemes);

            if (match.Success)
            {
                Super.ReportSuccess(this, match.Result.MatchedText);
                return(new Match <IParseNode>(new BranchParseNode(this, match.Result.StartIndex, new[] { match.Result }), true));
            }
            else
            {
                Super.ReportFailure(this);
                return(new Match <IParseNode>(null, false));
            }
        }
Ejemplo n.º 4
0
        public override Match <IParseNode> Match(List <Lexeme> lexemes)
        {
            var index   = 0;
            var results = new List <IParseNode>();

            while (index < lexemes.Count)
            {
                Match <IParseNode> match = Rule.Match(lexemes.GetRange(index, lexemes.Count - index));
                if (match.Success)
                {
                    results.Add(match.Result);
                    index += match.Result.LexemeCount;
                }
                else
                {
                    break;
                }
            }

            return(new Match <IParseNode>(new BranchParseNode(this, lexemes.FirstOrDefault()?.StartIndex ?? -1, results), true));
        }