Skip to content

feat: Add error handling and tests for unknown keywords#16

Merged
Pallavrai merged 4 commits into
Pallavrai:mainfrom
ArjunDixit1:ci-basic-tests
Oct 4, 2025
Merged

feat: Add error handling and tests for unknown keywords#16
Pallavrai merged 4 commits into
Pallavrai:mainfrom
ArjunDixit1:ci-basic-tests

Conversation

@ArjunDixit1

@ArjunDixit1 ArjunDixit1 commented Oct 3, 2025

Copy link
Copy Markdown
Contributor

### 📝 Problem
The DogLang interpreter did not properly handle unknown keywords or typos (e.g., wagdog instead of wagtail). This would cause the parser to either crash or misinterpret the code, making it difficult for users to find simple mistakes.

### 💡 Solution
This PR implements robust syntax error handling to catch these typos during the parsing stage. If the interpreter encounters a word that is not a valid keyword in a context where one is expected, it will now halt immediately and provide a clear, user-friendly error message that includes the line number.

This successfully meets all acceptance criteria:

Invalid keywords are detected during parsing.

A descriptive error message is shown: Syntax Error: Unknown keyword 'XYZ' at line N.

A new unit test has been added to verify this functionality.

### 🛠️ Technical Implementation
Custom Exceptions: Created a new DogLangSyntaxError in doglang/error.py for more specific error handling.

Line Number Tracking: The Tokenizer was enhanced to track and store the line number for every token it produces.

Parser Logic: The SyntaxAnalyser now uses a lookahead (peek()) to differentiate between a valid variable assignment (e.g., myvar = 5) and a standalone identifier, which is now correctly treated as an unknown keyword.

Unit Test: A new test file, tests/test_syntax_analyser.py, was added with a test case that confirms the parser fails correctly and with the exact error message when given a keyword typo.

image

Closes #6

@Pallavrai

Copy link
Copy Markdown
Owner

@ArjunDixit1 I will look into it today

@ArjunDixit1

Copy link
Copy Markdown
Contributor Author

@Pallavrai Okay Thanks

@ArjunDixit1

Copy link
Copy Markdown
Contributor Author

@Pallavrai Did u check?

@Pallavrai Pallavrai merged commit c23211b into Pallavrai:main Oct 4, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add Unit Tests for Invalid Keywords

2 participants