[Tool/Web/Other] QPreprocessor 1.0.0[experimental release]
#1

What is QPreprocessor?

QPreprocessor is tokeniser and parser which is written for adding new features to Pawn. It supports new features like namespaces. It is currently tested on 37 scripts.

What are the advantages?

At the moment, there are not much advantages. We will explain each advantage in this topic. The list:
Quote:
  • Namespaces are supported.
  • New directives. ( #comment, (in future probably #inc, #dec) )
  • Verbatim strings ( $"" ) (escape "\" character would be treated as "\\") (look verbatim strings in google)
  • Long strings ( [""] ) (doesnt require '\' character every line ending. )
  • String formatting with '+' operator is supported. ( $variableName = "" + "" ... )
  • New constants ( _FILE_, _LINE_, __Q_MAJOR_VERSION__, __Q_MINOR_VERSION__, __Q_BUG__VERSION__ )
  • Open-source
What are the disadvantages?
Quote:
  • A whole new layer for preprocessing unit. That means there would be bugs. It is experimental release for now. Be careful what's happening in the background.
  • Preprocessor will not delete '.qp' file. You may want to see precompiled file. If there is something wrong, you should contact with me.
New Directives

At the moment there is just one new directive. In future, I am planning to add more directives.
Quote:
  • #comment 3rd comment style. Catching this style from another application(like editors) is easier.
New Constants

Quote:
  • __FILE__ The full-path of file. Not only file-name
  • __LINE__ It is clear to understand.
  • __COLUMN__ No usefulness, but exists if you want.
  • __Q_MAJOR_VERSION__ It is clear to understand.
  • __Q_MINOR_VERSION__ It is clear to understand.
  • __Q_BUG_VERSION__ It is clear to understand.
  • Version Definition: (Major).(Minor).(Bug)
Verbatim strings
Quote:
  • Verbatim string starts with "$" character. It equals to @"" in C#.
  • Verbatim strings do not have escape character. It is based on the characters in file. '\' character will be treated as "\\".
  • Multi-line supported without '\'.
  • Every line ends with '\n' automatically. Example:
    $"Hello
    Bro"
    will be translated into "Hello\nBro"
  • $"Hello\nBro" will be translated into "Hello\\nBro"
  • Escaping from double-quote character needs writing it multiple.
    False syntax: $"Hello\"Bro" will be translated into "Hello\\"Bro" and that will cause an error.
    True syntax: $"Hello""Bro" will be translated into "Hello\"Bro" and that will work perfect.
Long strings
Quote:
  • Long string starts with ' [" ' character and ends with ' "] '. It half-equals to "[[ ]]" in Lua.
  • Long strings have escape character. It is regular strings like in pawn.
  • Multi-line supported without '\'.
  • Every line ends with '\n' automatically. Example:
    ["Hello
    Bro"]
    will be translated into "Hello\nBro"
  • ["Hello\nBro"] will be translated into "Hello\nBro"
  • Escaping from double-quote character needs '\' as like in (normal)strings in pawn-self.
    True syntax: ["Hello\"Bro"] will be translated into "Hello\"Bro" and that will work perfect
Formatting strings
Quote:
  • Another great feature is formatting strings with '+' operator.
  • Formatting syntax starts with "$" character.
  • After "$" variable name comes.
    (like: $myformattedstring, also variable must be declared before.
    new myformattedstring[10];
    $myformattedstring=...;
    )
  • You can concat strings now.
  • $myformattedstring = "Hello " + "world";
  • But thats not enough. You can use variables after '+' operator like;
  • $myformattedstring = "Hello " + $pName + ", welcome!";
    $ is important because it points the variable format type is '%s'
    $ points '%s' $stringVariableName
    . points '%d' .integerVariableName
    : points '%f' :floatVariableName
    ~ points '%x' ~hexadecimalVariableName
  • We also know that there is much more format types. Than you can put your type manually:
    $myformattedstring = "Hello, your X pos: " + '0.2f'playerPosX;
    '-format type-'variable name (Note: Do not use '%' character in manuel format type.)
  • You have to use this formatting alone. You cant use like SendClientMessageToAll(0, $var=...);
  • Here is example:
Code:
new str[256];
new str2[256];
$str = "hello" + " world";
new numb = 5;
new Float:flo = 45.0;
$str2 = "Str 1 contains:" + $str + " and a number: "
   + .numb + " and a float: " + :flo
   + " and now manuel flo: " + '0.2f'flo;
printf("%s", str2);
It will automatically turns into:
Code:
new str [256];
new str2 [256];
format(str, sizeof(str), "hello world",0);
new numb =5;
new Float:flo =45.0;
format(str2, sizeof(str2), "Str 1 contains:%s and a number: %d and a float: %f and now manuel flo: %0.2f",str,numb,flo,flo,0);
printf("%s",str2);
NAMESPACES!
Quote:
  • The great functionality in this preprocessor is namespaces.
  • namespace namespace_name { ... }
  • Variables not supported yet.
  • Stock functions are supported.
  • Forward&Public is not supported due to CallRemoteFunction
  • Every namespace is turned into prefix by Q.
  • To save from length(because pawns function name limit is 31), namespaces has id.
  • Namespaces has currently 3 functions automatically.
    ns_id Returns id of namespace.
    ns_name Returns name of namespace
    ns_prefix Returns prefix of namespace. It is ("n" + ns_id + "_") (n0_, n01_, ...)
  • Examples: n0_functionName, n0_getMe, n1_GetLol

    Code:
    namespace out {
    	stock println () {
    	    printf("Namespace id: %d, name: %s, prefix: %s" , ::ns_id(), ::ns_name(), ::ns_prefix());
    	    print($"System.
    	        Out.println");
    		print(["System.
    		    out.println"]);
    		new str[256];
    		new str2[256];
    		$str = "hello" + " world";
    		new numb = 5;
    		new Float:flo = 45.0;
    		$str2 = "Str 1 contains:" + $str + " and a number: "
    		   + .numb + " and a float: " + :flo
    		   + " and now manuel flo: " + '0.2f'flo;
    		printf("%s", str2);
    	}
    }
    /* as you can see namespaces can be divided aparts */
    namespace out {
    	stock println2() {
    	    print("System.out.println2\n");
    	}
    }
    
    namespace bb2 {
    	stock println3() {
    	    print("System.out.println3\n");
    	}
    }
    Q will compile it like that:
    Code:
    stock n0_ns_id() { return 0; }
    stock n0_ns_prefix() { new _prefix[10]="n0_"; return _prefix; }
    stock n0_ns_name() { new _name[64]="out"; return _name; }
    
    stock  n0_println(){
        printf("Namespace id: %d, name: %s, prefix: %s", n0_ns_id(), n0_ns_name(), n0_ns_prefix());
        print(
        "System.\n	        Out.println");
        print(
        "System.\n		    out.println");
        new str [256];
        new str2 [256];
        format(str, sizeof(str), "hello world",0);
        new numb =5;
        new Float:flo =45.0;
        format(str2, sizeof(str2), "Str 1 contains:%s and a number: %d and a float: %f and now manuel flo: %0.2f",str,numb,flo,flo,0);
        printf("%s",str2);
    }
    
    
    stock  n0_println2(){
        print("System.out.println2\n");
    }
    
    stock n1_ns_id() { return 1; }
    stock n1_ns_prefix() { new _prefix[10]="n1_"; return _prefix; }
    stock n1_ns_name() { new _name[64]="bb2"; return _name; }
    
    stock  n1_println3(){
        print("System.out.println3\n");
    }
  • If you want to call namespace function in same namespace you have to add '::' operator beggining of the function.
    Like
    Code:
    ::println3()
  • If you want to call namespace function outside namespace you have to add '(namespace_name)::' operator beggining of the function.
    Like
    Code:
    out::println3()
INSTALLATION:
  • Download '.zip' package. If you want to compile yourself, you have to install MinGW.
  • Otherwise copy '.zip/pawno' folder contents into 'your server/pawno'

Download:

Source + Binary
Reply
#2

What's the advantage of using this? And what exactly does this do?
Reply
#3

Does this compile the script or what does it do, lol ?
Reply
#4

Quote:
Originally Posted by Abagail
View Post
What's the advantage of using this? And what exactly does this do?
It is written in first message.

@Ahmad: It is preprocessor. Means, It pre-compiles your script and then compiles it with pawncc.exe.
Basically think like that:

Code:
#define A 5
A
Pawn preprocessor changes A to 5.

Code:
namespace a {
stock b() { }
}
a::b();
Q preprocessor changes namespace a to n0_ and a::b to n0_b();

It is expression-replacer , adds new features to Pawn scripts.
Reply
#5

Very nice! Do you plan on adding more OOP features such as classes, objects, and methods?
Reply
#6

What the Q stands for ?
Reply
#7

I love the new formatting :3, using format is so annoying lol.

1 question though:

What if you have a bunch of formats in your script, and a bunch of the stuff you can do with your preprocessor to format, will it work fine?
Reply
#8

Quote:
Originally Posted by Chaser98
View Post
Very nice! Do you plan on adding more OOP features such as classes, objects, and methods?
Of course, QLexicalAnalyzer can recognize classes and methods. I haven't add them into QParser yet.

Quote:
Originally Posted by Kaperstone
View Post
What the Q stands for ?
Nothing, I just love Q prefix.

Quote:
Originally Posted by Smileys
View Post
I love the new formatting :3, using format is so annoying lol.

1 question though:

What if you have a bunch of formats in your script, and a bunch of the stuff you can do with your preprocessor to format, will it work fine?
I didn't get your question well but probably the answer is "Yes, it will work fine." Can you give me an example?
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)