コード例 #1
0
        private void InitParentheses(UnparseControl unparseControl)
        {
            // NOTE: operators should be determined regardless that the user specified expressions and parentheses
            DetermineOperatorsParenthesesExpressions();
            RegisteringExpressionsThatNeedParentheses(unparseControl);

#if DEBUG
            tsParentheses.Debug("");
            tsParentheses.Debug("----------------------------------------");
            tsParentheses.Debug("");
            tsParentheses.Debug("expressionsThatCanCauseOthersBeingParenthesized:");
            tsParentheses.Debug("");

            foreach (BnfTerm expression in expressionsThatCanCauseOthersBeingParenthesized)
            {
                tsParentheses.Debug(expression);
            }

            tsParentheses.Debug("");
            tsParentheses.Debug("expressionThatMayNeedParenthesesToParentheses:");
            tsParentheses.Debug("");

            foreach (var pair in expressionThatMayNeedParenthesesToParentheses)
            {
                tsParentheses.Debug("{0}; left parenthesis: '{1}', right parenthesis: '{2}'", pair.Key, pair.Value.LeftParenthesis, pair.Value.RightParenthesis);
            }
#endif
        }
コード例 #2
0
        private void RegisteringExpressionsThatNeedParentheses(UnparseControl unparseControl)
        {
            if (unparseControl.ExpressionToParenthesesHasBeenSet)
            {
                this.expressionsThatCanCauseOthersBeingParenthesized = new HashSet <BnfTerm>(unparseControl.GetExpressionToParentheses().Keys());
                this.expressionThatMayNeedParenthesesToParentheses   = unparseControl.GetExpressionToParentheses().ToDictionary(pair => pair.Key, pair => pair.Value);
            }
            else
            {
                this.expressionsThatCanCauseOthersBeingParenthesized = new HashSet <BnfTerm>();
                this.expressionThatMayNeedParenthesesToParentheses   = new Dictionary <BnfTerm, ParenthesizedExpression>();
                this._examinedBnfTermsInCurrentPath = new Bag <BnfTerm>();

                RegisteringExpressionsThatNeedParentheses(unparser.Grammar.Root);

                lock (unparseControl)
                {   // handle concurrent unparsers initializations with one shared grammar and unparseControl
                    if (!unparseControl.ExpressionToParenthesesHasBeenSet)
                    {
                        unparseControl.SetExpressionToParentheses(expressionThatMayNeedParenthesesToParentheses);
                    }
                }
            }
        }
コード例 #3
0
 public ExpressionUnparser(Unparser unparser, UnparseControl unparseControl)
 {
     this.unparser = unparser;
     InitParentheses(unparseControl);
 }