public MethodSymbol AddMethod(IdentToken token, Type type, FormalParamSymbol[] formalParams, MethodInfo methodInfo)
        {
            var result = new MethodSymbol(token, type, formalParams, methodInfo);

            symbolTable.Peek().Add(token.value, result);
            return(result);
        }
Пример #2
0
        static ClassSelector Consume_Class_Selector(DataConsumer <CssToken> Stream)
        {
            Stream.Consume();// Consume the '.' prefixing the classname
            IdentToken Ident = Stream.Consume <IdentToken>();

            return(new ClassSelector(Ident.Value));
        }
        public FormalParamSymbol AddFormalParam(IdentToken token, Type type, ParameterBuilder parameterInfo)
        {
            var result = new FormalParamSymbol(token, type, parameterInfo);

            symbolTable.Peek().Add(token.value, result);
            return(result);
        }
Пример #4
0
        private Identifier ParseIdentifier(Token at = null)
        {
            Contracts.AssertValueOrNull(at);

            IdentToken tok;

            if (_curs.TidCur == TokKind.Ident)
            {
                tok = _curs.TokMove().As <IdentToken>();
                if (tok.HasDelimiterStart && !tok.HasDelimiterEnd)
                {
                    PostError(tok, TexlStrings.ErrClosingBracketExpected);
                }
                else if (tok.IsModified)
                {
                    PostError(tok, TexlStrings.ErrEmptyInvalidIdentifier);
                }
            }
            else if (_curs.TidCur == TokKind.ReplaceableLit)
            {
                tok = new IdentToken(_curs.TokMove().As <ReplaceableToken>());
            }
            else
            {
                ErrorTid(_curs.TokCur, TokKind.Ident);
                int ich = _curs.TokCur.Span.Min;
                tok = new IdentToken(string.Empty, new Span(ich, ich));
            }

            return(new Identifier(at, tok));
        }
        public FieldSymbol AddField(IdentToken token, FieldInfo field)
        {
            var result = new FieldSymbol(token, field);

            fieldScope.Add(token.value, result);
            return(result);
        }
        public LocalVarSymbol AddLocalVar(IdentToken token, LocalBuilder localBuilder)
        {
            var result = new LocalVarSymbol(token, localBuilder);

            symbolTable.Peek().Add(token.value, result);
            return(result);
        }
Пример #7
0
 public ParameterNode(IdentToken ident, OperatorToken opr, LiteralNode literal, TypeNode typeNode)
     : base(SyntaxKind.ParameterNode)
 {
     AddNode(ident);
     AddNode(opr);
     AddNode(literal);
     AddNode(typeNode);
 }
Пример #8
0
 public ParameterNode(IdentToken ident, TypeNode typeNode)
     : base(SyntaxKind.ParameterNode)
 {
     AddNode(ident);
     if (typeNode != null)
     {
         AddNode(typeNode);
     }
 }
Пример #9
0
        public Identifier(DPath theNamespace, Token atToken, IdentToken tok)
        {
            Contracts.Assert(theNamespace.IsValid);
            Contracts.AssertValueOrNull(atToken);
            Contracts.AssertValue(tok);
            Contracts.Assert(tok.Name.IsValid);

            Namespace = theNamespace;
            AtToken   = atToken;
            Token     = tok;
            Name      = tok.Name;
        }
Пример #10
0
        /// <summary>
        /// Consumes and returns an An+B token from a <see cref="TokenStream"/>
        /// </summary>
        /// <param name="Tokens"></param>
        /// <returns></returns>
        public static CssAnBMatcher Consume(DataConsumer <CssToken> Stream)
        {
            // TODO: Test An+B syntax parsing
            int A = 0;
            int B = 0;

            if (Stream.Next.Type == ECssTokenType.Ident)// this token is a word, but we only accept 'even' or 'odd'
            {
                IdentToken word = Stream.Consume <IdentToken>();
                if (word.Value.Equals("even", StringComparison.OrdinalIgnoreCase))
                {
                    return(new CssAnBMatcher(2, 0));                                                              //{ A = 2; B = 0; }
                }
                else if (word.Value.Equals("odd", StringComparison.OrdinalIgnoreCase))
                {
                    return(new CssAnBMatcher(2, 1));                                                                  //{ A = 2; B = 1; }
                }
                else
                {
                    throw new CssSyntaxErrorException($"Invalid identity token ({word.Value}) within An+B syntax");
                }

                // if (Stream.Next != Stream.EOF_ITEM) throw new CssSyntaxError("Expected EOF!");
                // return null;
            }
            else if (Stream.Next.Type == ECssTokenType.Dimension)
            {
                DimensionToken dim = Stream.Consume() as DimensionToken;
                if (dim.DataType == ENumericTokenType.Integer && dim.Unit.Equals("n", StringComparison.OrdinalIgnoreCase))
                {// <n-dimension>
                    throw new NotImplementedException($"{nameof(CssAnBMatcher)} Has not implemented parsing support for {nameof(ECssTokenType.Dimension)}");
                }
                else if (dim.DataType == ENumericTokenType.Integer && dim.Unit.Equals("n-", StringComparison.OrdinalIgnoreCase))
                {// <ndash-dimension>
                    throw new NotImplementedException($"{nameof(CssAnBMatcher)} Has not implemented parsing support for {nameof(ECssTokenType.Dimension)}");
                }
                else if (dim.DataType == ENumericTokenType.Integer && dim.Unit.StartsWith("n-", StringComparison.OrdinalIgnoreCase))
                {// <ndashdigit-dimension>
                    throw new NotImplementedException($"{nameof(CssAnBMatcher)} Has not implemented parsing support for {nameof(ECssTokenType.Dimension)}");
                }
            }
            else if (Stream.Next.Type == ECssTokenType.Ident)
            {
                throw new NotImplementedException($"{nameof(CssAnBMatcher)} Has not implemented parsing support for {nameof(ECssTokenType.Ident)}");
            }
            else if (Stream.Next.Type == ECssTokenType.Number)
            {
                throw new NotImplementedException($"{nameof(CssAnBMatcher)} Has not implemented parsing support for {nameof(ECssTokenType.Number)}");
            }

            return(new CssAnBMatcher(A, B));
        }
