GeneratedTreeSitterNode constructor
GeneratedTreeSitterNode({
- required int symbol,
- int? structuralSymbol,
- required String type,
- required int startByte,
- required int endByte,
- required TreeSitterTablePoint startPoint,
- required TreeSitterTablePoint endPoint,
- required bool named,
- required bool visible,
- required bool extra,
- int productionId = 0,
- int dynamicPrecedence = 0,
- bool missing = false,
- bool missingNameIsNamed = false,
- bool recoveryRepeat = false,
- int? unexpectedCharacter,
- List<
GeneratedTreeSitterNode> children = const [], - List<
GeneratedTreeSitterField> fields = const [], - List<
GeneratedTreeSitterProductionField> productionFields = const [], - int parseState = 0,
- int? firstLeafSymbol,
- int firstLeafParseState = 0,
- int paddingBytes = 0,
- TreeSitterTablePoint paddingExtent = const TreeSitterTablePoint(0, 0),
- int? sizeBytes,
- TreeSitterTablePoint? sizeExtent,
- int lookaheadBytes = 0,
- bool hasChanges = false,
- bool fragileLeft = false,
- bool fragileRight = false,
- bool dependsOnColumn = false,
- bool isKeyword = false,
- bool hasExternalTokens = false,
- List<
int> externalScannerStateBefore = const <int>[], - List<
int> externalScannerStateAfter = const <int>[],
Implementation
GeneratedTreeSitterNode({
required this.symbol,
int? structuralSymbol,
required this.type,
required this.startByte,
required this.endByte,
required this.startPoint,
required this.endPoint,
required this.named,
required this.visible,
required this.extra,
this.productionId = 0,
this.dynamicPrecedence = 0,
this.missing = false,
this.missingNameIsNamed = false,
bool recoveryRepeat = false,
this.unexpectedCharacter,
List<GeneratedTreeSitterNode> children = const [],
List<GeneratedTreeSitterField> fields = const [],
List<GeneratedTreeSitterProductionField> productionFields = const [],
this.parseState = 0,
this.firstLeafSymbol,
this.firstLeafParseState = 0,
this.paddingBytes = 0,
this.paddingExtent = const TreeSitterTablePoint(0, 0),
int? sizeBytes,
TreeSitterTablePoint? sizeExtent,
this.lookaheadBytes = 0,
this.hasChanges = false,
this.fragileLeft = false,
this.fragileRight = false,
this.dependsOnColumn = false,
this.isKeyword = false,
this.hasExternalTokens = false,
List<int> externalScannerStateBefore = const <int>[],
List<int> externalScannerStateAfter = const <int>[],
}) : structuralSymbol = structuralSymbol ?? symbol,
_recoveryRepeat = recoveryRepeat,
children = children.isEmpty
? const <GeneratedTreeSitterNode>[]
: List<GeneratedTreeSitterNode>.unmodifiable(children),
fields = fields.isEmpty
? const <GeneratedTreeSitterField>[]
: List<GeneratedTreeSitterField>.unmodifiable(fields),
productionFields = productionFields.isEmpty
? const <GeneratedTreeSitterProductionField>[]
: List<GeneratedTreeSitterProductionField>.unmodifiable(
productionFields,
),
externalScannerStateBefore = _freezeScannerState(
externalScannerStateBefore,
),
externalScannerStateAfter = _freezeScannerState(
externalScannerStateAfter,
),
sizeBytes = sizeBytes ?? endByte - startByte,
_sizeExtent = sizeExtent {
var first = _mixHash(symbol, productionId);
first = _mixHash(first, dynamicPrecedence);
first = _mixHash(first, startByte);
first = _mixHash(first, endByte);
first = _mixHash(first, missing ? 1 : 0);
first = _mixHash(first, recoveryRepeat ? 1 : 0);
first = _mixHash(first, unexpectedCharacter ?? -2);
var second = _mixHash2(symbol, productionId);
second = _mixHash2(second, dynamicPrecedence);
second = _mixHash2(second, startByte);
second = _mixHash2(second, endByte);
second = _mixHash2(second, missing ? 1 : 0);
second = _mixHash2(second, recoveryRepeat ? 1 : 0);
second = _mixHash2(second, unexpectedCharacter ?? -2);
var subtreeNodeCount = visible ? 1 : 0;
// Native `ts_node_has_error` is derived from subtree error cost. Missing
// named and anonymous nodes therefore mark every ancestor as erroneous
// even when there is no explicit ERROR node in the CST.
var containsRecoveryError =
missing || unexpectedCharacter != null || type == 'ERROR';
var hasRecoveryCost =
recoveryRepeat || missing || (type == 'ERROR' && children.isNotEmpty);
var visibleDescendantCount = 0;
var nodeErrorCost = 0;
var acceptedNodeErrorCost = 0;
for (final child in children) {
first = _mixHash(first, child._shapeHash);
second = _mixHash2(second, child._shapeHash2);
subtreeNodeCount += child._subtreeNodeCount;
containsRecoveryError = containsRecoveryError || child._containsError;
hasRecoveryCost = hasRecoveryCost || child._hasErrorCost;
visibleDescendantCount += child.visible
? 1
: child._visibleDescendantCount;
nodeErrorCost += child._nodeErrorCost;
acceptedNodeErrorCost += child._acceptedNodeErrorCost;
}
for (final field in fields) {
first = _mixHash(first, field.name.hashCode);
first = _mixHash(first, field.inherited ? 1 : 0);
second = _mixHash2(second, field.name.hashCode);
second = _mixHash2(second, field.inherited ? 1 : 0);
}
for (final field in productionFields) {
first = _mixHash(first, field.name.hashCode);
first = _mixHash(first, field.childIndex);
first = _mixHash(first, field.inherited ? 1 : 0);
second = _mixHash2(second, field.name.hashCode);
second = _mixHash2(second, field.childIndex);
second = _mixHash2(second, field.inherited ? 1 : 0);
}
_shapeHash = first;
_shapeHash2 = second;
_subtreeNodeCount = subtreeNodeCount;
_containsError = containsRecoveryError;
_hasErrorCost = hasRecoveryCost;
_visibleDescendantCount = visibleDescendantCount;
if (recoveryRepeat) {
nodeErrorCost = 0;
acceptedNodeErrorCost = 0;
} else if (missing) {
nodeErrorCost = 610;
acceptedNodeErrorCost = 610;
} else if (type == 'ERROR' && children.isNotEmpty) {
for (final child in children) {
if (child._recoveryRepeat) {
acceptedNodeErrorCost += 100 * child._visibleDescendantCount;
} else if (!child.extra &&
!(child.type == 'ERROR' && child.children.isEmpty)) {
acceptedNodeErrorCost += child.visible
? 100
: 100 * child._visibleDescendantCount;
}
if (!child.extra &&
!(child.type == 'ERROR' && child.children.isEmpty)) {
nodeErrorCost += child.visible
? 100
: 100 * child._visibleDescendantCount;
}
}
final recoveryCost =
500 + endByte - startByte + (endPoint.row - startPoint.row) * 30;
nodeErrorCost += recoveryCost;
acceptedNodeErrorCost += recoveryCost;
}
_nodeErrorCost = nodeErrorCost;
_acceptedNodeErrorCost = acceptedNodeErrorCost;
}