コード例 #1
0
        public static PhonemeDefinition Get(string text)
        {
            text = text.ToLower();

            if (text.Last().IsNumeric())
            {
                //Stress = int.Parse(text.Last().ToString());
                text = text.Substring(0, text.Length - 1);
                //Id = Text + Stress;
            }
            else
            {
                //Stress = -1;
                //Id = Text;
            }

            lock (Definitions) {
                if (!Definitions.ContainsKey(text))
                {
                    Definitions.Add(text, new PhonemeDefinition(text));
                }

                return(Definitions[text]);
            }
        }
コード例 #2
0
ファイル: EntityFactory.cs プロジェクト: twogoldjin/DNAI.Core
        /// <summary>
        /// Find an entity in the dictionaries
        /// </summary>
        /// <remarks>Throws a KeyNotFoundException if entity hasn't been found</remarks>
        /// <param name="definition_uid">Identifier of an entity</param>
        /// <returns>The entity to find</returns>
        public IDefinition Find(UInt32 definition_uid)
        {
            if (!Definitions.ContainsKey(definition_uid))
            {
                throw new KeyNotFoundException("EntityFactory.find : given definition of id " + definition_uid.ToString() + " hasn't been found");
            }

            return(Definitions[definition_uid]);
        }
コード例 #3
0
        public override DataItem LoadData(XElement element, UndoRedoManager undoRedo)
        {
            var key = element.Attribute(MetaNS + "RefKey")?.Value?.ToString();

            if (key == null)
            {
                key = element.Attribute("RefKey")?.Value?.ToString();
            }

            if (key == null && Definitions.Count == 1 && !IsNullable)
            {
                key = Definitions.First().Key;
            }

            ReferenceItem item = null;

            if (key != null && Definitions.ContainsKey(key))
            {
                var def = Definitions[key];

                item = new ReferenceItem(this, undoRedo);
                item.ChosenDefinition = def;

                var loaded = def.LoadData(element, undoRedo);
                item.WrappedItem = loaded;
            }
            else
            {
                item = CreateData(undoRedo) as ReferenceItem;
            }

            foreach (var att in Attributes)
            {
                var      el      = element.Attribute(att.Name);
                DataItem attItem = null;

                if (el != null)
                {
                    attItem = att.LoadData(new XElement(el.Name, el.Value.ToString()), undoRedo);
                }
                else
                {
                    attItem = att.CreateData(undoRedo);
                }
                item.Attributes.Add(attItem);
            }

            return(item);
        }
コード例 #4
0
ファイル: EntityFactory.cs プロジェクト: twogoldjin/DNAI.Core
        /// <summary>
        /// Remove an entity from the internal dictionaries
        /// </summary>
        /// <remarks>
        /// Throws an InvalidOperationException if trying to remove default added entity
        /// Throws a KeyNotFoundException if an entity is not identified by the given id
        /// </remarks>
        /// <param name="definition_uid">Identifier of the entity to remove</param>
        public void RemoveEntity(UInt32 definition_uid)
        {
            if (definition_uid <= 5)
            {
                throw new InvalidOperationException("EntityFactory.remove : cannot remove base entities");
            }

            if (!Definitions.ContainsKey(definition_uid))
            {
                throw new KeyNotFoundException("EntityFactory.remove : given definition uid hasn't been found");
            }

            ids.Remove(Definitions[definition_uid]);
            Definitions.Remove(definition_uid);
        }
コード例 #5
0
        public Schema GetOrRegister(Type type)
        {
            var schema = CreateInlineSchema(type);

            // Ensure Schema's have been fully generated for all referenced types
            while (_referencedTypes.Any(entry => entry.Value.Schema == null))
            {
                var typeMapping = _referencedTypes.First(entry => entry.Value.Schema == null);
                var schemaInfo  = typeMapping.Value;

                schemaInfo.Schema = CreateDefinitionSchema(typeMapping.Key);
                if (!Definitions.ContainsKey(schemaInfo.SchemaId))
                {
                    Definitions.Add(schemaInfo.SchemaId, schemaInfo.Schema);
                }
            }

            return(schema);
        }
