Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public bool GetTemplateInfo(KStream stream, ref KTemplateInfo info, ref int linecount)
- {
- List<Template> templates = new List<Template>();
- do
- {
- Template template = new Template();
- moveToNext(CharType.Char); // file usually begins with \n | second+ read will move our position to the next reserved word
- string resWord = readWord(CharType.Char);
- if (isReservedWord(resWord) && resWord == "template")
- {
- template.Name = readWord(CharType.OBracket); // template name
- if (string.IsNullOrEmpty(template.Name))
- throw new InvalidDataException("block_name cannot be empty!");
- try
- {
- resWord = readWord(CharType.Char); // template guid
- template.Guid = new System.Guid(resWord);
- }
- catch (Exception ex) { throw ex; }
- do
- {
- TemplateMember tMem = new TemplateMember();
- tMem.Type = MemberType.Char;
- resWord = readWord(CharType.Char);
- if (string.IsNullOrEmpty(resWord))
- throw new InvalidDataException("resWord cannot be empty!");
- if (!isReservedWord(resWord))
- tMem.Type = MemberType.Template;
- else
- {
- int rwIdx = reserved_word.FindIndex(rW => rW == resWord);
- if (rwIdx == -1)
- throw new Exception($"Could not find the index of reserved word: {resWord}");
- tMem.Type = (MemberType)rwIdx;
- }
- tMem.Name = readDelimitedWord(new List<char>() { '[', ';' });
- char delimiter = currentDelimiterType; //We must get our current delimiter char since we did not move!
- bool breakLoop = false;
- switch (delimiter)
- {
- case '[': // member has array
- {
- //TODO: read the next delimited word by ']' and assign it as the value then goto case ';'
- string arrayVal = readDelimitedWord(new List<char>() { ']' });
- int aVal = default;
- if (int.TryParse(arrayVal, out aVal))
- tMem.ArrayVal = aVal;
- else
- tMem.ArrayVal = arrayVal;
- if (readChar() == ';')
- goto case ';';
- }
- break;
- case ';':
- {
- if (peekNextNonWS() == CharType.CBracket)
- {
- breakLoop = true;
- break;
- }
- }
- break;
- }
- template.Members.Add(tMem);
- if (breakLoop) // we have hit the end of this block
- break;
- }
- while (peek() != CharType.NewLine); //Since we are manually parsing it is ok to assume that each new line by the time we peek() seperates current and new block
- templates.Add(template);
- }
- else
- throw new InvalidDataException("Unexpected word in stream!");
- }
- while (moveToNext(CharType.Char) != -1);
- return false;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement