Exemple #1
0
def GenerateTags(buff):
    """Create a DocStruct object that represents a NSIS Script
    @param buff: a file like buffer object (StringIO)
    @todo: generate tags for lua tables?

    """
    rtags = taglib.DocStruct()

    # Set Descriptions of Document Element Types
    rtags.SetElementDescription('variable', "Defines")
    rtags.SetElementDescription('section', "Section Definitions")
    rtags.SetElementDescription('macro', "Macro Definitions")
    rtags.SetElementDescription('function', "Function Definitions")
    rtags.SetElementPriority('variable', 4)
    rtags.SetElementPriority('section', 3)
    rtags.SetElementPriority('function', 2)
    rtags.SetElementPriority('macro', 1)

    # Parse the lines for code objects
    for lnum, line in enumerate(buff):
        line = line.strip()
        llen = len(line)

        # Skip comment and empty lines
        if line.startswith(u"#") or line.startswith(u";") or not line:
            continue

        # Look for functions and sections
        if parselib.IsToken(line, 0, u'Function'):
            parts = line.split()
            if len(parts) > 1:
                rtags.AddFunction(taglib.Function(parts[1], lnum))
        elif parselib.IsToken(line, 0, u'Section'):
            parts = line.split()
            if len(parts) > 1 and parts[1][0] not in ['"', "'", "`"]:
                rtags.AddElement('section', taglib.Section(parts[1], lnum))
            else:
                for idx, part in enumerate(parts[1:]):
                    if parts[idx][-1] in ['"', "'", "`"]:
                        rtags.AddElement('section', taglib.Section(part, lnum))
                        break
        elif parselib.IsToken(line, 0, u'!macro'):
            parts = line.split()
            if len(parts) > 1:
                rtags.AddElement('macro', taglib.Macro(parts[1], lnum))
        elif parselib.IsToken(line, 0, u'!define'):
            parts = line.split()
            if len(parts) > 1 and parts[1][0].isalpha():
                rtags.AddVariable(taglib.Variable(parts[1], lnum))
        else:
            continue

    return rtags
Exemple #2
0
def GenerateTags(buff):
    """Create a DocStruct object that represents a Configuration File
    @param buff: a file like buffer object (StringIO)

    """
    rtags = taglib.DocStruct()
    rtags.SetElementDescription('section', "Sections")
    section = None

    for lnum, line in enumerate(buff):
        line = line.strip()

        # Skip comment and empty lines
        if line.startswith(u"#") or line.startswith(u";") or not line:
            continue

        # Check for a section
        if line.startswith(u"["):
            secend = line.find(u"]")
            if secend != -1:
                section = taglib.Section(line[1:secend], lnum)
                rtags.AddElement('section', section)
            continue # Go to next line

        # Look for keys
        if u"=" in line and section is not None:
            key = taglib.Variable(line.split(u"=")[0], lnum)
            section.AddElement('key', key)

    return rtags
Exemple #3
0
def GenerateTags(buff):
    """Create a DocStruct object that represents a batch Script
    @param buff: a file like buffer object (StringIO)
    @todo: generate tags for batch tables?

    """
    rtags = taglib.DocStruct()
    rtags.SetElementDescription('label', "Labels")
    rtags.SetElementDescription('section', "Labels")

    for lnum, line in enumerate(buff):
        line = line.strip()
        llen = len(line)

        # Skip comment and empty lines
        if (line.startswith(u"rem") and llen > 3 and line[3].isspace()) or not line:
            continue

        # Check for labels
        if line.startswith(u":"):
            name = parselib.GetFirstIdentifier(line[1:])
            if name is not None:
                rtags.AddElement('label', taglib.Section(name, lnum))

    return rtags
Exemple #4
0
def GenerateTags(buff):
    """Create a DocStruct object that represents an Inno Setup Script
    @param buff: a file like buffer object (StringIO)
    @todo: perhaps group functions, procedures within the Scope of a Section
           object.

    """
    rtags = taglib.DocStruct()
    rtags.SetElementDescription('section', "Sections")
    rtags.SetElementDescription('variable', "Defines")
    rtags.SetElementDescription('function', "Function Definitions")
    rtags.SetElementDescription('procedure', "Procedure Definitions")
    rtags.SetElementPriority('section', 3)
    rtags.SetElementPriority('function', 2)
    rtags.SetElementPriority('procedure', 1)

    for lnum, line in enumerate(buff):
        line = line.strip()

        # Skip comment and empty lines
        if line.startswith(u";") or not line:
            continue

        # Check for a section
        if line.startswith(u"["):
            secend = line.find(u"]")
            if secend != -1:
                section = taglib.Section(line[1:secend], lnum)
                rtags.AddElement('section', section)
        elif line.startswith(u"function") and \
              len(line) > 8 and line[8].isspace():
            name = parselib.GetFirstIdentifier(line[8:].strip())
            if name is not None:
                rtags.AddFunction(taglib.Function(name, lnum))
        elif line.startswith(u"procedure") and \
              len(line) > 9 and line[9].isspace():
            name = parselib.GetFirstIdentifier(line[9:].strip())
            if name is not None:
                rtags.AddElement('procedure',
                                 taglib.Function(name, lnum, 'procedure'))
        elif line.startswith(u"#define") and \
              len(line) > 7 and line[7].isspace():
            name = parselib.GetFirstIdentifier(line[7:].strip())
            if name is not None:
                rtags.AddVariable(taglib.Variable(name, lnum))
        else:
            pass

    return rtags