private void _parser_main(YamlFileData file) { Output = new ParserArray(file.LineNumber); Output.Indent = -1; Output.ChildrenIndent = -1; _readNode(file, Output, 0, YamlListType.NotDefined); if (Output.ParserType == ParserTypes.Array) { var parserArray = Output.To <ParserArray>(); // Copy pate handling if (parserArray.Objects.Count > 0 && parserArray.Objects[0].ParserType == ParserTypes.Array) { var tmp_list = new ParserList(0); var tmp_keyValue = new ParserKeyValue("copy_paste", 0); tmp_list.Objects.AddRange(parserArray.Objects); tmp_keyValue.Value = tmp_list; parserArray.Objects.Clear(); parserArray.Objects.Add(tmp_keyValue); } } // Calculate lengths if (Output != null) { _calculateLength(Output); Output.Length = _getLength(Output); } }
internal BaseScripter(CSLite_Scripter owner) { this.Owner = owner; this.symbol_table = new SymbolTable(this); this.code = new Code(this); this.module_list = new ModuleList(this); this.parser_list = new ParserList(); this.Error_List = new ErrorList(this); this.Warning_List = new ErrorList(this); this.PPDirectiveList = new StringList(false); this.RegisteredTypes = new RegisteredTypeList(); this.RegisteredNamespaces = new StringList(false); this.UserTypes = new Hashtable(); this.UserNamespaces = new StringList(false); this.ForbiddenNamespaces = new StringList(false); this.UserInstances = new Hashtable(); this.UserVariables = new Hashtable(); this.OperatorHelpers = new Hashtable(); this.available_types = new StringList(false); this.ForbiddenTypes = new StringList(false); this.EntryId = 0; this.event_dispatcher = new EventDispatcher(this, "CSLiteEventDispatcher"); if (CSLite_Scripter.AUTO_IMPORTING_SWITCH) { this.RegisterAvailableNamespaces(); } }
public SaveFile(ParserList parsers) { _parsers = new List <INodeParser>(); switch (parsers) { case ParserList.All: var interfaceType = typeof(INodeParser); var types = AppDomain.CurrentDomain.GetAssemblies().SelectMany(s => s.GetTypes()).Where(p => interfaceType.IsAssignableFrom(p) && p.IsClass && p != typeof(DefaultParser)); foreach (var type in types) { INodeParser instance = (INodeParser)Activator.CreateInstance(type); _parsers.Add(instance); } break; case ParserList.Enhanced: _parsers.Add(new StatsSystemParser()); _parsers.Add(new StatPoolSystemParser()); goto case ParserList.Simple; case ParserList.Simple: _parsers.Add(new ItemDataParser()); _parsers.Add(new InventoryParser()); _parsers.Add(new ItemDropStorageManagerParser()); _parsers.Add(new ItemDropStorageParser()); _parsers.Add(new CharacterCustomizationAppearancesParser()); _parsers.Add(new FactsDBParser()); _parsers.Add(new FactsTableParser()); break; } Guid = Guid.NewGuid(); FlatNodes = new List <NodeEntry>(); Nodes = new List <NodeEntry>(); MappingHelper.Init(); }
public static void Loader(DbDebugItem <int> debug, AbstractDb <int> db) { //foreach (DbAttribute attribute in ServerItemGroupSubAttributes.AttributeList.Attributes) { // db.Attached[attribute.DisplayName] = false; //} if (debug.FileType == FileType.Txt) { _loadItemsGroupdDb(db, debug.DbSource, debug.FilePath); } else if (debug.FileType == FileType.Conf) { Table <int, ReadableTuple <int> > itemsDb = db.GetMeta <int>(ServerDbs.Items); var items = itemsDb.FastItems; int index = ServerItemAttributes.AegisName.Index; // The reverse table is used for an optimization // All the items are stored in a dictionary by their name instead of their ID _reverseTable = new Dictionary <string, int>(StringComparer.OrdinalIgnoreCase); foreach (var item in items) { _reverseTable[item.GetStringValue(index)] = item.Key; } var ele = new LibconfigParser(debug.FilePath); var table = debug.AbsractDb.Table; foreach (ParserKeyValue group in ele.Output.OfType <ParserKeyValue>()) { string groupAegisName = group.Key; int groupId = _aegisNameToId(groupAegisName); if (groupId == -1) { debug.ReportIdException("Item ID '" + groupAegisName + "' couldn't be found.", groupAegisName, ErrorLevel.Critical); continue; } if (!table.ContainsKey(groupId)) { ReadableTuple <int> tupleParent = new ReadableTuple <int>(groupId, db.AttributeList); tupleParent.SetRawValue(ServerItemGroupAttributes.Table, new Dictionary <int, ReadableTuple <int> >()); table.Add(groupId, tupleParent); } var dico = (Dictionary <int, ReadableTuple <int> >)table.GetRaw(groupId, ServerItemGroupAttributes.Table); foreach (var itemEntry in group.Value) { string itemName; int quantity; if (itemEntry is ParserList) { ParserList list = (ParserList)itemEntry; itemName = list.Objects[0].ObjectValue; quantity = Int32.Parse(list.Objects[1].ObjectValue); } else if (itemEntry is ParserString) { itemName = itemEntry.ObjectValue; quantity = 1; } else { debug.ReportIdException("Unknown item entry in group '" + groupAegisName + "'.", groupAegisName, ErrorLevel.Critical); continue; } int itemId = _aegisNameToId(itemName); if (itemId == -1) { debug.ReportIdException("Failed to parse the item '" + itemName + "'.", itemName, ErrorLevel.Critical); continue; } ReadableTuple <int> tuple = new ReadableTuple <int>(itemId, ServerItemGroupSubAttributes.AttributeList); tuple.SetRawValue(ServerItemGroupSubAttributes.Rate, quantity); tuple.SetRawValue(ServerItemGroupSubAttributes.ParentGroup, groupId); dico[itemId] = tuple; } } } }
private void _readNode(YamlFileData file, ParserObject parent, int indent, YamlListType listType) { string word_s = null; while (file.CanRead) { char c = file.PeekChar(); switch (c) { case '#': file.SkipLine(); continue; case '\r': // Ignore character file.Position++; continue; case '\n': file.Position++; file.NextLine(); continue; case '-': file.SetupParent(parent, indent); if (listType == YamlListType.NotDefined) { listType = YamlListType.Array; } // Validate parent indent switch (parent.ParserType) { case ParserTypes.List: case ParserTypes.Array: if (file.CurrentLineIndent < parent.ChildrenIndent) { return; } if (file.CurrentLineIndent > parent.ChildrenIndent) { throw file.GetException("Unexpected indent (parent indent: " + parent.Indent + ", parent child indent: " + parent.ChildrenIndent + ", current indent: " + file.CurrentLineIndent + ")."); } break; } if (!(file.Position + 2 < file.Length && file.Data[file.Position + 1] == ' ' && file.IsLetter((char)file.Data[file.Position + 2]))) { throw file.GetException("Expected a space after the hyphen for the list declaration."); } // Array declaration ParserArray array = new ParserArray(file.LineNumber); array.Indent = file.CurrentLineIndent; file.CurrentLineIndent += 2; array.ChildrenIndent = file.CurrentLineIndent; file.Position += 2; _readNode(file, array, file.CurrentLineIndent, YamlListType.NotDefined); switch (parent.ParserType) { case ParserTypes.List: ((ParserList)parent).AddElement(array); break; case ParserTypes.Array: // Used for copy pasting only ((ParserArray)parent).AddElement(array); break; default: throw file.GetException("Unexpected parent node type. It can either be a list or an array, found a '" + parent.ParserType + "'."); } continue; case ' ': file.CurrentLineIndent++; file.Position++; continue; case ':': if (string.IsNullOrEmpty(word_s)) { throw file.GetException("Missing declaration key before ':'."); } file.Position++; file.Trim(); ParserKeyValue keyValue = new ParserKeyValue(word_s, file.LineNumber); keyValue.Indent = parent.Indent; word_s = null; // List declaration if (file.EoL()) { ParserList list = new ParserList(file.LineNumber); list.Indent = -1; list.ChildrenIndent = -1; keyValue.Value = list; _readNode(file, list, file.CurrentLineIndent, YamlListType.NotDefined); } else if (file.Data[file.Position] == '[') // Aggregate parsing, does not support multi-line { file.Position++; ParserAggregate aggregate = new ParserAggregate(file.LineNumber); aggregate.Parent = parent; while (file.CanRead) { c = file.PeekChar(); if (c == '\r' || c == '\n') { throw file.GetException("Unexpected syntax; multi-line aggregate arrays are not supported."); } if (c == ']') { break; } word_s = c == '\"' ? file.ReadValue() : file.ReadWord(); aggregate.AddElement(new ParserString(word_s.Trim(' '), file.LineNumber)); c = file.PeekChar(); while (c != '\n' && (c == ',' || c == ' ' || c == '\r')) { file.Position++; c = file.PeekChar(); } } word_s = null; keyValue.Value = aggregate; } else // KeyValue, get the line number first! { var parserString = new ParserString(null, file.LineNumber); parserString.Value = file.ReadValue(); parserString.Length = file.ValueLength; keyValue.Value = parserString; } switch (parent.ParserType) { case ParserTypes.List: ((ParserList)parent).AddElement(keyValue); break; case ParserTypes.Array: ((ParserArray)parent).AddElement(keyValue); break; } continue; default: file.SetupParent(parent, indent); if (listType == YamlListType.NotDefined) { listType = YamlListType.KeyValue; } // Validate parent indent switch (parent.ParserType) { case ParserTypes.List: if (file.CurrentLineIndent < parent.ChildrenIndent) { return; } if (file.CurrentLineIndent == parent.ChildrenIndent && listType != YamlListType.KeyValue) { return; } if (file.CurrentLineIndent > parent.ChildrenIndent) { throw file.GetException("Unexpected indent while reading key (parent indent: " + parent.Indent + ", parent child indent: " + parent.ChildrenIndent + ", current indent: " + file.CurrentLineIndent + ")."); } break; case ParserTypes.Array: if (file.CurrentLineIndent < parent.ChildrenIndent) { return; } if (file.CurrentLineIndent > parent.ChildrenIndent) { throw file.GetException("Unexpected indent while reading key (parent indent: " + parent.Indent + ", parent child indent: " + parent.ChildrenIndent + ", current indent: " + file.CurrentLineIndent + ")."); } break; } word_s = file.ReadKey(); if (word_s.Length == 0) { throw file.GetException("Null-length word. This is most likely caused by an unexpected character in a string."); } file.Trim(); continue; } } }
private void _parse(byte[] buffer) { try { _buffer = buffer; _bufferIndex = 0; while (_bufferIndex < buffer.Length) { switch ((char)buffer[_bufferIndex]) { case '/': if (buffer[_bufferIndex + 1] == '/') { _skipLine(); continue; } if (buffer[_bufferIndex + 1] == '*') { _skipCommentBlock(); continue; } break; case ':': ParserKeyValue keyValue = new ParserKeyValue(_word, Line); if (_latest == null && Output != null) { // The file contains multiple arrays ParserArray tempList = new ParserArray(Line); tempList.AddElement(Output); Output.Parent = tempList; Output = tempList; _latest = tempList; } if (_latest == null) { Output = keyValue; _latest = Output; } else { keyValue.Parent = _latest; switch (_latest.ParserType) { case ParserTypes.Array: ((ParserArray)_latest).AddElement(keyValue); _latest = keyValue; break; default: throw new Exception("Expected an Array."); } } break; case '<': _readMultilineQuote(); if (_latest != null) { switch (_latest.ParserType) { case ParserTypes.KeyValue: ((ParserKeyValue)_latest).Value = new ParserString(_word, Line); _latest.Length = Line - _latest.Line + 1; _latest = _latest.Parent; break; default: throw new Exception("Expected a KeyValue."); } } break; case '(': ParserList list = new ParserList(Line); if (_latest == null) { throw new Exception("Trying to open a List type without a parent."); } switch (_latest.ParserType) { case ParserTypes.List: ((ParserList)_latest).AddElement(list); list.Parent = _latest; _latest = list; break; case ParserTypes.KeyValue: ((ParserKeyValue)_latest).Value = list; list.Parent = _latest; _latest = list; break; default: throw new Exception("Expected a KeyValue."); } break; case '{': ParserArray array = new ParserArray(Line); if (_latest == null) { // Used for copy pasting inputs, create a temporary list Output = new ParserKeyValue("copy_paste", Line) { Value = new ParserList(Line) }; _latest = Output["copy_paste"]; } switch (_latest.ParserType) { case ParserTypes.List: ((ParserList)_latest).AddElement(array); array.Parent = _latest; _latest = array; break; case ParserTypes.KeyValue: ((ParserKeyValue)_latest).Value = array; array.Parent = _latest; _latest = array; break; default: throw new Exception("Expected a List."); } break; case '[': ParserAggregate aggregate = new ParserAggregate(Line); if (_latest == null) { throw new Exception("Trying to open an Aggregate type without a parent."); } switch (_latest.ParserType) { case ParserTypes.KeyValue: ((ParserKeyValue)_latest).Value = aggregate; _latest.Length = Line - _latest.Line + 1; aggregate.Parent = _latest; _latest = aggregate; break; default: throw new Exception("Expected a KeyValue."); } break; case ']': case ')': case '}': if (_latest == null) { throw new Exception("Trying to close a statement without knowing its beginning."); } switch (_latest.ParserType) { case ParserTypes.Aggregate: case ParserTypes.Array: case ParserTypes.List: _latest.Length = Line - _latest.Line + 1; _latest = _latest.Parent; if (_latest is ParserKeyValue) { _latest = _latest.Parent; } break; case ParserTypes.KeyValue: _latest = _latest.Parent; _latest.Length = Line - _latest.Line + 1; break; default: throw new Exception("Expected a KeyValue or an Array."); } break; case '\"': _readQuote(); if (_latest == null) { throw new Exception("Trying to read a quote without a parent."); } switch (_latest.ParserType) { case ParserTypes.KeyValue: ((ParserKeyValue)_latest).Value = new ParserString(_word, Line); _latest.Length = Line - _latest.Line + 1; _latest = _latest.Parent; break; case ParserTypes.List: ((ParserList)_latest).AddElement(new ParserString(_word, Line)); break; default: throw new Exception("Expected a KeyValue."); } continue; case ',': case '\t': case ' ': case '\r': break; case '\n': Line++; break; default: _readWord(); if (_word == "") { throw new Exception("Null-length word. This is most likely caused by an unexpected character in a string."); } if (_buffer[_bufferIndex] == ':') { continue; } if (_latest != null) { switch (_latest.ParserType) { case ParserTypes.KeyValue: ((ParserKeyValue)_latest).Value = new ParserString(_word, Line); _latest.Length = Line - _latest.Line + 1; _latest = _latest.Parent; break; case ParserTypes.List: case ParserTypes.Aggregate: ((ParserArrayBase)_latest).AddElement(new ParserString(_word, Line)); break; default: // It will be handled by the ':' parsing. break; } } continue; } _bufferIndex++; } } catch (Exception err) { throw new Exception("Failed to parse " + _file + " at line " + Line + ", position " + LinePosition, err); } }