mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
[Gardening] Fix W291 trailing whitespace
This commit is contained in:
@@ -169,7 +169,7 @@ def compare_sizes(old_sizes, new_sizes, name_key, title, total_size_key="",
|
|||||||
|
|
||||||
if total_size_key:
|
if total_size_key:
|
||||||
if csv:
|
if csv:
|
||||||
csv.writerow([title, name_key,
|
csv.writerow([title, name_key,
|
||||||
old_size, old_size * 100.0 / old_total_size,
|
old_size, old_size * 100.0 / old_total_size,
|
||||||
new_size, new_size * 100.0 / new_total_size,
|
new_size, new_size * 100.0 / new_total_size,
|
||||||
perc])
|
perc])
|
||||||
@@ -190,7 +190,7 @@ def compare_sizes(old_sizes, new_sizes, name_key, title, total_size_key="",
|
|||||||
(title, name_key, old_size, new_size, perc))
|
(title, name_key, old_size, new_size, perc))
|
||||||
|
|
||||||
|
|
||||||
def compare_sizes_of_file(old_files, new_files, all_sections, list_categories,
|
def compare_sizes_of_file(old_files, new_files, all_sections, list_categories,
|
||||||
csv=None):
|
csv=None):
|
||||||
old_sizes = collections.defaultdict(int)
|
old_sizes = collections.defaultdict(int)
|
||||||
new_sizes = collections.defaultdict(int)
|
new_sizes = collections.defaultdict(int)
|
||||||
@@ -214,13 +214,13 @@ def compare_sizes_of_file(old_files, new_files, all_sections, list_categories,
|
|||||||
if list_categories:
|
if list_categories:
|
||||||
for cat in categories:
|
for cat in categories:
|
||||||
cat_name = cat[0]
|
cat_name = cat[0]
|
||||||
compare_sizes(old_sizes, new_sizes, cat_name, "", "__text",
|
compare_sizes(old_sizes, new_sizes, cat_name, "", "__text",
|
||||||
csv=csv)
|
csv=csv)
|
||||||
|
|
||||||
if all_sections:
|
if all_sections:
|
||||||
section_title = " section"
|
section_title = " section"
|
||||||
|
|
||||||
compare_sizes(old_sizes, new_sizes, "__textcoal_nt", section_title,
|
compare_sizes(old_sizes, new_sizes, "__textcoal_nt", section_title,
|
||||||
csv=csv)
|
csv=csv)
|
||||||
compare_sizes(old_sizes, new_sizes, "__stubs", section_title, csv=csv)
|
compare_sizes(old_sizes, new_sizes, "__stubs", section_title, csv=csv)
|
||||||
compare_sizes(old_sizes, new_sizes, "__const", section_title, csv=csv)
|
compare_sizes(old_sizes, new_sizes, "__const", section_title, csv=csv)
|
||||||
|
|||||||
@@ -203,7 +203,7 @@ How to specify files:
|
|||||||
if parsed_arguments.sum_sizes:
|
if parsed_arguments.sum_sizes:
|
||||||
compare_sizes_of_file(old_files, new_files,
|
compare_sizes_of_file(old_files, new_files,
|
||||||
parsed_arguments.all_sections,
|
parsed_arguments.all_sections,
|
||||||
parsed_arguments.list_categories,
|
parsed_arguments.list_categories,
|
||||||
csv=csv_out)
|
csv=csv_out)
|
||||||
else:
|
else:
|
||||||
if len(old_files) != len(new_files):
|
if len(old_files) != len(new_files):
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
# utils/update_confusables.py - Utility to update definitions of unicode
|
# utils/update_confusables.py - Utility to update definitions of unicode
|
||||||
# confusables
|
# confusables
|
||||||
#
|
#
|
||||||
# This source file is part of the Swift.org open source project
|
# This source file is part of the Swift.org open source project
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ UID_KEYS = [
|
|||||||
KEY('SourceText', 'key.sourcetext'),
|
KEY('SourceText', 'key.sourcetext'),
|
||||||
KEY('EnableSyntaxMap', 'key.enablesyntaxmap'),
|
KEY('EnableSyntaxMap', 'key.enablesyntaxmap'),
|
||||||
KEY('SyntaxTreeTransferMode', 'key.syntaxtreetransfermode'),
|
KEY('SyntaxTreeTransferMode', 'key.syntaxtreetransfermode'),
|
||||||
KEY('SyntaxTreeSerializationFormat',
|
KEY('SyntaxTreeSerializationFormat',
|
||||||
'key.syntax_tree_serialization_format'),
|
'key.syntax_tree_serialization_format'),
|
||||||
KEY('EnableStructure', 'key.enablesubstructure'),
|
KEY('EnableStructure', 'key.enablesubstructure'),
|
||||||
KEY('Description', 'key.description'),
|
KEY('Description', 'key.description'),
|
||||||
@@ -413,8 +413,8 @@ UID_KINDS = [
|
|||||||
KIND('SyntaxTreeOff', 'source.syntaxtree.transfer.off'),
|
KIND('SyntaxTreeOff', 'source.syntaxtree.transfer.off'),
|
||||||
KIND('SyntaxTreeIncremental', 'source.syntaxtree.transfer.incremental'),
|
KIND('SyntaxTreeIncremental', 'source.syntaxtree.transfer.incremental'),
|
||||||
KIND('SyntaxTreeFull', 'source.syntaxtree.transfer.full'),
|
KIND('SyntaxTreeFull', 'source.syntaxtree.transfer.full'),
|
||||||
KIND('SyntaxTreeSerializationJSON',
|
KIND('SyntaxTreeSerializationJSON',
|
||||||
'source.syntaxtree.serialization.format.json'),
|
'source.syntaxtree.serialization.format.json'),
|
||||||
KIND('SyntaxTreeSerializationByteTree',
|
KIND('SyntaxTreeSerializationByteTree',
|
||||||
'source.syntaxtree.serialization.format.bytetree'),
|
'source.syntaxtree.serialization.format.bytetree'),
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -10,9 +10,9 @@ ATTRIBUTE_NODES = [
|
|||||||
Node('NonEmptyTokenList', kind='SyntaxCollection',
|
Node('NonEmptyTokenList', kind='SyntaxCollection',
|
||||||
element='Token', omit_when_empty=True),
|
element='Token', omit_when_empty=True),
|
||||||
|
|
||||||
# attribute -> '@' identifier '('?
|
# attribute -> '@' identifier '('?
|
||||||
# ( identifier
|
# ( identifier
|
||||||
# | string-literal
|
# | string-literal
|
||||||
# | integer-literal
|
# | integer-literal
|
||||||
# | availability-spec-list
|
# | availability-spec-list
|
||||||
# | specialize-attr-spec-list
|
# | specialize-attr-spec-list
|
||||||
@@ -24,7 +24,7 @@ ATTRIBUTE_NODES = [
|
|||||||
An `@` attribute.
|
An `@` attribute.
|
||||||
''',
|
''',
|
||||||
children=[
|
children=[
|
||||||
Child('AtSignToken', kind='AtSignToken',
|
Child('AtSignToken', kind='AtSignToken',
|
||||||
description='The `@` sign.'),
|
description='The `@` sign.'),
|
||||||
Child('AttributeName', kind='Token', classification='Attribute',
|
Child('AttributeName', kind='Token', classification='Attribute',
|
||||||
description='The name of the attribute.'),
|
description='The name of the attribute.'),
|
||||||
@@ -38,10 +38,10 @@ ATTRIBUTE_NODES = [
|
|||||||
Child('String', kind='StringLiteralToken'),
|
Child('String', kind='StringLiteralToken'),
|
||||||
Child('Integer', kind='IntegerLiteralToken'),
|
Child('Integer', kind='IntegerLiteralToken'),
|
||||||
Child('Availability', kind='AvailabilitySpecList'),
|
Child('Availability', kind='AvailabilitySpecList'),
|
||||||
Child('SpecializeArguments',
|
Child('SpecializeArguments',
|
||||||
kind='SpecializeAttributeSpecList'),
|
kind='SpecializeAttributeSpecList'),
|
||||||
Child('ObjCName', kind='ObjCSelector'),
|
Child('ObjCName', kind='ObjCSelector'),
|
||||||
Child('ImplementsArguments',
|
Child('ImplementsArguments',
|
||||||
kind='ImplementsAttributeArguments'),
|
kind='ImplementsAttributeArguments'),
|
||||||
Child('NamedAttributeString',
|
Child('NamedAttributeString',
|
||||||
kind='NamedAttributeStringArgument'),
|
kind='NamedAttributeStringArgument'),
|
||||||
@@ -64,9 +64,9 @@ ATTRIBUTE_NODES = [
|
|||||||
element='Attribute'),
|
element='Attribute'),
|
||||||
|
|
||||||
# The argument of '@_specialize(...)'
|
# The argument of '@_specialize(...)'
|
||||||
# specialize-attr-spec-list -> labeled-specialize-entry
|
# specialize-attr-spec-list -> labeled-specialize-entry
|
||||||
# specialize-spec-attr-list?
|
# specialize-spec-attr-list?
|
||||||
# | generic-where-clause
|
# | generic-where-clause
|
||||||
# specialize-spec-attr-list?
|
# specialize-spec-attr-list?
|
||||||
Node('SpecializeAttributeSpecList', kind='SyntaxCollection',
|
Node('SpecializeAttributeSpecList', kind='SyntaxCollection',
|
||||||
description='''
|
description='''
|
||||||
@@ -87,11 +87,11 @@ ATTRIBUTE_NODES = [
|
|||||||
''',
|
''',
|
||||||
traits=['WithTrailingComma'],
|
traits=['WithTrailingComma'],
|
||||||
children=[
|
children=[
|
||||||
Child('Label', kind='IdentifierToken',
|
Child('Label', kind='IdentifierToken',
|
||||||
description='The label of the argument'),
|
description='The label of the argument'),
|
||||||
Child('Colon', kind='ColonToken',
|
Child('Colon', kind='ColonToken',
|
||||||
description='The colon separating the label and the value'),
|
description='The colon separating the label and the value'),
|
||||||
Child('Value', kind='Token',
|
Child('Value', kind='Token',
|
||||||
description='The value for this argument'),
|
description='The value for this argument'),
|
||||||
Child('TrailingComma', kind='CommaToken',
|
Child('TrailingComma', kind='CommaToken',
|
||||||
is_optional=True, description='''
|
is_optional=True, description='''
|
||||||
@@ -131,7 +131,7 @@ ATTRIBUTE_NODES = [
|
|||||||
'''),
|
'''),
|
||||||
]),
|
]),
|
||||||
# The argument of '@_implements(...)'
|
# The argument of '@_implements(...)'
|
||||||
# implements-attr-arguments -> simple-type-identifier ','
|
# implements-attr-arguments -> simple-type-identifier ','
|
||||||
# (identifier | operator) decl-name-arguments
|
# (identifier | operator) decl-name-arguments
|
||||||
Node('ImplementsAttributeArguments', kind='Syntax',
|
Node('ImplementsAttributeArguments', kind='Syntax',
|
||||||
description='''
|
description='''
|
||||||
@@ -143,7 +143,7 @@ ATTRIBUTE_NODES = [
|
|||||||
The type for which the method with this attribute \
|
The type for which the method with this attribute \
|
||||||
implements a requirement.
|
implements a requirement.
|
||||||
'''),
|
'''),
|
||||||
Child('Comma', kind='CommaToken',
|
Child('Comma', kind='CommaToken',
|
||||||
description='''
|
description='''
|
||||||
The comma separating the type and method name
|
The comma separating the type and method name
|
||||||
'''),
|
'''),
|
||||||
@@ -154,7 +154,7 @@ ATTRIBUTE_NODES = [
|
|||||||
Child('Identifier', kind='IdentifierToken'),
|
Child('Identifier', kind='IdentifierToken'),
|
||||||
Child('Operator', kind='PrefixOperatorToken'),
|
Child('Operator', kind='PrefixOperatorToken'),
|
||||||
]),
|
]),
|
||||||
Child('DeclNameArguments', kind='DeclNameArguments',
|
Child('DeclNameArguments', kind='DeclNameArguments',
|
||||||
is_optional=True, description='''
|
is_optional=True, description='''
|
||||||
The argument labels of the protocol\'s requirement if it \
|
The argument labels of the protocol\'s requirement if it \
|
||||||
is a function requirement.
|
is a function requirement.
|
||||||
|
|||||||
@@ -3,11 +3,11 @@ from Node import Node # noqa: I201
|
|||||||
|
|
||||||
AVAILABILITY_NODES = [
|
AVAILABILITY_NODES = [
|
||||||
# availability-spec-list -> availability-entry availability-spec-list?
|
# availability-spec-list -> availability-entry availability-spec-list?
|
||||||
Node('AvailabilitySpecList', kind='SyntaxCollection',
|
Node('AvailabilitySpecList', kind='SyntaxCollection',
|
||||||
element='AvailabilityArgument'),
|
element='AvailabilityArgument'),
|
||||||
|
|
||||||
# Wrapper for all the different entries that may occur inside @available
|
# Wrapper for all the different entries that may occur inside @available
|
||||||
# availability-entry -> '*' ','?
|
# availability-entry -> '*' ','?
|
||||||
# | identifier ','?
|
# | identifier ','?
|
||||||
# | availability-version-restriction ','?
|
# | availability-version-restriction ','?
|
||||||
# | availability-versioned-argument ','?
|
# | availability-versioned-argument ','?
|
||||||
@@ -22,11 +22,11 @@ AVAILABILITY_NODES = [
|
|||||||
node_choices=[
|
node_choices=[
|
||||||
Child('Star', kind='SpacedBinaryOperatorToken',
|
Child('Star', kind='SpacedBinaryOperatorToken',
|
||||||
text_choices=['*']),
|
text_choices=['*']),
|
||||||
Child('IdentifierRestriction',
|
Child('IdentifierRestriction',
|
||||||
kind='IdentifierToken'),
|
kind='IdentifierToken'),
|
||||||
Child('AvailabilityVersionRestriction',
|
Child('AvailabilityVersionRestriction',
|
||||||
kind='AvailabilityVersionRestriction'),
|
kind='AvailabilityVersionRestriction'),
|
||||||
Child('AvailabilityLabeledArgument',
|
Child('AvailabilityLabeledArgument',
|
||||||
kind='AvailabilityLabeledArgument'),
|
kind='AvailabilityLabeledArgument'),
|
||||||
]),
|
]),
|
||||||
Child('TrailingComma', kind='CommaToken', is_optional=True,
|
Child('TrailingComma', kind='CommaToken', is_optional=True,
|
||||||
@@ -44,9 +44,9 @@ AVAILABILITY_NODES = [
|
|||||||
a value, e.g. `message: "This has been deprecated"`.
|
a value, e.g. `message: "This has been deprecated"`.
|
||||||
''',
|
''',
|
||||||
children=[
|
children=[
|
||||||
Child('Label', kind='IdentifierToken',
|
Child('Label', kind='IdentifierToken',
|
||||||
description='The label of the argument'),
|
description='The label of the argument'),
|
||||||
Child('Colon', kind='ColonToken',
|
Child('Colon', kind='ColonToken',
|
||||||
description='The colon separating label and value'),
|
description='The colon separating label and value'),
|
||||||
Child('Value', kind='Syntax',
|
Child('Value', kind='Syntax',
|
||||||
node_choices=[
|
node_choices=[
|
||||||
@@ -63,7 +63,7 @@ AVAILABILITY_NODES = [
|
|||||||
certain platform to a version, e.g. `iOS 10` or `swift 3.4`.
|
certain platform to a version, e.g. `iOS 10` or `swift 3.4`.
|
||||||
''',
|
''',
|
||||||
children=[
|
children=[
|
||||||
Child('Platform', kind='IdentifierToken',
|
Child('Platform', kind='IdentifierToken',
|
||||||
classification='Keyword',
|
classification='Keyword',
|
||||||
description='''
|
description='''
|
||||||
The name of the OS on which the availability should be \
|
The name of the OS on which the availability should be \
|
||||||
@@ -73,8 +73,8 @@ AVAILABILITY_NODES = [
|
|||||||
Child('Version', kind='VersionTuple'),
|
Child('Version', kind='VersionTuple'),
|
||||||
]),
|
]),
|
||||||
|
|
||||||
# version-tuple -> integer-literal
|
# version-tuple -> integer-literal
|
||||||
# | float-literal
|
# | float-literal
|
||||||
# | float-literal '.' integer-literal
|
# | float-literal '.' integer-literal
|
||||||
Node('VersionTuple', kind='Syntax',
|
Node('VersionTuple', kind='Syntax',
|
||||||
description='''
|
description='''
|
||||||
@@ -98,7 +98,7 @@ AVAILABILITY_NODES = [
|
|||||||
If the version contains a patch number, the period \
|
If the version contains a patch number, the period \
|
||||||
separating the minor from the patch number.
|
separating the minor from the patch number.
|
||||||
'''),
|
'''),
|
||||||
Child('PatchVersion', kind='IntegerLiteralToken',
|
Child('PatchVersion', kind='IntegerLiteralToken',
|
||||||
is_optional=True, description='''
|
is_optional=True, description='''
|
||||||
The patch version if specified.
|
The patch version if specified.
|
||||||
'''),
|
'''),
|
||||||
|
|||||||
@@ -473,7 +473,7 @@ EXPR_NODES = [
|
|||||||
traits=['Parenthesized'],
|
traits=['Parenthesized'],
|
||||||
children=[
|
children=[
|
||||||
Child('Backslash', kind='BackslashToken'),
|
Child('Backslash', kind='BackslashToken'),
|
||||||
Child('LeftParen', kind='LeftParenToken',
|
Child('LeftParen', kind='LeftParenToken',
|
||||||
classification='StringInterpolationAnchor',
|
classification='StringInterpolationAnchor',
|
||||||
force_classification=True),
|
force_classification=True),
|
||||||
Child('Expression', kind='Expr'),
|
Child('Expression', kind='Expr'),
|
||||||
@@ -500,17 +500,17 @@ EXPR_NODES = [
|
|||||||
Node('KeyPathExpr', kind='Expr',
|
Node('KeyPathExpr', kind='Expr',
|
||||||
children=[
|
children=[
|
||||||
Child('Backslash', kind='BackslashToken'),
|
Child('Backslash', kind='BackslashToken'),
|
||||||
Child('RootExpr', kind='Expr', is_optional=True,
|
Child('RootExpr', kind='Expr', is_optional=True,
|
||||||
node_choices=[
|
node_choices=[
|
||||||
Child('IdentifierExpr', kind='IdentifierExpr'),
|
Child('IdentifierExpr', kind='IdentifierExpr'),
|
||||||
Child('SpecializeExpr', kind='SpecializeExpr')
|
Child('SpecializeExpr', kind='SpecializeExpr')
|
||||||
]),
|
]),
|
||||||
Child('Expression', kind='Expr'),
|
Child('Expression', kind='Expr'),
|
||||||
]),
|
]),
|
||||||
|
|
||||||
# The period in the key path serves as the base on which the
|
# The period in the key path serves as the base on which the
|
||||||
# right-hand-side of the key path is evaluated
|
# right-hand-side of the key path is evaluated
|
||||||
Node('KeyPathBaseExpr', kind='Expr',
|
Node('KeyPathBaseExpr', kind='Expr',
|
||||||
children=[
|
children=[
|
||||||
Child('Period', kind='PeriodToken'),
|
Child('Period', kind='PeriodToken'),
|
||||||
]),
|
]),
|
||||||
|
|||||||
@@ -78,7 +78,7 @@ class Node(object):
|
|||||||
|
|
||||||
def shall_be_omitted_when_empty(self):
|
def shall_be_omitted_when_empty(self):
|
||||||
"""
|
"""
|
||||||
Returns 'True' if this node shall not be created while parsing if it
|
Returns 'True' if this node shall not be created while parsing if it
|
||||||
has no children.
|
has no children.
|
||||||
"""
|
"""
|
||||||
return self.omit_when_empty
|
return self.omit_when_empty
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ class Token(object):
|
|||||||
Represents the specification for a Token in the TokenSyntax file.
|
Represents the specification for a Token in the TokenSyntax file.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, name, kind, serialization_code, unprefixed_kind=None,
|
def __init__(self, name, kind, serialization_code, unprefixed_kind=None,
|
||||||
text=None, classification='None', is_keyword=False):
|
text=None, classification='None', is_keyword=False):
|
||||||
self.name = name
|
self.name = name
|
||||||
self.kind = kind
|
self.kind = kind
|
||||||
@@ -33,10 +33,10 @@ class Keyword(Token):
|
|||||||
Represents a keyword token.
|
Represents a keyword token.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, name, text, serialization_code,
|
def __init__(self, name, text, serialization_code,
|
||||||
classification='Keyword'):
|
classification='Keyword'):
|
||||||
Token.__init__(self, name, 'kw_' + text, serialization_code,
|
Token.__init__(self, name, 'kw_' + text, serialization_code,
|
||||||
unprefixed_kind=text, text=text,
|
unprefixed_kind=text, text=text,
|
||||||
classification=classification, is_keyword=True)
|
classification=classification, is_keyword=True)
|
||||||
|
|
||||||
def macro_name(self):
|
def macro_name(self):
|
||||||
@@ -74,10 +74,10 @@ class SilKeyword(Keyword):
|
|||||||
|
|
||||||
|
|
||||||
class PoundKeyword(Token):
|
class PoundKeyword(Token):
|
||||||
def __init__(self, name, kind, text, serialization_code,
|
def __init__(self, name, kind, text, serialization_code,
|
||||||
classification='Keyword'):
|
classification='Keyword'):
|
||||||
Token.__init__(self, name, 'pound_' + kind, serialization_code,
|
Token.__init__(self, name, 'pound_' + kind, serialization_code,
|
||||||
unprefixed_kind=kind, text=text,
|
unprefixed_kind=kind, text=text,
|
||||||
classification=classification, is_keyword=True)
|
classification=classification, is_keyword=True)
|
||||||
|
|
||||||
def macro_name(self):
|
def macro_name(self):
|
||||||
@@ -85,9 +85,9 @@ class PoundKeyword(Token):
|
|||||||
|
|
||||||
|
|
||||||
class PoundObjectLiteral(PoundKeyword):
|
class PoundObjectLiteral(PoundKeyword):
|
||||||
def __init__(self, name, kind, text, serialization_code, description,
|
def __init__(self, name, kind, text, serialization_code, description,
|
||||||
protocol, classification='ObjectLiteral'):
|
protocol, classification='ObjectLiteral'):
|
||||||
PoundKeyword.__init__(self, name, kind, text, serialization_code,
|
PoundKeyword.__init__(self, name, kind, text, serialization_code,
|
||||||
classification)
|
classification)
|
||||||
self.description = description
|
self.description = description
|
||||||
self.protocol = protocol
|
self.protocol = protocol
|
||||||
@@ -102,9 +102,9 @@ class PoundConfig(PoundKeyword):
|
|||||||
|
|
||||||
|
|
||||||
class PoundDirectiveKeyword(PoundKeyword):
|
class PoundDirectiveKeyword(PoundKeyword):
|
||||||
def __init__(self, name, kind, text, serialization_code,
|
def __init__(self, name, kind, text, serialization_code,
|
||||||
classification='PoundDirectiveKeyword'):
|
classification='PoundDirectiveKeyword'):
|
||||||
PoundKeyword.__init__(self, name, kind, text, serialization_code,
|
PoundKeyword.__init__(self, name, kind, text, serialization_code,
|
||||||
classification)
|
classification)
|
||||||
|
|
||||||
def macro_name(self):
|
def macro_name(self):
|
||||||
@@ -112,9 +112,9 @@ class PoundDirectiveKeyword(PoundKeyword):
|
|||||||
|
|
||||||
|
|
||||||
class PoundConditionalDirectiveKeyword(PoundDirectiveKeyword):
|
class PoundConditionalDirectiveKeyword(PoundDirectiveKeyword):
|
||||||
def __init__(self, name, kind, text, serialization_code,
|
def __init__(self, name, kind, text, serialization_code,
|
||||||
classification='PoundDirectiveKeyword'):
|
classification='PoundDirectiveKeyword'):
|
||||||
PoundKeyword.__init__(self, name, kind, text, serialization_code,
|
PoundKeyword.__init__(self, name, kind, text, serialization_code,
|
||||||
classification)
|
classification)
|
||||||
|
|
||||||
def macro_name(self):
|
def macro_name(self):
|
||||||
@@ -133,7 +133,7 @@ class Literal(Token):
|
|||||||
|
|
||||||
class Misc(Token):
|
class Misc(Token):
|
||||||
def macro_name(self):
|
def macro_name(self):
|
||||||
return "MISC"
|
return "MISC"
|
||||||
|
|
||||||
|
|
||||||
SYNTAX_TOKENS = [
|
SYNTAX_TOKENS = [
|
||||||
@@ -211,56 +211,56 @@ SYNTAX_TOKENS = [
|
|||||||
Punctuator('RightParen', 'r_paren', text=')', serialization_code=89),
|
Punctuator('RightParen', 'r_paren', text=')', serialization_code=89),
|
||||||
Punctuator('LeftBrace', 'l_brace', text='{', serialization_code=90),
|
Punctuator('LeftBrace', 'l_brace', text='{', serialization_code=90),
|
||||||
Punctuator('RightBrace', 'r_brace', text='}', serialization_code=91),
|
Punctuator('RightBrace', 'r_brace', text='}', serialization_code=91),
|
||||||
Punctuator('LeftSquareBracket', 'l_square', text='[',
|
Punctuator('LeftSquareBracket', 'l_square', text='[',
|
||||||
serialization_code=92),
|
serialization_code=92),
|
||||||
Punctuator('RightSquareBracket', 'r_square', text=']',
|
Punctuator('RightSquareBracket', 'r_square', text=']',
|
||||||
serialization_code=93),
|
serialization_code=93),
|
||||||
Punctuator('LeftAngle', 'l_angle', text='<', serialization_code=94),
|
Punctuator('LeftAngle', 'l_angle', text='<', serialization_code=94),
|
||||||
Punctuator('RightAngle', 'r_angle', text='>', serialization_code=95),
|
Punctuator('RightAngle', 'r_angle', text='>', serialization_code=95),
|
||||||
|
|
||||||
Punctuator('Period', 'period', text='.', serialization_code=85),
|
Punctuator('Period', 'period', text='.', serialization_code=85),
|
||||||
Punctuator('PrefixPeriod', 'period_prefix', text='.',
|
Punctuator('PrefixPeriod', 'period_prefix', text='.',
|
||||||
serialization_code=87),
|
serialization_code=87),
|
||||||
Punctuator('Comma', 'comma', text=',', serialization_code=84),
|
Punctuator('Comma', 'comma', text=',', serialization_code=84),
|
||||||
Punctuator('Colon', 'colon', text=':', serialization_code=82),
|
Punctuator('Colon', 'colon', text=':', serialization_code=82),
|
||||||
Punctuator('Semicolon', 'semi', text=';', serialization_code=83),
|
Punctuator('Semicolon', 'semi', text=';', serialization_code=83),
|
||||||
Punctuator('Equal', 'equal', text='=', serialization_code=86),
|
Punctuator('Equal', 'equal', text='=', serialization_code=86),
|
||||||
Punctuator('AtSign', 'at_sign', text='@', classification='Attribute',
|
Punctuator('AtSign', 'at_sign', text='@', classification='Attribute',
|
||||||
serialization_code=80),
|
serialization_code=80),
|
||||||
Punctuator('Pound', 'pound', text='#', serialization_code=81),
|
Punctuator('Pound', 'pound', text='#', serialization_code=81),
|
||||||
|
|
||||||
Punctuator('PrefixAmpersand', 'amp_prefix', text='&',
|
Punctuator('PrefixAmpersand', 'amp_prefix', text='&',
|
||||||
serialization_code=96),
|
serialization_code=96),
|
||||||
Punctuator('Arrow', 'arrow', text='->', serialization_code=78),
|
Punctuator('Arrow', 'arrow', text='->', serialization_code=78),
|
||||||
|
|
||||||
|
|
||||||
Punctuator('Backtick', 'backtick', text='`', serialization_code=79),
|
Punctuator('Backtick', 'backtick', text='`', serialization_code=79),
|
||||||
|
|
||||||
Punctuator('Backslash', 'backslash', text='\\\\', serialization_code=100),
|
Punctuator('Backslash', 'backslash', text='\\\\', serialization_code=100),
|
||||||
|
|
||||||
Punctuator('ExclamationMark', 'exclaim_postfix', text='!',
|
Punctuator('ExclamationMark', 'exclaim_postfix', text='!',
|
||||||
serialization_code=99),
|
serialization_code=99),
|
||||||
|
|
||||||
Punctuator('PostfixQuestionMark', 'question_postfix', text='?',
|
Punctuator('PostfixQuestionMark', 'question_postfix', text='?',
|
||||||
serialization_code=97),
|
serialization_code=97),
|
||||||
Punctuator('InfixQuestionMark', 'question_infix', text='?',
|
Punctuator('InfixQuestionMark', 'question_infix', text='?',
|
||||||
serialization_code=98),
|
serialization_code=98),
|
||||||
|
|
||||||
Punctuator('StringQuote', 'string_quote', text='\\\"',
|
Punctuator('StringQuote', 'string_quote', text='\\\"',
|
||||||
classification='StringLiteral', serialization_code=102),
|
classification='StringLiteral', serialization_code=102),
|
||||||
Punctuator('MultilineStringQuote', 'multiline_string_quote',
|
Punctuator('MultilineStringQuote', 'multiline_string_quote',
|
||||||
text='\\\"\\\"\\\"', classification='StringLiteral',
|
text='\\\"\\\"\\\"', classification='StringLiteral',
|
||||||
serialization_code=103),
|
serialization_code=103),
|
||||||
|
|
||||||
# Keywords prefixed with a '#'.
|
# Keywords prefixed with a '#'.
|
||||||
|
|
||||||
PoundKeyword('PoundKeyPath', 'keyPath', text='#keyPath',
|
PoundKeyword('PoundKeyPath', 'keyPath', text='#keyPath',
|
||||||
serialization_code=74),
|
serialization_code=74),
|
||||||
PoundKeyword('PoundLine', 'line', text='#line',
|
PoundKeyword('PoundLine', 'line', text='#line',
|
||||||
serialization_code=69),
|
serialization_code=69),
|
||||||
PoundKeyword('PoundSelector', 'selector', text='#selector',
|
PoundKeyword('PoundSelector', 'selector', text='#selector',
|
||||||
serialization_code=73),
|
serialization_code=73),
|
||||||
PoundKeyword('PoundFile', 'file', text='#file',
|
PoundKeyword('PoundFile', 'file', text='#file',
|
||||||
serialization_code=68),
|
serialization_code=68),
|
||||||
PoundKeyword('PoundColumn', 'column', text='#column',
|
PoundKeyword('PoundColumn', 'column', text='#column',
|
||||||
serialization_code=70),
|
serialization_code=70),
|
||||||
@@ -273,60 +273,60 @@ SYNTAX_TOKENS = [
|
|||||||
|
|
||||||
PoundDirectiveKeyword('PoundSourceLocation', 'sourceLocation',
|
PoundDirectiveKeyword('PoundSourceLocation', 'sourceLocation',
|
||||||
text='#sourceLocation', serialization_code=65),
|
text='#sourceLocation', serialization_code=65),
|
||||||
PoundDirectiveKeyword('PoundWarning', 'warning', text='#warning',
|
PoundDirectiveKeyword('PoundWarning', 'warning', text='#warning',
|
||||||
serialization_code=66),
|
serialization_code=66),
|
||||||
PoundDirectiveKeyword('PoundError', 'error', text='#error',
|
PoundDirectiveKeyword('PoundError', 'error', text='#error',
|
||||||
serialization_code=67),
|
serialization_code=67),
|
||||||
|
|
||||||
PoundConditionalDirectiveKeyword('PoundIf', 'if', text='#if',
|
PoundConditionalDirectiveKeyword('PoundIf', 'if', text='#if',
|
||||||
serialization_code=64),
|
serialization_code=64),
|
||||||
PoundConditionalDirectiveKeyword('PoundElse', 'else', text='#else',
|
PoundConditionalDirectiveKeyword('PoundElse', 'else', text='#else',
|
||||||
serialization_code=62),
|
serialization_code=62),
|
||||||
PoundConditionalDirectiveKeyword('PoundElseif', 'elseif',
|
PoundConditionalDirectiveKeyword('PoundElseif', 'elseif',
|
||||||
text='#elseif', serialization_code=63),
|
text='#elseif', serialization_code=63),
|
||||||
PoundConditionalDirectiveKeyword('PoundEndif', 'endif',
|
PoundConditionalDirectiveKeyword('PoundEndif', 'endif',
|
||||||
text='#endif', serialization_code=61),
|
text='#endif', serialization_code=61),
|
||||||
|
|
||||||
PoundConfig('PoundAvailable', 'available', text='#available',
|
PoundConfig('PoundAvailable', 'available', text='#available',
|
||||||
serialization_code=60),
|
serialization_code=60),
|
||||||
|
|
||||||
PoundObjectLiteral('PoundFileLiteral', 'fileLiteral',
|
PoundObjectLiteral('PoundFileLiteral', 'fileLiteral',
|
||||||
text='#fileLiteral', serialization_code=76,
|
text='#fileLiteral', serialization_code=76,
|
||||||
description='file reference',
|
description='file reference',
|
||||||
protocol='ExpressibleByFileReferenceLiteral'),
|
protocol='ExpressibleByFileReferenceLiteral'),
|
||||||
PoundObjectLiteral('PoundImageLiteral', 'imageLiteral',
|
PoundObjectLiteral('PoundImageLiteral', 'imageLiteral',
|
||||||
text='#imageLiteral', serialization_code=77,
|
text='#imageLiteral', serialization_code=77,
|
||||||
description='image',
|
description='image',
|
||||||
protocol='ExpressibleByImageLiteral'),
|
protocol='ExpressibleByImageLiteral'),
|
||||||
PoundObjectLiteral('PoundColorLiteral', 'colorLiteral',
|
PoundObjectLiteral('PoundColorLiteral', 'colorLiteral',
|
||||||
text='#colorLiteral', serialization_code=75,
|
text='#colorLiteral', serialization_code=75,
|
||||||
description='color',
|
description='color',
|
||||||
protocol='ExpressibleByColorLiteral'),
|
protocol='ExpressibleByColorLiteral'),
|
||||||
|
|
||||||
Literal('IntegerLiteral', 'integer_literal',
|
Literal('IntegerLiteral', 'integer_literal',
|
||||||
classification='IntegerLiteral', serialization_code=111),
|
classification='IntegerLiteral', serialization_code=111),
|
||||||
Literal('FloatingLiteral', 'floating_literal',
|
Literal('FloatingLiteral', 'floating_literal',
|
||||||
classification='FloatingLiteral', serialization_code=112),
|
classification='FloatingLiteral', serialization_code=112),
|
||||||
Literal('StringLiteral', 'string_literal',
|
Literal('StringLiteral', 'string_literal',
|
||||||
classification='StringLiteral', serialization_code=113),
|
classification='StringLiteral', serialization_code=113),
|
||||||
|
|
||||||
Misc('Unknown', 'unknown', serialization_code=115),
|
Misc('Unknown', 'unknown', serialization_code=115),
|
||||||
Misc('Identifier', 'identifier', classification=None,
|
Misc('Identifier', 'identifier', classification=None,
|
||||||
serialization_code=105),
|
serialization_code=105),
|
||||||
Misc('UnspacedBinaryOperator', 'oper_binary_unspaced',
|
Misc('UnspacedBinaryOperator', 'oper_binary_unspaced',
|
||||||
serialization_code=107),
|
serialization_code=107),
|
||||||
Misc('SpacedBinaryOperator', 'oper_binary_spaced', serialization_code=108),
|
Misc('SpacedBinaryOperator', 'oper_binary_spaced', serialization_code=108),
|
||||||
Misc('PostfixOperator', 'oper_postfix', serialization_code=110),
|
Misc('PostfixOperator', 'oper_postfix', serialization_code=110),
|
||||||
Misc('PrefixOperator', 'oper_prefix', serialization_code=109),
|
Misc('PrefixOperator', 'oper_prefix', serialization_code=109),
|
||||||
Misc('DollarIdentifier', 'dollarident', classification='DollarIdentifier',
|
Misc('DollarIdentifier', 'dollarident', classification='DollarIdentifier',
|
||||||
serialization_code=106),
|
serialization_code=106),
|
||||||
|
|
||||||
Misc('ContextualKeyword', 'contextual_keyword', classification='Keyword',
|
Misc('ContextualKeyword', 'contextual_keyword', classification='Keyword',
|
||||||
serialization_code=114),
|
serialization_code=114),
|
||||||
Misc('StringSegment', 'string_segment', classification='StringLiteral',
|
Misc('StringSegment', 'string_segment', classification='StringLiteral',
|
||||||
serialization_code=104),
|
serialization_code=104),
|
||||||
Misc('StringInterpolationAnchor', 'string_interpolation_anchor',
|
Misc('StringInterpolationAnchor', 'string_interpolation_anchor',
|
||||||
text=')', classification='StringInterpolationAnchor',
|
text=')', classification='StringInterpolationAnchor',
|
||||||
serialization_code=101),
|
serialization_code=101),
|
||||||
Misc('Yield', 'kw_yield', serialization_code=116, text='yield'),
|
Misc('Yield', 'kw_yield', serialization_code=116, text='yield'),
|
||||||
|
|
||||||
@@ -339,7 +339,7 @@ def verify_no_duplicate_serialization_codes(tokens):
|
|||||||
used_codes = set()
|
used_codes = set()
|
||||||
for token in tokens:
|
for token in tokens:
|
||||||
if token.serialization_code in used_codes:
|
if token.serialization_code in used_codes:
|
||||||
error("Serialization code %d used twice for tokens" %
|
error("Serialization code %d used twice for tokens" %
|
||||||
token.serialization_code)
|
token.serialization_code)
|
||||||
used_codes.add(token.serialization_code)
|
used_codes.add(token.serialization_code)
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ from kinds import lowercase_first_word
|
|||||||
|
|
||||||
|
|
||||||
class Trivia(object):
|
class Trivia(object):
|
||||||
def __init__(self, name, comment, serialization_code, characters=[],
|
def __init__(self, name, comment, serialization_code, characters=[],
|
||||||
swift_characters=[], is_new_line=False, is_comment=False):
|
swift_characters=[], is_new_line=False, is_comment=False):
|
||||||
self.name = name
|
self.name = name
|
||||||
self.comment = comment
|
self.comment = comment
|
||||||
@@ -27,12 +27,12 @@ class Trivia(object):
|
|||||||
|
|
||||||
|
|
||||||
TRIVIAS = [
|
TRIVIAS = [
|
||||||
Trivia('Space', 'A space \' \' character.', characters=[' '],
|
Trivia('Space', 'A space \' \' character.', characters=[' '],
|
||||||
serialization_code=0),
|
serialization_code=0),
|
||||||
Trivia('Tab', 'A tab \'\\t\' character.', characters=['\\t'],
|
Trivia('Tab', 'A tab \'\\t\' character.', characters=['\\t'],
|
||||||
serialization_code=1),
|
serialization_code=1),
|
||||||
Trivia('VerticalTab', 'A vertical tab \'\\v\' character.',
|
Trivia('VerticalTab', 'A vertical tab \'\\v\' character.',
|
||||||
characters=['\\v'], swift_characters=['\\u{2B7F}'],
|
characters=['\\v'], swift_characters=['\\u{2B7F}'],
|
||||||
serialization_code=2),
|
serialization_code=2),
|
||||||
Trivia('Formfeed', 'A form-feed \'f\' character.', characters=['\\f'],
|
Trivia('Formfeed', 'A form-feed \'f\' character.', characters=['\\f'],
|
||||||
swift_characters=['\\u{240C}'], serialization_code=3),
|
swift_characters=['\\u{240C}'], serialization_code=3),
|
||||||
@@ -67,7 +67,7 @@ def verify_no_duplicate_serialization_codes(trivias):
|
|||||||
used_codes = set()
|
used_codes = set()
|
||||||
for trivia in trivias:
|
for trivia in trivias:
|
||||||
if trivia.serialization_code in used_codes:
|
if trivia.serialization_code in used_codes:
|
||||||
error("Serialization code %d used twice for trivia" %
|
error("Serialization code %d used twice for trivia" %
|
||||||
trivia.serialization_code)
|
trivia.serialization_code)
|
||||||
used_codes.add(trivia.serialization_code)
|
used_codes.add(trivia.serialization_code)
|
||||||
|
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ SYNTAX_TOKENS = Token.SYNTAX_TOKENS
|
|||||||
SYNTAX_TOKEN_MAP = Token.SYNTAX_TOKEN_MAP
|
SYNTAX_TOKEN_MAP = Token.SYNTAX_TOKEN_MAP
|
||||||
SYNTAX_CLASSIFICATIONS = Classification.SYNTAX_CLASSIFICATIONS
|
SYNTAX_CLASSIFICATIONS = Classification.SYNTAX_CLASSIFICATIONS
|
||||||
|
|
||||||
verify_syntax_node_serialization_codes(SYNTAX_NODES,
|
verify_syntax_node_serialization_codes(SYNTAX_NODES,
|
||||||
SYNTAX_NODE_SERIALIZATION_CODES)
|
SYNTAX_NODE_SERIALIZATION_CODES)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -16,12 +16,12 @@ def main():
|
|||||||
formatter_class=argparse.RawDescriptionHelpFormatter,
|
formatter_class=argparse.RawDescriptionHelpFormatter,
|
||||||
description='Utility for testing incremental syntax parsing',
|
description='Utility for testing incremental syntax parsing',
|
||||||
epilog='''
|
epilog='''
|
||||||
Based of a single template the utility generates a pre-edit and a post-edit
|
Based of a single template the utility generates a pre-edit and a post-edit
|
||||||
file. It then verifies that incrementally parsing the post-edit file base
|
file. It then verifies that incrementally parsing the post-edit file base
|
||||||
on the pre-edit file results in the same syntax tree as reparsing the
|
on the pre-edit file results in the same syntax tree as reparsing the
|
||||||
post-edit file from scratch.
|
post-edit file from scratch.
|
||||||
|
|
||||||
To generate the pre-edit and the post-edit file from the template, it
|
To generate the pre-edit and the post-edit file from the template, it
|
||||||
operates on markers of the form:
|
operates on markers of the form:
|
||||||
|
|
||||||
<<test_case<pre|||post>>>
|
<<test_case<pre|||post>>>
|
||||||
@@ -49,7 +49,7 @@ def main():
|
|||||||
'--swiftsyntax-lit-test-helper', required=True,
|
'--swiftsyntax-lit-test-helper', required=True,
|
||||||
help='The path to the lit-test-helper binary of SwiftSyntax')
|
help='The path to the lit-test-helper binary of SwiftSyntax')
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'--serialization-format', choices=['json', 'byteTree'],
|
'--serialization-format', choices=['json', 'byteTree'],
|
||||||
default='json', help='''
|
default='json', help='''
|
||||||
The format that shall be used to transfer the syntax tree
|
The format that shall be used to transfer the syntax tree
|
||||||
''')
|
''')
|
||||||
@@ -80,29 +80,29 @@ def main():
|
|||||||
|
|
||||||
# Generate the syntax tree once incrementally and once from scratch
|
# Generate the syntax tree once incrementally and once from scratch
|
||||||
try:
|
try:
|
||||||
serializeIncrParseMarkupFile(test_file=test_file,
|
serializeIncrParseMarkupFile(test_file=test_file,
|
||||||
test_case=test_case,
|
test_case=test_case,
|
||||||
mode='pre-edit',
|
mode='pre-edit',
|
||||||
serialization_mode='full',
|
serialization_mode='full',
|
||||||
serialization_format=serialization_format,
|
serialization_format=serialization_format,
|
||||||
omit_node_ids=False,
|
omit_node_ids=False,
|
||||||
output_file=pre_edit_tree_file,
|
output_file=pre_edit_tree_file,
|
||||||
temp_dir=temp_dir,
|
temp_dir=temp_dir,
|
||||||
swift_syntax_test=swift_syntax_test,
|
swift_syntax_test=swift_syntax_test,
|
||||||
print_visual_reuse_info=False)
|
print_visual_reuse_info=False)
|
||||||
|
|
||||||
serializeIncrParseMarkupFile(test_file=test_file,
|
serializeIncrParseMarkupFile(test_file=test_file,
|
||||||
test_case=test_case,
|
test_case=test_case,
|
||||||
mode='incremental',
|
mode='incremental',
|
||||||
serialization_mode='incremental',
|
serialization_mode='incremental',
|
||||||
serialization_format=serialization_format,
|
serialization_format=serialization_format,
|
||||||
omit_node_ids=False,
|
omit_node_ids=False,
|
||||||
output_file=incremental_tree_file,
|
output_file=incremental_tree_file,
|
||||||
temp_dir=temp_dir,
|
temp_dir=temp_dir,
|
||||||
swift_syntax_test=swift_syntax_test,
|
swift_syntax_test=swift_syntax_test,
|
||||||
print_visual_reuse_info=False)
|
print_visual_reuse_info=False)
|
||||||
except TestFailedError as e:
|
except TestFailedError as e:
|
||||||
print('Test case "%s" of %s FAILed' % (test_case, test_file),
|
print('Test case "%s" of %s FAILed' % (test_case, test_file),
|
||||||
file=sys.stderr)
|
file=sys.stderr)
|
||||||
print(e.message, file=sys.stderr)
|
print(e.message, file=sys.stderr)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
@@ -114,7 +114,7 @@ def main():
|
|||||||
['-incr-tree', incremental_tree_file] +
|
['-incr-tree', incremental_tree_file] +
|
||||||
['-out', after_roundtrip_source_file])
|
['-out', after_roundtrip_source_file])
|
||||||
except subprocess.CalledProcessError as e:
|
except subprocess.CalledProcessError as e:
|
||||||
print('Test case "%s" of %s FAILed' % (test_case, test_file),
|
print('Test case "%s" of %s FAILed' % (test_case, test_file),
|
||||||
file=sys.stderr)
|
file=sys.stderr)
|
||||||
print('Deserializing the swift file failed:\n', file=sys.stderr)
|
print('Deserializing the swift file failed:\n', file=sys.stderr)
|
||||||
print(e.output, file=sys.stderr)
|
print(e.output, file=sys.stderr)
|
||||||
@@ -129,10 +129,10 @@ def main():
|
|||||||
after_roundtrip_source_file
|
after_roundtrip_source_file
|
||||||
])
|
])
|
||||||
except subprocess.CalledProcessError as e:
|
except subprocess.CalledProcessError as e:
|
||||||
print('Test case "%s" of %s FAILed' % (test_case, test_file),
|
print('Test case "%s" of %s FAILed' % (test_case, test_file),
|
||||||
file=sys.stderr)
|
file=sys.stderr)
|
||||||
print('Source file after incrementally transferring the syntax tree '
|
print('Source file after incrementally transferring the syntax tree '
|
||||||
'to swiftSyntax does not match post-edit source file:\n\n',
|
'to swiftSyntax does not match post-edit source file:\n\n',
|
||||||
file=sys.stderr)
|
file=sys.stderr)
|
||||||
print(e.output, file=sys.stderr)
|
print(e.output, file=sys.stderr)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|||||||
@@ -16,11 +16,11 @@ def main():
|
|||||||
formatter_class=argparse.RawDescriptionHelpFormatter,
|
formatter_class=argparse.RawDescriptionHelpFormatter,
|
||||||
description='Utility for testing incremental syntax tree transfer',
|
description='Utility for testing incremental syntax tree transfer',
|
||||||
epilog='''
|
epilog='''
|
||||||
Based of a single template the utility generates a pre-edit and a post-edit
|
Based of a single template the utility generates a pre-edit and a post-edit
|
||||||
file. It then verifies that the incrementally transferred syntax tree
|
file. It then verifies that the incrementally transferred syntax tree
|
||||||
matches the syntax tree passed as --expected-incremental-syntax-tree.
|
matches the syntax tree passed as --expected-incremental-syntax-tree.
|
||||||
|
|
||||||
To generate the pre-edit and the post-edit file from the template, it
|
To generate the pre-edit and the post-edit file from the template, it
|
||||||
operates on markers of the form:
|
operates on markers of the form:
|
||||||
|
|
||||||
<<test_case<pre|||post>>>
|
<<test_case<pre|||post>>>
|
||||||
@@ -65,18 +65,18 @@ def main():
|
|||||||
+ test_case + '.incr.json'
|
+ test_case + '.incr.json'
|
||||||
|
|
||||||
try:
|
try:
|
||||||
serializeIncrParseMarkupFile(test_file=test_file,
|
serializeIncrParseMarkupFile(test_file=test_file,
|
||||||
test_case=test_case,
|
test_case=test_case,
|
||||||
mode='incremental',
|
mode='incremental',
|
||||||
serialization_mode='incremental',
|
serialization_mode='incremental',
|
||||||
serialization_format='json',
|
serialization_format='json',
|
||||||
omit_node_ids=False,
|
omit_node_ids=False,
|
||||||
output_file=incremental_serialized_file,
|
output_file=incremental_serialized_file,
|
||||||
temp_dir=temp_dir + '/temp',
|
temp_dir=temp_dir + '/temp',
|
||||||
swift_syntax_test=swift_syntax_test,
|
swift_syntax_test=swift_syntax_test,
|
||||||
print_visual_reuse_info=False)
|
print_visual_reuse_info=False)
|
||||||
except TestFailedError as e:
|
except TestFailedError as e:
|
||||||
print('Test case "%s" of %s FAILed' % (test_case, test_file),
|
print('Test case "%s" of %s FAILed' % (test_case, test_file),
|
||||||
file=sys.stderr)
|
file=sys.stderr)
|
||||||
print(e.message, file=sys.stderr)
|
print(e.message, file=sys.stderr)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
@@ -90,7 +90,7 @@ def main():
|
|||||||
expected_syntax_tree_file
|
expected_syntax_tree_file
|
||||||
])
|
])
|
||||||
except subprocess.CalledProcessError as e:
|
except subprocess.CalledProcessError as e:
|
||||||
print('Test case "%s" of %s FAILed' % (test_case, test_file),
|
print('Test case "%s" of %s FAILed' % (test_case, test_file),
|
||||||
file=sys.stderr)
|
file=sys.stderr)
|
||||||
print('Syntax tree of incremental parsing does not match expected '
|
print('Syntax tree of incremental parsing does not match expected '
|
||||||
'incrementally transfer syntax tree:\n\n', file=sys.stderr)
|
'incrementally transfer syntax tree:\n\n', file=sys.stderr)
|
||||||
|
|||||||
@@ -25,12 +25,12 @@ def run_command(cmd):
|
|||||||
return subprocess.check_output(cmd, stderr=subprocess.STDOUT)
|
return subprocess.check_output(cmd, stderr=subprocess.STDOUT)
|
||||||
|
|
||||||
|
|
||||||
def parseLine(line, line_no, test_case, incremental_edit_args, reparse_args,
|
def parseLine(line, line_no, test_case, incremental_edit_args, reparse_args,
|
||||||
current_reparse_start):
|
current_reparse_start):
|
||||||
pre_edit_line = ""
|
pre_edit_line = ""
|
||||||
post_edit_line = ""
|
post_edit_line = ""
|
||||||
|
|
||||||
# We parse one tag at a time in the line while eating away a prefix of the
|
# We parse one tag at a time in the line while eating away a prefix of the
|
||||||
# line
|
# line
|
||||||
while line:
|
while line:
|
||||||
# The regular expression to match the template markers
|
# The regular expression to match the template markers
|
||||||
@@ -56,7 +56,7 @@ def parseLine(line, line_no, test_case, incremental_edit_args, reparse_args,
|
|||||||
# Compute the -incremental-edit argument for swift-syntax-test
|
# Compute the -incremental-edit argument for swift-syntax-test
|
||||||
column = len(pre_edit_line) + len(prefix) + 1
|
column = len(pre_edit_line) + len(prefix) + 1
|
||||||
edit_arg = '%d:%d-%d:%d=%s' % \
|
edit_arg = '%d:%d-%d:%d=%s' % \
|
||||||
(line_no, column, line_no, column + len(pre_edit),
|
(line_no, column, line_no, column + len(pre_edit),
|
||||||
post_edit)
|
post_edit)
|
||||||
incremental_edit_args.append('-incremental-edit')
|
incremental_edit_args.append('-incremental-edit')
|
||||||
incremental_edit_args.append(edit_arg)
|
incremental_edit_args.append(edit_arg)
|
||||||
@@ -82,8 +82,8 @@ def parseLine(line, line_no, test_case, incremental_edit_args, reparse_args,
|
|||||||
'in line %d' % line_no)
|
'in line %d' % line_no)
|
||||||
reparse_args.append('-reparse-region')
|
reparse_args.append('-reparse-region')
|
||||||
reparse_args.append(
|
reparse_args.append(
|
||||||
'%d:%d-%d:%d' % (current_reparse_start[0],
|
'%d:%d-%d:%d' % (current_reparse_start[0],
|
||||||
current_reparse_start[1],
|
current_reparse_start[1],
|
||||||
line_no, column))
|
line_no, column))
|
||||||
current_reparse_start = None
|
current_reparse_start = None
|
||||||
else:
|
else:
|
||||||
@@ -105,9 +105,9 @@ def parseLine(line, line_no, test_case, incremental_edit_args, reparse_args,
|
|||||||
return (pre_edit_line, post_edit_line, current_reparse_start)
|
return (pre_edit_line, post_edit_line, current_reparse_start)
|
||||||
|
|
||||||
|
|
||||||
def serializeIncrParseMarkupFile(test_file, test_case, mode,
|
def serializeIncrParseMarkupFile(test_file, test_case, mode,
|
||||||
serialization_mode, serialization_format,
|
serialization_mode, serialization_format,
|
||||||
omit_node_ids, output_file, temp_dir,
|
omit_node_ids, output_file, temp_dir,
|
||||||
swift_syntax_test, print_visual_reuse_info):
|
swift_syntax_test, print_visual_reuse_info):
|
||||||
test_file_name = os.path.basename(test_file)
|
test_file_name = os.path.basename(test_file)
|
||||||
pre_edit_file = temp_dir + '/' + test_file_name + '.' + test_case + \
|
pre_edit_file = temp_dir + '/' + test_file_name + '.' + test_case + \
|
||||||
@@ -120,7 +120,7 @@ def serializeIncrParseMarkupFile(test_file, test_case, mode,
|
|||||||
|
|
||||||
# =========================================================================
|
# =========================================================================
|
||||||
# First generate the pre-edit and post-edit Swift file and gather the edits
|
# First generate the pre-edit and post-edit Swift file and gather the edits
|
||||||
# and expected reparse regions. This is the parser for the special edit
|
# and expected reparse regions. This is the parser for the special edit
|
||||||
# markup for testing incremental parsing
|
# markup for testing incremental parsing
|
||||||
# =========================================================================
|
# =========================================================================
|
||||||
|
|
||||||
@@ -128,7 +128,7 @@ def serializeIncrParseMarkupFile(test_file, test_case, mode,
|
|||||||
open(pre_edit_file, mode='w+') as pre_edit_file_handle, \
|
open(pre_edit_file, mode='w+') as pre_edit_file_handle, \
|
||||||
open(post_edit_file, mode='w+') as post_edit_file_handle:
|
open(post_edit_file, mode='w+') as post_edit_file_handle:
|
||||||
|
|
||||||
# Gather command line arguments for swift-syntax-test specifiying the
|
# Gather command line arguments for swift-syntax-test specifiying the
|
||||||
# performed edits in this list
|
# performed edits in this list
|
||||||
incremental_edit_args = []
|
incremental_edit_args = []
|
||||||
reparse_args = []
|
reparse_args = []
|
||||||
@@ -136,7 +136,7 @@ def serializeIncrParseMarkupFile(test_file, test_case, mode,
|
|||||||
|
|
||||||
line_no = 1
|
line_no = 1
|
||||||
for line in test_file_handle.readlines():
|
for line in test_file_handle.readlines():
|
||||||
parseLineRes = parseLine(line, line_no, test_case,
|
parseLineRes = parseLine(line, line_no, test_case,
|
||||||
incremental_edit_args,
|
incremental_edit_args,
|
||||||
reparse_args, current_reparse_start)
|
reparse_args, current_reparse_start)
|
||||||
(pre_edit_line, post_edit_line, current_reparse_start) = \
|
(pre_edit_line, post_edit_line, current_reparse_start) = \
|
||||||
@@ -155,12 +155,12 @@ def serializeIncrParseMarkupFile(test_file, test_case, mode,
|
|||||||
# Now generate the requested serialized file
|
# Now generate the requested serialized file
|
||||||
# =========================================================================
|
# =========================================================================
|
||||||
|
|
||||||
# Build the command to serialize the tree depending on the command line
|
# Build the command to serialize the tree depending on the command line
|
||||||
# arguments
|
# arguments
|
||||||
|
|
||||||
try:
|
try:
|
||||||
command = [
|
command = [
|
||||||
swift_syntax_test,
|
swift_syntax_test,
|
||||||
'-serialize-raw-tree',
|
'-serialize-raw-tree',
|
||||||
'-output-filename', output_file
|
'-output-filename', output_file
|
||||||
]
|
]
|
||||||
@@ -170,20 +170,20 @@ def serializeIncrParseMarkupFile(test_file, test_case, mode,
|
|||||||
|
|
||||||
if serialization_mode == 'full':
|
if serialization_mode == 'full':
|
||||||
# Nothing to do. This is the default behaviour of swift-syntax-test
|
# Nothing to do. This is the default behaviour of swift-syntax-test
|
||||||
pass
|
pass
|
||||||
elif serialization_mode == 'incremental':
|
elif serialization_mode == 'incremental':
|
||||||
command.extend(['-incremental-serialization'])
|
command.extend(['-incremental-serialization'])
|
||||||
else:
|
else:
|
||||||
raise ValueError('Unknown serialization mode "%s"' %
|
raise ValueError('Unknown serialization mode "%s"' %
|
||||||
serialization_mode)
|
serialization_mode)
|
||||||
|
|
||||||
if serialization_format == 'json':
|
if serialization_format == 'json':
|
||||||
# Nothing to do. This is the default behaviour of swift-syntax-test
|
# Nothing to do. This is the default behaviour of swift-syntax-test
|
||||||
pass
|
pass
|
||||||
elif serialization_format == 'byteTree':
|
elif serialization_format == 'byteTree':
|
||||||
command.extend(['-serialize-byte-tree'])
|
command.extend(['-serialize-byte-tree'])
|
||||||
else:
|
else:
|
||||||
raise ValueError('Unknown serialization format "%s"' %
|
raise ValueError('Unknown serialization format "%s"' %
|
||||||
serialization_format)
|
serialization_format)
|
||||||
|
|
||||||
if mode == 'pre-edit':
|
if mode == 'pre-edit':
|
||||||
@@ -191,27 +191,27 @@ def serializeIncrParseMarkupFile(test_file, test_case, mode,
|
|||||||
elif mode == 'post-edit':
|
elif mode == 'post-edit':
|
||||||
command.extend(['-input-source-filename', post_edit_file])
|
command.extend(['-input-source-filename', post_edit_file])
|
||||||
elif mode == 'incremental':
|
elif mode == 'incremental':
|
||||||
# We need to build the syntax tree of the pre-edit file first so
|
# We need to build the syntax tree of the pre-edit file first so
|
||||||
# that we can pass it to swift-syntax-test to perform incremental
|
# that we can pass it to swift-syntax-test to perform incremental
|
||||||
# parsing
|
# parsing
|
||||||
pre_edit_tree_file = pre_edit_file + '.serialized.json'
|
pre_edit_tree_file = pre_edit_file + '.serialized.json'
|
||||||
|
|
||||||
run_command([swift_syntax_test] +
|
run_command([swift_syntax_test] +
|
||||||
['-serialize-raw-tree'] +
|
['-serialize-raw-tree'] +
|
||||||
['-input-source-filename', pre_edit_file] +
|
['-input-source-filename', pre_edit_file] +
|
||||||
['-output-filename', pre_edit_tree_file])
|
['-output-filename', pre_edit_tree_file])
|
||||||
|
|
||||||
# Then perform incremental parsing with the old syntax tree on the
|
# Then perform incremental parsing with the old syntax tree on the
|
||||||
# post-edit file
|
# post-edit file
|
||||||
command.extend(['-input-source-filename', post_edit_file])
|
command.extend(['-input-source-filename', post_edit_file])
|
||||||
command.extend(['-old-syntax-tree-filename',
|
command.extend(['-old-syntax-tree-filename',
|
||||||
pre_edit_tree_file])
|
pre_edit_tree_file])
|
||||||
command.extend(['--old-source-filename', pre_edit_file])
|
command.extend(['--old-source-filename', pre_edit_file])
|
||||||
command.extend(incremental_edit_args)
|
command.extend(incremental_edit_args)
|
||||||
command.extend(reparse_args)
|
command.extend(reparse_args)
|
||||||
if print_visual_reuse_info:
|
if print_visual_reuse_info:
|
||||||
command.extend([
|
command.extend([
|
||||||
'-print-visual-reuse-info',
|
'-print-visual-reuse-info',
|
||||||
'-force-colored-output'
|
'-force-colored-output'
|
||||||
])
|
])
|
||||||
else:
|
else:
|
||||||
@@ -229,13 +229,13 @@ def main():
|
|||||||
formatter_class=argparse.RawDescriptionHelpFormatter,
|
formatter_class=argparse.RawDescriptionHelpFormatter,
|
||||||
description='Utility for testing incremental syntax parsing',
|
description='Utility for testing incremental syntax parsing',
|
||||||
epilog='''
|
epilog='''
|
||||||
This utility can parse a special markup to dedicate a pre-edit and a
|
This utility can parse a special markup to dedicate a pre-edit and a
|
||||||
post-edit version of a file simulateously and generate a serialized version
|
post-edit version of a file simulateously and generate a serialized version
|
||||||
of the libSyntax tree by parsing either the pre-edit file, the post-edit
|
of the libSyntax tree by parsing either the pre-edit file, the post-edit
|
||||||
file or the edits that are required to retrieve the post-edit file from the
|
file or the edits that are required to retrieve the post-edit file from the
|
||||||
pre-edit file incrementally.
|
pre-edit file incrementally.
|
||||||
|
|
||||||
To generate the pre-edit and the post-edit file from the template, it
|
To generate the pre-edit and the post-edit file from the template, it
|
||||||
operates on markers of the form:
|
operates on markers of the form:
|
||||||
|
|
||||||
<<test_case<pre|||post>>>
|
<<test_case<pre|||post>>>
|
||||||
@@ -252,7 +252,7 @@ def main():
|
|||||||
help='The test case to execute. If no test case is specified all \
|
help='The test case to execute. If no test case is specified all \
|
||||||
unnamed substitutions are applied')
|
unnamed substitutions are applied')
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'--mode', choices=['pre-edit', 'incremental', 'post-edit'],
|
'--mode', choices=['pre-edit', 'incremental', 'post-edit'],
|
||||||
required=True, help='''
|
required=True, help='''
|
||||||
The type of parsing to perform:
|
The type of parsing to perform:
|
||||||
- pre-edit: Serialize the syntax tree when parsing the pre-edit file \
|
- pre-edit: Serialize the syntax tree when parsing the pre-edit file \
|
||||||
@@ -263,13 +263,13 @@ def main():
|
|||||||
post-edit file from scratch
|
post-edit file from scratch
|
||||||
''')
|
''')
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'--serialization-mode', choices=['full', 'incremental'],
|
'--serialization-mode', choices=['full', 'incremental'],
|
||||||
default='full', help='''
|
default='full', help='''
|
||||||
Only applicable if `--mode` is `incremental`. Whether to serialize the
|
Only applicable if `--mode` is `incremental`. Whether to serialize the
|
||||||
entire tree or use the incremental transfer mode. Default is `full`.
|
entire tree or use the incremental transfer mode. Default is `full`.
|
||||||
''')
|
''')
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'--serialization-format', choices=['json', 'byteTree'],
|
'--serialization-format', choices=['json', 'byteTree'],
|
||||||
default='json', help='''
|
default='json', help='''
|
||||||
The format in which the syntax tree shall be serialized.
|
The format in which the syntax tree shall be serialized.
|
||||||
''')
|
''')
|
||||||
@@ -307,15 +307,15 @@ def main():
|
|||||||
visual_reuse_info = args.print_visual_reuse_info
|
visual_reuse_info = args.print_visual_reuse_info
|
||||||
|
|
||||||
try:
|
try:
|
||||||
serializeIncrParseMarkupFile(test_file=test_file,
|
serializeIncrParseMarkupFile(test_file=test_file,
|
||||||
test_case=test_case,
|
test_case=test_case,
|
||||||
mode=mode,
|
mode=mode,
|
||||||
serialization_mode=serialization_mode,
|
serialization_mode=serialization_mode,
|
||||||
serialization_format=serialization_format,
|
serialization_format=serialization_format,
|
||||||
omit_node_ids=omit_node_ids,
|
omit_node_ids=omit_node_ids,
|
||||||
output_file=output_file,
|
output_file=output_file,
|
||||||
temp_dir=temp_dir,
|
temp_dir=temp_dir,
|
||||||
swift_syntax_test=swift_syntax_test,
|
swift_syntax_test=swift_syntax_test,
|
||||||
print_visual_reuse_info=visual_reuse_info)
|
print_visual_reuse_info=visual_reuse_info)
|
||||||
except TestFailedError as e:
|
except TestFailedError as e:
|
||||||
print(e.message, file=sys.stderr)
|
print(e.message, file=sys.stderr)
|
||||||
|
|||||||
@@ -16,12 +16,12 @@ def main():
|
|||||||
formatter_class=argparse.RawDescriptionHelpFormatter,
|
formatter_class=argparse.RawDescriptionHelpFormatter,
|
||||||
description='Utility for testing incremental syntax parsing',
|
description='Utility for testing incremental syntax parsing',
|
||||||
epilog='''
|
epilog='''
|
||||||
Based of a single template the utility generates a pre-edit and a post-edit
|
Based of a single template the utility generates a pre-edit and a post-edit
|
||||||
file. It then verifies that incrementally parsing the post-edit file base
|
file. It then verifies that incrementally parsing the post-edit file base
|
||||||
on the pre-edit file results in the same syntax tree as reparsing the
|
on the pre-edit file results in the same syntax tree as reparsing the
|
||||||
post-edit file from scratch.
|
post-edit file from scratch.
|
||||||
|
|
||||||
To generate the pre-edit and the post-edit file from the template, it
|
To generate the pre-edit and the post-edit file from the template, it
|
||||||
operates on markers of the form:
|
operates on markers of the form:
|
||||||
|
|
||||||
<<test_case<pre|||post>>>
|
<<test_case<pre|||post>>>
|
||||||
@@ -70,33 +70,33 @@ def main():
|
|||||||
|
|
||||||
# Generate the syntax tree once incrementally and once from scratch
|
# Generate the syntax tree once incrementally and once from scratch
|
||||||
try:
|
try:
|
||||||
serializeIncrParseMarkupFile(test_file=test_file,
|
serializeIncrParseMarkupFile(test_file=test_file,
|
||||||
test_case=test_case,
|
test_case=test_case,
|
||||||
mode='incremental',
|
mode='incremental',
|
||||||
serialization_mode='full',
|
serialization_mode='full',
|
||||||
serialization_format='json',
|
serialization_format='json',
|
||||||
omit_node_ids=True,
|
omit_node_ids=True,
|
||||||
output_file=incremental_serialized_file,
|
output_file=incremental_serialized_file,
|
||||||
temp_dir=temp_dir + '/temp',
|
temp_dir=temp_dir + '/temp',
|
||||||
swift_syntax_test=swift_syntax_test,
|
swift_syntax_test=swift_syntax_test,
|
||||||
print_visual_reuse_info=visual_reuse_info)
|
print_visual_reuse_info=visual_reuse_info)
|
||||||
if visual_reuse_info:
|
if visual_reuse_info:
|
||||||
# If we just want the reuse info, we don't need to parse the file
|
# If we just want the reuse info, we don't need to parse the file
|
||||||
# from scratch or validate it
|
# from scratch or validate it
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
serializeIncrParseMarkupFile(test_file=test_file,
|
serializeIncrParseMarkupFile(test_file=test_file,
|
||||||
test_case=test_case,
|
test_case=test_case,
|
||||||
mode='post-edit',
|
mode='post-edit',
|
||||||
serialization_mode='full',
|
serialization_mode='full',
|
||||||
serialization_format='json',
|
serialization_format='json',
|
||||||
omit_node_ids=True,
|
omit_node_ids=True,
|
||||||
output_file=post_edit_serialized_file,
|
output_file=post_edit_serialized_file,
|
||||||
temp_dir=temp_dir + '/temp',
|
temp_dir=temp_dir + '/temp',
|
||||||
swift_syntax_test=swift_syntax_test,
|
swift_syntax_test=swift_syntax_test,
|
||||||
print_visual_reuse_info=visual_reuse_info)
|
print_visual_reuse_info=visual_reuse_info)
|
||||||
except TestFailedError as e:
|
except TestFailedError as e:
|
||||||
print('Test case "%s" of %s FAILed' % (test_case, test_file),
|
print('Test case "%s" of %s FAILed' % (test_case, test_file),
|
||||||
file=sys.stderr)
|
file=sys.stderr)
|
||||||
print(e.message, file=sys.stderr)
|
print(e.message, file=sys.stderr)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
@@ -110,7 +110,7 @@ def main():
|
|||||||
post_edit_serialized_file
|
post_edit_serialized_file
|
||||||
])
|
])
|
||||||
except subprocess.CalledProcessError as e:
|
except subprocess.CalledProcessError as e:
|
||||||
print('Test case "%s" of %s FAILed' % (test_case, test_file),
|
print('Test case "%s" of %s FAILed' % (test_case, test_file),
|
||||||
file=sys.stderr)
|
file=sys.stderr)
|
||||||
print('Syntax tree of incremental parsing does not match '
|
print('Syntax tree of incremental parsing does not match '
|
||||||
'from-scratch parsing of post-edit file:\n\n', file=sys.stderr)
|
'from-scratch parsing of post-edit file:\n\n', file=sys.stderr)
|
||||||
|
|||||||
@@ -223,7 +223,7 @@ def obtain_additional_swift_sources(pool_args):
|
|||||||
print("Cloning '" + repo_name + "'")
|
print("Cloning '" + repo_name + "'")
|
||||||
|
|
||||||
if skip_history:
|
if skip_history:
|
||||||
shell.run(['git', 'clone', '--recursive', '--depth', '1',
|
shell.run(['git', 'clone', '--recursive', '--depth', '1',
|
||||||
'--branch', repo_branch, remote, repo_name],
|
'--branch', repo_branch, remote, repo_name],
|
||||||
echo=True)
|
echo=True)
|
||||||
else:
|
else:
|
||||||
@@ -536,7 +536,7 @@ By default, updates your checkouts of Swift, SourceKit, LLDB, and SwiftPM.""")
|
|||||||
|
|
||||||
# Quick check whether somebody is calling update in an empty directory
|
# Quick check whether somebody is calling update in an empty directory
|
||||||
directory_contents = os.listdir(SWIFT_SOURCE_ROOT)
|
directory_contents = os.listdir(SWIFT_SOURCE_ROOT)
|
||||||
if not ('cmark' in directory_contents or
|
if not ('cmark' in directory_contents or
|
||||||
'llvm' in directory_contents or
|
'llvm' in directory_contents or
|
||||||
'clang' in directory_contents):
|
'clang' in directory_contents):
|
||||||
print("You don't have all swift sources. "
|
print("You don't have all swift sources. "
|
||||||
|
|||||||
Reference in New Issue
Block a user