Пример #1
0
 public Token(TokenDescriptor descriptor, int line, int column, string value)
 {
     Descriptor = descriptor;
     Line       = line;
     Column     = column;
     Value      = value;
 }
Пример #2
0
        public ParsingState <T> WhenNextTokenIs(TokenDescriptor descriptor, Action <ParsingState <T> > action)
        {
            // Ignore white spaces
            InvokeIfMatching(descriptor, action);

            return(this);
        }
Пример #3
0
 private bool IsDeclModifier(TokenDescriptor tokenDescriptor)
 {
     return(tokenDescriptor.Kind == TokenKind.Keyword &&
            (tokenDescriptor == TokenDescriptor.InternalKeyword ||
             tokenDescriptor == TokenDescriptor.PublicKeyword ||
             tokenDescriptor == TokenDescriptor.ProtectedKeyword ||
             tokenDescriptor == TokenDescriptor.PrivateKeyword ||
             tokenDescriptor == TokenDescriptor.AbstractKeyword
            ));
 }
Пример #4
0
        public ParsingState <T> Expect(TokenDescriptor descriptor, Action <ParsingState <T> >?action = null)
        {
            if (InvokeIfMatching(descriptor, action))
            {
                return(this);
            }

            var actualToken = _lexer.PeekToken();

            throw new CaliParseException($"Expected '{descriptor.ReportableName}' but found '{actualToken.Value}'", 0,
                                         0);
        }
Пример #5
0
        private bool InvokeIfMatching(TokenDescriptor descriptor, Action <ParsingState <T> >?action)
        {
            // Ignore white spaces
            while (_lexer.PeekToken().Descriptor == TokenDescriptor.Space)
            {
                _lexer.NextToken();
            }

            if (_lexer.PeekToken().Descriptor == descriptor)
            {
                action?.Invoke(this);
                return(true);
            }

            return(false);
        }
Пример #6
0
        public ParsingState <T> Expect(TokenDescriptor descriptor, Action <T, Token> action)
        {
            // Ignore white spaces
            while (_lexer.PeekToken().Descriptor == TokenDescriptor.Space)
            {
                _lexer.NextToken();
            }

            if (_lexer.PeekToken().Descriptor == descriptor)
            {
                action(Syntax, _lexer.NextToken());
            }
            else
            {
                throw new CaliParseException(
                          $"Expecting '{descriptor.ReportableName}' but found '{_lexer.PeekToken().Value}'",
                          _lexer.PeekToken());
            }

            return(this);
        }
Пример #7
0
 internal TokenState(Lexer lexer, TokenDescriptor descriptor)
 {
     _lexer     = lexer;
     Descriptor = descriptor;
 }