Пример #11
0
        static AttributeSelector Consume_Attribute_Selector(DataConsumer <CssToken> Stream)
        {
            Stream.Consume();// Consume the '[' prefix

            NamespacePrefixToken NS = null;

            if (Starts_NamespacePrefix(Stream.Next, Stream.NextNext))
            {
                NS = Consume_NamespacePrefix(Stream);
            }

            //QualifiedNameToken attrName = Stream.Consume<QualifiedNameToken>();
            IdentToken attrName = Stream.Consume <IdentToken>();
            CssToken   Tok      = Stream.Consume();

            if (Tok.Type == ECssTokenType.SqBracket_Close)
            {
                return(new AttributeSelector(NS, attrName.Value));
            }

            CssToken OperatorToken = Tok;
            CssToken value         = Stream.Consume();

            if (value.Type == ECssTokenType.SqBracket_Close)
            {
                return(null);                                            // Parse error
            }
            if (Stream.Next.Type != ECssTokenType.SqBracket_Close)
            {
                return(null); // Parse error
            }
            Stream.Consume(); // Consume the closing bracket

            if (value.Type == ECssTokenType.String)
            {
                return(new AttributeSelector(NS, attrName.Value, OperatorToken, (value as StringToken).Value));
            }
            else if (value.Type == ECssTokenType.Ident)
            {
                return(new AttributeSelector(NS, attrName.Value, OperatorToken, (value as IdentToken).Value));
            }

            return(null);// Parse error
        }
        public void AugmentCompletionSession(ICompletionSession session, IList <CompletionSet> completionSets)
        {
            SourceText sourceText        = this.m_sourceTextCache.Get(m_textBuffer.CurrentSnapshot);
            SyntaxTree syntaxTree        = this.m_parseTreeCache.Get(sourceText);
            var        triggerPoint      = (SnapshotPoint)session.GetTriggerPoint(m_textBuffer.CurrentSnapshot);
            var        ch                = triggerPoint.GetChar();
            Token      currentToken      = null;
            int        currentTokenIndex = 0;

            for (; currentTokenIndex < syntaxTree.Tokens.Count; currentTokenIndex++)
            {
                var token = syntaxTree.Tokens[currentTokenIndex];
                if ((token.Start <= triggerPoint.Position) && (token.Start + token.Length) >= triggerPoint.Position)
                {
                    currentToken = token;
                    break;
                }
            }
            List <string> strList = new List <string>();

            if (currentToken == null)
            {
                return;
            }
            if (currentToken.Kind == SyntaxKind.Dot)
            {
                //user inputs dot. Try search members
                var targetname = syntaxTree.Tokens[currentTokenIndex - 1].Text;
                if (syntaxTree.Root != null && targetname == "m")
                {
                    syntaxTree.Root
                    .Descendants()
                    .OfType <BlockNode>()
                    .Where(b =>
                           b.Start <triggerPoint.Position &&
                                    b.End> triggerPoint.Position &&
                           !b.Descendants().OfType <BlockNode>().Any(c => c.Start <triggerPoint.Position && c.End> triggerPoint.Position))
                    .SelectMany(b => b.Children)
                    .OfType <LabelledStatementNode>()
                    .ToList()
                    .ForEach(l =>
                    {
                        var ident = l.Children.OfType <IdentToken>().FirstOrDefault();
                        if (ident != null)
                        {
                            strList.Add(ident.Name);
                        }
                    });
                }
                m_memberlist = true;
            }
            else
            {
                //list all variables and keywords
                strList.AddRange(GetList());
                strList.Add("m");

                if (syntaxTree.Root != null)
                {
                    syntaxTree.Root
                    .Descendants()
                    .OfType <SourceElementNode>()
                    .ToList()
                    .ForEach(e =>
                    {
                        var ident = e.Children.OfType <IdentToken>().FirstOrDefault();
                        if (ident != null)
                        {
                            strList.Add(ident.Name);
                        }
                    });

                    syntaxTree.Root
                    .Descendants()
                    .OfType <SourceElementNode>()
                    .Where(e =>
                           e.Start <triggerPoint.Position &&
                                    e.End> triggerPoint.Position &&
                           !e.Descendants()
                           .OfType <FunctionExpressionNode>()
                           .Any(c => c.Start <triggerPoint.Position && c.End> triggerPoint.Position))
                    .ToList()
                    .SelectMany(e => e.Children.OfType <StatementListNode>())
                    .SelectMany(e => e.Children.OfType <AssignStatementNode>())
                    .ToList()
                    .ForEach(e =>
                    {
                        IdentToken ident = e.Children.OfType <IdentToken>().FirstOrDefault();
                        if (ident == null)
                        {
                            var left = e.Children[0] as SyntaxNode;
                            ident    = left.Descendants().OfType <IdentToken>().FirstOrDefault();
                        }

                        if (ident != null)
                        {
                            strList.Add(ident.Name);
                        }
                    });

                    syntaxTree.Root
                    .Descendants()
                    .OfType <FunctionExpressionNode>()
                    .Where(f =>
                           f.Start <triggerPoint.Position &&
                                    f.End> triggerPoint &&
                           !f.Descendants()
                           .OfType <FunctionExpressionNode>()
                           .Any(c => c.Start <triggerPoint.Position && c.End> triggerPoint.Position))
                    .SelectMany(e => e.Children.OfType <StatementListNode>())
                    .SelectMany(e => e.Children.OfType <AssignStatementNode>())
                    .ToList()
                    .ForEach(e =>
                    {
                        var ident = e.Children.OfType <IdentToken>().FirstOrDefault();
                        if (ident == null)
                        {
                            var left = e.Children[0] as SyntaxNode;
                            ident    = left.Descendants().OfType <IdentToken>().FirstOrDefault();
                        }

                        if (ident != null)
                        {
                            strList.Add(ident.Name);
                        }
                    });
                }
                m_memberlist = false;
            }
            strList.Sort();
            this.m_compList = new List <Completion>();
            foreach (string str in strList)
            {
                this.m_compList.Add(new Completion(str, str, str, null, null));
            }

            completionSets.Add(new CompletionSet(
                                   "Tokens", // the non-localized title of the tab
                                   "Tokens", // the display title of the tab
                                   this.FindTokenSpanAtPosition(session.GetTriggerPoint(this.m_textBuffer),
                                                                session),
                                   m_compList,
                                   null));
        }
