コード例 #1
0
ファイル: Parser.cs プロジェクト: pipe01/LICC
 private void AdvanceUntil(LexemeKind kind)
 {
     while (Current.Kind != kind)
     {
         Advance();
     }
 }
コード例 #2
0
 public Lexeme(LexemeKind kind, SourceLocation begin, SourceLocation end, string content)
 {
     this.Kind    = kind;
     this.Begin   = begin;
     this.End     = end;
     this.Content = content;
 }
コード例 #3
0
ファイル: Lexer.cs プロジェクト: NeatWolf/LogicScript
        private Lexeme Lexeme(LexemeKind kind)
        {
            var content = Builder.ToString();

            Builder.Clear();

            return(Lexeme(kind, content));
        }
コード例 #4
0
ファイル: Parser.cs プロジェクト: pipe01/LICC
        private bool Peek(LexemeKind kind, bool ignoreWhitespace = true)
        {
            if (ignoreWhitespace)
            {
                SkipWhitespaces();
            }

            return(Index < Lexemes.Length - 1 && Lexemes[Index + 1].Kind == kind);
        }
コード例 #5
0
ファイル: PiLexer.cs プロジェクト: pipe01/pi
        private Lexeme Lexeme(LexemeKind kind, string content = null)
        {
            content = content ?? Buffer;
            Buffer  = "";

            var begin = Location;
            var end   = new SourceLocation(Line, Column + content.Length, Index + content.Length);

            return(new Lexeme(kind, begin, end, content));
        }
コード例 #6
0
        private Lexeme Lexeme(LexemeKind kind, string content = null)
        {
            if (kind == LexemeKind.NewLine)
            {
                Column = 0;
                Line++;
            }

            content = content ?? kind.GetCharacter() ?? Buffer.ToString();
            Buffer.Clear();

            return(new Lexeme(kind, Location, content));
        }
コード例 #7
0
        private Lexeme Take(LexemeKind lexemeKind, bool ignoreWhitespace = true)
        {
            if (ignoreWhitespace)
            {
                SkipWhitespaces();
            }

            if (Current.Kind != lexemeKind)
            {
                Error($"Unexpected lexeme: expected {lexemeKind}, found {Current}");
            }

            return(TakeAny());
        }
コード例 #8
0
ファイル: Parser.cs プロジェクト: pipe01/LICC
        private Lexeme Take(LexemeKind lexemeKind, string expected = null, bool ignoreWhitespace = true)
        {
            if (ignoreWhitespace)
            {
                SkipWhitespaces();
            }

            if (Current.Kind != lexemeKind)
            {
                var lexemeChar = lexemeKind.GetCharacter();
                Error($"expected {expected ?? lexemeKind.ToString()}{(lexemeChar != null ? $" '{lexemeChar}'" : "")}, found '{Current.Content}' ({Current.Kind})");
            }

            return(TakeAny());
        }
コード例 #9
0
        private bool Take(LexemeKind lexemeKind, out Lexeme lexeme, bool ignoreWhitespace = true)
        {
            if (ignoreWhitespace)
            {
                SkipWhitespaces();
            }

            if (Current.Kind == lexemeKind)
            {
                lexeme = TakeAny();
                return(true);
            }

            lexeme = null;
            return(false);
        }
コード例 #10
0
ファイル: Lexer.cs プロジェクト: NeatWolf/LogicScript
 private Lexeme Lexeme(LexemeKind kind, string content) => new Lexeme(kind, content, new SourceLocation(Line, Column - (content?.Length ?? 0)));
コード例 #11
0
ファイル: LexemeKind.cs プロジェクト: pipe01/LICC
 public static string GetCharacter(this LexemeKind kind)
 {
     return(CharCache.TryGetValue(kind, out var c)
         ? c
         : CharCache[kind] = typeof(LexemeKind).GetField(kind.ToString()).GetCustomAttribute <DescriptionAttribute>()?.Description);
 }
コード例 #12
0
 public Lexeme(LexemeKind kind)
 {
     Kind = kind;
 }
コード例 #13
0
ファイル: Lexeme.cs プロジェクト: NeatWolf/LogicScript
 public Lexeme(LexemeKind kind, string content, SourceLocation location)
 {
     this.Kind     = kind;
     this.Content  = content;
     this.Location = location;
 }