Skip to content

Allow for custom parsing solutions#113

Draft
eoyoa wants to merge 13 commits intoslag-plt:mainfrom
eoyoa:custom-tokenizer
Draft

Allow for custom parsing solutions#113
eoyoa wants to merge 13 commits intoslag-plt:mainfrom
eoyoa:custom-tokenizer

Conversation

@eoyoa
Copy link
Copy Markdown
Collaborator

@eoyoa eoyoa commented Jul 21, 2025

The Parsons Problems group in Glimmer is looking to support Parsons Problem generation based on template solutions.
For example, say we have the template Scamper solution:

(reduce `+ `(list 1 2))

We hope for this to generate the following blocks:

- (reduce _ _)
- +
- (list 1 2)

In order to accomplish our goals, we need a custom Scamper parser to support our special syntax:

  • backticks (`) to denote the following expression should be popped out as a block, and
  • carets (^) to denote all of a block's arguments to be automatically popped out.

This PR:

  1. refactors some of the parsing code to allow for easy extensibility, and
  2. allows for custom extensions to be passed into tokenizer/parser functions.

Thus, no functionality/Parsons Problem-specific code gets added to this repository, but it allows us to reuse the existing tokenizer/parser.

@eoyoa eoyoa marked this pull request as draft July 22, 2025 16:15
@eoyoa
Copy link
Copy Markdown
Collaborator Author

eoyoa commented Jul 22, 2025

@psosera psosera requested review from Copilot and psosera July 23, 2025 20:09
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR refactors the parsing code to support custom extensions while preserving existing functionality. The refactoring enables the Parsons Problems group to add custom parsing logic for template solutions without modifying core repository code.

Key changes:

  • Refactors the monolithic parser into modular token and parse handlers with extensible interfaces
  • Introduces handler-based architecture allowing custom tokenizer and parser extensions to be injected
  • Adds comprehensive test coverage for the tokenizer functionality

Reviewed Changes

Copilot reviewed 11 out of 30 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
src/parser/parser.ts Main parser logic extracted from original parser.ts with extensibility support
src/parser/tokenhandler.ts Token handling logic with pluggable handler interface
src/parser/parsehandler.ts Parse handling logic with pluggable handler interface
test/parser.test.ts New test suite covering tokenizer functionality
src/web/ide.ts Updated import path and commented out AST description functionality
src/scamper.ts Updated import path to new parser location
src/ast.ts Enhanced AST node handling and commented out description method
package.json Added Jest globals dependency and updated test script
jest.config.ts Added ESM support configuration
pnpm-workspace.yaml Added workspace configuration
src/parser.ts Removed original monolithic parser file

Comment thread src/web/ide.ts
Comment on lines +78 to +83
/*const descriptionEl = document.createElement('div')
descriptionEl.setAttribute('id', 'ast-desc')
descriptionEl.innerText = parsed.ast.describe()
descriptionEl.setAttribute('tabindex', '0')
descriptionEl.setAttribute('role', 'region')
outputPane!.appendChild(descriptionEl)
outputPane!.appendChild(descriptionEl)*/
Copy link

Copilot AI Jul 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of commenting out code, consider removing it entirely or using a feature flag if this functionality might be restored later.

Copilot uses AI. Check for mistakes.
Comment thread src/ast.ts
Comment on lines +19 to +20
//name: string = ''
//parentname: string | null = null;
Copy link

Copilot AI Jul 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove commented-out code rather than leaving it in the codebase. If this property might be needed later, consider using a feature flag or documenting the decision.

Suggested change
//name: string = ''
//parentname: string | null = null;

Copilot uses AI. Check for mistakes.
// the entire sequence and let Javascript handle interpreting the
// sequence for us!
} else if (ch === '\\') {
tokenizer.advance() // advance past '\\
Copy link

Copilot AI Jul 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment has an incorrect escape sequence. It should be "advance past '\'" with proper escaping.

Suggested change
tokenizer.advance() // advance past '\\
tokenizer.advance() // advance past '\\'

Copilot uses AI. Check for mistakes.
Comment thread src/parser/parser.ts
Comment on lines +270 to +271
// NOTE: skip the extra \ that we parsed in this case. If/when we support
// extended escape codes, the size of the jump will obviously grow!
Copy link

Copilot AI Jul 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The comment refers to skipping "the extra \" but should clarify it's skipping the escaped character, not just the backslash.

Suggested change
// NOTE: skip the extra \ that we parsed in this case. If/when we support
// extended escape codes, the size of the jump will obviously grow!
// NOTE: skip the escaped character (including the backslash) that we parsed in this case.
// If/when we support extended escape codes, the size of the jump will obviously grow!

Copilot uses AI. Check for mistakes.
Comment thread test/parser.test.ts
@@ -0,0 +1,38 @@
import {stringToTokens} from "../src/parser/parser";
Copy link

Copilot AI Jul 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Consider importing only the specific functions needed rather than destructuring from a large module, or use a barrel export for better organization.

Copilot uses AI. Check for mistakes.
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.

3 participants