this post was submitted on 28 Nov 2023
1 points (100.0% liked)

Lisp

55 readers
3 users here now

founded 1 year ago
MODERATORS
 

I'm hoping to read some C code (XPM image files) using Common Lisp, and I am thinking that it would help to equip the Lisp parser to skip over C-style comments (primarily /* ... */ comments, maybe also //, not sure if that's necessary yet).

Can anyone say how to define a readtable which skips over C-style comments? A web search didn't bring up anything from what I can tell.

I only need to read the C code, so it's acceptable that skipping C-style comments makes it impossible to read some valid Common Lisp constructs.

top 6 comments
sorted by: hot top controversial new old
[–] noogai03@alien.top 1 points 1 year ago

Wait you're loading image files directly using the lisp loader? This sounds risky

[–] PetriciaKerman@alien.top 1 points 1 year ago (1 children)

You could use the c pre-processor to remove the comments. It might be a good idea to use the cpp anyway as it will also expand macros and what not for you which may be difficult to do otherwise.

[–] corvid_booster@alien.top 1 points 1 year ago

Thanks for your response. One of the constraints is that it needs to be an entirely Common Lisp solution; external tools or C libraries via FFI can't be part of the solution.

You're right that macros or other C constructs can complicate the picture. Whether or not that's an issue depends on the assumptions that tools writing XPM files make. At this point I'm willing to just get past the comments issue and then see how far that gets me.

[–] dzecniv@alien.top 1 points 1 year ago (1 children)

This one has a readtable with C-style /* */ comments: https://github.com/y2q-actionman/with-c-syntax (found on awesome-cl)

[–] corvid_booster@alien.top 1 points 1 year ago

Thanks, that looks promising, I will take a closer look.

[–] ruricolist@alien.top 1 points 1 year ago

Vacietis might be a good project to look at.