mint.lexical handler - Palamecia/mint GitHub Wiki

Module mint.lexical-handler

Description

load mint.lexical-handler

This module provides the LexicalHandler class which provides an interface to parse a mint script and get callbacks on each token.

Enums

LexicalHandler.Token

This enum describes the token types used in the onToken method.

| Constant | Value | Description ||----------|-------|-------------|

| Amp | 49 | The token is a & operator. | | AmpEqual | 63 | The token is a &= operator. | | Assert | 0 | The token is an assert keyword. | | Asterisk | 85 | The token is a * operator. | | AsteriskEqual | 58 | The token is a *= operator. | | Async | 1 | The token is an async keyword. | | At | 41 | The token is a @ operator. | | Await | 2 | The token is an await keyword. | | BackSlash | 43 | The token is a \ operator. | | Break | 3 | The token is a break keyword. | | Caret | 48 | The token is a ^ or xor operator. | | CaretEqual | 65 | The token is a ^= operator. | | Case | 4 | The token is a case keyword. | | Catch | 5 | The token is a catch keyword. | | Class | 6 | The token is a class keyword. | | CloseBrace | 102 | The token is a } operator. | | CloseBracket | 100 | The token is a ] operator. | | CloseBracketEqual | 55 | The token is a ]= operator. | | CloseParenthesis | 98 | The token is a ) operator. | | Colon | 53 | The token is a : operator. | | ColonEqual | 54 | The token is a := operator. | | Comma | 44 | The token is a , operator. | | Comment | 39 | The token is a comment. | | Const | 7 | The token is a const keyword. | | Constant | 32 | The token is a constant value like true, false, null or none. | | Continue | 8 | The token is a continue keyword. | | DblAmp | 46 | The token is a && or and operator. | | DblAsterisk | 95 | The token is a ** operator. | | DblDot | 68 | The token is a .. operator. | | DblEqual | 70 | The token is a == operator. | | DblLeftAngled | 81 | The token is a << operator. | | DblLeftAngledEqual | 61 | The token is a <<= operator. | | DblMinus | 94 | The token is a -- operator. | | DblPipe | 45 | The token is a &#124;&#124; or or operator. | | DblPlus | 93 | The token is a ++ operator. | | DblRightAngled | 82 | The token is a >> operator. | | DblRightAngledEqual | 62 | The token is a >>= operator. | | Def | 9 | The token is a def keyword. | | Default | 10 | The token is a default keyword. | | Defined | 92 | The token is a defined operator. | | Dollar | 40 | The token is a $ operator. | | Dot | 96 | The token is a . operator. | | Elif | 11 | The token is a elif keyword. | | Else | 12 | The token is a else keyword. | | Enum | 13 | The token is a enum keyword. | | Equal | 50 | The token is a = operator. | | EqualColon | 66 | The token is a =: operator. | | EqualRightAngled | 67 | The token is a => operator. | | EqualTilde | 75 | The token is a =~ operator. | | Exclamation | 88 | The token is a ! or not operator. | | ExclamationDblEqual | 73 | The token is a !== operator. | | ExclamationEqual | 72 | The token is a != operator. | | ExclamationTilde | 76 | The token is a !~ operator. | | Exit | 14 | The token is a exit keyword. | | FileEnd | 38 | The token is an end of file. | | Final | 15 | The token is a final keyword. | | For | 16 | The token is a for keyword. | | If | 17 | The token is a if keyword. | | In | 18 | The token is a in keyword. | | Is | 74 | The token is a is operator. | | LeftAngled | 77 | The token is a < operator. | | LeftAngledEqual | 79 | The token is a <= operator. | | Let | 19 | The token is a let keyword. | | Lib | 20 | The token is a lib keyword. | | LineEnd | 37 | The token is a non escaped end of line. | | Load | 21 | The token is a load keyword. | | Membersof | 91 | The token is a membersof operator. | | Minus | 84 | The token is a - operator. | | MinusEqual | 57 | The token is a -= operator. | | ModulePath | 103 | The token is a module path element. | | NoLineEnd | 36 | The token is an escaped end of line. | | Number | 34 | The token is a number. | | OpenBrace | 101 | The token is a { operator. | | OpenBracket | 99 | The token is a [ operator. | | OpenParenthesis | 97 | The token is a ( operator. | | Override | 22 | The token is a override keyword. | | Package | 23 | The token is a package keyword. | | Percent | 87 | The token is a % operator. | | PercentEqual | 60 | The token is a %= operator. | | Pipe | 47 | The token is a &#124; operator. | | PipeEqual | 64 | The token is a &#124;= operator. | | Plus | 83 | The token is a + operator. | | PlusEqual | 56 | The token is a += operator. | | Print | 24 | The token is a print keyword. | | Question | 51 | The token is a ? operator. | | QuestionDot | 52 | The token is a ?. operator. | | Raise | 25 | The token is a raise keyword. | | Regex | 104 | The token is a regular expression literal. | | Return | 26 | The token is a return keyword. | | RightAngled | 78 | The token is a > operator. | | RightAngledEqual | 80 | The token is a >= operator. | | Sharp | 42 | The token is a # operator. | | Slash | 86 | The token is a / operator. | | SlashEqual | 59 | The token is a /= operator. | | String | 33 | The token is a string literal. | | Switch | 27 | The token is a switch keyword. | | Symbol | 35 | The token is a symbol. | | Tilde | 89 | The token is a ~ operator. | | TplDot | 69 | The token is a ... operator. | | TplEqual | 71 | The token is a === operator. | | Try | 28 | The token is a try keyword. | | Typeof | 90 | The token is a typeof operator. | | Var | 31 | The token is a var keyword. | | While | 29 | The token is a while keyword. | | Yield | 30 | The token is a yield keyword. |

