コード例 #1
0
        // Setting up a "with" statement - creating a new scope
        public void Push(string alias, CompoundIdentifier expansion)
        {
            // Create a new scope and push it on the stack
            var scope = new Scope();

            scopes.Push(scope);

            // Add the alias
            scope.AddAlias(alias, expansion);
        }
コード例 #2
0
        public override bool VisitAlias(TypeAliasAST alias)
        {
            //se asume que no habra problema
            alias.ReturnType = TigerType.GetType <NoType>();
            //la clase base verifica q el id del type sea valido
            //aqui si se ve q el return true hace falta
            if (VisitTypeDeclaration(alias))
            {
                TigerType tt;
                //se verifica que exista el tipo del cual se esta creando un alias
                if (_scope.HasType(alias.AliasToWho, out tt) != ScopeLocation.NotDeclared)
                {
                    //se anade una nueva entrada del mismo type, lo q con otro id
                    _scope.AddAlias(alias.TypeId, alias.AliasToWho);
                    return(true);
                }
                int savedErrorPos = _errorListener.Count;
                //manejador de evento
                _scope.TypeAdded += (sender, args) =>
                {
                    if (args.TypeName == alias.AliasToWho)
                    {
                        _scope.AddType(alias.TypeId, args.NewType);
                    }
                };

                //manejador de evento
                _scope.FinalizeScope += (sender, args) =>
                {
                    if (sender.HasType(alias.AliasToWho) == ScopeLocation.NotDeclared)
                    {
                        _errorListener.Insert(savedErrorPos, AnalysisError.TypeIsNotDefined(alias, alias.AliasToWho));
                        alias.ReturnType = TigerType.GetType <ErrorType>();
                    }
                };
                return(true);
            }
            return(false);
        }
コード例 #3
0
        public void Push(JObject doc)
        {
            Scope currentScope = new Scope();

            JToken t;
            if (doc.TryGetValue("@context", out t))
            {
                JObject context = (JObject)t;
                foreach (JProperty prop in context.Properties())
                {
                    if (prop.Value.Type == JTokenType.Object)
                    {
                        currentScope.Add(prop.Name, new TermDefinition((JObject)prop.Value));
                    }
                    else
                    {
                        string value = prop.Value.ToString();

                        switch (prop.Name)
                        {
                            case "@base":
                                currentScope.Base = value;
                                break;
                            case "@vocab":
                                currentScope.Vocab = value;
                                break;
                            case "@language":
                                currentScope.Language = value;
                                break;
                            default:
                                switch (value)
                                {
                                    case "@id":
                                    case "@type":
                                        //TODO: other keywords
                                        currentScope.AddAlias(prop.Name, value);
                                        break;
                                    default:
                                        currentScope.Add(prop.Name, new TermDefinition(value));
                                        break;
                                }
                                break;
                        }
                    }
                }

                currentScope.Expand(this);
            }

            _context.Push(currentScope);
        }