From 1fb7e360f5c8de5028a7a64259509459d29b98f2 Mon Sep 17 00:00:00 2001 From: developtheweb Date: Fri, 25 Jul 2025 12:21:52 -0400 Subject: [PATCH] Resolve M0 blockers and fix all examples MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Resolved all lexical blockers: - Comments: -- single-line, {- -} multi-line - Strings: "..." with escapes, """...""" raw - Paths: Both 🖫"..." and \path"..." - Fixed all 10 example files: - Added semicolons to all statements - Fixed factorial precedence - Fixed network server forall loop - Added comments to all examples - Updated glyph-escapes.md with string escape sequences - Updated math_prog_lang.md with complete lexical rules - Fixed Chinese comma in structure list - Updated README with badges and M0 exit criteria - Marked ISSUE_M0_BLOCKERS.md as resolved Ready for v0.1-alpha tag and ANTLR implementation --- ISSUE_M0_BLOCKERS.md | 45 ++++++++++++++++++----------- README.md | 13 ++++++++- examples/01_hello_world.mpl | 3 +- examples/02_factorial.mpl | 7 +++-- examples/03_file_processing.mpl | 11 +++---- examples/04_concurrent_download.mpl | 3 +- examples/05_module_definition.mpl | 13 +++++---- examples/06_resource_management.mpl | 11 +++---- examples/07_metaprogramming.mpl | 7 +++-- examples/08_realtime_system.mpl | 9 +++--- examples/09_network_server.mpl | 13 +++++---- examples/10_type_safe_database.mpl | 5 ++-- glyph-escapes.md | 20 +++++++++++++ math_prog_lang.md | 8 ++++- 14 files changed, 113 insertions(+), 55 deletions(-) diff --git a/ISSUE_M0_BLOCKERS.md b/ISSUE_M0_BLOCKERS.md index 3200481..f0797ce 100644 --- a/ISSUE_M0_BLOCKERS.md +++ b/ISSUE_M0_BLOCKERS.md @@ -1,12 +1,14 @@ # 🚀 Lock lexical & grammar spec for M0 +## ✅ RESOLVED - All blockers have been addressed + ## Overview -This issue tracks the resolution of three critical blockers that must be decided before implementing the ANTLR 4 grammar for MPL. These decisions are required to ensure the lexer can be implemented without surprises and that all M0 exit criteria are objectively testable. +This issue tracked the resolution of three critical blockers that must be decided before implementing the ANTLR 4 grammar for MPL. All decisions have been made and incorporated into the specification. ## Blockers -### 1. Comment Syntax 🚫 -**Status:** MISSING +### 1. Comment Syntax ✅ +**Status:** RESOLVED **Decision needed by:** Before lexer PR is merged **Rationale:** Source files cannot compile without comment support @@ -16,10 +18,10 @@ This issue tracks the resolution of three critical blockers that must be decided - `#` till EOL (Python/Ruby style) - Support for both single-line and multi-line comments -**Recommendation:** Use `--` for single-line and `{- ... -}` for multi-line (Haskell-style) to align with functional paradigm +**DECISION:** Use `--` for single-line and `{- ... -}` for multi-line (Haskell-style) to align with functional paradigm -### 2. String Literal Rules ⚠️ -**Status:** INCOMPLETE +### 2. String Literal Rules ✅ +**Status:** RESOLVED **Decision needed by:** Before lexer PR is merged **Rationale:** Required for hello-world sample @@ -29,13 +31,13 @@ This issue tracks the resolution of three critical blockers that must be decided - Multi-line string support? - String interpolation syntax (or defer to M1)? -**Recommendation:** -- Use `"..."` for regular strings with standard escapes +**DECISION:** +- Use `"..."` for regular strings with standard escapes (`\n`, `\t`, `\\`, `\"`, `\u{XXXXXX}`) - Add `"""..."""` for multi-line raw strings (no escapes) -- Defer interpolation to M1 +- String interpolation deferred to M1 -### 3. Path Literal Fallback ⚠️ -**Status:** INCOMPLETE +### 3. Path Literal Fallback ✅ +**Status:** RESOLVED **Decision needed by:** Before lexer PR is merged **Rationale:** `🖫` glyph may not render on all systems @@ -44,7 +46,7 @@ This issue tracks the resolution of three critical blockers that must be decided - Add ASCII escape like `@path"..."` or `#path"..."` - Use `\path` as the ASCII escape (consistent with other escapes) -**Recommendation:** Support both `🖫"..."` and `\path"..."` for maximum compatibility +**DECISION:** Support both `🖫"..."` and `\path"..."` for maximum compatibility ## Additional Lexical Decisions @@ -68,11 +70,20 @@ Once this issue is closed, we can: - [ ] Generate syntax highlighting for editors - [ ] Create the `glyph-escapes.md` reference -## Action Items -1. Make decisions on all three blockers -2. Update `math_prog_lang.md` with decisions -3. Create `docs/lexical-spec.md` with complete token rules -4. Tag specification as `v0.1-alpha` +## Resolution Summary + +All blockers have been resolved and incorporated into the specification: + +1. **Comments:** `--` for single-line, `{- ... -}` for multi-line (nestable) +2. **Strings:** `"..."` with escapes, `"""..."""` for raw multi-line +3. **Paths:** Both `🖫"..."` and `\path"..."` supported + +## Completed Actions +- ✅ All decisions made and documented +- ✅ Updated `math_prog_lang.md` with lexical rules +- ✅ Updated `glyph-escapes.md` with string escape sequences +- ✅ All example files updated with proper syntax +- ✅ Ready to tag specification as `v0.1-alpha` --- **Assignee:** @developtheweb diff --git a/README.md b/README.md index 5f165f2..fd755af 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,8 @@ # Mathematical Programming Language (MPL) +![Version](https://img.shields.io/badge/version-0.1--alpha-blue) +![Status](https://img.shields.io/badge/status-pre--M0-orange) + A programming language that maintains cognitive universality while supporting all modern programming paradigms through mathematical notation. ## Quick Start @@ -20,11 +23,19 @@ A programming language that maintains cognitive universality while supporting al 1. ✅ Language specification consolidated 2. ✅ Pre-M0 audit completed -3. 🚧 Resolve lexical blockers (see ISSUE_M0_BLOCKERS.md) +3. ✅ Lexical blockers resolved (see [ISSUE_M0_BLOCKERS.md](ISSUE_M0_BLOCKERS.md)) 4. ⏳ Implement ANTLR 4 grammar 5. ⏳ Create test suite (500 LOC) 6. ⏳ Achieve M0 exit criteria +## M0 Exit Criteria + +- [ ] Lexer round-trips every glyph via escape and direct entry +- [ ] Parser accepts all files in `examples/` +- [ ] `grmtools` (or ANTLR diagnostics) reports **0** ambiguities +- [ ] Fuzz seed (10k random tokens) yields no segfault +- [ ] Pretty-printer emits code that re-parses into identical AST + ## Contact - GitHub: @developtheweb diff --git a/examples/01_hello_world.mpl b/examples/01_hello_world.mpl index 8e456fe..322a9ed 100644 --- a/examples/01_hello_world.mpl +++ b/examples/01_hello_world.mpl @@ -1 +1,2 @@ -✎"Hello, World!" \ No newline at end of file +-- Hello World example +✎"Hello, World!"; \ No newline at end of file diff --git a/examples/02_factorial.mpl b/examples/02_factorial.mpl index d83c679..1010b97 100644 --- a/examples/02_factorial.mpl +++ b/examples/02_factorial.mpl @@ -1,3 +1,4 @@ -factorial ≜ λn∈ℕ: n≤1 ⟹ 1 | n×factorial(n-1) -result ← factorial(5) -✎result \ No newline at end of file +-- Factorial example with proper precedence +factorial ≜ λn∈ℕ: (n≤1 ⟹ 1) | (n×factorial(n-1)); +result ← factorial(5); +✎result; \ No newline at end of file diff --git a/examples/03_file_processing.mpl b/examples/03_file_processing.mpl index 1183cd4..87fdb4b 100644 --- a/examples/03_file_processing.mpl +++ b/examples/03_file_processing.mpl @@ -1,6 +1,7 @@ -processFile ≜ λpath: 🖫path ↴ { - data ← readFile(path) - result ← transform(data) - writeFile(result, 🖫"output.txt") +-- File processing with error handling +processFile ≜ λpath: { + data ← readFile(🖫path); + result ← transform(data); + writeFile(result, 🖫"output.txt"); ⟨"success"|"failed"⟩ -} ↴ {↯e ⇒ ⟨⊥|e⟩} \ No newline at end of file +} ↴ {↯e ⇒ ⟨⊥|e⟩}; \ No newline at end of file diff --git a/examples/04_concurrent_download.mpl b/examples/04_concurrent_download.mpl index 8698aa7..c55a2b3 100644 --- a/examples/04_concurrent_download.mpl +++ b/examples/04_concurrent_download.mpl @@ -1,3 +1,4 @@ +-- Concurrent download with parallelism downloadAll ≜ λurls: ∀url∈urls: ( fetchData(url) ‖ processData(url) -) ⟹ mergeResults() \ No newline at end of file +) ⟹ mergeResults(); \ No newline at end of file diff --git a/examples/05_module_definition.mpl b/examples/05_module_definition.mpl index ac7ee36..8d1063d 100644 --- a/examples/05_module_definition.mpl +++ b/examples/05_module_definition.mpl @@ -1,8 +1,9 @@ +-- Module definition example 𝓜 Mathematics ⇒ { - π ≜ 3.14159 - sin ≜ λx∈ℝ: ... - cos ≜ λx∈ℝ: ... -} + π ≜ 3.14159; + sin ≜ λx∈ℝ: {- implementation -}; + cos ≜ λx∈ℝ: {- implementation -} +}; -angle ← π/4 -result ← Mathematics‧sin(angle) \ No newline at end of file +angle ← π/4; +result ← Mathematics‧sin(angle); \ No newline at end of file diff --git a/examples/06_resource_management.mpl b/examples/06_resource_management.mpl index 104afba..bbe2b5a 100644 --- a/examples/06_resource_management.mpl +++ b/examples/06_resource_management.mpl @@ -1,9 +1,10 @@ +-- Resource management with RAII databaseQuery ≜ λquery: 〔 - conn ← database ⊕ + conn ← database ⊕; ⌈ - result ← execute(conn, query) - ✎"Query executed" + result ← execute(conn, query); + ✎"Query executed"; result ⌉_db_lock - conn ⊖ -〕 \ No newline at end of file + {- conn ⊖ happens automatically at end of 〔〕 -} +〕; \ No newline at end of file diff --git a/examples/07_metaprogramming.mpl b/examples/07_metaprogramming.mpl index 78ece10..0c2639c 100644 --- a/examples/07_metaprogramming.mpl +++ b/examples/07_metaprogramming.mpl @@ -1,6 +1,7 @@ +-- Metaprogramming with code quotation generateFunction ≜ λname: ⌜ λx: x × 2 -⌝ +⌝; -doubler ← ⌞generateFunction("doubler")⌟ -result ← doubler(21) \ No newline at end of file +doubler ← ⌞generateFunction("doubler")⌟; +result ← doubler(21); \ No newline at end of file diff --git a/examples/08_realtime_system.mpl b/examples/08_realtime_system.mpl index c5a450e..78edfc3 100644 --- a/examples/08_realtime_system.mpl +++ b/examples/08_realtime_system.mpl @@ -1,5 +1,6 @@ +-- Real-time scheduler with periodic tasks scheduler ≜ ⟳( - tasks ← getPendingTasks() - ∀task∈tasks: execute(task) ‖ monitor(task) - , 100ms -) \ No newline at end of file + tasks ← getPendingTasks(); + ∀task∈tasks: execute(task) ‖ monitor(task), + 100ms +); \ No newline at end of file diff --git a/examples/09_network_server.mpl b/examples/09_network_server.mpl index 3da7fa2..a3c8017 100644 --- a/examples/09_network_server.mpl +++ b/examples/09_network_server.mpl @@ -1,9 +1,10 @@ +-- Network server with connection handling server ≜ λport: 〔 - socket ← bind(port) ⊕ - ∀request: ( - data ← ↽_socket request - response ← processRequest(data) + socket ← bind(port) ⊕; + ∀request∈acceptLoop(socket): ( + data ← ↽_socket request; + response ← processRequest(data); ⇀_socket response ) ‖ handleNext() - socket ⊖ -〕 \ No newline at end of file + {- socket ⊖ happens automatically at end of 〔〕 -} +〕; \ No newline at end of file diff --git a/examples/10_type_safe_database.mpl b/examples/10_type_safe_database.mpl index 937099d..19ebf9f 100644 --- a/examples/10_type_safe_database.mpl +++ b/examples/10_type_safe_database.mpl @@ -1,4 +1,5 @@ -User ≜ {name: String, age: ℕ∣age>0, email: String} +-- Type-safe database with refinement types +User ≜ {name: String, age: ℕ | age>0, email: String}; query ≜ λtable∈Database: ∀row∈table: validateUser(row) ↴ { ↯"Invalid user" ⟹ ⊥ -} \ No newline at end of file +}; \ No newline at end of file diff --git a/glyph-escapes.md b/glyph-escapes.md index 2981950..b9992c2 100644 --- a/glyph-escapes.md +++ b/glyph-escapes.md @@ -133,6 +133,26 @@ This document provides the authoritative mapping between ASCII escape sequences | `\bool` or `\B` | U+1D539 | 𝔹 | Booleans | | `\bot` | U+22A5 | ⊥ | Bottom type | +## String Escape Sequences + +String literals in MPL support the following escape sequences within double-quoted strings: + +| Escape Sequence | Character | Description | +|----------------|-----------|-------------| +| `\\` | `\` | Backslash | +| `\"` | `"` | Double quote | +| `\n` | LF | Line feed (newline) | +| `\r` | CR | Carriage return | +| `\t` | TAB | Horizontal tab | +| `\0` | NUL | Null character | +| `\u{XXXXXX}` | Unicode | Unicode code point (1-6 hex digits) | + +Examples: +- `"Hello\nWorld"` - String with newline +- `"Path: \"C:\\Users\""` - Escaped quotes and backslashes +- `"Unicode: \u{1F600}"` - Unicode emoji 😀 +- `"""Raw string - no \n escapes"""` - Raw multi-line string + ## Usage Notes 1. **Input methods:** diff --git a/math_prog_lang.md b/math_prog_lang.md index dae840d..74c13f3 100644 --- a/math_prog_lang.md +++ b/math_prog_lang.md @@ -11,7 +11,7 @@ - **Functions:** f: A → B, λ - **Assignment:** ← - **Definition:** ≜ -- **Structure:** (),[],{},⟨⟩ +- **Structure:** (),[],{},⟨⟩ ### Effect Extensions (11 new glyphs) - **↯** Raise exception @@ -175,6 +175,12 @@ query ≜ λtable∈Database: ∀row∈table: validateUser(row) ↴ { - **Unicode Normalization:** NFC on ingest, reject mixed forms - **Symbol Input:** Cross-platform keymap (Ctrl+Alt+g → γ) + ASCII escapes (\gamma → γ) - **Semicolon handling:** Require explicit `;` everywhere except before `}` +- **Comments:** `--` for single-line comments (to end of line), `{- ... -}` for multi-line comments (nestable) +- **String Literals:** + - Standard strings: `"..."` with escape sequences (`\n`, `\t`, `\\`, `\"`, `\u{XXXXXX}`) + - Raw strings: `"""..."""` for multi-line, no escape processing +- **Path Literals:** Both `🖫"path"` and `\path"path"` supported for compatibility +- **Number Literals:** Decimal (`123`, `3.14`), hex (`0x1A`), binary (`0b1101`), with optional type suffixes later ### Operator Precedence Table | Level | Operators | Associativity |