Classes

LexicalHandler

This class provides an interface to parse mint scripts using the parse method. Each encountered token will be provided to a callback method like onToken.

Public members

Modifiers Member Description
enum Token This enum describes the token types used in the LexicalHandler.Token.onToken ...
const new Creates a new handler.
onComment The parser calls this method when it has parsed a line of comment. The token ...
onCommentBegin The parser calls this method when it has parsed the begin of a comment. The o...
onCommentEnd The parser calls this method when it has parsed the end of a comment. The offset...
onModulePathToken The parser calls this method when it has parsed an element of a module path. ...
onNewLine The parser calls this method when it is about to parse a new line. The lineNu...
onScriptBegin The parser calls this method when it begin the parsing of the script. The par...
onScriptEnd The parser calls this method when the parsing reach the end of the script. Th...
onSymbolToken The parser calls this method when it has parsed an user defined symbol. The c...
onToken The parser calls this method when it has parsed a token. The type parameter i...
onWhiteSpace The parser calls this method when it has parsed blank characters. The token p...
const parse Parses the script provided by stream. The stream parameter must implement the...

Private members

Modifiers Member Description
final d_ptr Object data.
@ const g_lib Global library handle.

Descriptions

LexicalHandler.Token.Amp

49

The token is a & operator.

LexicalHandler.Token.AmpEqual

63

The token is a &= operator.

LexicalHandler.Token.Assert

0

The token is an assert keyword.

LexicalHandler.Token.Asterisk

85

The token is a * operator.

LexicalHandler.Token.AsteriskEqual

58

The token is a *= operator.

LexicalHandler.Token.Async

1

The token is an async keyword.

LexicalHandler.Token.At

41

The token is a @ operator.

LexicalHandler.Token.Await

2

The token is an await keyword.

LexicalHandler.Token.BackSlash

43

The token is a \ operator.

LexicalHandler.Token.Break

3

The token is a break keyword.

LexicalHandler.Token.Caret

48

The token is a ^ or xor operator.

LexicalHandler.Token.CaretEqual

65

The token is a ^= operator.

LexicalHandler.Token.Case

4

The token is a case keyword.

LexicalHandler.Token.Catch

5

The token is a catch keyword.

LexicalHandler.Token.Class

6

The token is a class keyword.

LexicalHandler.Token.CloseBrace

102

The token is a } operator.

LexicalHandler.Token.CloseBracket

100

The token is a ] operator.

LexicalHandler.Token.CloseBracketEqual

55

The token is a ]= operator.

LexicalHandler.Token.CloseParenthesis

98

The token is a ) operator.

LexicalHandler.Token.Colon

53

The token is a : operator.

LexicalHandler.Token.ColonEqual

54

The token is a := operator.

LexicalHandler.Token.Comma

44

The token is a , operator.

LexicalHandler.Token.Comment

39

The token is a comment.

LexicalHandler.Token.Const

7

The token is a const keyword.

LexicalHandler.Token.Constant

32

The token is a constant value like true, false, null or none.

LexicalHandler.Token.Continue

8

The token is a continue keyword.

