Implement our parser, . field access, comment preservation and line number tracking for source-level debugging #26
Reference in New Issue
Block a user
Delete Branch "our-parser"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Closes #16
Built and ran this on CHICKEN 6.0.0 (worktree at
d83ee32). Unit tests are green; the issue #16 success program is not.What I ran
make sexc./sex-tests(incl. line-directives, unicodeunkebabify)hello-world.sex,lists.sex,unicode.sexviasextestmake run-teststests/sex-programs/comments.sexis not in the treesexc -Cccrejectssexccompile (no-C) of a tiny programChicken 6.0.0 names process ports from the child (
process-input-portis writable). That part of the migration is correct.vs issue #16
Field access and the
plusmacro work:a.pos.x + a.pos.y. Struct / enum / vectors look right. The rest of the golden sample does not.|/||are not C operators. Actual-Coutput:cc:expected expression before '|'/stray '\'. Oldc-bit-orstill emits1 | 2 | 4. The reader can produce the symbols;sex-fmt-cstill only special-casesc-or/c-bit-orand otherwise goes throughc-apply. The(string->symbol ".")cond is the pattern to extend for"|","||","|=".In-arg comments insert a comma:
Comments are not packed; extra
;s are kept:A
;in anifarm shifts clauses. Source:became
if (1) { /* comment*/ } else if (puts("then")) { puts("else"); }.A
;betweenforclauses does the same:for (int i = 0; /* between*/; i < 1)with++imoved into the body.Fn headers already strip comments so positional accessors do not shift. That needs to apply to
if/for/while/ calls /switchas well — or comments should be spliced as whitespace, not list elements, except in statement position.Merge-blocking
comments.sex—make run-testscannot succeed.make sex-tests(make run-testsis commented out). Unit tests alone would look green; they never compiled the golden sample.--line-directivesworks as--line-directives=statement(getopt-long 4.0). Space-separated form errors. Help already shows=ARG.-Cwithout that flag emits no#line, as intended.What looks solid
The reader,
#linetests, Chicken 6 build, unicode identifiers / octal string escapes, andsextestsharingreader.scmare in good shape. I would not merge until|/||lower to operators, comments splice as comments, the golden sample is a test, andcomments.sexexists or is dropped fromSEX_TEST_PROGRAMS.@@ -59,3 +59,3 @@cp ./tools/sextest/sextest .SEX_TEST_PROGRAMS = hello-world listsSEX_TEST_PROGRAMS = hello-world lists comments unicodecommentsis listed here, buttests/sex-programs/comments.sexis not in the tree.make run-testsdies on(open-input-file) … comments.sexafter hello-world, so unicode never runs either. Add the file or drop it fromSEX_TEST_PROGRAMS.Oops
@@ -19,0 +61,4 @@`(%begin ,(line-directive src) ,(walk-expr s))(walk-expr s))))(define (walk-if-clauses clauses)This is strictly
test stmt test stmt …. A;comment is a list element, so it is treated as an arm and shifts the rest.became
if (1) { /* comment*/ } else if (puts("then")) { puts("else"); }. Same class of bug as stripping comments from fn headers — those accessors would otherwise shift too.@@ -88,6 +137,28 @@(('c-or . rest) (apply c-or (map walk-expr rest)))Still only
c-or/c-bit-or/c-bit-or=. After the new reader,(| B A R)and(|| 0 1)are those symbols, not these names.sexc -Cof the #16 sample emitted\|\\||(B, A, R)andccrejected it.c-bit-orstill works (1 | 2 | 4).@@ -91,0 +146,4 @@(('while test . body)(cons* 'while (walk-expr test) (walk-body body)))(('for init test step . body)(cons* 'for (walk-expr init) (walk-expr test) (walk-expr step)Same positional trap: a
;betweeninit/test/stepbinds to the wrong slot. Observed:c-applyalso joins args with", ", so(printf "%d" ; c\n x)becomesprintf("%d", /* c */, x)— extra comma, andccfails on the #16 sample.Re-review of
7e6e324on CHICKEN 6.0.0. Previous items on comments andmake run-testsare fixed. The issue #16 success program still does not compile.What I ran
make run-tests....— hello-world, lists, comments, unicode)codegen/argssexc -CccFixed since last review
tests/sex-programs/comments.sexexists.;;;lines pack, and leading;s are stripped:/* Main entry point/Multi line comments should be packed */.if/for/while/var/castno longer steal positional slots. The newcodegentests pin this, including the silentelse ifcase.(g 1 ;; c\n 2)→g(1, 2)).--now passes non-dash compiler args;c-castparenthesises binary operands;c-switchruns the scrutinee throughc-expr.Still blocking Closes #16
|/||are still not C operators. Same golden file as last time:and
(|| 0 1)still emits|\|\||(0, 1).ccdies onexpected expression before '|'/stray '\'.The reader already produces those symbols.
walk-exprstill only special-casesc-or/c-bit-or/c-bit-or=(and those still work:1 | 2 | 4).c-expr/sexpalready has the(string->symbol ".")cond —"|","||","|="belong there. There is still no codegen test for this, which is why the new suite is green while #16 is not.Everything else in the sample is right: packed comments,
.field access,plus, struct/enum/vectors. The printf comment is dropped rather than kept as/* the printf */between arguments; that matches the new tests, but it is a remaining gap vs the issue's sketched C.CI still runs only
make sex-tests, so this|hole would not show up there either.I would not merge until
(| B A R)and(|| …)emitB | A | R/a || band that is pinned next to the othercodegencases.@@ -85,4 +192,4 @@(('enum . _) (walk-enum form));; | is problematic... And c-or/bit-or/etc are actually;; procedures, so we have to call the procedure itself(('c-or . rest) (apply c-or (map walk-expr rest)))This is the remaining #16 hole. After the new reader,
(| B A R)is the symbol|, notc-bit-or.sexc -Cof the issue sample still emits\|\\||(B, A, R)andccrejects it. Same for||. The(string->symbol ".")cond inc-expr/sexpis the pattern;c-bit-orcan stay as an alias.@@ -0,0 +77,4 @@;; A comment among a call's arguments used to become an argument,;; and c-apply put a comma on each side of it -- which does not;; compile. It is dropped, as in any other expression context.(test-group "comments among arguments"These tests are why the suite is green while the #16 sample still fails: they pin comments and casts, but not
(| B A R)→B | A | Ror(|| a b)→a || b. A couple ofemits?cases here would have caught it.Re-review of
5f9f90eon CHICKEN 6.0.0. The last blocker is gone.What I ran
make run-testssexc -Cthencc30 1.500000 3(| B A R)now emitsB | A | R. Renaming|/||/\|=inatom-to-fmt-cto heads fmt-c can actually spell is the right fix, and the tests pin both the new spelling and the oldc-or/c-bit-oraliases.Remaining nits, not blocking
;among call arguments is still dropped, so the issue sketch's/* the printf */does not appear. That matches the tests; it is the one leftover vs the #16 C sample./* Main entry point/Multi line… */). Harmless.make sex-tests.sextestand the golden sample would not run there.Looks good to merge for Closes #16.