Beispiel #1
0
def getkw(input, output):
    out = file(output, 'w')

    # Copy template from an existing file.
    print(HEADER, file=out)

    output_info = {'command': [], 'option': [], 'auto': []}
    for line in file(input):
        m = r_line.match(line)
        if m:
            # Decide which output gets mapped to d
            if 'vimCommand' in m.group(1):
                d = output_info['command']
            elif 'AutoEvent' in m.group(1):
                d = output_info['auto']
            else:
                d = output_info['option']

            # Extract all the shortened versions
            for i in r_item.finditer(m.group(2)):
                d.append('(%r,%r)' %
                         (i.group(1), "%s%s" % (i.group(1), i.group(2) or '')))

    output_info['option'].append("('nnoremap','nnoremap')")
    output_info['option'].append("('inoremap','inoremap')")
    output_info['option'].append("('vnoremap','vnoremap')")

    for key, keywordlist in output_info.items():
        keywordlist.sort()
        body = format_lines('var', keywordlist, raw=True, indent_level=1)
        print(METHOD % locals(), file=out)
def test_format_lines():
    lst = ['cat', 'dog']
    output = util.format_lines('var', lst)
    d = {}
    exec(output, d)
    assert isinstance(d['var'], tuple)
    assert ('cat', 'dog') == d['var']
Beispiel #3
0
 def test_format_lines(self):
     lst = ['cat', 'dog']
     output = util.format_lines('var', lst)
     d = {}
     exec(output, d)
     self.assertTrue(isinstance(d['var'], tuple))
     self.assertEqual(('cat', 'dog'), d['var'])
Beispiel #4
0
def getkw(input, output):
    out = file(output, 'w')

    # Copy template from an existing file.
    print(HEADER, file=out)

    output_info = {'command': [], 'option': [], 'auto': []}
    for line in file(input):
        m = r_line.match(line)
        if m:
            # Decide which output gets mapped to d
            if 'vimCommand' in m.group(1):
                d = output_info['command']
            elif 'AutoEvent' in m.group(1):
                d = output_info['auto']
            else:
                d = output_info['option']

            # Extract all the shortened versions
            for i in r_item.finditer(m.group(2)):
                d.append('(%r,%r)' % (i.group(1), "%s%s" %
                                      (i.group(1), i.group(2) or '')))

    output_info['option'].append("('nnoremap','nnoremap')")
    output_info['option'].append("('inoremap','inoremap')")
    output_info['option'].append("('vnoremap','vnoremap')")

    for key, keywordlist in output_info.items():
        keywordlist.sort()
        body = format_lines('var', keywordlist, raw=True, indent_level=1)
        print(METHOD % locals(), file=out)
Beispiel #5
0
    def regenerate(filename, natives):
        with open(filename) as fp:
            content = fp.read()

        header = content[:content.find('FUNCTIONS = (')]
        footer = content[content.find("if __name__ == '__main__':") - 1:]

        with open(filename, 'w') as fp:
            fp.write(header)
            fp.write(format_lines('FUNCTIONS', natives))
            fp.write(footer)
    def regenerate(filename, natives):
        with open(filename) as fp:
            content = fp.read()

        header = content[:content.find('FUNCTIONS = (')]
        footer = content[content.find("if __name__ == '__main__':")-1:]


        with open(filename, 'w') as fp:
            fp.write(header)
            fp.write(format_lines('FUNCTIONS', natives))
            fp.write(footer)
    def update_consts(filename, constname, content):
        with open(filename) as f:
            data = f.read()

        # Line to start/end inserting
        re_match = re.compile(r"^%s\s*=\s*\($.*?^\s*\)$" % constname, re.M | re.S)
        m = re_match.search(data)
        if not m:
            raise ValueError("Could not find existing definition for %s" % (constname,))

        new_block = format_lines(constname, content)
        data = data[: m.start()] + new_block + data[m.end() :]

        with open(filename, "w") as f:
            f.write(data)
    def update_consts(filename, constname, content):
        with open(filename) as f:
            data = f.read()

        # Line to start/end inserting
        re_match = re.compile(r'^%s\s*=\s*\($.*?^\s*\)$' % constname, re.M | re.S)
        m = re_match.search(data)
        if not m:
            raise ValueError('Could not find existing definition for %s' %
                             (constname,))

        new_block = format_lines(constname, content)
        data = data[:m.start()] + new_block + data[m.end():]

        with open(filename, 'w') as f:
            f.write(data)
Beispiel #9
0
    def update_content(field_name, content):
        """Overwrite this file with content parsed from MySQL's source code."""

        with open(__file__) as f:
            data = f.read()

        # Line to start/end inserting
        re_match = re.compile(r'^%s\s*=\s*\($.*?^\s*\)$' % field_name, re.M | re.S)
        m = re_match.search(data)
        if not m:
            raise ValueError('Could not find an existing definition for %s' % field_name)

        new_block = format_lines(field_name, content)
        data = data[:m.start()] + new_block + data[m.end():]

        with open(__file__, 'w', newline='\n') as f:
            f.write(data)
    :copyright: Copyright 2006-2022 by the Pygments team, see AUTHORS.
    :license: BSD, see LICENSE for details.
"""


from pygments.util import format_lines
import json
import urllib.request

HEADER = '''\
"""
    pygments.lexers._css_builtins
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    This file is autogenerated by scripts/get_css_properties.py

    :copyright: Copyright 2006-2022 by the Pygments team, see AUTHORS.
    :license: BSD, see LICENSE for details.
"""
'''

if __name__ == "__main__":
    data_request = urllib.request.urlopen('https://www.w3.org/Style/CSS/all-properties.en.json')
    data = json.load(data_request)
    names = set([p['property'] for p in data if p['property'] != '--*'])

    with open('../pygments/lexers/_css_builtins.py', 'w') as builtin_file:
        builtin_file.write(HEADER)
        builtin_file.write(format_lines('_css_properties', sorted(names)))