Example #1
0
        private void ProcessMultiLine(CandidateDefinition matchingToken)
        {
            var multiLineType = _current.Type;
            var multiLineToken = new System.Text.StringBuilder(_current.Value);

            Match continuation;
            do
            {
                continuation = matchingToken.Definition.MultiLineContinuation.Match(_line);
                if (continuation.Value.Length > 0)
                {
                    AdvanceCurrentToken(
                        continuation,
                        matchingToken.Definition.Type
                    );

                    var linesConsumed = ReadNextLine();
                    multiLineToken.Append(_current.Value);
                    for (int i = 0; i < linesConsumed; i++)
                        multiLineToken.AppendLine();
                }
            }
            while (HasMoreTokens && continuation != null && continuation.Value.Length > 0);

            Match terminationMatch = matchingToken.Definition.MultiLineTerminator.Match(_line);
            if (terminationMatch.Value.Length < 0)
                throw new SyntaxException(String.Format("Failed to find terminal for {0}", matchingToken.Definition.Type));

            AdvanceCurrentToken(terminationMatch, matchingToken.Definition.Type);
            multiLineToken.Append(_current.Value);

            _current = new Token(multiLineToken.ToString(), multiLineType);
        }
Example #2
0
        private void ProcessMultiLine(CandidateDefinition matchingToken)
        {
            var multiLineType  = _current.Type;
            var multiLineToken = new System.Text.StringBuilder(_current.Value);

            Match continuation;

            do
            {
                continuation = matchingToken.Definition.MultiLineContinuation.Match(_line);
                if (continuation.Value.Length > 0)
                {
                    AdvanceCurrentToken(
                        continuation,
                        matchingToken.Definition.Type
                        );

                    var linesConsumed = ReadNextLine();
                    multiLineToken.Append(_current.Value);
                    for (int i = 0; i < linesConsumed; i++)
                    {
                        multiLineToken.AppendLine();
                    }
                }
            }while (HasMoreTokens && continuation != null && continuation.Value.Length > 0);

            Match terminationMatch = matchingToken.Definition.MultiLineTerminator.Match(_line);

            if (terminationMatch.Value.Length < 0)
            {
                throw new SyntaxException(String.Format("Failed to find terminal for {0}", matchingToken.Definition.Type));
            }

            AdvanceCurrentToken(terminationMatch, matchingToken.Definition.Type);
            multiLineToken.Append(_current.Value);

            _current = new Token(multiLineToken.ToString(), multiLineType);
        }