Process a line of source text that has been identified as a Regenerate start and/or end of comment line
770759
def processCommandLine(parsedCommandLine, lineNumber)
      #puts "command: #{parsedCommandLine}"
      if @currentComponent && (@currentComponent.is_a? StaticHtml) # finish any current static HTML component
        @currentComponent.finishText
        @currentComponent = nil
      end
      if @currentComponent # we are in a page component other than a static HTML component
        if parsedCommandLine.sectionStart # we have already started, so we cannot start again
          raise ParseException.new("Unexpected section start #{parsedCommandLine} inside component")
        end
        @currentComponent.processEndComment(parsedCommandLine) # so, command must be a command to end the page component
        @currentComponent = nil
      else # not in any page component, so we need to start a new one
        if !parsedCommandLine.sectionStart # if it's an end command, error, because there is nothing to end
          raise ParseException.new("Unexpected section end #{parsedCommandLine}, outside of component")
        end
        if parsedCommandLine.isInstanceVar # it's a page component that defines an instance variable value
          if parsedCommandLine.hasCommentEnd # the value will be an HTML value
            startNewComponent(HtmlVariable.new, parsedCommandLine)
          else # the value will be an HTML-commented value
            startNewComponent(CommentVariable.new, parsedCommandLine)
          end
        else # not an instance var, so it must be a special command
          if parsedCommandLine.name == "ruby" # Ruby page component containing Ruby that will be executed in the 
                                              # context of the page object
            startNewComponent(RubyCode.new(lineNumber+1), parsedCommandLine)
          elsif parsedCommandLine.name == "class" # Specify Ruby class for the page object
            startNewComponent(SetPageObjectClass.new(parsedCommandLine.value), parsedCommandLine)
          else # not a known special command
            raise ParseException.new("Unknown section type #{parsedCommandLine.name.inspect}")
          end
        end
        if @currentComponent.finished # Did the processing cause the current page component to be finished?
          @currentComponent = nil # clear the current component
        end
      end
      
    end
100659
def _comment_handler(c, ctx, whence):
    """"""
    assert c == _SLASH
    c, self = yield
    if c == _SLASH:
        ctx.set_line_comment()
        block_comment = False
    elif c == _ASTERISK:
        if ctx.line_comment:
            # This happens when a block comment immediately follows a line comment.
            ctx.set_line_comment(False)
        block_comment = True
    else:
        _illegal_character(c, ctx, 'Illegal character sequence "/%s".' % (_chr(c),))
    done = False
    prev = None
    trans = ctx.immediate_transition(self)
    while not done:
        c, _ = yield trans
        if block_comment:
            if prev == _ASTERISK and c == _SLASH:
                done = True
            prev = c
        else:
            if c in _NEWLINES or BufferQueue.is_eof(c):
                done = True
    yield ctx.set_self_delimiting(True).immediate_transition(whence)
234977
def get_transition(self,  # suppress(too-many-arguments)
                       line,
                       line_index,
                       column,
                       is_escaped,
                       comment_system_transitions,
                       eof=False):
        """"""
        # If we are at the beginning of a line, to see if we should
        # disable processing from this point onward and get out - this will
        # happen if we reach the end of some comment block that doesn't have
        # an explicit end marker. We can't detect line endings here because
        # we want a disabled region to continue across multiple lines.
        if (column == 0 and
                comment_system_transitions.should_terminate_now(
                    line,
                    self._resume_waiting_for
                )):
            return (InTextParser(), 0, None)

        # Need to be a bit careful here, since we need to check what the
        # disabled parser was waiting for and disable on that, too.
        if (_token_at_col_in_line(line,
                                  column,
                                  "```",
                                  3) and
                not _is_escaped(line, column, is_escaped)):
            # Hit a disable token, so we resume the old parser
            return (self._resume_parser((line_index, column + 3),
                                        self._resume_waiting_for),
                    3,
                    None)
        elif self._resume_waiting_for != ParserState.EOL:
            wait_until_len = len(self._resume_waiting_for)
            if (_token_at_col_in_line(line,
                                      column,
                                      self._resume_waiting_for,
                                      wait_until_len) and
                    not _is_escaped(line, column, is_escaped)):

                # Skip ahead to end of this token
                return (InTextParser(),
                        len(self._waiting_until),
                        None)
        elif eof:
            # We hit the end of the file and were still in a comment
            # state. Grab everything up to here.
            return (InTextParser(), 0, None)

        # Move ahead by one character otherwise
        return (self, 1, None)
550762
def strip_comments(tokens):
    
    prev_typ = None
    prev_end_col = 0
    for typ, tok, (start_row, start_col), (end_row, end_col), line in tokens:
        if typ in (tokenize.NL, tokenize.NEWLINE):
            if prev_typ in (tokenize.NL, tokenize.NEWLINE):
                start_col = 0
            else:
                start_col = prev_end_col
            end_col = start_col + 1
        elif typ == tokenize.COMMENT and start_row > 2:
            continue
        prev_typ = typ
        prev_end_col = end_col
        yield typ, tok, (start_row, start_col), (end_row, end_col), line
1140853
private boolean commentLinesBefore( String content, int line ) {
        int offset = rootElement.getElement(line).getStartOffset();
        // Start of comment not found, nothing to do
        int startDelimiter = lastIndexOf(content, getStartDelimiter(), offset - 2);
        if (startDelimiter < 0)
            return false;
        // Matching start/end of comment found, nothing to do
        int endDelimiter = indexOf(content, getEndDelimiter(), startDelimiter);
        if (endDelimiter < offset & endDelimiter != -1)
            return false;
        // End of comment not found, highlight the lines
        doc.setCharacterAttributes(startDelimiter, offset - startDelimiter + 1, comment, false);
        return true;
    }
