diff --git a/uncompyle6/semantics/fragments.py b/uncompyle6/semantics/fragments.py index 5fc880e4..6bd61362 100644 --- a/uncompyle6/semantics/fragments.py +++ b/uncompyle6/semantics/fragments.py @@ -1,6 +1,4 @@ # Copyright (c) 2015-2017 by Rocky Bernstein -# Copyright (c) 2005 by Dan Pascu -# Copyright (c) 2000-2002 by hartmut Goebel # Copyright (c) 1999 John Aycock """ @@ -97,7 +95,6 @@ TABLE_DIRECT_FRAGMENT = { 'importfrom': ( '%|from %[2]{pattr}%x import %c\n', (2, (0, 1)), 3), 'importmultiple': ( '%|import%b %c%c\n', 0, 2, 3 ), 'list_for': (' for %c%x in %c%c', 2, (2, (1, )), 0, 3 ), - 'forstmt': ( '%|for%b %c%x in %c:\n%+%c%-\n\n', 0, 3, (3, (2, )), 1, 4 ), 'forelsestmt': ( '%|for %c%x in %c:\n%+%c%-%|else:\n%+%c%-\n\n', 3, (3, (2,)), 1, 4, -2), 'forelselaststmt': ( diff --git a/uncompyle6/semantics/pysource.py b/uncompyle6/semantics/pysource.py index 61aff590..3b1df2c8 100644 --- a/uncompyle6/semantics/pysource.py +++ b/uncompyle6/semantics/pysource.py @@ -25,21 +25,28 @@ Python. # of the nonterminal is suffixed with "_exit" it will be called after # all of its children are called. # -# However if this were done for all of the rules, this file would be even longer -# than it is already. +# After a while writing methods this way, you'll find many routines which do similar +# sorts of things, and soon you'll find you want a short notation to +# describe rules and not have to create methods at all. # -# Another more compact way to specify a semantic rule for a nonterminal is via -# rule given in one of the tables MAP_R0, MAP_R, or MAP_DIRECT. +# So another other way to specify a semantic rule for a nonterminal is via +# one of the tables MAP_R0, MAP_R, or MAP_DIRECT where the key is the +# nonterminal name. # -# These uses a printf-like syntax to direct substitution from attributes -# of the nonterminal and its children.. +# These dictionaries use a printf-like syntax to direct substitution +# from attributes of the nonterminal and its children.. # # The rest of the below describes how table-driven semantic actions work # and gives a list of the format specifiers. The default() and # template_engine() methods implement most of the below. # -# Step 1 determines a table (T) and a path to a -# table key (K) from the node type (N) (other nodes are shown as O): +# We allow for a couple of ways to interact with a node in a tree. So +# step 1 after not seeing a custom method for a nonterminal is to +# determine from what point of view tree-wise the rule is applied. +# In the diagram below, "N" is a nonterminal name, and K is the table +# key name; we show where those are with respect to each other in the +# AST tree for N. +# # # N N N&K # / | ... \ / | ... \ / | ... \ @@ -49,7 +56,10 @@ Python. # # MAP_R0 (TABLE_R0) MAP_R (TABLE_R) MAP_DIRECT (TABLE_DIRECT) # -# The default is a direct mapping. The key K is then extracted from the +# The default is a "TABLE_DIRECT" mapping By far, most rules used work this way. +# TABLE_R0 is rarely used. +# +# The key K is then extracted from the # subtree and used to find a table entry T[K], if any. The result is a # format string and arguments (a la printf()) for the formatting engine. # Escapes in the format string are: