grammar.py: Add support for --irrelevant-symbols

Arguments to --irrelevant-symbols are not meant to be represented in the
AST resulting from parsing.

Also, add pad() to misc.py.

Signed-off-by: Jan Lindemann <jan@janware.com>
This commit is contained in:
Jan Lindemann 2017-10-30 10:00:25 +01:00
commit 8c5934725c
4 changed files with 43 additions and 19 deletions

View file

@ -3,6 +3,7 @@ import syslog
import sys
import inspect
from os.path import basename
import misc
EMERG = syslog.LOG_EMERG
ALERT = syslog.LOG_ALERT
@ -63,15 +64,6 @@ prio_colors = {
EMERG : [ CONSOLE_FONT_BOLD + CONSOLE_FONT_MAGENTA, CONSOLE_FONT_OFF ],
}
def __pad(token, total_size, right_align = False):
add = total_size - len(token)
if add <= 0:
return token
space = ' ' * add
if right_align:
return space + token
return token + space
def get_caller_pos(up = 1):
assert(up == 1) # TODO: implement this
caller_frame = inspect.currentframe().f_back.f_back
@ -95,7 +87,7 @@ def slog(prio, *args, **kwargs): # export
name, line = kwargs['caller']
else:
name, line = get_caller_pos(1)
msg += __pad(name, 20) + '[' + __pad(str(line), 4, True) + ']'
msg += misc.pad(name, 20) + '[' + misc.pad(str(line), 4, True) + ']'
if f_color in flags:
color_on, color_off = prio_colors[prio]