Skip to content

Commit

Permalink
Preparing to release
Browse files Browse the repository at this point in the history
  • Loading branch information
mapio committed Apr 12, 2024
1 parent 3697b3f commit c29092d
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 7 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
Changelog
=========

v1.7.5 (2024-04-12)
-------------------

- Added the line number as attribute of the ANTLR annotated parse tree.
- Now TopDownInstantaneousDescription.predict does not put the ε on the stack.

v1.7.4 (2024-04-11)
-------------------

Expand Down
7 changes: 4 additions & 3 deletions src/liblet/antlr.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,8 @@ def tree(self, text, symbol, simple=False, antlr_hook=None):
- ``name``: the *rule label* or *token name* (or the rule name if it has no label: or, similarly, the token itself if it has no name),
- ``value``: the *token* value (only present for *tokens* named in the *lexer* part of the grammar),
- ``rule``: the *rule* name (only present for *rules*, will be different from ``name`` for labelled rules).
- ``src``: the first (and last token, in case of a rule), corredponding to the node.
- ``src``: the first (and last token, in case of a rule), corresponding to the node.
- ``line``: the line number of the (first) token.
Note that the values are strings (so if the *value* is a number, it should be converted before usage).
Expand All @@ -217,7 +218,7 @@ def _rule(ctx):
name = ctx.__class__.__name__
name = name[:-7] # remove trailing 'Context'
name = name[0].lower() + name[1:]
return {'type': 'rule', 'name': name, 'rule': rule, 'src': ctx.getSourceInterval()}
return {'type': 'rule', 'name': name, 'rule': rule, 'src': ctx.getSourceInterval(), 'line': ctx.start.line}

def _token(token):
ts = token.symbol
Expand All @@ -230,7 +231,7 @@ def _token(token):
name = '<INVALID>'
if name == '<INVALID>':
name = self.Parser.literalNames[ts.type][1:-1]
return {'type': 'token', 'name': name, 'value': text, 'src': token.symbol.tokenIndex}
return {'type': 'token', 'name': name, 'value': text, 'src': ts.tokenIndex, 'line': ts.line}

class TreeVisitor(ParseTreeVisitor):
def visitTerminal(self, t):
Expand Down
2 changes: 1 addition & 1 deletion src/liblet/automaton.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ def predict(self, P):
c.stack.pop()
c.steps += (P,)
for X in reversed(P.rhs):
c.stack.push(X)
if X != ε :c.stack.push(X)
return c
raise ValueError('The top of the stack does not correspond to the production lhs.')

Expand Down
2 changes: 1 addition & 1 deletion src/liblet/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
DIAMOND = '◇'
HASH = '♯'
GV_FONT_NAME = 'Fira Code'
GV_FONT_SIZE = '8'
GV_FONT_SIZE = '12' # must be a string
HTML_FONT_NAME = GV_FONT_NAME
4 changes: 2 additions & 2 deletions src/liblet/display.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,10 @@ def __repr__(self):
class GVWrapper:
def __init__(self, gv_graph_args=None, node_wrapper=None):
gv_graph_args = gv_graph_args or {}
gv_graph_args['node_attr'] = {'fontname': f"'{GV_FONT_NAME}'", 'fontsize': f"'{GV_FONT_SIZE}'"} | (
gv_graph_args['node_attr'] = {'fontname': GV_FONT_NAME, 'fontsize': GV_FONT_SIZE} | (
gv_graph_args['node_attr'] if 'node_attr' in gv_graph_args else {}
)
gv_graph_args['edge_attr'] = {'fontname': f"'{GV_FONT_NAME}'", 'fontsize': f"'{GV_FONT_SIZE}'"} | (
gv_graph_args['edge_attr'] = {'fontname': GV_FONT_NAME, 'fontsize': GV_FONT_SIZE} | (
gv_graph_args['edge_attr'] if 'edge_attr' in gv_graph_args else {}
)
node_wrapper = node_wrapper or make_node_wrapper()
Expand Down

0 comments on commit c29092d

Please sign in to comment.