LexicalHandler.Token.DblAmp

46

The token is a && or and operator.

LexicalHandler.Token.DblAsterisk

95

The token is a ** operator.

LexicalHandler.Token.DblDot

68

The token is a .. operator.

LexicalHandler.Token.DblEqual

70

The token is a == operator.

LexicalHandler.Token.DblLeftAngled

81

The token is a << operator.

LexicalHandler.Token.DblLeftAngledEqual

61

The token is a <<= operator.

LexicalHandler.Token.DblMinus

94

The token is a -- operator.

LexicalHandler.Token.DblPipe

45

The token is a || or or operator.

LexicalHandler.Token.DblPlus

93

The token is a ++ operator.

LexicalHandler.Token.DblRightAngled

82

The token is a >> operator.

LexicalHandler.Token.DblRightAngledEqual

62

The token is a >>= operator.

LexicalHandler.Token.Def

9

The token is a def keyword.

LexicalHandler.Token.Default

10

The token is a default keyword.

LexicalHandler.Token.Defined

92

The token is a defined operator.

LexicalHandler.Token.Dollar

40

The token is a $ operator.

LexicalHandler.Token.Dot

96

The token is a . operator.

LexicalHandler.Token.Elif

11

The token is a elif keyword.

LexicalHandler.Token.Else

12

The token is a else keyword.

LexicalHandler.Token.Enum

13

The token is a enum keyword.

LexicalHandler.Token.Equal

50

The token is a = operator.

LexicalHandler.Token.EqualColon

66

The token is a =: operator.

LexicalHandler.Token.EqualRightAngled

67

The token is a => operator.

LexicalHandler.Token.EqualTilde

75

The token is a =~ operator.

LexicalHandler.Token.Exclamation

88

The token is a ! or not operator.

LexicalHandler.Token.ExclamationDblEqual

73

The token is a !== operator.

LexicalHandler.Token.ExclamationEqual

72

The token is a != operator.

LexicalHandler.Token.ExclamationTilde

76

The token is a !~ operator.

LexicalHandler.Token.Exit

14

The token is a exit keyword.

LexicalHandler.Token.FileEnd

38

The token is an end of file.

LexicalHandler.Token.Final

15

The token is a final keyword.

LexicalHandler.Token.For

16

The token is a for keyword.

LexicalHandler.Token.If

17

The token is a if keyword.

LexicalHandler.Token.In

18

The token is a in keyword.

LexicalHandler.Token.Is

74

The token is a is operator.

LexicalHandler.Token.LeftAngled

77

The token is a < operator.

LexicalHandler.Token.LeftAngledEqual

79

The token is a <= operator.

LexicalHandler.Token.Let

19

The token is a let keyword.

LexicalHandler.Token.Lib

20

The token is a lib keyword.

LexicalHandler.Token.LineEnd

37

The token is a non escaped end of line.

LexicalHandler.Token.Load

21

The token is a load keyword.

LexicalHandler.Token.Membersof

91

The token is a membersof operator.

LexicalHandler.Token.Minus

84

The token is a - operator.

LexicalHandler.Token.MinusEqual

57

The token is a -= operator.

LexicalHandler.Token.ModulePath

103

The token is a module path element.

LexicalHandler.Token.NoLineEnd

36

The token is an escaped end of line.

LexicalHandler.Token.Number

34

The token is a number.

LexicalHandler.Token.OpenBrace

101