Пример #13
0
        public void EncodeTest(string Value)
        {
            string Actual = new IdentToken(Value).Encode();

            Assert.Equal(Value, Actual);
        }
Пример #14
0
 public Identifier(Token atToken, IdentToken token)
     : this(DPath.Root, atToken, token)
 {
 }
Пример #15
0
        static IMediaCondition Consume_Media_Feature(DataConsumer <CssToken> Stream)
        {/* Docs: https://drafts.csswg.org/mediaqueries-4/#mq-syntax */
            if (Stream is null)
            {
                throw new CssParserException(CssErrors.STREAM_IS_NULL);
            }


            /* Consume feature name */
            if (ParserCommon.Starts_Boolean_Feature(Stream.AsSpan()))
            {
                /* Consume feature name */
                IdentToken nameTok = Stream.Consume() as IdentToken;

                /* Resolve the name */
                if (!Lookup.TryEnum(nameTok.Value, out EMediaFeatureName Name))
                {
                    throw new CssParserException(String.Format(CultureInfo.InvariantCulture, CssErrors.INVALID_MEDIA_TYPE, nameTok.Value), Stream);
                }

                return(new MediaFeature(Name));
            }
            else if (ParserCommon.Starts_Discreet_Feature(Stream.AsSpan()))
            {
                /* Consume feature name */
                IdentToken nameTok = Stream.Consume() as IdentToken;

                /* Resolve the name */
                if (!Lookup.TryEnum(nameTok.Value, out EMediaFeatureName Name))
                {
                    throw new CssParserException(String.Format(CultureInfo.InvariantCulture, CssErrors.INVALID_MEDIA_TYPE, nameTok.Value), Stream);
                }

                /* Consume the value to match */
                Consume_All_Whitespace(Stream);
                var value = Consume_MediaFeature_Value(Stream);

                return(new MediaFeature(new CssValue[] { CssValue.From(Name), value }, new EMediaOperator[] { EMediaOperator.EqualTo }));
            }
            else if (ParserCommon.Starts_Range_Feature(Stream.AsSpan()))
            {
                /* This is a range feature of some sort, it could be a short one or a long one */
                /* Repeatedly consume CssValues, operator, and a single ident */
                LinkedList <CssValue>       Values = new LinkedList <CssValue>();
                LinkedList <EMediaOperator> Ops    = new LinkedList <EMediaOperator>();
                bool firstToken        = true;
                bool lastWasComparator = false;

                while (Stream.Next != CssToken.EOF)
                {
                    Consume_All_Whitespace(Stream);

                    if (Stream.Next.Type == ECssTokenType.Parenth_Close)
                    {
                        break;
                    }
                    else if (Stream.Next.Type == ECssTokenType.Ident)
                    {
                        if (!firstToken && !lastWasComparator)
                        {
                            throw new CssSyntaxErrorException(CssErrors.EXPECTING_COMPARATOR, Stream);
                        }

                        var nameTok = (IdentToken)Stream.Consume();
                        /* Resolve the name */
                        if (!Lookup.TryEnum(nameTok.Value, out EMediaFeatureName Name))
                        {
                            throw new CssParserException(String.Format(CultureInfo.InvariantCulture, CssErrors.INVALID_MEDIA_TYPE, nameTok.Value), Stream);
                        }

                        var value = CssValue.From(Name);
                        Values.AddLast(value);
                        lastWasComparator = false;
                    }
                    else if (ParserCommon.Starts_MF_Ident_Or_Value(Stream.AsSpan()))
                    {
                        if (!firstToken && !lastWasComparator)
                        {
                            throw new CssSyntaxErrorException(CssErrors.EXPECTING_COMPARATOR, Stream);
                        }

                        CssValue value = Consume_MediaFeature_Value(Stream);
                        Values.AddLast(value);
                        lastWasComparator = false;
                    }
                    else if (ParserCommon.Is_Comparator(Stream.Next))
                    {
                        if (lastWasComparator || firstToken)
                        {
                            throw new CssSyntaxErrorException(CssErrors.UNEXPECTED_TOKEN, Stream);
                        }

                        var comparatorTok = (ValuedTokenBase)Stream.Consume();
                        if (!Lookup.TryEnum(comparatorTok.Value, out EMediaOperator outComparator))
                        {
                            throw new CssParserException(CssErrors.EXPECTING_COMPARATOR, Stream);
                        }

                        Ops.AddLast(outComparator);
                        lastWasComparator = true;
                    }

                    firstToken = false;
                }

                return(new MediaFeature(Values.ToArray(), Ops.ToArray()));
            }

            return(null);
        }
 public FieldSymbol(IdentToken token, FieldInfo fieldInfo) : base(token.line, token.column, token.value)
 {
     FieldInfo = fieldInfo;
 }
 public FormalParamSymbol(IdentToken token, Type paramType, ParameterBuilder parameterInfo) : base(token.line, token.column, token.value)
 {
     ParamType     = paramType;
     ParameterInfo = parameterInfo;
 }
 public TypeSymbol(IdentToken token, Type type) : base(token.line, token.column, token.value)
 {
     this.type = type;
 }
