Open
Conversation
- Moved error handling logic to a dedicated errors module, improving organization and maintainability.
Contributor
Author
|
Just discovered from link that the code is slow: Turns out that instead of the post-processor function being executed when all statements are matched it gets executed at every increment: with 0 statements This was benchmarking result of simple ackermann function In order to ensure the Nearley parser emitted the current internal Python AST , we created these post-processor functions. However they are slow. A move to Nearley parser might require rethinking the internal Python AST |
This merge integrates the WASM compiler from main while preserving the new Nearley-based parser from NearleyDSL. Key changes: - Adapted pyRunner.ts to use new parser (Tokenizer + Parser + Resolver) - Updated AST type definitions to avoid duplication - Fixed resolver to use new validators subsystem - Merged package dependencies for both parser and WASM compiler - Removed old translator and parser error handling (superseded by Nearley) - Updated test utilities to work with new parser architecture - Kept WASM compiler (now uses new AST types from py-slang parser) The CSE machine already expected the new AST types, so no changes were needed there. Both the WASM compiler and CSE machine now consume the unified AST generated by the new Nearley parser. Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
- Fixed parser imports: use NearleyParser from parser-adapter - Fixed Resolver constructor calls to match new signature (source, ast) - Fixed WASM compiler imports and complex number parsing - Fixed PyWasmEvaluator result type conversion - Ensured all compilers work with new unified AST types Build now completes successfully.
- Use NearleyParser from parser-adapter instead of non-existent Parser module - Fix Resolver constructor to pass AST instead of chapter number Parser and analysis tests now pass successfully.
Changed parser grammar to create BigIntLiteral nodes for integer literals instead of Literal nodes with parsed numbers. This ensures integers stay as bigint type throughout arithmetic operations instead of being converted to float. Now 23+1 returns 24 (bigint) instead of 24.0 (float).
Tests now expect BigIntLiteral for integer literals instead of Literal, reflecting the grammar changes to properly preserve integer types.
The issue was that we were creating a Tokenizer separately and passing tokens to the Nearley parser, which has its own integrated lexer and ignores the tokens parameter. Reverted to using the parse() function from parser-adapter, which matches the original implementation and allows Nearley to use its integrated lexer correctly for handling indentation and nested structures. This fixes the 'Unexpected token: else' error in nested if statements.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Summary:
This pull request (Fixes #68) introduces unified Nearley + Moo–based parsing system. It replaces the old, fragmented setup (manual tokenizer, static grammar, separate AST DSL) with a single declarative pipeline that integrates tokenization, grammar rules, and AST generation.
Key Improvements:
generate-ast.ts.Benefits:
grammar.ne+lexer.moo).TokenTypeenums — no manual syncing.tokenizer.tsandGrammar.gram.Next Steps:
+=, comprehensions, etc.).generate-ast.ts-> currently creates ExprNS/StmtNS objects