ソースを参照

test: cover underscore identifiers and module names

Eric Streit 1 日 前
親
コミット
b37ff1a526
6 ファイル変更、14 行追加、13 行削除
  1. 1 1
      compiler/run_tests.sh
  2. 3 3
      compiler/src/M2.atg
  3. 3 3
      compiler/src/M2.lst
  4. 4 3
      compiler/tests/t_under.mod
  5. 2 2
      docs/OOP.txt
  6. 1 1
      docs/features.md

+ 1 - 1
compiler/run_tests.sh

@@ -5,7 +5,7 @@ pass=0; fail=0
 SHIM="../runtime/syslib/shim.c"
 
 modof() {
-  sed -n 's/^MODULE \([A-Za-z][A-Za-z0-9]*\).*/\1/p' "tests/$1" | head -n 1
+  sed -n 's/^MODULE \([A-Za-z_][A-Za-z0-9_]*\).*/\1/p' "tests/$1" | head -n 1
 }
 
 expect_run() {

+ 3 - 3
compiler/src/M2.atg

@@ -26,8 +26,8 @@ COMPILER M2
    inheritance + CLASS IMPLEMENTATION blocks, methods with ";"
    (per the Table example, not the sketch's ","), VIRTUAL flagged.
    Scopes and member checks now; lowering later (one 230 per
-   class/impl block). Classic identifiers: no underscores, so the
-   Table example's _names stay lexically out of reach.
+   class/impl block). ISO identifiers may contain underscores, so
+   the Table example's _names are lexically accepted.
    Step 3.1 arrays: "ARRAY [lo..hi, ...] OF T" (folded literal
    bounds, int/char) and open "ARRAY OF T" formals; index suffixes
    with per-level checks (217/218, trap on breach via $abort);
@@ -1854,7 +1854,7 @@ PRODUCTIONS
      inheritance + IMPLEMENTATION blocks. Scopes and member checks
      now; lowering (vtable, dispatch, THIS) later — one 230 per
      class/impl block. Methods end with ";" per the Table example
-     (not "," as in the sketch). No underscores in identifiers. *)
+     (not "," as in the sketch). Identifiers may contain underscores. *)
   (* Single CLASS item in both loops: separating declaration from
      IMPLEMENTATION at the loop level needs 2-token lookahead
      (CLASS ident vs CLASS IMPLEMENTATION), which LL(1) cannot do.

+ 3 - 3
compiler/src/M2.lst

@@ -50,8 +50,8 @@ Listing:
    26     inheritance + CLASS IMPLEMENTATION blocks, methods with ";"
    27     (per the Table example, not the sketch's ","), VIRTUAL flagged.
    28     Scopes and member checks now; lowering later (one 230 per
-   29     class/impl block). Classic identifiers: no underscores, so the
-   30     Table example's _names stay lexically out of reach.
+   29     class/impl block). ISO identifiers may contain underscores, so
+   30     the Table example's _names are lexically accepted.
    31     Step 3.1 arrays: "ARRAY [lo..hi, ...] OF T" (folded literal
    32     bounds, int/char) and open "ARRAY OF T" formals; index suffixes
    33     with per-level checks (217/218, trap on breach via $abort);
@@ -1869,7 +1869,7 @@ Listing:
  1845       inheritance + IMPLEMENTATION blocks. Scopes and member checks
  1846       now; lowering (vtable, dispatch, THIS) later — one 230 per
  1847       class/impl block. Methods end with ";" per the Table example
- 1848       (not "," as in the sketch). No underscores in identifiers. *)
+ 1848       (not "," as in the sketch). Identifiers may contain underscores. *)
  1849    (* Single CLASS item in both loops: separating declaration from
  1850       IMPLEMENTATION at the loop level needs 2-token lookahead
  1851       (CLASS ident vs CLASS IMPLEMENTATION), which LL(1) cannot do.

+ 4 - 3
compiler/tests/t_under.mod

@@ -1,6 +1,7 @@
-MODULE TUnder;
+MODULE T_Under;
 (* ISO identifiers may contain underscores; the scanner must accept them
-   (previously `my_var` lexed as `my` then `_var`).  Exit 42. *)
+   in module names and ordinary identifiers (previously `my_var` lexed as
+   `my` then `_var`).  Exit 42. *)
 VAR
   my_var, ExitCode : INTEGER;
 
@@ -12,4 +13,4 @@ END add_two;
 BEGIN
   my_var := add_two(40);
   ExitCode := my_var
-END TUnder.
+END T_Under.

+ 2 - 2
docs/OOP.txt

@@ -37,8 +37,8 @@ NOTES (V3 implementation, m2compiler-V3):
   not ',' as earlier drafts of this sketch had it.
 - "PEOCEDURE" typo in the original sketch fixed to PROCEDURE.
 - Single inheritance only: extra parents are rejected (230).
-- Classic identifiers only (no '_'); the Table example's
-  _Find-style names are lexically out of reach for now.
+- Identifiers may contain '_' (ISO); the Table example's _Find-style
+  names are lexically accepted.
 - Class lowering lands (see docs/summary_class-lowering.md): fields,
   methods (value/VAR formals, results), single inheritance and a
   hidden THIS receiver all generate code.

+ 1 - 1
docs/features.md

@@ -8,7 +8,7 @@ Pipeline: Coco/R `M2.atg` (1748 lines, 73 productions) → `gm2`-built
 Legend: ✅ done · 🔄 partial · ⏸ not started / deferred.
 
 ## Lexical / syntax
-- ✅ Classic idents (no `_`), `0x`/`0X` hex (no `H`), reals with `E`
+- ✅ Identifiers may contain `_`, `0x`/`0X` hex (no `H`), reals with `E`
   exponents, `#` `<` `<=` `>` `>=` `=`, `//` + nested `(* *)`,
   strings `'…'`/`"…"`, `0x` array bounds.
 - ✅ `NOT`/`AND`/`OR` (no `~`/`&`), unary minus at expr start,