parent
8d33c8b0e2
commit
33dc4ff2e3
|
@ -131,35 +131,35 @@ sub get_reporting_aliases {
|
|||
my $self = shift;
|
||||
|
||||
my $rdmr = TBB::DataManager::Relational->new(
|
||||
host => "reports.v2.tbb",
|
||||
port => 5432,
|
||||
db => "reporting",
|
||||
user => "tbbv2db",
|
||||
host => "reports.v2.tbb",
|
||||
port => 5432,
|
||||
db => "reporting",
|
||||
user => "tbbv2db",
|
||||
password => "reports",
|
||||
);
|
||||
|
||||
my $aliases_aref = $rdmr->select(select => "alias, question, type",
|
||||
from => "user_data_alias");
|
||||
from => "user_data_alias");
|
||||
|
||||
$self->{aliases} = [];
|
||||
|
||||
# make sure each alias is valid; undefined formulas or conditions will give
|
||||
# us problems down the road
|
||||
foreach my $alias (@$aliases_aref) {
|
||||
eval {
|
||||
my $id = TBB::ID::normalize($alias->{question});
|
||||
$alias->{question} = $id;
|
||||
if(TBB::ID::is_a($id, "question")) {
|
||||
push(@{$self->{aliases}}, $alias);
|
||||
} elsif($TBB::BenefitDelivery::ResourceManager->get_component($id)) {
|
||||
push(@{$self->{aliases}}, $alias);
|
||||
} else {
|
||||
write_log("error", "Alias \"$alias->{question}\" does not exist");
|
||||
eval {
|
||||
my $id = TBB::ID::normalize($alias->{question});
|
||||
$alias->{question} = $id;
|
||||
if(TBB::ID::is_a($id, "question")) {
|
||||
push(@{$self->{aliases}}, $alias);
|
||||
} elsif($TBB::BenefitDelivery::ResourceManager->get_component($id)) {
|
||||
push(@{$self->{aliases}}, $alias);
|
||||
} else {
|
||||
write_log("error", "Alias \"$alias->{question}\" does not exist");
|
||||
}
|
||||
};
|
||||
if($@) {
|
||||
write_log("error", "There was a problem with \"$alias->{question}\": $@");
|
||||
}
|
||||
};
|
||||
if($@) {
|
||||
write_log("error", "There was a problem with \"$alias->{question}\": $@");
|
||||
}
|
||||
}
|
||||
|
||||
# this will help to make sure that the exports for each user are proceeding
|
||||
|
@ -248,31 +248,31 @@ sub populate {
|
|||
}
|
||||
|
||||
my $csd = TBB::ClientSystemData->new($system_id, "reporter");
|
||||
my $dms = $csd->retrieve_data_manager_session();
|
||||
my $dms = $csd->retrieve_data_manager_session();
|
||||
|
||||
my $user_data = TBB::UserData::New->new(data_manager_relational => $self->{dmr},
|
||||
data_manager_session => $dms,
|
||||
client_system_data => $csd,
|
||||
current_client_id => $client_id);
|
||||
data_manager_session => $dms,
|
||||
client_system_data => $csd,
|
||||
current_client_id => $client_id);
|
||||
|
||||
my $user_data_obj = {'id_user' => $client_id};
|
||||
foreach my $alias_href (@{$self->{aliases}}) {
|
||||
my $alias = $alias_href->{alias};
|
||||
my $id = $alias_href->{question};
|
||||
my $type = $alias_href->{type};
|
||||
foreach my $alias_href (@{$self->{aliases}}) {
|
||||
my $alias = $alias_href->{alias};
|
||||
my $id = $alias_href->{question};
|
||||
my $type = $alias_href->{type};
|
||||
|
||||
my $value = $user_data->retrieve_value(base => $id,
|
||||
this_id_user => $client_id);
|
||||
$value ||= "";
|
||||
my $value = $user_data->retrieve_value(base => $id,
|
||||
this_id_user => $client_id);
|
||||
$value ||= "";
|
||||
|
||||
$user_data_obj->{$alias} = $value;
|
||||
$user_data_obj->{$alias} = $value;
|
||||
}
|
||||
|
||||
my @values = ();
|
||||
foreach my $name (@report_fields) {
|
||||
push(@values, $user_data_obj->{$name});
|
||||
}
|
||||
$sth->execute(@values);
|
||||
my @values = ();
|
||||
foreach my $name (@report_fields) {
|
||||
push(@values, $user_data_obj->{$name});
|
||||
}
|
||||
$sth->execute(@values);
|
||||
|
||||
write_log('debug', " Saving " . scalar(keys(%$user_data_obj)) . " components") if TBB::LogManager::writes_at('debug');
|
||||
#write_log('debug', " User Data Obj: " . Dumper($user_data_obj)) if TBB::LogManager::writes_at('debug');
|
||||
|
|
|
@ -1,14 +1,35 @@
|
|||
import sys
|
||||
|
||||
color_list = []
|
||||
color_list.extend(['\033[3%dm' % x for x in range(0, 8)])
|
||||
color_list.extend(['\033[3%d;1m' % x for x in range(0, 8)])
|
||||
color_list.append('\033[0m')
|
||||
|
||||
color_names = [
|
||||
'black', 'dred', 'dgreen', 'brown', 'dblue', 'dpurple', 'dcyan', 'lgrey',
|
||||
'dgrey', 'lred', 'lgreen', 'yellow', 'lblue', 'lpurple', 'lcyan', 'white',
|
||||
'unset',
|
||||
]
|
||||
|
||||
color_dict ={}
|
||||
for i in range(0, len(color_list)):
|
||||
color_dict[color_names[i]] = color_list[i]
|
||||
|
||||
class Highlighter:
|
||||
def __init__(self, lexer):
|
||||
self.lexer = lexer
|
||||
self.tokens = []
|
||||
|
||||
def display(self):
|
||||
def display(self, token_colors={}, debug=False):
|
||||
for group in self.tokens:
|
||||
for token in group:
|
||||
if token.name in token_colors:
|
||||
color_name = token_colors[token.name]
|
||||
sys.stdout.write(color_dict[color_name])
|
||||
elif debug:
|
||||
raise Exception, "no highlighting for %r" % token.name
|
||||
sys.stdout.write(token.string)
|
||||
sys.stdout.write('\n')
|
||||
sys.stdout.write('\n')
|
||||
|
||||
def highlight(self, lines):
|
||||
self.tokens = [[] for l in lines]
|
||||
|
|
4
lex2.py
4
lex2.py
|
@ -221,6 +221,10 @@ class DualRegionRule(Rule):
|
|||
|
||||
class Grammar:
|
||||
rules = []
|
||||
def __init__(self):
|
||||
for rule in self.rules:
|
||||
if hasattr(rule, 'grammar') and rule.grammar is None:
|
||||
rule.grammar = self
|
||||
|
||||
class Lexer:
|
||||
def __init__(self, name, grammar):
|
||||
|
|
32
lex2_perl.py
32
lex2_perl.py
|
@ -115,11 +115,11 @@ class PerlGrammar(Grammar):
|
|||
pattern=r"(?<!->)(?:STDIN|STDERR|STDOUT|and|cmp|continue|do|else|elsif|eq|eval|foreach|for|if|last|my|next|ne|not|or|our|package|require|return|sub|undef|unless|until|use|while)(?![a-zA-Z0-9_])",
|
||||
),
|
||||
PatternRule(
|
||||
name=r'hash_bareword_index',
|
||||
name=r'bareword_hash_index',
|
||||
pattern=r'(?<={) *[A-Za-z0-9_]+(?=})',
|
||||
),
|
||||
PatternRule(
|
||||
name=r'literal_hash_bareword_index',
|
||||
name=r'bareword_hash_key',
|
||||
pattern=r'[A-Za-z0-9_]+(?= *=>)',
|
||||
),
|
||||
PatternRule(
|
||||
|
@ -226,7 +226,7 @@ class PerlGrammar(Grammar):
|
|||
),
|
||||
PatternRule(
|
||||
name=r'sub',
|
||||
pattern=r"(?<=sub )[a-zA-Z_][a-zA-Z_0-9]*(?=[ \n]*{)",
|
||||
pattern=r"(?<=sub )[a-zA-Z_][a-zA-Z_0-9]*(?= *{)",
|
||||
),
|
||||
PatternRule(
|
||||
name=r'use',
|
||||
|
@ -258,11 +258,33 @@ class PerlGrammar(Grammar):
|
|||
),
|
||||
PatternRule(
|
||||
name=r'bareword_method',
|
||||
pattern=r"(?:[a-zA-Z_][a-zA-Z_0-9]*::)*[a-zA-Z_][a-zA-Z_0-9]* *\(",
|
||||
pattern=r"(?:[a-zA-Z_][a-zA-Z_0-9]*::)*[a-zA-Z_][a-zA-Z_0-9]*(?= *\()",
|
||||
),
|
||||
#PatternRule(
|
||||
# name=r'delimiter',
|
||||
# pattern=r"\(|\)|\[|\]|{|}|,|;|->|=>|=|\?|(?<!:):(?!=:)",
|
||||
#),
|
||||
RegionRule(
|
||||
name=r'paren',
|
||||
start=r'\(',
|
||||
grammar=None,
|
||||
end=r'\)',
|
||||
),
|
||||
RegionRule(
|
||||
name=r'brace',
|
||||
start=r'{',
|
||||
grammar=None,
|
||||
end=r'}',
|
||||
),
|
||||
RegionRule(
|
||||
name=r'bracket',
|
||||
start=r'\[',
|
||||
grammar=None,
|
||||
end=r'\]',
|
||||
),
|
||||
PatternRule(
|
||||
name=r'delimiter',
|
||||
pattern=r"\(|\)|\[|\]|{|}|,|;|->|=>|=|\?|(?<!:):(?!=:)",
|
||||
pattern=r",|;|->|=>|=|\?|(?<!:):(?!=:)",
|
||||
),
|
||||
PatternRule(
|
||||
name=r'unary_operator',
|
||||
|
|
16
test3.py
16
test3.py
|
@ -1,5 +1,5 @@
|
|||
import sys
|
||||
import lex2, lex2_perl
|
||||
import lex2, lex2_perl, highlight2
|
||||
|
||||
color_list = []
|
||||
color_list.extend(['\033[3%dm' % x for x in range(0, 8)])
|
||||
|
@ -87,15 +87,7 @@ for path in paths:
|
|||
|
||||
grammar = lex2_perl.PerlGrammar()
|
||||
lexer = lex2.Lexer('lexer', grammar)
|
||||
highlighter = highlight2.Highlighter(lexer)
|
||||
|
||||
lexer.lex(lines)
|
||||
y = 0
|
||||
for token in lexer:
|
||||
while token.y > y:
|
||||
sys.stdout.write('\n')
|
||||
y += 1
|
||||
#color_name = token_colors.get(token.name, 'white')
|
||||
color_name = token_colors[token.name]
|
||||
sys.stdout.write(color_dict[color_name])
|
||||
sys.stdout.write(token.string)
|
||||
sys.stdout.write('\n')
|
||||
highlighter.highlight(lines)
|
||||
highlighter.display(token_colors)
|
||||
|
|
Loading…
Reference in New Issue