def test_parse_escaped_strings(self):
        text = r'''
string a = "Hello \"world\""
string b = "Hello \"world\"\\"
int c = 8;
'''
        file_parser = FileParser()
        result, _ = file_parser._parse_strings_comments(text)
        self.assertEqual(r'"Hello \"world\""', result[0].content)
        self.assertEqual(r'"Hello \"world\"\\"', result[1].content)
Esempio n. 2
0
    def test_parse_escaped_strings(self):
        text = r'''
string a = "Hello \"world\""
string b = "Hello \"world\"\\"
int c = 8;
'''
        file_parser = FileParser()
        result, _ = file_parser._parse_strings_comments(text)
        self.assertEqual(r'"Hello \"world\""', result[0].content)
        self.assertEqual(r'"Hello \"world\"\\"', result[1].content)
Esempio n. 3
0
    def test_multiline_define(self):
        text = r'''#if !defined(_WIN32) && !defined(WIN32) && !defined(_WRS_KERNEL) \
 && !defined(__minux)
void kk(int a);
# else
void pun(int a);
 # endif'''

        parser = FileParser()
        includes, refs, declarations, definitions, comments = parser.parse(text)
        self.assertIn(CPPItem(CPPItem.METHOD, 'pun', ''), declarations)
        self.assertIn(CPPItem(CPPItem.METHOD, 'kk', ''), declarations)
Esempio n. 4
0
 def test_escape_single_character(self):
     text = r"""int a=3;
     char b='\'';
     char c='c';
     char d='\'';
     char e='e';
     int main(){
     }
     """
     parser = FileParser()
     includes, refs, declarations, definitions, comments = parser.parse(text)
     #print parser.declarations
     #print parser.definitions
     self.assertIn(CPPItem(CPPItem.METHOD, 'main', ''), definitions)
     self.assertIn(CPPItem(CPPItem.VAR, 'a', ''), definitions)
     self.assertIn(CPPItem(CPPItem.VAR, 'b', ''), definitions)
     self.assertIn(CPPItem(CPPItem.VAR, 'c', ''), definitions)
     self.assertIn(CPPItem(CPPItem.VAR, 'd', ''), definitions)
     self.assertIn(CPPItem(CPPItem.VAR, 'e', ''), definitions)
Esempio n. 5
0
def migrate_block_files(block_name, block_files, biiout):
    """ actual migration, takes params
    param block_name: BlockName
    param block_files: {CellName: Blob load}
    param biiout: standar bii output
    """
    old_names = ['requirements', 'parents', 'paths', 'dependencies', 'mains']
    old_names = OrderedDict([(k, k) for k in old_names])
    old_names['parents'] = 'parent'

    old_files = [
        name for name in old_names if 'bii/%s.bii' % name in block_files
    ]
    if not old_files:
        return

    deleted = []

    if BIICODE_FILE in block_files:
        biiout.warn(
            "The following old configuration files exist in your %s block\n"
            "%s\nMigrating them to your existing %s file, please check it" %
            (block_name, ', '.join(old_files), BIICODE_FILE))

    current_config = [
        "# Biicode configuration file migrated from old config files\n"
    ]
    for file_name, config_name in old_names.iteritems():
        current_config.append("[%s]" % config_name)
        if file_name in old_files:
            config_file = 'bii/%s.bii' % file_name
            biiout.warn("Migrating old %s file to new %s configuration file" %
                        (config_file, BIICODE_FILE))
            content = block_files.pop(config_file)
            deleted.append(config_file)
            for line in content.splitlines():
                current_config.append("\t%s" % line)
        current_config.append("")

    current_config.append('[hooks]\n\n[includes]\n\n[data]')
    # This migrate the old data defined in the bii:// way
    for name, content in block_files.iteritems():
        biitype = BiiType.from_extension(CellName(name).extension)
        if biitype == CPP:
            _, data, _, _, _ = FileParser().parse(content)
            if data:
                data_str = ' '.join(d.name for d in data)
                current_config.append('\t%s + %s' % (name, data_str))

    config_text = '\n'.join(current_config)
    return config_text, deleted
Esempio n. 6
0
 def parse(self, code):
     parser = FileParser()
     self.includes, self.references, self.declarations, self.definitions, \
         self.tags = parser.parse(code)
 def test_parse_escaped_strings2(self):
     text = r'''cout << "   \"" << (char *)testSet[i].input << '\"';'''
     file_parser = FileParser()
     result, _ = file_parser._parse_strings_comments(text)
     self.assertEqual(r'"   \""', result[0].content)
     self.assertEqual(r"'\"'", result[1].content)
Esempio n. 8
0
 def test_parse_escaped_strings2(self):
     text = r'''cout << "   \"" << (char *)testSet[i].input << '\"';'''
     file_parser = FileParser()
     result, _ = file_parser._parse_strings_comments(text)
     self.assertEqual(r'"   \""', result[0].content)
     self.assertEqual(r"'\"'", result[1].content)
Esempio n. 9
0
 def parse(self, code):
     parser = FileParser()
     self.includes, self.references, self.declarations, self.definitions, \
         self.tags = parser.parse(code)