コード例 #1
0
        private void ParseInlineListToken(Scope.Node node,
                                          ImmutableDictionary <Scope, Dictionary <string, object> > symbolTable, IDictionary <string, object> dict)
        {
            Dictionary <string, object> innerDict = ParseScope(node.InnerScope, symbolTable);
            string inlineListName = string.Concat(innerDict.Keys.Select(e => e.ToLower()));

            dict.Add(inlineListName, innerDict.Values);
        }
コード例 #2
0
        private void ParseVariableNameToken(NamedToken namedToken, Scope.Node node,
                                            ImmutableDictionary <Scope, Dictionary <string, object> > symbolTable, IDictionary <string, object> dict)
        {
            Dictionary <string, object> innerDict = ParseScope(node.InnerScope, symbolTable);

            // if the variable is specified by only one token, we treat this as
            // a "renaming" action and surpress the additional inner wrapper
            dict.Add(namedToken.Name, innerDict.Count == 1 ? innerDict.Values.First() : innerDict);
        }
コード例 #3
0
        private void ParseListToken(ListToken listToken, Scope.Node node, Scope scope,
                                    ImmutableDictionary <Scope, Dictionary <string, object> > symbolTable, IDictionary <string, object> dict)
        {
            if (listToken.Delimiters != null)
            {
                throw new NotImplementedException("List delimiters are not supported yet.");
            }

            // get the number of iterations needed
            var repetitions = 0;

            switch (listToken.Range)
            {
            // automatic
            case AutomaticRange automaticRange:
                throw new NotImplementedException("Automatic range notation is not supported yet.");

            // fixed number
            case NumericRange numericRange:
                repetitions = numericRange.Repetitions;
                break;

            // value of some named token
            case TokenRange tokenRange:
                object referencedValue = FindNamedTokenValue(tokenRange.ReferencedName, scope, symbolTable);
                if (referencedValue is int value)
                {
                    repetitions = value;
                }
                else
                {
                    throw new ParserException($"Could not use the non-numeric value '{referencedValue}' " +
                                              $"of token '{tokenRange.ReferencedName}' as an repetition number.");
                }

                break;
            }

            // parse the inner scope a number of times
            var expandedList = new List <object>();

            for (var i = 0; i < repetitions; i++)
            {
                Dictionary <string, object> innerRepeatedDict = ParseScope(node.InnerScope, symbolTable);
                expandedList.Add(innerRepeatedDict.First().Value);
            }

            // find a name
            Scope.Node innerNode = node;
            while (innerNode.HasInnerScope)
            {
                innerNode = innerNode.InnerScope.First();
            }

            string name = "listToken";

            if (innerNode.Token is NamedToken named)
            {
                name = named.Name + "s";
            }

            dict.Add(name, expandedList);
        }