# XN Syntax ## Comments Comments are single line only prefixed with the pound sign ('#'). ## Rules Rules consists of two parts, a selector, and a block containing statements. A selector is an XPath string surrounded with braces prefixed with a dollar sign. The XPath selects zero or more document nodes which will serve as the context for the statement block. ## Bangs Bangs are function calls combined with a statement block. They are prefixed with an exclaimation mark. A bang function always produces context nodes for the statement block. ## Statement Block A statement block are multiple statements terminated with a semicolon, surrounded by curly braces. ## Statements A statement can be an expression, a function call, a rule or a bang. To note is that a nested rule will use its parents context to refine the selection further. ## Expressions An expression can consist of function calls, operators, strings or numbers. Operators supported: | Operator | Function | |----------|----------------------| | + | addition | | - | subtraction | | * | multiplication | | / | division | | ** | power | | & | bitwise and | | | | bitwise or | | ^ | bitwise exclusive or | | .. | string concatenate | ## Example ``` # Select the RxPdo with Index 0x1600 $("RxPdo/Index[.="#x1600"]/..") { # Function call swap("Entry[3]", "Entry[4]"); # Of that RxPdo, select the 3rd Entry via a nested rule $("Entry[3]") { # This bang has "RxPdo/Index[.="#x1600"]/../Entry[3]" as its context !before("Entry") { # Function call contains an expression, which evaluates here to "!#xFFFF" !add("Index") { text("!"..hexlit(2**16-1)); }; !add("SubIndex") { text("3"); } !add("BitLen") { text("256"); } !add("Name") { text("Test"); } !add("DataType") { text("UINT"); } } } } # One .xn can contain multiple rules $("//Module[@Crc32]") { attr("Crc32", hexlit(crc32())); }; ```