rollnw.script
- class rollnw.script.AssignExpression
Assignment operation expression
- lhs: VariableExpression | DotExpression
Expression being assigned to. Note that in a simple language like NWScript this can only be a variable expression or a dot expression (i.e. assigning a struct member)
- rhs: Expression
The expression being assigned
- class rollnw.script.Ast
Class containing a parsed ast
- __getitem__(index: int) Declaration
Gets a toplevel declaration
- __iter__() Iterator[Declaration]
Gets an iterator of toplevel declarations
- __len__() int
Gets number of toplevel declarations
- defines: dict[str, str]
Defines from
#define
directive. Only used in command script, i.e. nwscript.nss
- find_comment(line) str
Finds first comment that the source range of which ends on
line
orline
- 1
- class rollnw.script.AstNode
Base Ast Node class
- class rollnw.script.BinaryExpression
Binary operation expression
- lhs: Expression
Lefthand side of the binary expression
- rhs: Expression
Righthand side of the binary expression
- class rollnw.script.BlockStatement
Block statement
- range
Range in source code
- Type:
- __len__() int
Gets the number of statements
- class rollnw.script.CallExpression
Call operation expression
- __getitem__(idx: int) Expression
Gets an argument
- __iter__() Iterator[Expression]
Gets iterator of arguments
- __len__() int
Gets the number of arguments
- expr: Expression
The expression prior to
(...)
- class rollnw.script.ComparisonExpression
Comparison operation expression
- lhs: Expression
Lefthand side of the Comparison expression
- rhs: Expression
Righthand side of the Comparison expression
- class rollnw.script.ConditionalExpression
Conditional operation expression
- test: Expression
The expression that is tested
- class rollnw.script.Context(include_paths: List[str] = [], command_script: str = 'nwscript')
Provides a context for parsing a NWScript file
Every context contains its own resource manager that has as a parent the global resource manager. Ultimately, this will be changed to each context having its own unique resource manager.
- Parameters:
include_paths ([str], optional) – A list of include paths to load into internal resource manager. Default:
[]
.command_script (str, optional) – Command script to load. Default: “nwscript”.
- __init__(include_paths: List[str] = [], command_script: str = 'nwscript')
- add_include_path(path: str)
Adds path to internal resman
- class rollnw.script.DeclList
- __getitem__(idx: int) Declaration
Gets a declaration
- __iter__() Iterator[Declaration]
Gets iterator of statements
- __len__() int
Gets the number of declarations
- class rollnw.script.Declaration
Base Declaration class type
- identifier() str
Get declaration identifier
- class rollnw.script.Diagnostic
Information for a script diagnostic
- location: SourceRange
Source range in script
- message: str
A helpful message
- script: str
Name of script
- severity: DiagnosticSeverity
The severity of the diagnostic
- type: DiagnosticType
The type of the diagnostic
- enum rollnw.script.DiagnosticSeverity(value)
- Member Type:
int
Valid values are as follows:
- error = <DiagnosticSeverity.error: 1>
- hint = <DiagnosticSeverity.hint: 2>
- information = <DiagnosticSeverity.information: 3>
- warning = <DiagnosticSeverity.warning: 4>
- enum rollnw.script.DiagnosticType(value)
- Member Type:
int
Valid values are as follows:
- lexical = <DiagnosticType.lexical: 1>
- parse = <DiagnosticType.parse: 2>
- semantic = <DiagnosticType.semantic: 3>
- class rollnw.script.DoStatement
Do statement
- block: BlockStatement
The do block statement
- test: Expression
The test at the end of the block
- class rollnw.script.DotExpression
Dot operation expression
- lhs: VariableExpression | CallExpression
In NWScript the only two possible expressions on the left hand of the dot are var_expr.var_expr or call_expr.var_expr
- rhs: VariableExpression
The right hand side of a dot operator
- class rollnw.script.EmptyExpression
Empty expression only used in case of expression parsing erros
- class rollnw.script.EmptyStatement
Empty statement
- class rollnw.script.ExprStatement
Expression statement
- expr: Expression
An expression
- class rollnw.script.Expression
Base Expression AST node
- class rollnw.script.ForStatement
For statement
- increment: Expression | None
An optional increment expression
- init: AstNode | None
An optional initialization. Normally this is a Declaration or just an expression
- test: Expression | None
An optional expression that determines if the loop is to continue
- class rollnw.script.FunctionDecl
Function declaration
- __getitem__(idx: int) Declaration
Gets a parameter
- __iter__() Iterator[Declaration]
Gets iterator of parameters
- __len__() int
Gets the number of parameters
- class rollnw.script.FunctionDefinition
Function definition
- block: BlockStatement
Block of the function
- decl: FunctionDecl
Declaration of the function definition
- class rollnw.script.GroupingExpression
Grouping operation expression
- expr: Expression
Expression contained in the grouping parenthesis.
- class rollnw.script.IfStatement
If statement
- test: Expression
The expression that is tested
- class rollnw.script.Include
Abstracts a script include
- location: SourceRange
Source range in script
- resref: str
Resref of included script
- used: int
Number of times include is used in script file
- class rollnw.script.InlayHint
An inlay source code hint for an LSP
- message: str
Helpful message to display inline or a type, etc.
- position: SourcePosition
The postion where the hint should be displayed
- class rollnw.script.JumpStatement
Jump statement
- expr: Expression | None
Optional expression when returning a value
- class rollnw.script.LabelStatement
Label statement
- expr: Expression | None
Expression when label is a
case
.
- class rollnw.script.LiteralExpression
Literal expression
- class rollnw.script.LiteralVectorExpression
Literal vector expression
- class rollnw.script.LogicalExpression
Logical operation expression
- lhs: Expression
Lefthand side of the logical expression
- rhs: Expression
Righthand side of the logical expression
- class rollnw.script.Nss(path: str, ctx: Context, is_command_script: bool = False)
Implementation of nwscript
- complete(needle: str) List[Symbol]
Generates a list of potential completions (excluding dependencies)
- complete_at(needle: str, line: int, character: int) List[Symbol]
Get all completions (including dependencies)
- complete_dot(needle: str, line: int, character: int) List[Symbol]
Get all completions for struct fields
- diagnostics() List[Diagnostic]
- errors() int
Gets number of errors encountered while parsing
- static from_string(string: str, ctx: Context, is_command_script: bool = False) Nss
Loads Nss from string
- locate_export(is_type: bool, search_dependencies: bool = False) Symbol
Locate export, i.e. a top level symbols
- name() str
Gets script’s name
- parse()
Parses the script
- process_includes()
Process includes and dependencies
- resolve()
Resolves and type-checks Ast
- signature_help(line: int, character: int) SignatureHelp
Gets signature help for a call expression that contains the provided position
- view_from_range(range: SourceRange) str
Gets string view of the source at
range
- warnings() int
Gets number of errors encountered while parsing
- class rollnw.script.NssLexer(script: str)
A nwscript lexer
- __init__(script: str)
Constructs lexer from a string
- current()
Gets next token
- next()
Gets next token
- class rollnw.script.NssToken
Nss token
- loc: SourceLocation
The location of the token in a source file
- type: NssTokenType
The type of the token
- enum rollnw.script.NssTokenType(value)
- Member Type:
int
Valid values are as follows:
- INVALID = <NssTokenType.INVALID: 1>
- END = <NssTokenType.END: 2>
- IDENTIFIER = <NssTokenType.IDENTIFIER: 3>
- LPAREN = <NssTokenType.LPAREN: 4>
- RPAREN = <NssTokenType.RPAREN: 5>
- LBRACE = <NssTokenType.LBRACE: 6>
- RBRACE = <NssTokenType.RBRACE: 7>
- LBRACKET = <NssTokenType.LBRACKET: 8>
- RBRACKET = <NssTokenType.RBRACKET: 9>
- COMMA = <NssTokenType.COMMA: 10>
- COLON = <NssTokenType.COLON: 11>
- QUESTION = <NssTokenType.QUESTION: 12>
- SEMICOLON = <NssTokenType.SEMICOLON: 13>
- POUND = <NssTokenType.POUND: 14>
- DOT = <NssTokenType.DOT: 15>
- AND = <NssTokenType.AND: 16>
- ANDAND = <NssTokenType.ANDAND: 17>
- ANDEQ = <NssTokenType.ANDEQ: 18>
- DIV = <NssTokenType.DIV: 19>
- DIVEQ = <NssTokenType.DIVEQ: 20>
- EQ = <NssTokenType.EQ: 21>
- EQEQ = <NssTokenType.EQEQ: 22>
- GT = <NssTokenType.GT: 23>
- GTEQ = <NssTokenType.GTEQ: 24>
- LT = <NssTokenType.LT: 25>
- LTEQ = <NssTokenType.LTEQ: 26>
- MINUS = <NssTokenType.MINUS: 27>
- MINUSEQ = <NssTokenType.MINUSEQ: 28>
- MINUSMINUS = <NssTokenType.MINUSMINUS: 29>
- MOD = <NssTokenType.MOD: 30>
- MODEQ = <NssTokenType.MODEQ: 31>
- TIMES = <NssTokenType.TIMES: 32>
- TIMESEQ = <NssTokenType.TIMESEQ: 33>
- NOT = <NssTokenType.NOT: 34>
- NOTEQ = <NssTokenType.NOTEQ: 35>
- OR = <NssTokenType.OR: 36>
- OREQ = <NssTokenType.OREQ: 37>
- OROR = <NssTokenType.OROR: 38>
- PLUS = <NssTokenType.PLUS: 39>
- PLUSEQ = <NssTokenType.PLUSEQ: 40>
- PLUSPLUS = <NssTokenType.PLUSPLUS: 41>
- SL = <NssTokenType.SL: 42>
- SLEQ = <NssTokenType.SLEQ: 43>
- SR = <NssTokenType.SR: 44>
- SREQ = <NssTokenType.SREQ: 45>
- TILDE = <NssTokenType.TILDE: 46>
- USR = <NssTokenType.USR: 47>
- USREQ = <NssTokenType.USREQ: 48>
- XOR = <NssTokenType.XOR: 49>
- XOREQ = <NssTokenType.XOREQ: 50>
- FLOAT_CONST = <NssTokenType.FLOAT_CONST: 51>
- INTEGER_CONST = <NssTokenType.INTEGER_CONST: 52>
- OBJECT_INVALID_CONST = <NssTokenType.OBJECT_INVALID_CONST: 53>
- OBJECT_SELF_CONST = <NssTokenType.OBJECT_SELF_CONST: 54>
- STRING_CONST = <NssTokenType.STRING_CONST: 55>
- STRING_RAW_CONST = <NssTokenType.STRING_RAW_CONST: 56>
- ACTION = <NssTokenType.ACTION: 57>
- BREAK = <NssTokenType.BREAK: 58>
- CASE = <NssTokenType.CASE: 59>
- CASSOWARY = <NssTokenType.CASSOWARY: 60>
- CONST = <NssTokenType.CONST: 61>
- CONTINUE = <NssTokenType.CONTINUE: 62>
- DEFAULT = <NssTokenType.DEFAULT: 63>
- DO = <NssTokenType.DO: 64>
- EFFECT = <NssTokenType.EFFECT: 65>
- ELSE = <NssTokenType.ELSE: 66>
- EVENT = <NssTokenType.EVENT: 67>
- FLOAT = <NssTokenType.FLOAT: 68>
- FOR = <NssTokenType.FOR: 69>
- IF = <NssTokenType.IF: 70>
- INT = <NssTokenType.INT: 71>
- ITEMPROPERTY = <NssTokenType.ITEMPROPERTY: 72>
- JSON = <NssTokenType.JSON: 73>
- LOCATION = <NssTokenType.LOCATION: 74>
- OBJECT = <NssTokenType.OBJECT: 75>
- RETURN = <NssTokenType.RETURN: 76>
- STRING = <NssTokenType.STRING: 77>
- STRUCT = <NssTokenType.STRUCT: 78>
- SQLQUERY = <NssTokenType.SQLQUERY: 79>
- SWITCH = <NssTokenType.SWITCH: 80>
- TALENT = <NssTokenType.TALENT: 81>
- VECTOR = <NssTokenType.VECTOR: 82>
- VOID = <NssTokenType.VOID: 83>
- WHILE = <NssTokenType.WHILE: 84>
- JSON_CONST = <NssTokenType.JSON_CONST: 85>
- LOCATION_INVALID = <NssTokenType.LOCATION_INVALID: 86>
- class rollnw.script.PostfixExpression
Postfix operation expression
- lhs: Expression
Lefthand side of the postfix expression
- class rollnw.script.SignatureHelp
Data required for providing Signature Help in an LSP
- active_param: int
The currently active parameter, i.e. where the cursor is in the parameter
- decl: Declaration
The declaration for
expr
- expr: CallExpression
The current call expression
- class rollnw.script.SourceLocation
Nss source location
- length() int
Length of the source location
- range: SourceRange
Range in source code
- view() str
String view of the location
- class rollnw.script.SourcePosition
Position in source code
- column: int
Starting column
- line: int
Starting line
- class rollnw.script.SourceRange
Range into the source code
- end: SourcePosition
End
- start: SourcePosition
Start
- class rollnw.script.Statement
Base statement class
- class rollnw.script.StructDecl
Struct declaration
- __getitem__(idx: int) Declaration
Gets a struct member declaration
- __iter__() Iterator[Declaration]
Gets iterator of statements
- __len__() int
Gets the number of struct members
- class rollnw.script.SwitchStatement
Switch statement
- block: BlockStatement
The block of labels and stuff
- target: Expression
The target expression for the switch
- class rollnw.script.Symbol
Info regarding a particular symbol somewhere in a source file
- comment: str
Comment associated with the line the symbol is on or the line prior
- decl: Declaration
The declaration of the symbol
- kind: SymbolKind
The symbols kind, for use with an LSP
- type: str
The symbols type as a string
- view: str
A string view of the symbol in source
- enum rollnw.script.SymbolKind(value)
Enum of different symbol kinds
- Member Type:
int
Valid values are as follows:
- variable = <SymbolKind.variable: 1>
- function = <SymbolKind.function: 2>
- type = <SymbolKind.type: 3>
- param = <SymbolKind.param: 4>
- field = <SymbolKind.field: 5>
- class rollnw.script.UnaryExpression
Unary operation expression
- rhs: Expression
Righthand side of the postfix expression
- class rollnw.script.VarDecl
Variable declaration
- init: Expression | None
An optional expression to initialize declaration
- class rollnw.script.VariableExpression
Variable expression
- class rollnw.script.WhileStatement
While statement
- test: Expression
The expression that determines if the loop is to continue