The token is a { operator.

LexicalHandler.Token.OpenBracket

99

The token is a [ operator.

LexicalHandler.Token.OpenParenthesis

97

The token is a ( operator.

LexicalHandler.Token.Override

22

The token is a override keyword.

LexicalHandler.Token.Package

23

The token is a package keyword.

LexicalHandler.Token.Percent

87

The token is a % operator.

LexicalHandler.Token.PercentEqual

60

The token is a %= operator.

LexicalHandler.Token.Pipe

47

The token is a | operator.

LexicalHandler.Token.PipeEqual

64

The token is a |= operator.

LexicalHandler.Token.Plus

83

The token is a + operator.

LexicalHandler.Token.PlusEqual

56

The token is a += operator.

LexicalHandler.Token.Print

24

The token is a print keyword.

LexicalHandler.Token.Question

51

The token is a ? operator.

LexicalHandler.Token.QuestionDot

52

The token is a ?. operator.

LexicalHandler.Token.Raise

25

The token is a raise keyword.

LexicalHandler.Token.Regex

104

The token is a regular expression literal.

LexicalHandler.Token.Return

26

The token is a return keyword.

LexicalHandler.Token.RightAngled

78

The token is a > operator.

LexicalHandler.Token.RightAngledEqual

80

The token is a >= operator.

LexicalHandler.Token.Sharp

42

The token is a # operator.

LexicalHandler.Token.Slash

86

The token is a / operator.

LexicalHandler.Token.SlashEqual

59

The token is a /= operator.

LexicalHandler.Token.String

33

The token is a string literal.

LexicalHandler.Token.Switch

27

The token is a switch keyword.

LexicalHandler.Token.Symbol

35

The token is a symbol.

LexicalHandler.Token.Tilde

89

The token is a ~ operator.

LexicalHandler.Token.TplDot

69

The token is a ... operator.

LexicalHandler.Token.TplEqual

71

The token is a === operator.

LexicalHandler.Token.Try

28

The token is a try keyword.

LexicalHandler.Token.Typeof

90

The token is a typeof operator.

LexicalHandler.Token.Var

31

The token is a var keyword.

LexicalHandler.Token.While

29

The token is a while keyword.

LexicalHandler.Token.Yield

30

The token is a yield keyword.

LexicalHandler.d_ptr

null

Object data.

LexicalHandler.g_lib

lib ('libmint-mint')

Global library handle.

LexicalHandler.new

def (self)

Creates a new handler.

LexicalHandler.onComment

def (self, token, offset)

The parser calls this method when it has parsed a line of comment. The token parameter is a string containing the characters that were read. The offset parameter is the position of the token in the script. If the comment is split into multiple lines, this method is called for each lines of the comment.

If this method returns false the parser stops and reports an error.

LexicalHandler.onCommentBegin

def (self, offset)

The parser calls this method when it has parsed the begin of a comment. The offset parameter is the position of the comment in the script.

If this method returns false the parser stops and reports an error.

LexicalHandler.onCommentEnd

def (self, offset)

The parser calls this method when it has parsed the end of a comment. The offset parameter is the position after the comment in the script.

If this method returns false the parser stops and reports an error.

LexicalHandler.onModulePathToken

def (self, context, token, offset)

The parser calls this method when it has parsed an element of a module path. The context is an array containing the previous elements of the module path as strings and the token parameter is the current element being parsed. The offset parameter is the position of the token in the script.

If this method returns false the parser stops and reports an error.

LexicalHandler.onNewLine

def (self, lineNumber, offset)

The parser calls this method when it is about to parse a new line. The lineNumber parameter is the number of the next line starting from 1. The offset parameter is the position of the new line in the script.

If this method returns false the parser stops and reports an error.

LexicalHandler.onScriptBegin

def (self)

The parser calls this method when it begin the parsing of the script. The parser calls this method just once, after the call to parse, and before any other method in this class are called.

If this method returns false the parser stops and reports an error.

LexicalHandler.onScriptEnd

def (self)

The parser calls this method when the parsing reach the end of the script. The parser calls this method just once and is the last handler function called.

If this method returns false the parser stops and reports an error.

LexicalHandler.onSymbolToken

def (self, context, token, offset)

The parser calls this method when it has parsed an user defined symbol. The context is an array containing the path to the symbol as strings (e.g. ['System', 'OS'] for System.OS.getType) and the token parameter is the current symbol being parsed. The offset parameter is the position of the token in the script.

If this method returns false the parser stops and reports an error.

def (self, context, offset)

The parser calls this method when it was expecting an user defined symbol but found nothing. The context is an array containing the path to the expected symbol as strings (e.g. ['System', 'OS'] for System.OS.). The offset parameter is the position where the token was expected in the script.

If this method returns false the parser stops and reports an error.

LexicalHandler.onToken

def (self, % type, token, offset)

The parser calls this method when it has parsed a token. The type parameter is a value of Token that provides the type of the token and the token parameter is the string representation of the token. The offset parameter is the position of the token in the script.

If this method returns false the parser stops and reports an error.

LexicalHandler.onWhiteSpace

def (self, token, offset)

The parser calls this method when it has parsed blank characters. The token parameter is a string containing the characters that were read. The offset parameter is the position of the token in the script.

If this method returns false the parser stops and reports an error.

LexicalHandler.parse

def (const self, stream)

Parses the script provided by stream. The stream parameter must implement the read part of the serializer interface and provide a getChar method. Returns true on success; otherwise returns false.