Пример #19
0
        // get token element from current line feed

        // returns null if no token to get is found.
        public Token getNextToken()
        {
            //  Note from Colin:

            // write code to take chars out of string named

            // inputBufferLine

            // IMPORTANT: before  using this method, make sure to put this getNextToken with it's

            // own loop (in SPP.cs) nested inside one that reads a good newLine from the readAnotherLine

            // so we have something to read tokens from



            // only used for buffer if last look was peek. other wise a fresh new token is found

            //gives a previous new find

            if (this.preinspected_PEEK_token == null)
            {
                return(null);
            }



            if (this.ifPast_lookWasPeek == true && !this.makeANew_Peek)
            {
                // this only really gets set to false by a call purely from getNextToken in Parser
                // since
                //    peek's method behind the scenes set ifPast_lookWasPeek to true
                this.ifPast_lookWasPeek = false;

                return(this.preinspected_PEEK_token);
            }


            // else
            //  find a new token to be returned
            Token returnToken = null;

            try

            {
                // start parsing getToken() process off
                // by reading a line from input
                //   Is run once only : in SPP.
                if (!this.readFirstLine)
                {
                    this.readFirstLine = true;
                    // readAnotherLine returns false if there is no new line to be read!
                    this.noMoreLinesOfInput = this.readAnotherLine();
                    if (this.noMoreLinesOfInput == false)
                    {
                        Console.Error.WriteLine("error: no input given.");
                        this.preinspected_PEEK_token = null;
                        return(null);
                    }
                }

                // read another line :: because last line's characters are all used Up
                if (charIndexOfReadLine > this.inputBufferLine.Length - 1)
                {
                    // readAnotherLine returns false if there is no new line to be read!
                    this.noMoreLinesOfInput = this.readAnotherLine();
                }

                if (!this.noMoreLinesOfInput)
                {
                    this.preinspected_PEEK_token = null;
                    // return null value
                    return(returnToken);
                }



                int numberDotsForDecimal = 0;

                //bool currentTokenIsNumber = false;

                bool number_lastCharWasDecimal = false;



                // setup reference for a Start and End Index, of a String in input expression

                int someStringLowerBound;

                int someStringLength;

                int someStringUpperBound;



                // if true, stop reading characters in constant someString

                bool endOfSomeStringReached;



                // It would be more efficient if we'd maintain our own

                // input buffer and read characters out of that

                // buffer, but reading individual characters from the

                // input stream is easier.



                //// wrong code in original zip was: ch = reader.Read();

                char ch;



                ch = buf[charIndexOfReadLine];


                while (charIndexOfReadLine <= inputBufferLine.Length - 1)
                {
                    ch = buf[charIndexOfReadLine];

                    // if whitespace or a tab ... skip and iterate to next character.

                    if (ch == 32 || ch == 9)

                    {
                        charIndexOfReadLine++;

                        continue;
                    }

                    else
                    {
                        break;
                    }
                }
                // if end of current line read  ,  return getNextToken()
                if (charIndexOfReadLine > inputBufferLine.Length - 1)
                {
                    return(getNextToken());
                }


                // reset this boolean to null or false.

                endOfSomeStringReached = false;

                // reset all these to zero

                someStringLowerBound = 0;

                someStringLength = 0;

                someStringUpperBound = 0;



                numberDotsForDecimal = 0;

                // need to use this variable in revision number 1 that is to happen

                //currentTokenIsNumber = false;



                number_lastCharWasDecimal = false;



                // Special characters

                if (ch == '\'')

                {
                    this.quoteMark_engaged = true;

                    charIndexOfReadLine++;

                    Parser.quote_mark_misc_to_placed_cursor__is_not_new_data = true;

                    return(new Token(TokenType.LPAREN));
                }

                else if (ch == '(')

                {
                    // copy char to token

                    this.charIndexOfReadLine++;

                    //return new Token (TokenType.LPAREN);

                    numberParentheses_L++;

                    returnToken = new Token(TokenType.LPAREN);


                    return(returnToken);
                }

                else if (ch == ')')

                {
                    //return new Token (TokenType.RPAREN);

                    if (numberParentheses_R > numberParentheses_L)
                    {
                        this.charIndexOfReadLine++;
                        if (flag_debugger)
                        {
                            Console.WriteLine("RPAREN");
                        }
                        else
                        {
                            Console.Error.WriteLine("Too many Right Parentheses>: error! \n continued... :Last input ignored!");
                        }

                        return(getNextToken());
                    }
                    else

                    {
                        if (this.numberParentheses_L > this.numberParentheses_R)
                        {
                            this.numberParentheses_L--;
                        }

                        // copy char to token


                        this.charIndexOfReadLine++;

                        returnToken = new Token(TokenType.RPAREN);


                        return(returnToken);
                    }
                }

                else if (ch == '.')

                {
                    // copy char to token


                    this.charIndexOfReadLine++;



                    // We ignore the special identifier `...'.


                    returnToken = new Token(TokenType.DOT);
                    //return new Token (TokenType.DOT);

                    return(returnToken);
                }

                // Boolean constants

                else if (ch == '#')

                {
                    // note... Work on.. As said above:

                    charIndexOfReadLine++;



                    if (charIndexOfReadLine <= inputBufferLine.Length - 1)

                    {
                        ch = buf[charIndexOfReadLine];

                        if (ch == 't')

                        {
                            // copy char to token


                            this.charIndexOfReadLine++;

                            returnToken = new Token(TokenType.TRUE);


                            //return new Token (TokenType.TRUE);
                            return(returnToken);
                        }

                        else if (ch == 'f')

                        {
                            // copy char to token


                            this.charIndexOfReadLine++;

                            returnToken = new Token(TokenType.FALSE);



                            //return new Token (TokenType.FALSE);
                            return(returnToken);
                        }

                        else

                        {
                            this.charIndexOfReadLine++;
                            if (!flag_debugger)
                            {
                                Console.Error.WriteLine("Illegal character '" +

                                                        ch + "' following #");
                            }

                            //Console.Error.WriteLine ("Illegal character '" +

                            // char)ch + "' following #");

                            return(getNextToken());
                        }
                    }
                    return(getNextToken());
                }



                // String constants

                else if (ch == '"')

                {
                    // TODO: scan a string into the buffer variable buf

                    //return new StringToken (new String (buf, 0, 0));



                    // colin's dealing

                    someStringLowerBound = charIndexOfReadLine;

                    // increment by 1 more character in array

                    charIndexOfReadLine++;


                    // increment someStringLength 1  for quotation mark "
                    someStringLength++;



                    while (!endOfSomeStringReached && charIndexOfReadLine <= inputBufferLine.Length - 1)

                    {
                        // set tentative someStringLength...



                        someStringLength++;

                        // tentative upper bound of someString  for future reference....

                        someStringUpperBound = charIndexOfReadLine;



                        // check if next scanned character is backslash delimiter...

                        if (buf[charIndexOfReadLine] == '\\')

                        {
                            // skip past the delimiter backslash and also the following quote Char

                            charIndexOfReadLine += 2;

                            someStringLength++;
                        }

                        else if (buf[charIndexOfReadLine] == '"')

                        {
                            endOfSomeStringReached = true;

                            this.charIndexOfReadLine++;
                            someStringUpperBound = this.charIndexOfReadLine;
                        }

                        // iterate to next Char

                        else
                        {
                            charIndexOfReadLine++;
                        }
                    }

                    if (!endOfSomeStringReached)
                    {
                        Console.Error.WriteLine("String does not finish on line,... error: ran out of characters.");
                        return(null);
                    }


                    // Given that upperBound cannot have been written to be out of array bounds,

                    //    this checks if the end of quote is the last term in the current Line.

                    else if (someStringUpperBound == inputBufferLine.Length - 1)

                    {
                        returnToken = new StringToken(new String(buf, someStringLowerBound, someStringLength));

                        // return string literal ... that was just scanned

                        // return string literal ... that was just scanned
                        //if (!flag_debugger)
                        //Console.WriteLine("value: " + new String(buf, someStringLowerBound, someStringLength));

                        return(returnToken);

                        // remove comment not necessary
                        // Console.WriteLine("continuation Halted: lineTerminates Abruptedly");
                    }

                    // copy char to token


                    // return string literal ... that was just scanned

                    else if (someStringLength != 0)
                    {
                        // copy char to token

                        //if (!flag_debugger)
                        //Console.WriteLine("value: " + new String(buf, someStringLowerBound, someStringLength));

                        returnToken = new StringToken(new String(buf, someStringLowerBound, someStringLength));


                        return(returnToken);
                    }
                    // String has nothing to it  : i.e.  "[blank]
                    //else
                    // {
                    //    Console.WriteLine("value: error   Incomplete expression String literal");
                    //    return getNextToken();
                    //}

                    // dummy return null;
                    return(returnToken);
                }



                // Integer constants

                else if (ch >= '0' && ch <= '9')

                {
                    //int i = ch - '0';



                    someStringLength++;



                    someStringLowerBound = charIndexOfReadLine;



                    // increment by 1 more character in array

                    charIndexOfReadLine++;



                    // someStringLength starts at 0



                    while (!endOfSomeStringReached && charIndexOfReadLine <= inputBufferLine.Length - 1)

                    {
                        ch = buf[charIndexOfReadLine];



                        // if a space appears, ... move out of number retrieval loop

                        if (ch == 32 || ch == 9)

                        {
                            if (numberDotsForDecimal == 1 && number_lastCharWasDecimal)

                            {
                                // error
                                if (!flag_debugger)
                                {
                                    Console.Error.WriteLine("incorrect decimal form: needs a number for right side of decimal.");
                                }
                                else
                                {
                                    Console.WriteLine("unknown type number decimal: i.e. 10._blank");
                                }
                                return(getNextToken());
                            }

                            else

                            {
                                endOfSomeStringReached = true;

                                break;
                            }
                        }

                        /**
                         *  DONT NEED THIS
                         * else if (ch == '(')
                         * {
                         *
                         *
                         *  this.charIndexOfReadLine++;
                         *
                         *  Console.WriteLine("illegal previous number. Use of right ')' not correct.");
                         *
                         *  return getNextToken();
                         *
                         * }
                         *
                         **/

                        else if (ch == ')')

                        {
                            endOfSomeStringReached = true;

                            //return new Token (TokenType.RPAREN);

                            if (numberParentheses_R > numberParentheses_L)
                            {
                                this.charIndexOfReadLine++;
                                //Console.WriteLine("Too many Right Parentheses>: error! \n continued... :Last input ignored!");
                                return(getNextToken());
                            }
                            else

                            {
                                // rules out having a right Parenthesis  if number was like

                                // 10.)


                                if (number_lastCharWasDecimal)

                                {
                                    this.charIndexOfReadLine++;
                                    if (!flag_debugger)
                                    {
                                        Console.Error.WriteLine("illegal previous number. Use of right ')' not correct.");
                                    }
                                    else
                                    {
                                        Console.WriteLine("unknown type number decimal: i.e. 10.) so on ");
                                    }
                                    return(getNextToken());
                                }

                                else

                                {
                                    // copy char to token


                                    // need to configure token to take either decimal or integer.

                                    double intermediateVal = Convert.ToDouble(new String(buf, someStringLowerBound, someStringLength));

                                    int intVal = Convert.ToInt32(intermediateVal);
                                    returnToken = new IntToken(intVal);


                                    return(returnToken);

                                    //endOfSomeStringReached   dont activate   already printed



                                    //numberParentheses_L--;

                                    // on next getToken() call... take in token of parenthesis... later..
                                }
                            }
                        }



                        // scan over first decimal for a floating p

                        if (numberDotsForDecimal == 0 && ch == '.')

                        {
                            number_lastCharWasDecimal = true;



                            numberDotsForDecimal = 1;



                            // set tentative someStringLength...



                            someStringLength++;

                            charIndexOfReadLine++;

                            continue;
                        }

                        // rules out more than one dot symbol

                        else if (numberDotsForDecimal >= 1 && ch == '.')

                        {
                            this.charIndexOfReadLine++;
                            if (!flag_debugger)
                            {
                                Console.Error.WriteLine("illegal numeric decimal form: cannot have more than one period.");
                            }
                            else
                            {
                                Console.WriteLine("unknown type number decimal: i.e. 10.. ends abruptedly at number dot followed by dot");
                            }
                            return(getNextToken());

                            //break;
                        }

                        // rules out wrong symbols for numeric decimal digits right side of dot

                        else if (numberDotsForDecimal == 1 && number_lastCharWasDecimal && !(ch >= '0' && ch <= '9'))

                        {
                            this.charIndexOfReadLine++;
                            if (!flag_debugger)
                            {
                                Console.Error.WriteLine("incorrect decimal form: need a number for right side of decimal \n illegal start of identifier. : an identifier cannot start with numerical digits.");
                            }
                            else
                            {
                                Console.WriteLine("unknown type number decimal: i.e. 10.$*$U)) so on ");
                            }
                            return(getNextToken());

                            //break;
                        }



                        // rules out symbols that are not numbers

                        if (!(ch >= '0' && ch <= '9'))

                        {
                            this.charIndexOfReadLine++;
                            if (!flag_debugger)
                            {
                                Console.Error.WriteLine("illegal start of number. : an number cannot start with numerical digits.");
                            }
                            else
                            {
                                Console.WriteLine("unknown type number form : i.e. 10**$ so on ");
                            }
                            return(getNextToken());

                            //break;
                        }



                        // set tentative someStringLength... with our latest new character

                        someStringLength++;



                        // tentative upper bound of someString  for future reference....

                        someStringUpperBound = charIndexOfReadLine;



                        number_lastCharWasDecimal = false;



                        // proceed next increment of a loop

                        charIndexOfReadLine++;
                    }



                    // write out to console   any full decimal number



                    // Given that upperBound cannot have been written to be out of array bounds,

                    //    this checks if the end of quote is the last term in the current Line.

                    if (endOfSomeStringReached && someStringUpperBound == inputBufferLine.Length - 1)

                    {
                        // copy char to token



                        // need to configure token to take either decimal or integer.

                        double intermediateVal = Convert.ToDouble(new String(buf, someStringLowerBound, someStringLength));

                        int intVal = Convert.ToInt32(intermediateVal);
                        returnToken = new IntToken(intVal);



                        // if (flag_debugger)
                        //     Console.WriteLine("value: " + new String(buf, someStringLowerBound, someStringLength));

                        return(returnToken);



                        //Console.WriteLine("continuation Halted: lineTerminates Abruptedly");
                    }

                    else if (endOfSomeStringReached)
                    {
                        // copy char to token


                        // need to configure token to take either decimal or integer.

                        double intermediateVal = Convert.ToDouble(new String(buf, someStringLowerBound, someStringLength));


                        int intVal = Convert.ToInt32(intermediateVal);
                        returnToken = new IntToken(intVal);


                        // return string literal ... that was just scanned
                        // if (flag_debugger)
                        //     Console.WriteLine("value: " + new String(buf, someStringLowerBound, someStringLength));

                        return(returnToken);
                    }
                    // number ends at line's end  /after   the new line char delimiter
                    else if (!endOfSomeStringReached && (!number_lastCharWasDecimal && numberDotsForDecimal <= 1))

                    {
                        double intermediateVal = Convert.ToDouble(new String(buf, someStringLowerBound, someStringLength));

                        int intVal = Convert.ToInt32(intermediateVal);
                        returnToken = new IntToken(intVal);
                        // if (flag_debugger)
                        //     Console.WriteLine("number does not finish on line,... or,  error: ran out of characters current line.");

                        return(returnToken);
                    }

                    else if (!endOfSomeStringReached && (number_lastCharWasDecimal))
                    {
                        //    if (flag_debugger)
                        //        Console.WriteLine("number incomplete __ ends with decimal at end of line,... error: ran out of characters current line.");
                        return(getNextToken());
                    }


                    // dummy return;
                    return(returnToken);
                }

                // Identifiers

                else if ((ch >= 'A' && ch <= 'Z') || (ch >= 'a' && ch <= 'z') ||

                         ch == '!' || ch == '$' || ch == '%' || ch == '&' || ch == '*' ||

                         ch == '+' || ch == '-' || ch == '.' || ch == '/' || ch == ':' ||

                         ch == '<' || ch == '=' || ch == '>' || ch == '?' || ch == '@' ||

                         ch == '@' || ch == '^' || ch == '_' || ch == '~')

                {
                    // or ch is some other valid first character

                    // for an identifier) {

                    // TODO: scan an identifier into the buffer



                    // make sure that the character following the integer

                    // is not removed from the input stream

                    //return new IdentToken (new String (buf, 0, 0));


                    // check for quote token



                    someStringLength++;



                    someStringLowerBound = charIndexOfReadLine;



                    // increment by 1 more character in array

                    charIndexOfReadLine++;



                    // someStringLength starts at 0



                    while (!endOfSomeStringReached && charIndexOfReadLine <= inputBufferLine.Length - 1)

                    {
                        ch = buf[charIndexOfReadLine];



                        // noted as a extra evaluation of extended symbols

                        char Char1 = ch;



                        // if a space appears, ... move out of Identifier retrieval loop

                        if (ch == 32 || ch == 9)

                        {
                            endOfSomeStringReached = true;
                            this.charIndexOfReadLine++;
                            break;
                        }

                        else if (ch == ')')

                        {
                            //return new Token (TokenType.RPAREN);

                            if (numberParentheses_R > numberParentheses_L)
                            {
                                this.charIndexOfReadLine++;

                                if (flag_debugger)
                                {
                                    Console.WriteLine("RPAREN");
                                }
                                else
                                {
                                    Console.Error.WriteLine("Too many Right Parentheses>: error! \n continued... :Last input ignored!");
                                }

                                return(getNextToken());
                            }
                            else

                            {
                                // note:  need to configure token to take either decimal or integer.

                                //Console.WriteLine("Identifier: " + new String(buf, someStringLowerBound, someStringLength));



                                //endOfSomeStringReached   dont activate   already printed



                                //numberParentheses_L--;

                                //  take in token of parenthesis... later..


                                // copy char to token


                                // this.charIndexOfReadLine++;


                                //  Console.WriteLine("value: )");

                                endOfSomeStringReached = true;
                                break;
                            }
                        }

                        else if ((Char1 >= 'A' && Char1 <= 'Z') || (Char1 >= 'a' && Char1 <= 'z') ||

                                 (Char1 >= '0' && Char1 <= '9') ||

                                 Char1 == '!' || Char1 == '$' || Char1 == '%' || Char1 == '&' || Char1 == '*' ||

                                 Char1 == '+' || Char1 == '-' || Char1 == '.' || Char1 == '/' || Char1 == ':' ||

                                 Char1 == '<' || Char1 == '=' || Char1 == '>' || Char1 == '?' || Char1 == '@' ||

                                 Char1 == '@' || Char1 == '^' || Char1 == '_' || Char1 == '~')

                        {
                            // set tentative someStringLength... with our latest new character

                            someStringLength++;



                            // tentative upper bound of someString  for future reference....

                            someStringUpperBound = charIndexOfReadLine;



                            // proceed next increment of a loop

                            charIndexOfReadLine++;
                            continue;
                        }

                        else

                        {
                            this.charIndexOfReadLine++;
                            if (!flag_debugger)
                            {
                                Console.Error.WriteLine("illegal character within identifier: error with accepted char' code elements.");
                            }
                            else
                            {
                                Console.WriteLine("Ident_not_right");
                            }


                            return(getNextToken());
                            //break;
                        }
                    }



                    // write out to console   any full decimal number



                    // Given that upperBound cannot have been written to be out of array bounds,

                    //    this checks if the end of identifier quote is the last term in the current Line.

                    if (endOfSomeStringReached && someStringUpperBound == inputBufferLine.Length - 1)

                    {
                        // copy char to token



                        // return string literal ... that was just scanned

                        returnToken = new IdentToken(new String(buf, someStringLowerBound, someStringLength));
                        //if (flag_debugger)
                        //    Console.WriteLine("Identifier: " + new String(buf, someStringLowerBound, someStringLength));


                        return(returnToken);
                        // Console.WriteLine("continuation Halted: lineTerminates Abruptedly");
                    }

                    else if (endOfSomeStringReached)
                    {
                        // copy char to token


                        returnToken = new IdentToken(new String(buf, someStringLowerBound, someStringLength));
                        //if (flag_debugger)
                        //    Console.WriteLine("Identifier: " + new String(buf, someStringLowerBound, someStringLength));

                        return(returnToken);
                    }
                    else if (!endOfSomeStringReached)
                    {
                        // copy char to token


                        returnToken = new IdentToken(new String(buf, someStringLowerBound, someStringLength));
                        //if (flag_debugger)
                        //    Console.WriteLine("Identifier: " + new String(buf, someStringLowerBound, someStringLength));

                        return(returnToken);
                    }

                    return(returnToken);
                }



                // Illegal character

                else

                {
                    this.charIndexOfReadLine++;

                    Console.Error.WriteLine("Illegal input error char |_|.");


                    return(getNextToken());

                    //Console.WriteLine ("Illegal input character '"

                    //+ ch + '\'');

                    //return getNextToken ();

                    //return new Object();
                }
            }


            catch (IOException e)

            {
                Console.Error.WriteLine("IOException: " + e.Message);

                //return null;
            }

            return(returnToken);
        }
 public PrimitiveTypeSymbol(IdentToken token, Type type) : base(token, type)
 {
 }
