Skip to content

Commit

Permalink
Merge commit '9fa49ff3315987f715ce5666ff979a7742fa8a98'
Browse files Browse the repository at this point in the history
  • Loading branch information
Wilfred committed Feb 15, 2024
2 parents bf04703 + 9fa49ff commit e52849e
Show file tree
Hide file tree
Showing 12 changed files with 448,471 additions and 229,522 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

### Parsing

Updated JavaScript and TypeScript parser.
Updated JavaScript, TypeScript and QML parsers.

## 0.55 (released 1st February 2024)

Expand Down
11 changes: 10 additions & 1 deletion vendored_parsers/tree-sitter-qmljs/examples/Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
GIT = git
GIT_LOG_FLAGS = -p --reverse
QTDECLARATIVE_GIT_ID = 49ec094b7fb1eb6675fdc1db8348409cd3ff8184

.PHONY: all
all: qtdeclarative
Expand All @@ -7,4 +9,11 @@ all: qtdeclarative
qtdeclarative:
[ -d $@ ] || $(GIT) clone git://code.qt.io/qt/qtdeclarative.git $@
$(GIT) -C $@ fetch
$(GIT) -C $@ reset --hard 6ac764a4d9e3bd723e955e8e9d5efd8ef6900214
$(GIT) -C $@ reset --hard $(QTDECLARATIVE_GIT_ID)

.PHONY: review-qtdeclarative
review-qtdeclarative:
$(GIT) -C qtdeclarative log $(GIT_LOG_FLAGS) \
$(QTDECLARATIVE_GIT_ID)..origin/dev \
src/qml/compiler/qqmlirbuilder.cpp \
src/qml/parser
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ qtdeclarative/src/quick/doc/snippets/qml/image-ext.qml
qtdeclarative/tests/auto/qml/debugger/qqmlpreview/data/broken.qml
qtdeclarative/tests/auto/qml/qmlformat/data/settings/Example1.formatted_mac_cr.qml
qtdeclarative/tests/auto/qml/qmllint/data/failure1.qml
qtdeclarative/tests/auto/qml/qqmlecmascript/data/compatibilitySemicolon.qml
qtdeclarative/tests/auto/qml/qqmlecmascript/data/numberParsing_error.1.qml
qtdeclarative/tests/auto/qml/qqmlecmascript/data/numberParsing_error.2.qml
qtdeclarative/tests/auto/qml/qqmlecmascript/data/stringParsing_error.5.qml
Expand All @@ -24,5 +23,9 @@ qtdeclarative/tests/auto/qml/qqmllanguage/data/signal.2.qml
qtdeclarative/tests/auto/qml/qqmllanguage/data/signal.3.qml
qtdeclarative/tests/auto/qml/qqmllanguage/data/signal.5.qml
qtdeclarative/tests/auto/qml/qquickfolderlistmodel/data/dummy.qml
qtdeclarative/tests/auto/qmlls/utils/data/completions/missingRHS.parserfail.qml
qtdeclarative/tests/auto/qmlls/utils/data/completions/missingRHS.qml
qtdeclarative/tests/auto/qmlls/utils/data/emptyFile.qml
qtdeclarative/tests/auto/quick/qquickloader/data/InvalidSourceComponent.qml
qtdeclarative/tests/auto/quickcontrols/controls/data/tst_scrollbar.qml
qtdeclarative/tests/manual/qmllsformatter/test.qml
75 changes: 65 additions & 10 deletions vendored_parsers/tree-sitter-qmljs/grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// https://code.qt.io/cgit/qt/qtdeclarative.git/tree/src/qml/
// compiler/qqmlirbuilder.cpp
// parser/{qqmljs.g,qqmljsast_p.h,qqmljslexer.cpp}
// 6ac764a4d9e3bd723e955e8e9d5efd8ef6900214
// 49ec094b7fb1eb6675fdc1db8348409cd3ff8184