コード例 #6
0
ファイル: EAParser.cs プロジェクト: StanHash/ColorzCore
        private Maybe <IParamNode> ParseParam(MergeableGenerator <Token> tokens, ImmutableStack <Closure> scopes, bool expandDefs = true)
        {
            Token head = tokens.Current;

            switch (tokens.Current.Type)
            {
            case TokenType.OPEN_BRACKET:
                return(new Just <IParamNode>(new ListNode(head.Location, ParseList(tokens, scopes)).Simplify()));

            case TokenType.STRING:
                tokens.MoveNext();
                return(new Just <IParamNode>(new StringNode(head)));

            case TokenType.MAYBE_MACRO:
                //TODO: Move this and the one in ExpandId to a separate ParseMacroNode that may return an Invocation.
                if (expandDefs && ExpandIdentifier(tokens, scopes))
                {
                    return(ParseParam(tokens, scopes));
                }
                else
                {
                    tokens.MoveNext();
                    IList <IList <Token> > param = ParseMacroParamList(tokens);
                    //TODO: Smart errors if trying to redefine a macro with the same num of params.
                    return(new Just <IParamNode>(new MacroInvocationNode(this, head, param, scopes)));
                }

            case TokenType.IDENTIFIER:
                if (expandDefs && Definitions.ContainsKey(head.Content) && ExpandIdentifier(tokens, scopes))
                {
                    return(ParseParam(tokens, scopes, expandDefs));
                }
                else
                {
                    return(ParseAtom(tokens, scopes, expandDefs).Fmap((IAtomNode x) => (IParamNode)x.Simplify()));
                }

            default:
                return(ParseAtom(tokens, scopes, expandDefs).Fmap((IAtomNode x) => (IParamNode)x.Simplify()));
            }
        }
コード例 #7
0
        public Schema GetOrRegister(Type type)
        {
            var schema = CreateInlineSchema(type);

            // Iterate outstanding work items (i.e. referenced types) and generate the corresponding definition
            while (_workItems.Any(entry => entry.Value.Schema == null && !entry.Value.InProgress))
            {
                var typeMapping = _workItems.First(entry => entry.Value.Schema == null && !entry.Value.InProgress);
                var workItem    = typeMapping.Value;

                workItem.InProgress = true;
                workItem.Schema     = CreateDefinitionSchema(typeMapping.Key);
                if (!Definitions.ContainsKey(workItem.SchemaId))
                {
                    Definitions.Add(workItem.SchemaId, workItem.Schema);
                }
                workItem.InProgress = false;
            }

            return(schema);
        }
コード例 #8
0
ファイル: EAParser.cs プロジェクト: StanHash/ColorzCore
        /***
         *   Precondition: tokens.Current.Type == TokenType.IDENTIFIER || MAYBE_MACRO
         *   Postcondition: tokens.Current is fully reduced (i.e. not a macro, and not a definition)
         *   Returns: true iff tokens was actually expanded.
         */
        public bool ExpandIdentifier(MergeableGenerator <Token> tokens, ImmutableStack <Closure> scopes)
        {
            bool ret = false;

            //Macros and Definitions.
            if (tokens.Current.Type == TokenType.MAYBE_MACRO && Macros.ContainsName(tokens.Current.Content))
            {
                Token head = tokens.Current;
                tokens.MoveNext();
                IList <IList <Token> > parameters = ParseMacroParamList(tokens);
                if (Macros.HasMacro(head.Content, parameters.Count))
                {
                    tokens.PrependEnumerator(Macros.GetMacro(head.Content, parameters.Count).ApplyMacro(head, parameters, scopes).GetEnumerator());
                }
                else
                {
                    Error(head.Location, System.String.Format("No overload of {0} with {1} parameters.", head.Content, parameters.Count));
                }
                return(true);
            }
            else if (tokens.Current.Type == TokenType.MAYBE_MACRO)
            {
                Token head = tokens.Current;
                tokens.MoveNext();
                tokens.PutBack(new Token(TokenType.IDENTIFIER, head.Location, head.Content));
                return(true);
            }
            else if (Definitions.ContainsKey(tokens.Current.Content))
            {
                Token head = tokens.Current;
                tokens.MoveNext();
                tokens.PrependEnumerator(Definitions[head.Content].ApplyDefinition(head).GetEnumerator());
                return(true);
            }

            return(ret);
        }
