1) Macro %substr now has functionality like subchar. It is
nessesarily to add fourth parameter to specify the length
of substring:
%substr foo 'my string' 4 6 ;foo = 'string'
2) Need tokenizer to have the convenient way to get
separate words from sentence like this:
%token foo 'word1 word2 word3' 2 ;foo = 'word2'
or (to specify delimeters in fourth parameter):
%token foo 'word1, word2, word3' 2 ', ' ;foo = 'word2'
Logged In: NO
It should be possible to use multiple %SUBSTR and %+ to
achieve both (1) and (2). However, you might also want
to look at using a third-party preprocessor that offers
you more functionality than NASM's built-in "variant".
Logged In: YES
user_id=806493
I have implemented my variant of %substr with optional fourth
argument, but it was not simple to know on which token
evaluate() stops it work. I recognize it now by memorizing the
last token in ppscan, but there must be more convinient way,
like to return next token pointer in second parameter of
evaluate().
File with changed fragments of preproc.c is in attach.
Changes in preproc.c
Logged In: YES
user_id=806493
I have added to nasm support of all my requested features in
this topic (fourth optional parameter in %substr and tokenizer
%strtok) !
The source code (changes in preproc.c with surrounding
code) is in attach.
I would be very glad if you take a look on it.
And, at last, I have added support of new syntax, in which
source parameters of %substr and %strtok is delimited by
commas, like this:
%substr foo 'my string',4,6
is equivalent to
%substr foo 'my string' 4 6
%strtok foo 'word1. word2. word3', 2, '. '
is similar to
%strtok foo 'word1. word2. word3' 2 '. '
Changes in preproc.c (%substr + %strtok)
Logged In: YES
user_id=806493
I have added to nasm support of all my requested features in
this topic (fourth optional parameter in %substr and tokenizer
%strtok) !
The source code (changes in preproc.c with surrounding
code) is in attach.
I would be very glad if you take a look on it.
And, at last, I have added support of new syntax, in which
source parameters of %substr and %strtok is delimited by
commas, like this:
%substr foo 'my string',4,6
is equivalent to
%substr foo 'my string' 4 6
%strtok foo 'word1. word2. word3', 2, '. '
is similar to
%strtok foo 'word1. word2. word3' 2 '. '
Changes in preproc.c (%substr + %strtok)
Logged In: NO
I have experimented with your %SUBSTR changes, and I
think that they can/should be submitted.
I will look at %STRTOK next. Btw, would you mind if
that directive were named %SPLIT instead?
Also, the support for comma-separated arguments is not
really needed, since one can use parentheses to group
them, e.g. %SUBSTR s "text" 2 (-1+2). Unless someone
can think of a case where the commas are required, my
recommendation is to not allow them, so that we end up
with one valid syntax, not two.
Logged In: YES
user_id=806493
1) Why %split? This directive returns only one token. Split
associated, IMHO, with total string subdivision. But strtok is
not the best name too (however, it sounds ANSI-like).
2) Comma separation for arguments grouping source
parameters and make %substr and %strtok syntax similar with
%define, %assign:
<directive> <dest> <src>
It also more similar to multiline macro call.
Now we have three syntax types:
1. foo(x,y,z) fo single line macro;
2. foo x,y,z for assembler instructions and multiline macro;
3. %foo x y z for complex directives such as %substr and %
strtok(%split).
And I don't like the third type of syntax. It makes parameters
set indiscernible and odd. I just want to replace it with
intermediate syntax:
%foo x y,z,...
It groups parameters by purpose: <destination> and
<source>, like in %assign and %define.
And this syntax support costs a little - just to add two strings
between each parameters parsing:
while (tok_type_(tt, TOK_WHITESPACE)) tt = tt->next;
if (tok_is_(tt, ",")) tt = tt->next;
But I agree, this question should be discussed.
Logged In: NO
Sorry, but I didn't catch the ANSI C connection
earlier today -- of course it should be %STRTOK.
I was thinking in Perl, which I had just used a
few moments before writing my previous response.
As for comma separation of preprocessor directive
arguments, my main concerns are (a) having a bit
of uniformity for preprocessor directive syntax,
and (b) the possibility that supporting commas
may haunt us in a future version, when we try to
implement who-knows-what-new-feature. Think of it
as an uneasy gut feeling. Perhaps I can come up
with more/better reasons over the next few days.
Okay. Back to %STRTOK testing! I've already found
one minor bug...
Logged In: YES
user_id=806493
1) Ok, maybe I was wrong. This is not time to change syntax
of directives parameter pass convention. This would be simple
to remove commas support from source code.
2) What bug did you find? Can you tell me?
Logged In: NO
I'm still looking at your %STRTOK work. Patience please...
Logged In: YES
user_id=806493
Disclaimer: my %strtok is not effective (it always begins
tokenization from string start) and I want to replace it with %
split, which will split string into list of strings at once. And
then it will be availaible to analyse them with syntax,
described in developers forum topic '%ifid an so on'.
Do not you mind, if we move our discussion to the developers
forum also?
Logged In: YES
user_id=804543
I've got working code in my local forked version.