forked from b3log/lute
-
Notifications
You must be signed in to change notification settings - Fork 0
/
lexer.go
36 lines (33 loc) · 1.19 KB
/
lexer.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
// Lute - A structured markdown engine.
// Copyright (c) 2019-present, b3log.org
//
// Lute is licensed under the Mulan PSL v1.
// You can use this software according to the terms and conditions of the Mulan PSL v1.
// You may obtain a copy of Mulan PSL v1 at:
// http://license.coscl.org.cn/MulanPSL
// THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
// PURPOSE.
// See the Mulan PSL v1 for more details.
package lute
// lexer 描述了词法分析器结构。
type lexer struct {
input []byte // 输入的文本字节数组
length int // 输入的文本字节数组的长度
offset int // 当前读取字节位置
ln int // 当前行号
col int // 当前列号
width int // 最新一个 token 的宽度(字节数)
}
// newLexer 创建一个词法分析器。
func newLexer(input []byte) (ret *lexer) {
ret = &lexer{}
ret.input = input
ret.length = len(input)
if 0 < ret.length && itemNewline != ret.input[ret.length-1] {
// 以 \n 结尾预处理
ret.input = append(ret.input, itemNewline)
ret.length++
}
return
}