Refactor RobotLangVisitorUser to improve student ID extraction and clean up code

This commit is contained in:
bobbert committed 2026-04-27 18:33:09 +01:00
1 parent ad6935723e
commit 99e8b68078
3 files changed
+2 -9

No files matched your search

+1 -4
View File
@@ -5,9 +5,7 @@ class RobotLangVisitorUser(RobotLangVisitor):
self.student_id = "Unknown"
def visitHeader(self, ctx):
# Extract the number directly from the script
self.student_id = ctx.NUMBER().getText()
# Continue walking the rest of the tree
return self.visitChildren(ctx)
def visitMoveStat(self, ctx):
@@ -29,14 +27,13 @@ class RobotLangVisitorUser(RobotLangVisitor):
return self.visitChildren(ctx)
def visitLogStat(self, ctx):
val = ctx.STRING().getText()
val = ctx.STRING().getText()[1:-1]
print(f"{self.student_id} is logging: {val}.")
return self.visitChildren(ctx)
def visitRepeatStat(self, ctx):
times = int(ctx.NUMBER().getText())
for _ in range(times):
# Visit all statements inside the repeat block
for stat_ctx in ctx.stat():
self.visit(stat_ctx)
return None