The rewritten source code with proper indent.

 @return [String] rewritten code.
487659
def rewritten_code
      if rewritten_source.split("\n").length > 1
        "\n\n" + rewritten_source.split("\n").map { |line|
          indent(@node) + line
        }.join("\n")
      else
        "\n" + indent(@node) + rewritten_source
      end
    end
1070259
def to_sexp(indent=0)
      indented = "  " * indent
      sexp = "#{indented}(#{fancy_type}"

      children.each do |child|
        if child.is_a?(Node)
          sexp += "\n#{child.to_sexp(indent + 1)}"
        else
          sexp += " #{child.inspect}"
        end
      end

      sexp += ")"

      sexp
    end
496609
def generate_lambda_string(document, optimize: false)
      @document = document
      @buff = []
      @indent = 0
      @code_indent = 0
      @optimize = optimize

      buff_code '# frozen_string_literal: true' # so it can be faster on Ruby 2.3+
      buff_code ''
      buff_code "lambda do |#{NEW_LINE_NAME}: \"\\n\", #{BASE_INDENT_NAME}: '  '|"

      code_indent do
        buff_code "self.#{NEW_LINE_NAME} = #{NEW_LINE_NAME}"
        buff_code "self.#{BASE_INDENT_NAME} = #{BASE_INDENT_NAME}"

        visit_document(document)

        buff_code "output = #{BUFF_NAME}.join"
        buff_code 'self.__reset'
        buff_code 'output'
      end

      buff_code 'end'


      @document = nil

      @buff.join("\n")
    end
742147
function undent(code) {
  let lines = code.split("\n");
  let minIndent = Number.MAX_VALUE;

  // find min indent
  lines.forEach(line => {
    let startingSpaceMatch = line.match(/^\s*/);
    let indentLength = startingSpaceMatch[0].length;
    if (indentLength < minIndent) {
      minIndent = indentLength;
    }
  });

  // remove the indentation from each line
  return lines
    .map(line => {
      return line.substring(minIndent);
    })
    .join("\n");
}
477928
def compile(self, code):
        
        is_plain_text = True
        compiled_regex = r""
        for chunk in self.delimiter_regex().split(code):
            if is_plain_text:
                compiled_regex = compiled_regex + simex_escape(chunk, flexible_whitespace=self._flexible_whitespace)
            else:
                stripped_chunk = chunk.strip()
                if stripped_chunk in self._regexes.keys():
                    compiled_regex = u"{0}{1}".format(
                        compiled_regex,
                        self._regexes[stripped_chunk]
                    )
                else:
                    raise KeyNotFound("'{0}' not found in keys")
            is_plain_text = not is_plain_text
        if self._exact:
            compiled_regex = r"^" + compiled_regex + r"$"
        return compile(compiled_regex)
1088202
def gfm(text):
    
    def indent_code(matchobj):
        syntax = matchobj.group(1)
        code = matchobj.group(2)
        if syntax:
            result = '    :::' + syntax + '\n'
        else:
            result = ''
        # The last line will be blank since it had the closing "```". Discard it
        # when indenting the lines.
        return result + '\n'.join(['    ' + line for line in code.split('\n')[:-1]])

    use_crlf = text.find('\r') != -1
    if use_crlf:
        text = text.replace('\r\n', '\n')

    # Render GitHub-style ```code blocks``` into Markdown-style 4-space indented blocks
    text = CODEPATTERN_RE.sub(indent_code, text)

    text, code_blocks = remove_pre_blocks(text)
    text, inline_blocks = remove_inline_code_blocks(text)

    # Prevent foo_bar_baz from ending up with an italic word in the middle.
    def italic_callback(matchobj):
        s = matchobj.group(0)
        # don't mess with URLs:
        if 'http:' in s or 'https:' in s:
            return s

        return s.replace('_', r'\_')

    # fix italics for code blocks
    text = ITALICSPATTERN_RE.sub(italic_callback, text)

    # linkify naked URLs
    # wrap the URL in brackets: http://foo -> [http://foo](http://foo)
    text = NAKEDURL_RE.sub(r'\1[\2](\2)\3', text)

    # In very clear cases, let newlines become <br /> tags.
    def newline_callback(matchobj):
        if len(matchobj.group(1)) == 1:
            return matchobj.group(0).rstrip() + '  \n'
        else:
            return matchobj.group(0)

    text = NEWLINE_RE.sub(newline_callback, text)

    # now restore removed code blocks
    removed_blocks = code_blocks + inline_blocks
    for removed_block in removed_blocks:
        text = text.replace('{placeholder}', removed_block, 1)

    if use_crlf:
        text = text.replace('\n', '\r\n')

    return text
