예제 #1
0
 private DataSet RequirementsFilter(StructureToken structureToken, DataSet Followups)
 {
     return(Followups.Filter((x) => {
         if (x.HasKey(StructureConsts.KEYWORD_FOLLOWEDBY, out DataValue followups))
         {
             if (followups.value != structureToken.StructType)
             {
                 return false;
             }
         }
         return true;
     }));
 }
예제 #2
0
        private StructureToken ParseNext(DataSet allowedTokens)
        {
            Token token = m_TokenSet[m_Index++];

            if (!CheckToken(allowedTokens, token, out DataSet potentials))
            {
                throw new System.Exception("I can't be anything.. T-T");
            }

            if (potentials.Length == 1)
            {
                // There is only one potential thing this token could be
                // so we know exactly what we are without parsing the
                // follow up tokens
                StructureToken structureToken = new StructureToken(token);
                structureToken.StructType = potentials[0].Name;

                // How many types are there that are supposed to follow me?
                DataSet Followups = GetFollowUps(potentials);

                // If there is nothing that should follow me,
                // then its the end of this tree structure
                if (Followups.Length == 0)
                {
                    return(structureToken);
                }

                // If this structure continues until another structure is found
                // continue parsing children until the until value is met
                if (potentials[0].HasKey(TokenConsts.KEYWORD_UNTIL, out DataValue until))
                {
                    StructureToken structure;
                    do // EBIL
                    {
                        structure = ParseNext(Followups);
                        structureToken.Childs.Add(structure);
                    } while (structure.StructType != until.value);

                    // Return when we met the child ender
                    return(structureToken);
                }

                // Add the next token, leave
                structureToken.Childs.Add(ParseNext(Followups));
                return(structureToken);
            }


            // We can't be sure what we are, so we are going
            // to parse the next token first.
            StructureToken nextToken = ParseNext(GetFollowUps(potentials));

            // When this token is parsed, check what I could have been with
            // the type the next tokend became.
            DataSet set = RequirementsFilter(nextToken, potentials);

            // If we have only one thing we could have been at this point, hurray!
            // we know what we are.
            if (set.Length == 1)
            {
                StructureToken structureToken = new StructureToken(token);
                structureToken.StructType = set[0].Name;
                structureToken.Childs.Add(nextToken);

                // If this structure continues until another structure is found
                // continue parsing children until the until value is met
                if (set[0].HasKey(TokenConsts.KEYWORD_UNTIL, out DataValue until))
                {
                    StructureToken structure;
                    do // EBIL
                    {
                        structure = ParseNext(set);
                        structureToken.Childs.Add(structure);
                    } while (structure.StructType != until.value);

                    // Return when we met the child ender
                    return(structureToken);
                }
                return(structureToken);
            }

            throw new System.Exception("Parsed next token and I atill have no idea what I am T-T");
        }