Skip to content
⌘ NSIS Forum Archive

NSIS language extension -- BridleNSIS

17 posts

henrikor2#

NSIS language extension -- BridleNSIS

I've created a small language extension for NSIS to make things easier to express and rein in verbosity of NSIS at places.

First public version is available at https://github.com/henrikor2/bridlen...NSIS-0.1.0.exe. Source codes at https://github.com/henrikor2/bridlensis.

Here's an example what you can do with Bridle:


    uninst_exe = ReadRegStr("HKLM", \
"Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_NAME}-" + version, \
"UninstallString")

temp_file = GetTempFileName()

If FileCopy(uninst_exe, temp_file) != 0
Abort("Old version uninstaller not found.")
EndIf

result = ExecWait(temp_file + " /S _?=" + directory)

Delete(temp_file)

If result != 0
Abort("Old version uninstall returned " + result + ".")
EndIf
Any comments and suggestions are more than welcome.

BR,
Henri
Anders#
Interesting!

There is already a similar project @ https://sourceforge.net/projects/nslassembler/ , not sure how they compare.

Maybe you should change the "result != 0" part to "result <> 0" because the NSIS syntax uses ==, != for strings and =, <> for numbers...
henrikor2#
Thanks, I did not know about nsL Assembler project, good tip. Quick analysis: Both seem to have very similar features, nsL being more feature rich at the moment. The biggest difference is I tried to keep Bridle as transparent as possible. You can mix and match vanilla NSIS with Bridle keeping the threshold low for anyone wanting some syntactic sugar for their existing projects. While with nsL you need to use custom syntax throughout the project =rewrite.

Valid point about the integer comparison syntax in the above example. Bridle itself don't evaluate the comparisons but relies on Logic Lib that allows both cases (NSIS has no comparisons per se). "int != int" gives the same result but doesn't look as "pure" if you will.
Anders#
Yes but $0 != 0 and $0 <> 0 is not the same if $0 contains something that is not a valid number (empty string etc)
henrikor2#
Those two functions return 0 for success or 1 for failure so the end result would be still the same. Admittedly I should've used integer comparison for clarity.

Both signed integer and case-insensitive string comparisons are supported. And for unsigned integers, case sensitive strings, and whatnot, you can always stick with the plain NSIS.
Yathosho#
From a quick look at the manual, could you please clarify how CreateFont would work. Do you pass the last three parameters as in the vanilla NSIS command (/ITALIC /UNDERLINE /STRIKE) or without slash?
henrikor2#
Good question. Bridle won't modify the "instruction as function" arguments in any way but passes them as-is, i.e. you need to call:

CreateFont(face_name, ..., "/ITALIC", "/UNDERLINE", "/STRIKE")
If there are some instructions that are mostly used certain way it's pretty easy to add custom convenience functions for them. For example next public version will have custom functions for instructions File, ReserveFile, Rename, and RMDir, possibly some others as well:


If RMDir(pluginsdir) <> 0 ; Bridle syntax
DetailPrint "Error when trying to remove directory $PLUGINSDIR." ; NSIS syntax
...
T.Slappy#
This is definitely a good idea.

nslAssembler is very similar to your language but I think very few people use it.
Classic NSIS syntax is spread-ed wider.
Yathosho#
Sublime Text plugin for BridleNSIS, adding language syntax and command completion



For the moment, you have to set the scope to BridleNSIS by hand (or use the .bridle-nsis file extension)
henrikor2#
For the moment, you have to set the scope to BridleNSIS by hand (or use the .bridle-nsis file extension)
Jan T. Sott, AKA idleberg, I think we can work this out.

I'm proposing to add character 'B' in front of all built-in functions to distinguish them from NSIS native instructions. Now it would be the time since the project is still new to the community. Example:

BFile("autoexec.bat")
Keywords/reserved words should be kept the same however (if, else, etc.).