861636
def ast_to_code(ast, indent=0):
    # type: (Any, int) -> str
    
    code = []

    def append(line):
        # type: (str) -> None
        code.append(("    " * indent) + line)

    if isinstance(ast, Node):
        append("ast.{}(".format(ast.__class__.__name__))
        indent += 1
        for i, k in enumerate(ast._fields, 1):
            v = getattr(ast, k)
            append("{}={},".format(k, ast_to_code(v, indent)))
        if ast.loc:
            append("loc={}".format(ast_to_code(ast.loc, indent)))

        indent -= 1
        append(")")

    elif isinstance(ast, Loc):
        append("loc({}, {})".format(ast.start, ast.end))

    elif isinstance(ast, list):
        if ast:
            append("[")
            indent += 1

            for i, it in enumerate(ast, 1):
                is_last = i == len(ast)
                append(ast_to_code(it, indent) + ("," if not is_last else ""))

            indent -= 1
            append("]")
        else:
            append("[]")

    else:
        append(repr(ast))

    return "\n".join(code).strip()
217576
def evaluate(parent, indent)
      # Accept eval or multiline eval syntax and return a new node,
      return unless accept :eval

      multiline = accept(:text)

      if multiline
        # Get first evaluation line
        evaluate_code = accept(:line_feed) || ''

        # Get all the lines which are more indented than the current one
        eval_node = [:evaluate, evaluate_code.strip, {}, nil, indent]
        eval_node[@value] += accept(:newline) || ''
        eval_node[@value] += get_indented_lines(indent)
      else
        evaluate_code = accept(:line_feed) || ''
        eval_node = [:evaluate, evaluate_code.strip, {}, [], indent]

        root eval_node, indent
      end

      parent[@children] << eval_node
    end
21521
def pretty(self, indent=0, debug=False):
        
        debug_details = ''
        if debug:
            debug_details += '<isliteral=%r, iscanonical=%r>' % (self.isliteral, self.iscanonical)

        obj = "'%s'" % self.obj if isinstance(self.obj, basestring) else repr(self.obj)
        return (' ' * indent) + ('%s(%s%s)' % (self.__class__.__name__, debug_details, obj))
151861
def get_indented_lines(indent)
      buffer = ''

      # Gather multiple blank lines between lines of text
      blank_lines = proc do
        while lookahead_next_line :line_whitespace
          @line = @code[(@i += 1)]
          @offset = 0

          buffer += accept :line_whitespace
        end
      end

      # Get blank lines until we match something
      blank_lines[]

      # Get the next indentation after the parent line
      # and set it as primary indent
      first_indent = (lookahead_next_line(:indent).to_s || '').size
      next_indent = first_indent

      # While the indentation is smaller, add the line feed  to our buffer
      while next_indent > indent
        # Advance current line and reset offset
        @line = @code[(@i += 1)]
        @offset = 0

        # Get leading whitespace trimmed with first_indent's size
        next_line_indent = accept(:indent)[first_indent..-1] || ''
        next_line_indent = next_line_indent.size

        # Add next line feed, prepend the indent and append the newline
        buffer += ' ' * next_line_indent if next_line_indent > 0
        buffer += accept_stripped(:line_feed) || ''
        buffer += accept(:newline) || ''

        # Get blank lines until we match something
        blank_lines[]

        # Check the indentation on the following line. When we reach EOF,
        # set the indentation to 0 and cause the loop to stop
        if (next_indent = lookahead_next_line :indent)
          next_indent = next_indent[0].size
        else
          next_indent = 0
        end
      end

      buffer
    end
