flat assembler
Message board for the users of flat assembler.

Index > Projects and Ideas > fasmg as css preprocsesor

Author
Thread Post new topic Reply to topic
Enko



Joined: 03 Apr 2007
Posts: 676
Location: Mar del Plata
Enko 02 Oct 2017, 16:25
Now that fasmg has support for win,linux and macos... I am wondering how suited is fasmg as css preprocessor?

To generate from this example:
Code:
@macro inline-block(){
    display: inline-block;  
}
.class, .other-class{
    @include inline-block();
    $-blue{
        color: blue;
        .dark{
            color: darkblue;
        }
    }
    &.red{
        color: red;
    }
}    


Something like this output:
Code:
.class, .other-class{
    display: inline-block;
}
.class-blue, .other-class-blue{
    color: blue;
}
.class-blue .dark, .other-class-blue .dark{
    color: darkblue;
}
.class.red, .other-class.red{
    color: red;
}    


The first issue I see is the minus "-" character. Then again, I am horrible at fasm macros.

I think fasmg probably wasn't designed with this in mind but I am curious if its a viable posibility.

Some ideas or advices?

Best regards
Enko
Post 02 Oct 2017, 16:25
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8359
Location: Kraków, Poland
Tomasz Grysztar 02 Oct 2017, 16:46
Enko wrote:
The first issue I see is the minus "-" character. Then again, I am horrible at fasm macros.
This could be handled by MATCH. But the real issue here is that fasmg's source reader strips the ";" characters as comments, so you loose a portion of source text there.

If using modified variant of fasmg is an option to consider, you could tweak fasmg's source so that it would not strip comments. Then the processing you need could be done with "macro ?!".
Post 02 Oct 2017, 16:46
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8359
Location: Kraków, Poland
Tomasz Grysztar 02 Oct 2017, 17:38
With such modification in mind I tried to tweak fasmg source so that it would strip comments not upon reading source text from file, but later when preparing such line to be assembled. This change makes it easier to further tweak the sources so that semicolon-started comments would not be stripped at all, and even opens up a possibility of disabling this at the assembly time with some directive. Unfortunately, this also degrades performance a little bit, so I'm not eager to make it mainstream just for a couple of exotic applications.

Here's the diff of the tweak I made:
Code:
Index: source/assembler.inc
==================================================================
--- source/assembler.inc
+++ source/assembler.inc
@@ -1071,10 +1071,12 @@
        je      convert_name_symbol
        cmp     al,22h
        je      convert_quoted_string
        cmp     al,27h
        je      convert_quoted_string
+       cmp     al,';'
+       je      skip_comment
        stosb
        cmp     al,'`'
        je      convert_parameter
        cmp     al,'\'
        jne     preprocess_line_from_file
@@ -1082,10 +1084,29 @@
        jne     preprocess_line_from_file
        inc     esi
        dec     edi
        inc     [ebx+SourceEntry.number_of_attached_lines]
        jmp     preprocess_line_from_file
+    skip_comment:
+       lodsb
+       test    al,al
+       jz      file_ended
+       cmp     al,0Ah
+       je      line_ended
+       cmp     al,22h
+       je      skip_quoted_string
+       cmp     al,27h
+       je      skip_quoted_string
+       cmp     al,1Ah
+       jne     skip_comment
+       lodsd
+       lea     esi,[esi+eax+8]
+       jmp     skip_comment
+    skip_quoted_string:
+       lodsd
+       add     esi,eax
+       jmp     skip_comment
     convert_quoted_string:
        stosb
        mov     eax,esi
        stosd
        lodsd

Index: source/reader.inc
==================================================================
--- source/reader.inc
+++ source/reader.inc
@@ -246,23 +246,11 @@
        mov     [last_token],0Ah
        cmp     al,0Dh
        je      cr
        cmp     al,0Ah
        je      lf
-       cmp     al,3Bh
-       jne     end_of_file
-    skip_comment:
-       lodsb
-       cmp     al,0Dh
-       je      cr
-       cmp     al,0Ah
-       je      lf
-       cmp     al,1Ah
-       je      end_of_file
-       test    al,al
-       jnz     skip_comment
-    end_of_file:
        xor     al,al
        stosb
        mov     ecx,edi
        mov     eax,[tokenization_buffer]
        sub     ecx,eax

Index: source/tables.inc
==================================================================
--- source/tables.inc
+++ source/tables.inc
@@ -15,14 +15,14 @@
 PREPOSITION_AT = 0
 PREPOSITION_FROM = 1
 PREPOSITION_AS = 2
 PREPOSITION_DUP = 3
 
-control_characters db 0,9,0Ah,0Dh,1Ah,20h,3Bh
+control_characters db 0,9,0Ah,0Dh,1Ah,20h
 .count = $-control_characters
 
-syntactical_characters db '+-/*=<>()[]{}:?!,.|&~#`\'
+syntactical_characters db '+-/*=<>()[]{}:?!,.|&~#`\;'
 .count = $-syntactical_characters
 
 include_variable db 'INCLUDE',0
 
 separating_operators:    
To completely disable the comment stripping, do not apply the patch to "source/assembler.inc".
Post 02 Oct 2017, 17:38
View user's profile Send private message Visit poster's website Reply with quote
Enko



Joined: 03 Apr 2007
Posts: 676
Location: Mar del Plata
Enko 02 Oct 2017, 17:44
In the case of semicolon for the source code, I think it might be optional as the newline should finish the line instruction too. I'll refresh my memory on fasm macros and see what I can come up with.

Thank you for the tips!
Post 02 Oct 2017, 17:44
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.