module.exports = grammar(require('tree-sitter-typescript/typescript/grammar'), {
name: 'qmljs',
Expand All @@ -21,6 +21,8 @@ module.exports = grammar(require('tree-sitter-typescript/typescript/grammar'), {
$._ui_script_statement,
$._ui_qualified_id,
$._ui_identifier,
$._ui_simple_qualified_id,
$._ui_reserved_identifier,
]),

conflicts: ($, original) => original.concat([
Expand All @@ -45,7 +47,8 @@ module.exports = grammar(require('tree-sitter-typescript/typescript/grammar'), {
field('name', $.identifier), // PragmaId
optional(seq(
':',
field('value', $.identifier),
// TODO: or insert 'values': (ui_pragma_value_list ..)?
sep1(field('value', choice($.identifier, $.string)), ','),
)),
$._semicolon,
),
Expand All @@ -54,9 +57,8 @@ module.exports = grammar(require('tree-sitter-typescript/typescript/grammar'), {
'import',
field('source', choice(
$.string,
$.identifier,
$.nested_identifier,
)), // ImportId
$._ui_qualified_id,
)), // ImportId: MemberExpression
optional(field('version', $.ui_version_specifier)),
optional(seq(
'as',
Expand Down Expand Up @@ -94,10 +96,7 @@ module.exports = grammar(require('tree-sitter-typescript/typescript/grammar'), {

ui_annotation: $ => seq(
'@',
field('type_name', choice(
$.identifier,
$.nested_identifier,
)), // UiSimpleQualifiedId
field('type_name', $._ui_simple_qualified_id),
field('initializer', $.ui_object_initializer),
),

Expand Down Expand Up @@ -286,7 +285,7 @@ module.exports = grammar(require('tree-sitter-typescript/typescript/grammar'), {

_ui_identifier: $ => choice(
$.identifier,
alias($._reserved_identifier, $.identifier),
alias($._ui_reserved_identifier, $.identifier),
),

ui_nested_identifier: $ => seq(
Expand All @@ -295,6 +294,17 @@ module.exports = grammar(require('tree-sitter-typescript/typescript/grammar'), {
$.identifier,
),

_ui_simple_qualified_id: $ => choice(
$.identifier,
alias($.ui_simple_nested_identifier, $.nested_identifier),
),

ui_simple_nested_identifier: $ => seq(
$._ui_simple_qualified_id,
'.',
$.identifier,
),

// teach JavaScript/TypeScript grammar about QML keywords.
_reserved_identifier: ($, original) => choice(
original,
Expand All @@ -308,6 +318,51 @@ module.exports = grammar(require('tree-sitter-typescript/typescript/grammar'), {
'from',
'of',
),

_ui_reserved_identifier: $ => choice(
// JavaScript:
'get',
'set',
'async',
'static',
'export',
'let',

// TypeScript:
'declare',
'namespace',
'type',
'public',
'private',
'protected',
'override',
'readonly',
'module',
'any',
'number',
'boolean',
'string',
'symbol',
'export',
'object',
// 'new', ('new {}' would conflict at property value position)
'readonly',

// QML (see QmlIdentifier):
'property',
'signal',
'readonly',
'on',
'from',
'of',
'required',
'component',
),

// Patch up JavaScript string rules to support multi-line string literal.
// (See also the change b16c69a70be9 in tree-sitter-javascript.)
unescaped_double_string_fragment: _ => token.immediate(prec(1, /[^"\\]+/)),
unescaped_single_string_fragment: _ => token.immediate(prec(1, /[^'\\]+/)),
},
});

Expand Down
4 changes: 2 additions & 2 deletions vendored_parsers/tree-sitter-qmljs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
},
"devDependencies": {
"tree-sitter-cli": "^0.20.1",
"tree-sitter-javascript": "github:tree-sitter/tree-sitter-javascript#7a29d06274b7cf87d643212a433d970b73969016",
"tree-sitter-typescript": "github:tree-sitter/tree-sitter-typescript#faad9094f4061a43d4e9005439e9e85c6541ebe7"
"tree-sitter-javascript": "0.20.3",
"tree-sitter-typescript": "0.20.5"
},
"tree-sitter": [
{
Expand Down
Loading

0 comments on commit e52849e

Please sign in to comment.