示例#1
0
        public Lexer()
            : base(error => new SyntaxError((IssueId) error))
        {
            var alpha = Match.Letter.Else("_");
            var symbol1 = "({[)}];,".AnyChar();
            var textFrame = "'\"".AnyChar();
            var symbol = "°^!²§³$%&/=?\\@€*+~><|:.-".AnyChar();

            var identifier = (alpha + alpha.Else(Match.Digit).Repeat()).Else(symbol.Repeat(1));

            _any = symbol1.Else(identifier);

            _whiteSpaces = Match.WhiteSpace.Repeat(1);

            _comment =
                ("#" + " \t".AnyChar() + Match.LineEnd.Find)
                    .Else("#(" + Match.WhiteSpace + (Match.WhiteSpace + ")#").Find)
                    .Else("#(" + _any.Value(id => (Match.WhiteSpace + id + ")#").Box().Find))
                    .Else("#(" + Match.End.Find + _invalidComment)
                    .Else("#" + Match.End.Find + _invalidLineComment)
                ;

            _number = Match.Digit.Repeat(1);

            _text = textFrame.Value
            (
                head =>
                {
                    var textEnd = head.Else(Match.LineEnd + _invalidTextEnd);
                    return textEnd.Find + (head + textEnd.Find).Repeat();
                });
        }
示例#2
0
文件: Lexer.cs 项目: hahoyer/reni.cs
        Lexer()
            : base(error => new ScannerSyntaxError((IssueId) error))
        {
            var alpha = Match.Letter.Else("_");
            var symbol1 = SingleCharSymbol.AnyChar();
            var textFrame = "'\"".AnyChar();
            var symbol = Symbols.AnyChar();

            var identifier = (alpha + alpha.Else(Match.Digit).Repeat()).Else(symbol.Repeat(1));

            _any = symbol1.Else(identifier);

            _lineEnd = "\r\n".Box().Else("\n".Box()).Else("\r" + Match.End);
            _lineEndOrEnd = _lineEnd.Else(Match.End);

            _lineComment = "#"
                +
                _lineEndOrEnd
                    .Else
                    (
                        "(".AnyChar().Not +
                        _lineEnd.Find
                            .Else(Match.End.Find)
                    );

            _whiteSpace = " \t".AnyChar();
            _comment = "#("
                +
                (Match.WhiteSpace + (Match.WhiteSpace + ")#").Find)
                    .Else(identifier.Value(id => (Match.WhiteSpace + id + ")#").Box().Find))
                    .Else(Match.End.Find + _invalidComment)
                ;

            _commentHead = "#(" + Match.WhiteSpace.Else(identifier);

            _number = Match.Digit.Repeat(1);

            var varbatimText = "@("
                    +
                    (Match.WhiteSpace + (Match.WhiteSpace + ")@").Find)
                        .Else(identifier.Value(id => (Match.WhiteSpace + id + ")@").Box().Find))
                        .Else(Match.End.Find + _invalidTextEnd)
                ;

            _varbatimTextHead = "@(" + Match.WhiteSpace.Else(identifier);
            _text = textFrame.Value
                (
                    head =>
                    {
                        var textEnd = head.Else(_lineEndOrEnd + _invalidTextEnd);
                        return textEnd.Find + (head + textEnd.Find).Repeat();
                    })
                .Else(varbatimText);

            LineCommentItem = new LexerItem(new WhiteSpaceTokenType(), LineComment);
            CommentItem = new LexerItem(new WhiteSpaceTokenType(), Comment);
            LineEndItem = new LexerItem(new WhiteSpaceTokenType(), LineEnd);
            WhiteSpaceItem = new LexerItem(new WhiteSpaceTokenType(), WhiteSpace);
        }
示例#3
0
 public Lexer()
 {
     var alpha = Match.Letter.Else("_");
     var symbol1 = "({[)}];,".AnyChar();
     var symbol = "°^!²§³$%&/=?\\@€*+~><|:.-".AnyChar();
     var identifier = (alpha + alpha.Else(Match.Digit).Repeat()).Else(symbol.Repeat(1));
     _any = symbol1.Else(identifier);
     _whiteSpaces = Match.WhiteSpace.Repeat(1);
     _number = Match.Digit.Repeat(1);
 }
 public ErrorMatch(Match.IError error) { _error = error; }
 public static Match Else(this IMatch data, Match.IError other) => data.Else(other.Box());