Пример #21
0
        /// <summary>
        /// Consumes a new <see cref="MediaCondition"/> or <see cref="MediaFeature"/>
        /// </summary>
        /// <param name="Stream"></param>
        /// <returns></returns>
        static IMediaCondition Consume_Media_Condition(DataConsumer <CssToken> Stream)
        {/* Docs: https://www.w3.org/TR/mediaqueries-4/#media-condition */
            if (Stream is null)
            {
                throw new CssParserException(CssErrors.STREAM_IS_NULL);
            }

            Consume_All_Whitespace(Stream);
            if (ParserCommon.Starts_Media_Feature(Stream.AsSpan()))
            {
                /* Consume opening parentheses */
                Stream.Consume();
                var feature = Consume_Media_Feature(Stream);

                /* Consume closing parentheses */
                if (Stream.Next.Type == ECssTokenType.Parenth_Close)
                {
                    Stream.Consume();
                }

                return(feature);
            }
            else if (ParserCommon.Starts_Media_Condition(Stream.AsSpan()))
            {
                EMediaCombinator Combinator = EMediaCombinator.None;
                var conditionList           = new LinkedList <IMediaCondition>();


                if (Stream.Next.Type == ECssTokenType.Parenth_Close)
                {
                    /* Empty media condition block */
                    Stream.Consume();
                    return(new MediaCondition(EMediaCombinator.None, Array.Empty <MediaFeature>()));
                }
                else if (Stream.Next.Type == ECssTokenType.Parenth_Open)
                {
                    Stream.Consume();
                }

                Consume_All_Whitespace(Stream);
                /* Repeatedly consume sub-media-conditions until we hit a closing parentheses */
                do
                {
                    Consume_All_Whitespace(Stream);

                    if (Stream.Next.Type == ECssTokenType.Parenth_Close)
                    {
                        /* End of this media condition block */
                        break;
                    }

                    /* Anything other than the first condition *MUST* specify a combinator */
                    if (conditionList.Count > 0)
                    {
                        if (!ParserCommon.Is_Combinator(Stream.Next))
                        {
                            throw new CssSyntaxErrorException(CssErrors.EXPECTING_COMBINATOR, Stream);
                        }
                    }

                    /* Otherwise we just COULD have a combinator */
                    if (ParserCommon.Is_Combinator(Stream.Next))
                    {
                        /* Consume combinator */
                        IdentToken combinatorToken = Stream.Consume() as IdentToken;
                        if (!Lookup.TryEnum(combinatorToken.Value, out EMediaCombinator combLookup))
                        {
                            throw new CssSyntaxErrorException(String.Format(CultureInfo.InvariantCulture, CssErrors.INVALID_COMBINATOR, combinatorToken.Value), Stream);
                        }
                        else if (Combinator == EMediaCombinator.None)
                        {/* This is the first combinator specified */
                            Combinator = combLookup;
                        }
                        else if (Combinator != EMediaCombinator.None && combLookup != Combinator)
                        {/* Ensure this new combinator matches the combinator for this method group */
                            throw new CssSyntaxErrorException(CssErrors.INVALID_MULTIPLE_COMBINATORS_ON_MEDIARULE, Stream);
                        }
                    }

                    Consume_All_Whitespace(Stream);
                    if (Stream.Next.Type != ECssTokenType.Parenth_Open)
                    {
                        throw new CssSyntaxErrorException(CssErrors.EXPECTING_OPENING_PARENTHESES, Stream);
                    }

                    /* Oh look a yummy little sub-condition for us to gobble up! */
                    var feature = Consume_Media_Condition(Stream);
                    conditionList.AddLast(feature);
                }while (Stream.Next.Type != ECssTokenType.EOF);

                /* Consume closing parentheses */
                if (Stream.Next.Type == ECssTokenType.Parenth_Close)
                {
                    Stream.Consume();
                }

                return(new MediaCondition(Combinator, conditionList));
            }

            throw new CssSyntaxErrorException(CssErrors.EXPECTING_MEDIA_CONDITION_START, Stream);
        }
 public MethodSymbol(IdentToken token, Type returnType, FormalParamSymbol[] formalParams, MethodInfo methodInfo) : base(token.line, token.column, token.value)
 {
     this.returnType   = returnType;
     this.formalParams = formalParams;
     this.methodInfo   = methodInfo;
 }
            internal override bool TryAddSuggestionsForNodeKind(IntellisenseData.IntellisenseData intellisenseData)
            {
                Contracts.AssertValue(intellisenseData);

                TexlNode curNode   = intellisenseData.CurNode;
                int      cursorPos = intellisenseData.CursorPos;

                FirstNameNode firstNameNode = curNode.CastFirstName();
                Identifier    ident         = firstNameNode.Ident;
                int           min           = ident.Token.Span.Min;
                IdentToken    tok           = ident.Token;

                if (cursorPos < min)
                {
                    // Cursor is before the beginning of the identifier or of the global token if present.
                    // Suggest possibilities that can result in a value.
                    IntellisenseHelper.AddSuggestionsForValuePossibilities(intellisenseData, curNode);
                    intellisenseData.AddAdditionalSuggestionsForKeywordSymbols(curNode);
                }
                else if (cursorPos <= tok.Span.Lim)
                {
                    // Cursor is part of the identifier or global token if present.
                    // Get the matching string as a substring from the script so that the whitespace is preserved.
                    IEnumerable <string> possibleFirstNames = intellisenseData.Binding.GetFirstNames().Select(firstNameInfo => firstNameInfo.Name.Value)
                                                              .Union(intellisenseData.Binding.GetGlobalNames().Select(firstNameInfo => firstNameInfo.Name.Value))
                                                              .Union(intellisenseData.Binding.GetAliasNames().Select(firstNameInfo => firstNameInfo.Name.Value))
                                                              .Union(intellisenseData.SuggestableFirstNames);

                    int replacementLength = IntellisenseHelper.GetReplacementLength(intellisenseData, tok.Span.Min, tok.Span.Lim, possibleFirstNames);
                    intellisenseData.SetMatchArea(tok.Span.Min, cursorPos, replacementLength);
                    intellisenseData.BoundTo = intellisenseData.Binding.ErrorContainer.HasErrors(firstNameNode) ? string.Empty : ident.Name;

                    if (ident.AtToken != null || tok.Kind == TokKind.At)
                    {
                        // Suggest globals if cursor is after '@'.
                        AddSuggestionsForScopedGlobals(intellisenseData);
                    }
                    else if (tok.HasDelimiters && cursorPos > tok.Span.Min)
                    {
                        // Suggest top level fields and globals if cursor is after a opening square bracket.
                        IntellisenseHelper.AddSuggestionsForRuleScope(intellisenseData);
                        IntellisenseHelper.AddSuggestionsForTopLevel(intellisenseData, curNode);
                        IntellisenseHelper.AddSuggestionsForGlobals(intellisenseData);
                        intellisenseData.AddAdditionalSuggestionsForLocalSymbols();
                    }
                    else
                    {
                        // Suggest value posssibilities otherwise.
                        IntellisenseHelper.AddSuggestionsForValuePossibilities(intellisenseData, curNode);
                    }
                    intellisenseData.AddAdditionalSuggestionsForKeywordSymbols(curNode);
                }
                else if (IsBracketOpen(tok.Span.Lim, cursorPos, intellisenseData.Script))
                {
                    AddSuggestionsForScopeFields(intellisenseData, intellisenseData.Binding.GetType(firstNameNode));
                }
                else if (IntellisenseHelper.CanSuggestAfterValue(cursorPos, intellisenseData.Script))
                {
                    // Verify that cursor is after a space after the identifier.
                    // Suggest binary keywords.
                    IntellisenseHelper.AddSuggestionsForAfterValue(intellisenseData, intellisenseData.Binding.GetType(firstNameNode));
                }

                return(true);
            }
 public MemberExpressionNode(IdentToken ident)
     : base(SyntaxKind.MemberExpressionNode)
 {
     AddNode(ident);
 }