1066483
function makeSourceCode(text, ast) {
  if (SourceCode.length > 1) {
    // ESLint 3
    return new SourceCode(text, ast)
  } else {
    // ESLint 4, 5
    return new SourceCode({ text, ast })
  }
}
834505
def output_op(code, op, indent=2)
      case op
      when Dot
        code << indentify("_tmp = get_byte\n", indent)
      when LiteralString
        code << indentify("_tmp = match_string(#{op.string.dump})\n", indent)
      when LiteralRegexp
        if op.regexp.respond_to?(:kcode)
          lang = op.regexp.kcode.to_s[0,1]
        else
          # Let default ruby string handling figure it out
          lang = ""
        end
        code << indentify("_tmp = scan(/\\A#{op.regexp}/#{lang})\n", indent)
      when CharRange
        ss = save()
        if op.start.bytesize == 1 and op.fin.bytesize == 1
          code << indentify("#{ss} = self.pos\n", indent)
          code << indentify("_tmp = get_byte\n", indent)
          code << indentify("if _tmp\n", indent)

          if op.start.respond_to? :getbyte
            left  = op.start.getbyte 0
            right = op.fin.getbyte 0
          else
            left  = op.start[0]
            right = op.fin[0]
          end

          code << indentify("  unless _tmp >= #{left} and _tmp <= #{right}\n", indent)
          code << indentify("    self.pos = #{ss}\n", indent)
          code << indentify("    _tmp = nil\n", indent)
          code << indentify("  end\n", indent)
          code << indentify("end\n", indent)
        else
          raise "Unsupported char range - #{op.inspect}"
        end
      when Choice
        ss = save()
        code << "\n"
        code << indentify("#{ss} = self.pos\n", indent)
        code << indentify("while true # choice\n", indent)
        op.ops.each_with_index do |n,idx|
          output_op code, n, (indent+1)

          code << indentify("  break if _tmp\n", indent)
          code << indentify("  self.pos = #{ss}\n", indent)
          if idx == op.ops.size - 1
            code << indentify("  break\n", indent)
          end
        end
        code << indentify("end # end choice\n\n", indent)
      when Multiple
        ss = save()
        if op.min == 0 and op.max == 1
          code << indentify("#{ss} = self.pos\n", indent)
          output_op code, op.op, indent
          if op.save_values
            code << indentify("@result = nil unless _tmp\n", indent)
          end
          code << indentify("unless _tmp\n", indent)
          code << indentify("  _tmp = true\n", indent)
          code << indentify("  self.pos = #{ss}\n", indent)
          code << indentify("end\n", indent)
        elsif op.min == 0 and !op.max
          if op.save_values
            code << indentify("_ary = []\n", indent)
          end

          code << indentify("while true\n", indent)
          output_op code, op.op, (indent+1)
          if op.save_values
            code << indentify("  _ary << @result if _tmp\n", indent)
          end
          code << indentify("  break unless _tmp\n", indent)
          code << indentify("end\n", indent)
          code << indentify("_tmp = true\n", indent)

          if op.save_values
            code << indentify("@result = _ary\n", indent)
          end

        elsif op.min == 1 and !op.max
          code << indentify("#{ss} = self.pos\n", indent)
          if op.save_values
            code << indentify("_ary = []\n", indent)
          end
          output_op code, op.op, indent
          code << indentify("if _tmp\n", indent)
          if op.save_values
            code << indentify("  _ary << @result\n", indent)
          end
          code << indentify("  while true\n", indent)
          output_op code, op.op, (indent+2)
          if op.save_values
            code << indentify("    _ary << @result if _tmp\n", indent)
          end
          code << indentify("    break unless _tmp\n", indent)
          code << indentify("  end\n", indent)
          code << indentify("  _tmp = true\n", indent)
          if op.save_values
            code << indentify("  @result = _ary\n", indent)
          end
          code << indentify("else\n", indent)
          code << indentify("  self.pos = #{ss}\n", indent)
          code << indentify("end\n", indent)
        else
          code << indentify("#{ss} = self.pos\n", indent)
          code << indentify("_count = 0\n", indent)
          code << indentify("while true\n", indent)
          output_op code, op.op, (indent+1)
          code << indentify("  if _tmp\n", indent)
          code << indentify("    _count += 1\n", indent)
          code << indentify("    break if _count == #{op.max}\n", indent)
          code << indentify("  else\n", indent)
          code << indentify("    break\n", indent)
          code << indentify("  end\n", indent)
          code << indentify("end\n", indent)
          code << indentify("if _count >= #{op.min}\n", indent)
          code << indentify("  _tmp = true\n", indent)
          code << indentify("else\n", indent)
          code << indentify("  self.pos = #{ss}\n", indent)
          code << indentify("  _tmp = nil\n", indent)
          code << indentify("end\n", indent)
        end

      when Sequence
        ss = save()
        code << "\n"
        code << indentify("#{ss} = self.pos\n", indent)
        code << indentify("while true # sequence\n", indent)
        op.ops.each_with_index do |n, idx|
          output_op code, n, (indent+1)

          if idx == op.ops.size - 1
            code << indentify("  unless _tmp\n", indent)
            code << indentify("    self.pos = #{ss}\n", indent)
            code << indentify("  end\n", indent)
            code << indentify("  break\n", indent)
          else
            code << indentify("  unless _tmp\n", indent)
            code << indentify("    self.pos = #{ss}\n", indent)
            code << indentify("    break\n", indent)
            code << indentify("  end\n", indent)
          end
        end
        code << indentify("end # end sequence\n\n", indent)
      when AndPredicate
        ss = save()
        code << indentify("#{ss} = self.pos\n", indent)
        if op.op.kind_of? Action
          code << indentify("_tmp = begin; #{op.op.action}; end\n", indent)
        else
          output_op code, op.op, indent
        end
        code << indentify("self.pos = #{ss}\n", indent)
      when NotPredicate
        ss = save()
        code << indentify("#{ss} = self.pos\n", indent)
        if op.op.kind_of? Action
          code << indentify("_tmp = begin; #{op.op.action}; end\n", indent)
        else
          output_op code, op.op, indent
        end
        code << indentify("_tmp = _tmp ? nil : true\n", indent)
        code << indentify("self.pos = #{ss}\n", indent)
      when RuleReference
        if op.arguments
          code << indentify("_tmp = apply_with_args(:#{method_name op.rule_name}, #{op.arguments[1..-2]})\n", indent)
        else
          code << indentify("_tmp = apply(:#{method_name op.rule_name})\n", indent)
        end
      when InvokeRule
        if op.arguments
          code << indentify("_tmp = #{method_name op.rule_name}#{op.arguments}\n", indent)
        else
          code << indentify("_tmp = #{method_name op.rule_name}()\n", indent)
        end
      when ForeignInvokeRule
        if op.arguments
          code << indentify("_tmp = @_grammar_#{op.grammar_name}.external_invoke(self, :#{method_name op.rule_name}, #{op.arguments[1..-2]})\n", indent)
        else
          code << indentify("_tmp = @_grammar_#{op.grammar_name}.external_invoke(self, :#{method_name op.rule_name})\n", indent)
        end
      when Tag
        if op.tag_name and !op.tag_name.empty?
          output_op code, op.op, indent
          code << indentify("#{op.tag_name} = @result\n", indent)
        else
          output_op code, op.op, indent
        end
      when Action
        code << indentify("@result = begin; ", indent)
        code << op.action << "; end\n"
        if @debug
          code << indentify("puts \"   => \" #{op.action.dump} \" => \#{@result.inspect} \\n\"\n", indent)
        end
        code << indentify("_tmp = true\n", indent)
      when Collect
        code << indentify("_text_start = self.pos\n", indent)
        output_op code, op.op, indent
        code << indentify("if _tmp\n", indent)
        code << indentify("  text = get_text(_text_start)\n", indent)
        code << indentify("end\n", indent)
      when Bounds
        code << indentify("_bounds_start = self.pos\n", indent)
        output_op code, op.op, indent
        code << indentify("if _tmp\n", indent)
        code << indentify("  bounds = [_bounds_start, self.pos]\n", indent)
        code << indentify("end\n", indent)
      else
        raise "Unknown op - #{op.class}"
      end
    end
