Skip to content

Commit

Permalink
Fetching sections and the record objects by section #12
Browse files Browse the repository at this point in the history
  • Loading branch information
mugdhadhole1 committed Jul 18, 2024
1 parent 4860b68 commit 9e5046c
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
16 changes: 16 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Python Debugger: Current File with Arguments",
"type": "debugpy",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal",
"args": "test"
}
]
}
20 changes: 20 additions & 0 deletions trlc/ast.py
Original file line number Diff line number Diff line change
Expand Up @@ -3064,6 +3064,8 @@ def __init__(self, parent=None):
self.parent = parent
self.imported = []
self.table = OrderedDict()
self.trlc_files = []
self.section_names = []

@staticmethod
def simplified_name(name):
Expand All @@ -3082,6 +3084,24 @@ def all_names(self):
rv |= self.parent.all_names()
return rv

def iter_record_objects_by_section(self):
section_dictionary = {}
for record_object in self.iter_record_objects():
location = record_object.location.file_name
if location not in self.trlc_files:
self.trlc_files.append(location)
yield location
if record_object.section:
self.section_names = record_object.section
if len(self.section_names) > 0:
for i in range(len(self.section_names)):
if self.section_names[i].name not in section_dictionary.keys():
section_dictionary.update({self.section_names[i].name: True})
yield self.section_names[i].name
yield record_object.name
else:
yield record_object.name

def iter_record_objects(self):
# lobster-exclude: API for users
""" Iterate over all record objects
Expand Down
2 changes: 1 addition & 1 deletion trlc/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -1540,7 +1540,7 @@ def parse_section_declaration(self):
self.match("STRING")
sec = ast.Section(name = self.ct.value,
location = self.ct.location,
parent = self.section)
parent = self.section.copy())
sec.set_ast_link(self.ct)
sec.set_ast_link(t_section)
self.section.append(sec)
Expand Down

0 comments on commit 9e5046c

Please sign in to comment.