Example #1
0
        internal static void AssertSymbolInTable(string text, int sid, bool duplicate, ISymbolTable symbolTable)
        {
            if (text == null)
            {
                Assert.IsNull(symbolTable.FindKnownSymbol(sid));
                return;
            }

            if (sid != SymbolToken.UnknownSid)
            {
                Assert.AreEqual(text, symbolTable.FindKnownSymbol(sid));
            }

            if (duplicate)
            {
                return;
            }

            Assert.AreEqual(sid, symbolTable.FindSymbolId(text));
            var token = symbolTable.Find(text);

            Assert.AreEqual(SymbolToken.UnknownSid, token.Sid);
            Assert.AreEqual(text, token.Text);

            token = symbolTable.Intern(text);
            Assert.AreEqual(SymbolToken.UnknownSid, token.Sid);
            Assert.AreEqual(text, token.Text);
        }
        public override void AddTypeAnnotation(string annotation)
        {
            var symtok = _symbolTable.Find(annotation);

            if (symtok == default)
            {
                symtok = new SymbolToken(annotation, SymbolToken.UnknownSid);
            }

            _annotations.Add(symtok);
        }
Example #3
0
        /// <summary>
        /// Try to re-make the token in the context of the <paramref name="table"/>.
        /// </summary>
        /// <param name="table">Symbol table</param>
        /// <param name="token">Un-localized token</param>
        /// <returns>Localized token</returns>
        public static SymbolToken Localize(ISymbolTable table, SymbolToken token)
        {
            var newToken = token;

            //try to localize
            if (token.Text == null)
            {
                var text = table.FindKnownSymbol(token.Sid);
                if (text != null)
                {
                    newToken = new SymbolToken(text, token.Sid);
                }
            }
            else
            {
                newToken = table.Find(token.Text);
                if (newToken == default)
                {
                    newToken = new SymbolToken(token.Text, SymbolToken.UnknownSid);
                }
            }

            return(newToken);
        }