As you have said yourself, you just need to use a predicate like atom_chars/2
. You can interleave normal code into a DCG rule by enclosing it in {
and }
.
But there is something fishy about your problem definition. As you have also said yourself, you are parsing a list, not an atom. The list you are parsing should be already properly tokenized, otherwise you cannot expect to define a DCG that can parse it. Or am I seeing this wrong?
So in other words: you take your input, split into single chars, tokenize that using a DCG. Depending on your input, you can do the parsing in the same step.