Пример #25
0
 public Identifier(IdentToken token)
     : this(DPath.Root, null, token)
 {
 }
Пример #26
0
        /////////////////////////////////////////////////////////////////////////////////////////////////////


        #region Protected Utilities
        /////////////////////////////////////////////////////////////////////////////////////////////////////

        /// <summary>
        /// Checks that the client has been already logged in, and if this is not the case, automatically logins
        /// </summary>
        /// <returns>true if the login has been successful; false otherwise</returns>
        protected bool CheckLogin(bool forceReLogin = false)
        {
            int count = 1;

            if (forceReLogin)
            {
                WebConnector.Current.ResetLoginStatus();
            }

            while (!WebConnector.Current.IsLogged)
            {
                log.Info("Trying to connect to web server..." + count);

                // Login to site and acquire a valid session
                UserClient loginResp = null;
                if (useOneAll && !IdentToken.IsNullOrWhiteSpaceOrEOF())
                {
                    loginResp = WebConnector.Current.LoginWithOneAll(IdentToken);
                }
                else
                {
                    loginResp = WebConnector.Current.Login(Username, Password);
                }

                //check for timeout:
                if (WebConnector.Current.IsTimeout)
                {
                    SetLastError(log, ErrorCodes.TIMEOUT, "Web server doesn't reply to the requests");
                    return(false);
                }

                //check for invalid credentials:
                if ((loginResp != null) && !loginResp.IsValid)
                {
                    SetLastError(log, ErrorCodes.NOT_LOGGED_IN, "Login has retrieved an invalid user");
                    CurrentUser = null;
                    WebConnector.Current.ResetLoginStatus();
                    return(false);
                }

                //try to retrieve the current user:
                if (WebConnector.Current.IsLogged && (loginResp != null))
                {
                    CurrentUser = loginResp;

                    //retrieve user groups:
                    //this is very important in order to preload user groups!!
                    //don't remove these lines!!!!
                    log.InfoFormat("Retrieved groups: {0}", CurrentUser.Groups.Print());
                    log.InfoFormat("Retrieved administered groups: {0}", CurrentUser.AdministeredGroups.Print());
                }

                if (count++ > MAX_LOGIN_ATTEMPT)
                {
                    SetLastError(log, ErrorCodes.COMMUNICATION_ERROR, "Cannot login into the web server");
                    return(false);
                }
            }

            return(true);
        }
 public LocalVarSymbol(IdentToken token, LocalVariableInfo localVariableInfo) : base(token.line, token.column, token.value)
 {
     LocalVariableInfo = localVariableInfo;
 }
Пример #28
0
 public ExternalMethodSymbol(IdentToken token, MethodInfo[] methodInfo) : base(token.line, token.column, token.value)
 {
     MethodInfo = methodInfo;
 }