Struct
struct Position
public struct Position {
public let column: Int32
public let fileID: UInt32
public let line: Int32
public init()
public init(fileID: UInt32, line: Int32, column: Int32)
}
Description: Specifies the data structure of location information, including the file ID, line number, and column number.
let column
public let column: Int32
Description: Obtains a column number.
Type: Int32
let fileID
public let fileID: UInt32
Description: Obtains a file ID.
Type: UInt32
let line
public let line: Int32
Description: Obtains a line number.
Type: Int32
init()
public init()
Description: Constructs a default Position instance, in which, the fileID
, line
, and column
member variables are all 0
.
init(UInt32, Int32, Int32)
public init(fileID: UInt32, line: Int32, column: Int32)
Description: Constructs a Position instance.
Parameters:
func dump()
public func dump(): Unit
Description: Print the information of a Position instance.
func isEmpty()
public func isEmpty(): Bool
Description: Checks whether both the line number and column number are 0
.
Returns:
- Bool: true is returned if both the line number and column number are
0
.
operator func !=(Position)
public operator func !=(r: Position): Bool
Description: Checks whether two Position instances are not equal.
Parameters:
- r: Position: the other location instance to be compared with the current location
Returns:
operator func ==(Position)
public operator func ==(r: Position): Bool
Description: Checks whether two Position instances are equal.
Parameters:
- r: Position: the other location instance to be compared with the current location
Returns:
struct Token
public struct Token {
public let kind: TokenKind
public let pos: Position
public let value: String
public var delimiterNum: UInt16 = 1
public init()
public init(kind: TokenKind)
public init(kind: TokenKind, value: String)
}
Description: Specifies lexical unit types.
A lexical unit is the minimum unit of Cangjie source code. A syntax tree node can be generated after syntax parsing performed on a group of valid lexical units.
let kind
public let kind: TokenKind
Description: Obtains the type of a lexical unit. Lexical unit types include keywords, identifiers, operators, and constant values. For details, see TokenKind.
Type: TokenKind
let pos
public let pos: Position
Description: Obtains the location of a lexical unit in source code.
Type: Position
let value
public let value: String
Description: Obtains the literal value of a lexical unit.
Type: String
var delimiterNum
public var delimiterNum: UInt16 = 1
Description: Obtains and sets the '#' quantity in a multi-line string.
Type: UInt16
init()
public init()
Description: Constructs a default Token object, in which, the TokenKind instance is ILLEGAL
, the value
is an empty string, and member variables of the Position instance are all 0.
init(TokenKind)
public init(kind: TokenKind)
Description: Constructs a default Token object based on a lexical unit type.
Parameters:
- kind: TokenKind: type of the lexical unit to be constructed
init(TokenKind, String)
public init(kind: TokenKind, value: String)
Description: Constructs a Token object based on the lexical unit type kind
and lexical unit value value
.
Parameters:
- kind: TokenKind: type of the lexical unit to be constructed
- value: String:
value
value of the lexical unit to be constructed
Throws:
- IllegalArgumentException: If the passed
kind
does not matchvalue
, this exception is thrown.
func addPosition(UInt32, Int32, Int32)
public func addPosition(fileID: UInt32, line: Int32, colum: Int32): Token
Description: Adds the location information of a lexical unit.
Parameters:
- fileID: UInt32: fileID of Token
- line: Int32: number of the line where Token is located
- colum: Int32: number of the column where Token is located
Returns:
func dump()
public func dump(): Unit
Description: Print the information of a Token instance.
operator func !=(Token)
public operator func !=(r: Token): Bool
Description: Checks whether two Token objects are not equal.
Parameters:
Returns:
- Bool: If the type
ID
, value, and location of one lexical unit are different from those of another one, true is returned.
operator func +(Token)
public operator func +(r: Token): Tokens
Description: Obtains a new Tokens instance by adding the current Token instance with another Token instance.
Parameters:
Returns:
operator func +(Tokens)
public operator func +(r: Tokens): Tokens
Description: Obtains a new Tokens instance by adding the current Token instance with a Tokens instance.
Parameters:
Returns:
operator func ==(Token)
public operator func ==(r: Token): Bool
Description: Checks whether two Token objects are equal.
Parameters:
Returns:
- Bool: If the type
ID
, value, and location of one lexical unit are the same as those of another one, true is returned.