Example #1
0
        public string Evaluate()
        {
            IExpressionNode root = new TextNode(null);
            IExpressionNode node = root;

            for (int i = 0; i < _expr.Length; i++)
            {
                IExpressionNode tmp = null;

                switch (_expr[i])
                {
                case Tokens.VariableMark:
                {
                    // the next character exists, and is '{'
                    if (i + 1 < _expr.Length && _expr[i + 1] == Tokens.VariableStart)
                    {
                        // skip '{' - it belongs to '$'
                        tmp = new VariableNode(node, Resolve);
                        i++;
                    }
                    else
                    {
                        node = node.Push(_expr[i]);
                    }
                } break;

                case Tokens.VariableStart:
                    if (!_options.HasFlag(Options.LegacyVariables))
                    {
                        throw new JcShellFormatException("Legacy variables format is not enabled!");
                    }

                    tmp = new VariableNode(node, Resolve);
                    break;

                case Tokens.LengthMark:
                    tmp = new LengthNode(node);
                    break;

                case Tokens.LengthBerMark:
                    tmp = new BerLengthNode(node);
                    break;

                case Tokens.AsciiToHex:
                    if (node is AsciiToHexNode)
                    {
                        node = node.Parent;
                    }
                    else
                    {
                        tmp = new AsciiToHexNode(node);
                    }
                    break;

                default:
                    node = node.Push(_expr[i]);
                    break;
                }

                if (tmp == null)
                {
                    continue;
                }
                node.Push(tmp);
                node = tmp;
            }

            return(root.Evaluate());
        }