Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
02a9c151
Unverified
Commit
02a9c151
authored
Jan 25, 2023
by
Tae Hyung Kim
Committed by
GitHub
Jan 25, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix lexer issue where select/plural/other/underscores cannot be in identifier names. (#119190)
parent
a45727d8
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
32 additions
and
9 deletions
+32
-9
message_parser.dart
...s/flutter_tools/lib/src/localizations/message_parser.dart
+16
-9
message_parser_test.dart
...flutter_tools/test/general.shard/message_parser_test.dart
+16
-0
No files found.
packages/flutter_tools/lib/src/localizations/message_parser.dart
View file @
02a9c151
...
@@ -158,20 +158,14 @@ RegExp normalString = RegExp(r'[^{}]+');
...
@@ -158,20 +158,14 @@ RegExp normalString = RegExp(r'[^{}]+');
RegExp
brace
=
RegExp
(
r'{|}'
);
RegExp
brace
=
RegExp
(
r'{|}'
);
RegExp
whitespace
=
RegExp
(
r'\s+'
);
RegExp
whitespace
=
RegExp
(
r'\s+'
);
RegExp
pluralKeyword
=
RegExp
(
r'plural'
);
RegExp
selectKeyword
=
RegExp
(
r'select'
);
RegExp
otherKeyword
=
RegExp
(
r'other'
);
RegExp
numeric
=
RegExp
(
r'[0-9]+'
);
RegExp
numeric
=
RegExp
(
r'[0-9]+'
);
RegExp
alphanumeric
=
RegExp
(
r'[a-zA-Z0-9]+'
);
RegExp
alphanumeric
=
RegExp
(
r'[a-zA-Z0-9
|_
]+'
);
RegExp
comma
=
RegExp
(
r','
);
RegExp
comma
=
RegExp
(
r','
);
RegExp
equalSign
=
RegExp
(
r'='
);
RegExp
equalSign
=
RegExp
(
r'='
);
// List of token matchers ordered by precedence
// List of token matchers ordered by precedence
Map
<
ST
,
RegExp
>
matchers
=
<
ST
,
RegExp
>{
Map
<
ST
,
RegExp
>
matchers
=
<
ST
,
RegExp
>{
ST
.
empty
:
whitespace
,
ST
.
empty
:
whitespace
,
ST
.
plural
:
pluralKeyword
,
ST
.
select
:
selectKeyword
,
ST
.
other
:
otherKeyword
,
ST
.
number
:
numeric
,
ST
.
number
:
numeric
,
ST
.
comma
:
comma
,
ST
.
comma
:
comma
,
ST
.
equalSign
:
equalSign
,
ST
.
equalSign
:
equalSign
,
...
@@ -303,12 +297,25 @@ class Parser {
...
@@ -303,12 +297,25 @@ class Parser {
// Do not add whitespace as a token.
// Do not add whitespace as a token.
startIndex
=
match
.
end
;
startIndex
=
match
.
end
;
continue
;
continue
;
}
else
if
(<
ST
>[
ST
.
plural
,
ST
.
select
].
contains
(
matchedType
)
&&
tokens
.
last
.
type
==
ST
.
openBrace
)
{
}
else
if
(<
ST
>[
ST
.
identifier
].
contains
(
matchedType
)
&&
tokens
.
last
.
type
==
ST
.
openBrace
)
{
// Treat
"plural" or "select" as identifier if it comes right after an open brace
.
// Treat
any token as identifier if it comes right after an open brace, whether it's a keyword or not
.
tokens
.
add
(
Node
(
ST
.
identifier
,
startIndex
,
value:
match
.
group
(
0
)));
tokens
.
add
(
Node
(
ST
.
identifier
,
startIndex
,
value:
match
.
group
(
0
)));
startIndex
=
match
.
end
;
startIndex
=
match
.
end
;
continue
;
continue
;
}
else
{
}
else
{
// Handle keywords separately. Otherwise, lexer will assume parts of identifiers may be keywords.
final
String
tokenStr
=
match
.
group
(
0
)!;
switch
(
tokenStr
)
{
case
'plural'
:
matchedType
=
ST
.
plural
;
break
;
case
'select'
:
matchedType
=
ST
.
select
;
break
;
case
'other'
:
matchedType
=
ST
.
other
;
break
;
}
tokens
.
add
(
Node
(
matchedType
!,
startIndex
,
value:
match
.
group
(
0
)));
tokens
.
add
(
Node
(
matchedType
!,
startIndex
,
value:
match
.
group
(
0
)));
startIndex
=
match
.
end
;
startIndex
=
match
.
end
;
continue
;
continue
;
...
...
packages/flutter_tools/test/general.shard/message_parser_test.dart
View file @
02a9c151
...
@@ -226,6 +226,22 @@ void main() {
...
@@ -226,6 +226,22 @@ void main() {
expect
(
tokens
[
5
].
type
,
equals
(
ST
.
identifier
));
expect
(
tokens
[
5
].
type
,
equals
(
ST
.
identifier
));
});
});
testWithoutContext
(
'lexer identifier names can contain underscores'
,
()
{
final
List
<
Node
>
tokens
=
Parser
(
'keywords'
,
'app_en.arb'
,
'{ test_placeholder } { test_select, select, singular{test} other{hmm} }'
).
lexIntoTokens
();
expect
(
tokens
[
1
].
value
,
equals
(
'test_placeholder'
));
expect
(
tokens
[
1
].
type
,
equals
(
ST
.
identifier
));
expect
(
tokens
[
5
].
value
,
equals
(
'test_select'
));
expect
(
tokens
[
5
].
type
,
equals
(
ST
.
identifier
));
});
testWithoutContext
(
'lexer identifier names can contain the strings select or plural'
,
()
{
final
List
<
Node
>
tokens
=
Parser
(
'keywords'
,
'app_en.arb'
,
'{ selectTest } { pluralTest, select, singular{test} other{hmm} }'
).
lexIntoTokens
();
expect
(
tokens
[
1
].
value
,
equals
(
'selectTest'
));
expect
(
tokens
[
1
].
type
,
equals
(
ST
.
identifier
));
expect
(
tokens
[
5
].
value
,
equals
(
'pluralTest'
));
expect
(
tokens
[
5
].
type
,
equals
(
ST
.
identifier
));
});
testWithoutContext
(
'lexer: lexically correct but syntactically incorrect'
,
()
{
testWithoutContext
(
'lexer: lexically correct but syntactically incorrect'
,
()
{
final
List
<
Node
>
tokens
=
Parser
(
final
List
<
Node
>
tokens
=
Parser
(
'syntax'
,
'syntax'
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment