[cc65] .string()

From: Jeremy Turner <jeremiah.turner1gmail.com>
Date: 2013-09-27 14:16:22
Hi,

Regarding my recent question about .string() and tokenlists, I had send a
reply that contained a solution, but perhaps it got eaten by the spam
filters? I think it would be nice to have the solution in the archive. Here
it is again if the original message is lost:

The explanation from Mr. King gave me an idea for a work around that does
what I need. It won't match every token perfectly but should work fine in
the vast majority of cases.

Invoking:

printtokenlist foo

will print all the token list named foo to standard out at build. See below:

.scope PRINTIDENT
    __concatStrDefined__ .set 0
    _COUNTER_ .set 0
.endscope


.macro buildTokenStr Str

    .if PRINTIDENT::__concatStrDefined__
        .define _____tempStr_____ _____concatStr_____
        .undefine _____concatStr_____
        .define _____concatStr_____ .concat(_____tempStr_____,Str)
        .undefine _____tempStr_____
    .else
        .define _____concatStr_____ Str
        PRINTIDENT::__concatStrDefined__ .set 1
    .endif

.endmacro

.macro clrTokenString
    .if PRINTIDENT::__concatStrDefined__
        .undefine _____concatStr_____
        PRINTIDENT::__concatStrDefined__ .set 0
    .endif
.endmacro


.macro printtokenlist exp

    .if PRINTIDENT::_COUNTER_ >= .tcount({exp})
        .out _____concatStr_____
        PRINTIDENT::_COUNTER_ .set 0
        clrTokenString
        .exitmacro
    .endif

    .define THISTOKEN .mid(PRINTIDENT::_COUNTER_,1,{exp})
    .if .match(THISTOKEN, an_identname)
        buildTokenStr .concat( " ",.string(THISTOKEN), " ")
    .elseif .match(THISTOKEN, 12345)
        buildTokenStr .string(THISTOKEN)
    .elseif .xmatch(THISTOKEN, a)
        buildTokenStr "a "
    .elseif .xmatch(THISTOKEN, x)
        buildTokenStr "x "
    .elseif .xmatch(THISTOKEN, y)
        buildTokenStr "y "
    .elseif .xmatch(THISTOKEN, s)
        buildTokenStr "s "
    .elseif .xmatch(THISTOKEN, :=)
        buildTokenStr ":="
    .elseif .xmatch(THISTOKEN, =)
        buildTokenStr "="
    .elseif .xmatch(THISTOKEN, <>)
        buildTokenStr "<>"
    .elseif .xmatch(THISTOKEN, <)
        buildTokenStr ">"
    .elseif .xmatch(THISTOKEN, >)
        buildTokenStr ">"
    .elseif .xmatch(THISTOKEN, <=)
        buildTokenStr "<="
    .elseif .xmatch(THISTOKEN, >=)
        buildTokenStr ">="
    .elseif .xmatch(THISTOKEN, .and)
        buildTokenStr " .and "
    .elseif .xmatch(THISTOKEN, .or)
        buildTokenStr " .or "
    .elseif .xmatch(THISTOKEN, .xor)
        buildTokenStr " .xor "
    .elseif .xmatch(THISTOKEN, .not)
        buildTokenStr " .not "
    .elseif .xmatch(THISTOKEN, +)
        buildTokenStr " + "
    .elseif .xmatch(THISTOKEN, -)
        buildTokenStr " - "
    .elseif .xmatch(THISTOKEN, *)
        buildTokenStr " * "
    .elseif .xmatch(THISTOKEN, /)
        buildTokenStr " / "
    .elseif .xmatch(THISTOKEN, !)
        buildTokenStr " ! "
    .elseif .xmatch(THISTOKEN, |)
        buildTokenStr " | "
    .elseif .xmatch(THISTOKEN, ^)
        buildTokenStr "^"
    .elseif .xmatch(THISTOKEN, &)
        buildTokenStr " & "
    .elseif .xmatch(THISTOKEN, <<)
        buildTokenStr " << "
    .elseif .xmatch(THISTOKEN, >>)
        buildTokenStr " >> "
    .elseif .xmatch(THISTOKEN, ~)
        buildTokenStr "~"
    .elseif .xmatch(THISTOKEN, ::)
        buildTokenStr "::"
    .elseif .xmatch(THISTOKEN, {.})
        buildTokenStr "."
    .elseif .xmatch(THISTOKEN, {,})
        buildTokenStr ", "
    .elseif .xmatch(THISTOKEN, #)
        buildTokenStr "#"
    .elseif .xmatch(THISTOKEN, :)
        buildTokenStr ":"
    .elseif .xmatch(THISTOKEN, {(})
        buildTokenStr "( "
    .elseif .xmatch(THISTOKEN, {)})
        buildTokenStr " )"
    .elseif .xmatch(THISTOKEN, [)
        buildTokenStr "["
    .elseif .xmatch(THISTOKEN, ])
        buildTokenStr "]"
    .elseif .xmatch(THISTOKEN, Z:)
        buildTokenStr "Z:"
    .elseif .xmatch(THISTOKEN, a:)
        buildTokenStr "a:"
    .elseif .xmatch(THISTOKEN, f:)
        buildTokenStr "f:"
    .else
        buildTokenStr "?"
    .endif
    .undefine THISTOKEN

    PRINTIDENT::_COUNTER_ .set PRINTIDENT::_COUNTER_ + 1
    printIdent {exp}

.endmacro

----------------------------------------------------------------------
To unsubscribe from the list send mail to majordomo@musoftware.de with
the string "unsubscribe cc65" in the body(!) of the mail.
Received on Sat Sep 28 12:52:45 2013

This archive was generated by hypermail 2.1.8 : 2013-09-28 12:52:47 CEST