Skip to content

Commit c88ec01

Browse files
CarlSchwanalecthomas
authored andcommitted
Add QML lexer
1 parent 42e9638 commit c88ec01

File tree

3 files changed

+449
-0
lines changed

3 files changed

+449
-0
lines changed

Diff for: lexers/qml.go

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package lexers
2+
3+
import (
4+
. "github.com/alecthomas/chroma" // nolint
5+
"github.com/alecthomas/chroma/lexers/internal"
6+
)
7+
8+
// Qml lexer.
9+
var Qml = internal.Register(MustNewLexer(
10+
&Config{
11+
Name: "QML",
12+
Aliases: []string{"qml", "qbs"},
13+
Filenames: []string{"*.qml", "*.qbs"},
14+
MimeTypes: []string{"application/x-qml", "application/x-qt.qbs+qml"},
15+
DotAll: true,
16+
},
17+
Rules{
18+
"commentsandwhitespace": {
19+
{`\s+`, Text, nil},
20+
{`<!--`, Comment, nil},
21+
{`//.*?\n`, CommentSingle, nil},
22+
{`/\*.*?\*/`, CommentMultiline, nil},
23+
},
24+
"slashstartsregex": {
25+
Include("commentsandwhitespace"),
26+
{`/(\\.|[^[/\\\n]|\[(\\.|[^\]\\\n])*])+/([gim]+\b|\B)`, LiteralStringRegex, Pop(1)},
27+
{`(?=/)`, Text, Push("#pop", "badregex")},
28+
Default(Pop(1)),
29+
},
30+
"badregex": {
31+
{`\n`, Text, Pop(1)},
32+
},
33+
"root": {
34+
{`^(?=\s|/|<!--)`, Text, Push("slashstartsregex")},
35+
Include("commentsandwhitespace"),
36+
{`\+\+|--|~|&&|\?|:|\|\||\\(?=\n)|(<<|>>>?|==?|!=?|[-<>+*%&|^/])=?`, Operator, Push("slashstartsregex")},
37+
{`[{(\[;,]`, Punctuation, Push("slashstartsregex")},
38+
{`[})\].]`, Punctuation, nil},
39+
{`\bid\s*:\s*[A-Za-z][\w.]*`, KeywordDeclaration, Push("slashstartsregex")},
40+
{`\b[A-Za-z][\w.]*\s*:`, Keyword, Push("slashstartsregex")},
41+
{`(for|in|while|do|break|return|continue|switch|case|default|if|else|throw|try|catch|finally|new|delete|typeof|instanceof|void|this)\b`, Keyword, Push("slashstartsregex")},
42+
{`(var|let|with|function)\b`, KeywordDeclaration, Push("slashstartsregex")},
43+
{`(abstract|boolean|byte|char|class|const|debugger|double|enum|export|extends|final|float|goto|implements|import|int|interface|long|native|package|private|protected|public|short|static|super|synchronized|throws|transient|volatile)\b`, KeywordReserved, nil},
44+
{`(true|false|null|NaN|Infinity|undefined)\b`, KeywordConstant, nil},
45+
{`(Array|Boolean|Date|Error|Function|Math|netscape|Number|Object|Packages|RegExp|String|sun|decodeURI|decodeURIComponent|encodeURI|encodeURIComponent|Error|eval|isFinite|isNaN|parseFloat|parseInt|document|this|window)\b`, NameBuiltin, nil},
46+
{`[$a-zA-Z_]\w*`, NameOther, nil},
47+
{`[0-9][0-9]*\.[0-9]+([eE][0-9]+)?[fd]?`, LiteralNumberFloat, nil},
48+
{`0x[0-9a-fA-F]+`, LiteralNumberHex, nil},
49+
{`[0-9]+`, LiteralNumberInteger, nil},
50+
{`"(\\\\|\\"|[^"])*"`, LiteralStringDouble, nil},
51+
{`'(\\\\|\\'|[^'])*'`, LiteralStringSingle, nil},
52+
},
53+
},
54+
))

Diff for: lexers/testdata/qml.actual

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import QtQuick 2.12
2+
import QtQuick.Controls 2.15 as QQC2
3+
4+
import org.kde.kirigami 2.7 as Kirigami
5+
import org.kde.kcm 1.2
6+
import org.kde.kinfocenter.nic.private 1.0
7+
8+
ScrollViewKCM {
9+
ConfigModule.quickHelp: i18n("Network Information")
10+
clip: true
11+
12+
view: TableView {
13+
id: tableview
14+
clip: true
15+
16+
columnWidthProvider: function (column) {
17+
return tableview.model ? tableview.width / tableview.model.columnCount() : 0
18+
}
19+
20+
model: NetworkModel {
21+
id: model
22+
}
23+
24+
delegate: Rectangle {
25+
readonly property real cellPadding: 8
26+
readonly property color borderColor: Kirigami.Theme.Color
27+
color: row % 2 === 0 ? "transparent" : Kirigami.Theme.alternateBackgroundColor
28+
29+
implicitWidth: tableview.width / tableview.model.columnCount()
30+
implicitHeight: text.contentHeight + Kirigami.Units.largeSpacing
31+
32+
Text {
33+
id: text
34+
text: display
35+
x: Kirigami.Units.smallSpacing
36+
width: parent.width - Kirigami.Units.largeSpacing
37+
height: parent.height
38+
horizontalAlignment: Text.AlignHCenter
39+
verticalAlignment: Text.AlignVCenter
40+
color: "#ff26282a"
41+
wrapMode: Text.WrapAnywhere
42+
}
43+
}
44+
45+
topMargin: headerView.implicitHeight
46+
47+
QQC2.HorizontalHeaderView {
48+
id: headerView
49+
anchors.bottom: parent.top
50+
syncView: tableview
51+
}
52+
}
53+
54+
footer: QQC2.Button {
55+
text: i18nc("Update the information displayed", "Update")
56+
onClicked: model.update();
57+
}
58+
}
59+

0 commit comments

Comments
 (0)