Scripting How-To: Use the slax-doctor script to check for common syntax and programming errors

By Erdem posted 08-07-2015 17:27


Use the slax-doctor Script to Check for Syntax Errors


The slax-doctor script checks SLAX scripts for common syntax and programming errors.
One common problem with writing large SLAX scripts is the difficulty in isolating the location of the inevitable syntax errors. Unterminated comments or strings and other syntax problems tend to cause cascading errors, which do not point clearly to the line where the problem occurred. 
This script helps to locate these types of errors. It is not perfect but it can detect the following problems:


  •     Unterminated comments
  •     Unterminated strings
  •     Lines that lack proper termination
  •     Mixed up parenthesis and curly braces
  •     Missing brackets
  •     Missing parenthesis
  •     Unknown parameters included in template calls
  •     Missing default-less parameters in template calls
  •     Trying to treat template parameters like function arguments
  •     Trying to treat function arguments like template parameters
  •     Missing call statements when redirecting template results to variables
  •     Missing namespaces for <func:function> function names

Script Caveats:


  •     Comment delimiters within quotes will cause false errors
  •     Comment delimiters within comments will cause false errors
  •     Brackets, parenthesis, and braces within quotes will cause false errors
  •     Equal signs within quotes passed as function arguments will cause false errors
  •     More than one single-line comment within a line will cause false errors
  •     Location paths with /* will cause false errors
  •     Parameter checking only works within parenthesis, not using the with statement
  •     Code lines that are split across multiple file lines could cause false errors

To use the script, install it on a JUNOS device which also has the script that you want to check. To run the scrip, enter:


user@JUNOS> op slax-doctor filename problem-script.slax


The slax-doctor script will process the script file line by line, and reports any possible problems it finds.


Minimum JUNOS Version: 9.4.
Latest Script Version: 1.42
SHA-256 Checksum: b165914b2409c6aaa69b3f97a72dd225cdb6c882391ff436ae5f50d31487000e


See the document slax-doctor