Conversation
There was a problem hiding this comment.
Pull request overview
This PR introduces an initial formatter for Eunoia (.eo) files, intended to provide a consistent canonical layout (akin to clang-format) by parsing Eunoia as S-expressions, preserving comments, and applying syntax-directed indentation/alignment rules.
Changes:
- Adds a new
contrib/eo_format.pyCLI tool that lexes/parses.eofiles and re-emits formatted output with fixed indentation and line-width rules. - Implements special formatting for
programblocks, including inline-case alignment logic and comment preservation. - Adds recursive formatting over
includedependencies, plus--checkand--diffmodes.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+288
to
+291
| target = insert_before if insert_before is not None else len(lines) - 1 | ||
| lines[target:target] = self.format_comment_with_indent( | ||
| node, self.leading_whitespace(lines[target]) | ||
| ) |
| import sys | ||
| from dataclasses import dataclass | ||
| from pathlib import Path | ||
| from typing import Iterable, Optional |
| class Node: | ||
| kind: str | ||
| text: str = "" | ||
| children: list["Node"] | None = None |
Comment on lines
+414
to
+417
| def program_case_info( | ||
| self, children: list[Node], case_level: int | ||
| ) -> dict[int, Optional[dict[str, int | str]]]: | ||
| info: dict[int, Optional[dict[str, int | str]]] = {} |
Comment on lines
+514
to
+518
| def trailing_program_case_comments( | ||
| self, | ||
| children: list[Node], | ||
| case_info: dict[int, Optional[dict[str, int | str]]], | ||
| ) -> dict[int, Node]: |
Comment on lines
+994
to
+997
| if not resolved.exists(): | ||
| raise FormatError(f"{path}: file does not exist") | ||
| text = resolved.read_text() | ||
| nodes = parse_eunoia(text, str(resolved)) |
Comment on lines
+1017
to
+1020
| def format_file(path: Path, formatter: Formatter) -> tuple[str, str]: | ||
| original = path.read_text() | ||
| formatted = formatter.format_document(parse_eunoia(original, str(path))) | ||
| return original, formatted |
Comment on lines
+1071
to
+1074
| if args.diff: | ||
| print(unified_diff(path, original, formatted), end="") | ||
| elif not args.check: | ||
| path.write_text(formatted) |
Comment on lines
+440
to
+444
| def inline_program_cases( | ||
| self, | ||
| children: list[Node], | ||
| case_info: dict[int, Optional[dict[str, int | str]]], | ||
| ) -> dict[int, int]: |
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.
There is a need to give a common format to Eunoia files, similar to clang-format for C++.
Co-Authored-By: ChatGPT 5.5 noreply@openai.com