Added option to use english words as variable names
Took 15 minutes
This commit is contained in:
parent
d6f9a8684a
commit
1e22f5a968
|
@ -2,7 +2,7 @@ import random
|
|||
import string
|
||||
import xml.etree.ElementTree as ET
|
||||
|
||||
# from english_words import get_english_words_set
|
||||
from english_words import get_english_words_set
|
||||
|
||||
from constants import *
|
||||
|
||||
|
@ -38,13 +38,11 @@ class AstGenerator:
|
|||
self.symbol_table.append(global_scope) # NOTE for debug
|
||||
self.current_scope = global_scope
|
||||
|
||||
# names = get_english_words_set(['web2'], lower=True)
|
||||
names = random.choices(string.ascii_letters, k=self.settings['properties']['id-length']['max'])
|
||||
possible_names = filter(lambda x: self.settings['properties']['id-length']['min'] < len(x)
|
||||
< self.settings['properties']['id-length']['max'], names)
|
||||
names = get_english_words_set(['web2'], alpha=True)
|
||||
possible_names = filter(lambda x: self.settings['properties']['id-length']['max'] <= len(x) <= self.settings['properties']['id-length']['max'], names)
|
||||
|
||||
var_name_len = len(list(possible_names))
|
||||
var_name_list = list(possible_names)
|
||||
var_name_len = len(var_name_list)
|
||||
self.variable_names = var_name_list[0:var_name_len // 2]
|
||||
self.routine_names = var_name_list[var_name_len // 2:var_name_len]
|
||||
|
||||
|
@ -529,10 +527,13 @@ class AstGenerator:
|
|||
@param name_type:
|
||||
@return:
|
||||
"""
|
||||
if not self.settings['properties']['use-english-words']:
|
||||
length = random.randint(self.settings['properties']['id-length']['min'],
|
||||
self.settings['properties']['id-length']['max'])
|
||||
name = ''.join(random.choices(string.ascii_letters, k=length))
|
||||
return name
|
||||
else:
|
||||
return random.choice(self.variable_names)
|
||||
|
||||
def get_op(self, type):
|
||||
|
||||
|
|
|
@ -10,7 +10,7 @@ properties:
|
|||
use-english-words: True # use english words instead of random names (this may limit the maximum number of names)
|
||||
id-length: # length of identifiers
|
||||
min: 1
|
||||
max: 10
|
||||
max: 5
|
||||
function-name-length: # length of function names
|
||||
min: 1
|
||||
max: 10
|
||||
|
|
Loading…
Reference in a new issue