85600
def code(*content, sep=' '):
    
    return _md(_join(*content, sep=sep), symbols=MD_SYMBOLS[2])
375135
def get_selection_as_executable_code(self):
        """"""
        ls = self.get_line_separator()

        _indent = lambda line: len(line)-len(line.lstrip())

        line_from, line_to = self.get_selection_bounds()
        text = self.get_selected_text()
        if not text:
            return

        lines = text.split(ls)
        if len(lines) > 1:
            # Multiline selection -> eventually fixing indentation
            original_indent = _indent(self.get_text_line(line_from))
            text = (" "*(original_indent-_indent(lines[0])))+text

        # If there is a common indent to all lines, find it.
        # Moving from bottom line to top line ensures that blank
        # lines inherit the indent of the line *below* it,
        # which is the desired behavior.
        min_indent = 999
        current_indent = 0
        lines = text.split(ls)
        for i in range(len(lines)-1, -1, -1):
            line = lines[i]
            if line.strip():
                current_indent = _indent(line)
                min_indent = min(current_indent, min_indent)
            else:
                lines[i] = ' ' * current_indent
        if min_indent:
            lines = [line[min_indent:] for line in lines]

        # Remove any leading whitespace or comment lines
        # since they confuse the reserved word detector that follows below
        lines_removed = 0
        while lines:
            first_line = lines[0].lstrip()
            if first_line == '' or first_line[0] == '#':
                lines_removed += 1
                lines.pop(0)
            else:
                break

        # Add an EOL character after the last line of code so that it gets
        # evaluated automatically by the console and any quote characters
        # are separated from the triple quotes of runcell
        lines.append(ls)

        # Add removed lines back to have correct traceback line numbers
        leading_lines_str = ls * lines_removed

        return leading_lines_str + ls.join(lines)
165435
def raw_writer(indent=None):
    

    is_whitespace_str = isinstance(indent, str) and re.search(r'\A\s*\Z', indent, re.M) is not None
    if not (indent is None or is_whitespace_str):
        raise ValueError('The indent parameter must either be None or a string containing only whitespace')

    indent_bytes = six.b(indent) if isinstance(indent, str) else indent

    return writer_trampoline(_raw_writer_coroutine(indent=indent_bytes))
1118492
def strip_indent(s, n)
      while n > 0
        case s[0, 1]
        when ' '
          n -= 1
        when "\t"
          n -= TAB_SIZE
        else
          break
        end
        s = s[1..-1]
      end

      MDLine.new(s)
    end
492033
def pretty_str(self, indent=0):
        
        return '\n\n'.join(
                codeobj.pretty_str(indent=indent)
                for codeobj in self.children
        )