327356
def beginning_of_line(event):
    "  "
    buff = event.current_buffer
    buff.cursor_position += buff.document.get_start_of_line_position(after_whitespace=False)
235806
def endline_repl(self, inputstring, reformatting=False, **kwargs):
        """"""
        out = []
        ln = 1  # line number
        for line in inputstring.splitlines():
            add_one_to_ln = False
            try:
                if line.endswith(lnwrapper):
                    line, index = line[:-1].rsplit("#", 1)
                    new_ln = self.get_ref("ln", index)
                    if new_ln < ln:
                        raise CoconutInternalException("line number decreased", (ln, new_ln))
                    ln = new_ln
                    line = line.rstrip()
                    add_one_to_ln = True
                if not reformatting or add_one_to_ln:  # add_one_to_ln here is a proxy for whether there was a ln comment or not
                    line += self.comments.get(ln, "")
                if not reformatting and line.rstrip() and not line.lstrip().startswith("#"):
                    line += self.ln_comment(ln)
            except CoconutInternalException as err:
                complain(err)
            out.append(line)
            if add_one_to_ln:
                ln += 1
        return "\n".join(out)
1359717
def _split_comment(lineno, comment):
        """"""
        return [(lineno + index, line) for index, line in
                enumerate(comment.splitlines())]
334749
def process_source(self):
        """"""
        if isinstance(self.source, str):
            # Replace single and double quotes with escaped single-quote
            self.source = self.source.replace("'", "\'").replace('"', "\'")
            return "\"{source}\"".format(source=self.source)
        return self.source
201464
def comment_lines(lines, prefix):
    """"""
    if not prefix:
        return lines
    return [prefix + ' ' + line if line else prefix for line in lines]
479754
def _starts_till(src, probe, strip_comments=True):
    '''
    
    '''
    def _strip_comments(txt):
        '''
        Strip possible comments.
        Usually comments are one or two symbols at the beginning of the line, separated with space
        '''
        buff = txt.split(" ", 1)
        return len(buff) == 2 and len(buff[0]) < 2 and buff[1] or txt

    def _to_words(txt):
        '''
        Split by words
        '''
        return txt and [w for w in txt.strip().split(" ") if w.strip()] or txt

    no_match = -1
    equal = 0
    if not src or not probe:
        return no_match

    src = src.rstrip('\n\r')
    probe = probe.rstrip('\n\r')
    if src == probe:
        return equal

    src = _to_words(strip_comments and _strip_comments(src) or src)
    probe = _to_words(strip_comments and _strip_comments(probe) or probe)

    a_buff, b_buff = len(src) < len(probe) and (src, probe) or (probe, src)
    b_buff = ' '.join(b_buff)
    for idx in range(len(a_buff)):
        prb = ' '.join(a_buff[:-(idx + 1)])
        if prb and b_buff.startswith(prb):
            return idx

    return no_match
351622
def markdown_to_text(self, source):
        """"""
        if self.comment and self.comment != "#'":
            source = copy(source)
            comment_magic(source, self.language, self.comment_magics)

        return comment_lines(source, self.comment)
1267475
def _comment_type_from_line(line):
    
    regex = re.compile(r"^{0}".format(_ALL_COMMENT))
    match = regex.match(line)
    if match:
        return "{0} ".format(line[match.start():match.end()])

    raise RuntimeError("Unable to find comment header for {0}".format(line))
24007
def token_or_comment_or_line_generator(buffer):
    """"""
    tok_or_com_gen = token_or_comment_generator(buffer)
    line_gen = line_generator(buffer)

    tok_or_com = next(tok_or_com_gen, None)
    line = next(line_gen, None)

    while tok_or_com is not None or line is not None:
        if tok_or_com is None or (line is not None and
                                  tok_or_com.line_no > line.line_no):
            yield line
            line = next(line_gen, None)
        else:
            yield tok_or_com
            tok_or_com = next(tok_or_com_gen, None)
1289601
def _strip_top_comments(lines):
        """"""
        lines = copy.copy(lines)
        while lines and lines[0].startswith("#"):
            lines = lines[1:]
        return "\n".join(lines)
1273832
function(line, isInComment) {
  while (true || line.length > 0) {
    var startIndex = line.indexOf('{-');
    var endIndex = line.indexOf('-}');
    var singleLineComment = line.indexOf('--');

    // when we have a single line comment
    if (singleLineComment > -1 && !isInComment) {
      line = line.substr(0, singleLineComment);
      continue;
    }

    // when there's no comment chars
    if (startIndex === -1 && endIndex === -1) {
      return {
        line: isInComment ? '' : line,
        isInComment: isInComment,
      };
    }

    // when there's a start and end
    if (startIndex > -1 && endIndex > -1) {
      line = line.substr(0, startIndex) + line.substr(endIndex + 2);
      continue;
    }

    // when there's a start, but no end
    if (startIndex > -1)
      return { line: line.substr(0, startIndex), isInComment: true };

    // when there's an end, but no start
    if (endIndex > -1 && isInComment)
      return { line: line.substr(endIndex + 2), isInComment: false };
  }

  return { line: '', isInComment: isInComment };
}
1210042
def ConsumeCommentOrTrailingComment(self):
    """"""

    # Tokenizer initializes _previous_line and _previous_column to 0. As the
    # tokenizer starts, it looks like there is a previous token on the line.
    just_started = self._line == 0 and self._column == 0

    before_parsing = self._previous_line
    comment = self.ConsumeComment()

    # A trailing comment is a comment on the same line than the previous token.
    trailing = (self._previous_line == before_parsing
                and not just_started)

    return trailing, comment