コード例 #9
0
        public override DataItem LoadData(XElement element, UndoRedoManager undoRedo)
        {
            var key = element.Attribute(DataDefinition.MetaNS + "RefKey")?.Value?.ToString();

            if (key == null)
            {
                key = element.Attribute("RefKey")?.Value?.ToString();
            }

            GraphReferenceItem item = null;

            if (!element.HasElements)
            {
                item = new GraphReferenceItem(this, undoRedo);
                item.GuidToResolve = element.Value?.ToString();
                item.m_LinkType    = LinkType.Reference;
            }
            else if (key != null && Definitions.ContainsKey(key))
            {
                var def = Definitions[key];

                item = new GraphReferenceItem(this, undoRedo);
                item.ChosenDefinition = def;

                var loaded = def.LoadData(element, undoRedo) as GraphNodeItem;
                item.WrappedItem = loaded;
            }
            else
            {
                item = CreateData(undoRedo) as GraphReferenceItem;
            }

            foreach (var att in Attributes)
            {
                var      el      = element.Attribute(att.Name);
                DataItem attItem = null;

                if (el != null)
                {
                    attItem = att.LoadData(new XElement(el.Name, el.Value.ToString()), undoRedo);
                }
                else
                {
                    attItem = att.CreateData(undoRedo);
                }
                item.Attributes.Add(attItem);
            }

            var controlPoints = element.Attribute(DataDefinition.MetaNS + "ControlPoints")?.Value;

            if (controlPoints != null)
            {
                var points = controlPoints.Split('|');
                foreach (var point in points)
                {
                    var split = point.Split(',');
                    var x     = double.Parse(split[0]);
                    var y     = double.Parse(split[1]);
                    var flip  = split.Length == 3 ? bool.Parse(split[2]) : false;

                    item.ControlPoints.Add(new GraphReferenceControlPoint(item, new System.Windows.Point(x, y), flip));
                }
            }

            return(item);
        }
コード例 #10
0
ファイル: EAParser.cs プロジェクト: StanHash/ColorzCore
 public bool IsValidDefinitionName(string name)
 {
     return(!(Definitions.ContainsKey(name) || IsReservedName(name)));
 }
コード例 #11
0
 public bool HasPluginFor(Type type)
 {
     return(type.IsConcrete() ||
            Definitions.ContainsKey(type) ||
            (type.IsGenericType && Definitions.ContainsKey(type.GetGenericTypeDefinition())));
 }
コード例 #12
0
ファイル: QuakeBlock.cs プロジェクト: MarkWilds/Arbatel
        private void Parse(List <string> rawBlock)
        {
            int i = 0;

            while (i < rawBlock.Count)
            {
                string item = rawBlock[i];

                if (item.Contains(KeyValDelimiter))
                {
                    List <KeyValuePair <string, string> > rawKeyVals = ExtractKeyVals(item);

                    string classname = rawKeyVals.Find(s => s.Key == "classname").Value;

                    foreach (KeyValuePair <string, string> rawKeyVal in rawKeyVals)
                    {
                        Option newOption;
                        if (Definitions.ContainsKey(classname) && Definitions[classname].KeyValsTemplate.ContainsKey(rawKeyVal.Key))
                        {
                            newOption = new Option(Definitions[classname].KeyValsTemplate[rawKeyVal.Key]);
                        }
                        else
                        {
                            newOption = new Option();
                        }
                        newOption.Value = rawKeyVal.Value;

                        if (!KeyVals.ContainsKey(rawKeyVal.Key))
                        {
                            KeyVals.Add(rawKeyVal.Key, newOption);
                        }
                        else
                        {
                            KeyVals[rawKeyVal.Key] = newOption;
                        }
                    }

                    ++i;
                }
                // An open delimiter that's the first item in the raw block is just the
                // start of the top level block; any others indicate children.
                else if (item == OpenDelimiter && i != 0)
                {
                    int childOpenBraceIndex = i + 1;

                    var childBlock = new QuakeBlock(rawBlock, childOpenBraceIndex, Definitions);
                    Children.Add(childBlock);

                    i = childBlock.RawStartIndex + childBlock.RawLength;
                }
                else if (item.StartsWith("(", StringComparison.OrdinalIgnoreCase))
                {
                    string solid = item;
                    int    j     = i + 1;
                    while (rawBlock[j] != CloseDelimiter)
                    {
                        solid += rawBlock[j];
                        j++;
                    }

                    Solids.Add(new Solid(ExtractSides(solid)));

                    i += j;
                }
                else
                {
                    i++;
                }
            }
        }