Please feel free to send me private email if anyone wants to discuss it offline first (see https://github.com/henrikor2).
Yathosho#
Originally Posted by henrikor2 View Post
I'm proposing to add character 'B' in front of all built-in functions to distinguish them from NSIS native instructions
Not sure what to think of that, you think it's necessary? I added a character in the Sublime Text package to make separation easier (see screenshot; PS: I also used the b initially!). Should you decide to go with the a prefix, I'd suggest using a lowercase letter. That should improve legibility and be less confusing for those who already know NSIS syntax (e.g. bFile, bReboot etc.)
henrikor2#
I never thought about editor plugins and if it turns out to be a problem this would be one way to solve it within the language (see Qt). But no, it's not necessary.

Thanks for working with the plugin. I added link to the Bridle manual.
henrikor2#
Version 0.2.0

What's New
  • New convenience functions File, ReserveFile, FileCopy, FileRename, RMDir, DeleteRegKey, GetFullPathName, WordFind(S), and WordReplace(S)
  • Function aliases Delete, Copy, Rename, and RMDir
  • Function FileDelete Optional argument rebootok must be passed as defined in NSIS, e.g. `Delete("file.dat", "/REBOOTOK")`
  • Improved NSIS home directory detection unless specified with command-line argument `-n`
  • Documented BridleNSIS process error codes
  • Showing off more BridleNSIS features in the example script


Fixes
  • Fix `Not` not being a reserved word (may have caused ambiguous syntax and parser errors)
  • Fix `r2` ($R2) not being recognized as a built-in variable
  • Fix function optional arguments when using single-quote strings ('/arg')
  • Fix uninstaller leaving empty paths to registry


Download at https://github.com/henrikor2/bridlen...NSIS-0.2.0.exe.
henrikor2#
Version 0.3.0

What's New
  • BridleNSIS syntax is not allowed inside macros and anything defined inside macros is not visible for BridleNSIS parser
  • New convenience functions for all text and word function headers as defined in NSIS 3.0a2
  • Add support for defining several variables at once (Var a, b, c)
  • Improved syntax checks for function arguments and comparison statements
  • Improved integration with Sublime Text plugin


Fixes
  • Fix parsing LogicLib flag tests if followed by another comparison statement (If ${Errors} Or ...)
  • Fix parsing instruction options starting with slash character (e.g. Var /GLOBAL a)


Download at https://github.com/henrikor2/bridlen...NSIS-0.3.0.exe
henrikor2#
Version 0.3.1

What's New
  • New convenience functions for Push, Pop, Exch, StrCmp and IntCmp
  • New convenience functions for file function headers as defined in NSIS 3.0a2
  • Added Apache Ant task to compile BridleNSIS script installers


henrikor2#
Version 0.4.0

What's New
  • Possibility to call functions ad hoc, without them being introduced. This allows to use BridleNSIS syntax to call functions defined inside macros for example.
  • Added command-line option -d to define NSIS compiler (makensis.exe) work directory.
  • Added new Ant task attributes dir, failonerror, resultproperty, and outfile.


Fixes
  • Fixed overprotective comparison statement parser that caused syntax errors in some cases. Now BridleNSIS won't even try to detect syntax errors in comparison statements but falls back to LogicLib and NSIS compiler.
  • Fixed function MsgBox causing NSIS compile to fail when using three-buttons dialog (YESNOCANCEL or ABORTRETRYIGNOR).


Download at https://github.com/henrikor2/bridlen...NSIS-0.4.0.exe.
henrikor2#
Version 0.4.1

What's New
  • New command-line arguments -q and -v to control output logging.
  • New Apache Ant task argument loglevel=[0-3] to control output logging.
  • Redirect Apache Ant task printout to task logger instead of stdout.


Fixes
  • Fixed Apache Ant task failure when the argument output="path-to-file" file doesn't exist.


Download at https://github.com/henrikor2/bridlen...NSIS-0.4.1.exe.