thaddeus 1.0.18 → 1.0.27
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +14 -5
- package/src/QueryEngine.js +926 -0
- package/src/Task.js +49 -0
- package/src/Tool.js +61 -0
- package/src/assistant/gate.js +5 -0
- package/src/assistant/index.js +106 -0
- package/src/assistant/sessionHistory.js +145 -0
- package/src/bootstrap/state.js +1163 -0
- package/src/bridge/bridgeApi.js +304 -0
- package/src/bridge/bridgeConfig.js +39 -0
- package/src/bridge/bridgeDebug.js +73 -0
- package/src/bridge/bridgeEnabled.js +185 -0
- package/src/bridge/bridgeMain.js +2289 -0
- package/src/bridge/bridgeMessaging.js +353 -0
- package/src/bridge/bridgePermissionCallbacks.js +10 -0
- package/src/bridge/bridgePointer.js +175 -0
- package/src/bridge/bridgeStatusUtil.js +105 -0
- package/src/bridge/bridgeUI.js +411 -0
- package/src/bridge/capacityWake.js +35 -0
- package/src/bridge/codeSessionApi.js +111 -0
- package/src/bridge/createSession.js +273 -0
- package/src/bridge/debugUtils.js +115 -0
- package/src/bridge/envLessBridgeConfig.js +120 -0
- package/src/bridge/flushGate.js +65 -0
- package/src/bridge/inboundAttachments.js +152 -0
- package/src/bridge/inboundMessages.js +63 -0
- package/src/bridge/initReplBridge.js +431 -0
- package/src/bridge/jwtUtils.js +185 -0
- package/src/bridge/peerSessions.js +5 -0
- package/src/bridge/pollConfig.js +85 -0
- package/src/bridge/pollConfigDefaults.js +62 -0
- package/src/bridge/remoteBridgeCore.js +712 -0
- package/src/bridge/replBridge.js +1719 -0
- package/src/bridge/replBridgeHandle.js +30 -0
- package/src/bridge/replBridgeTransport.js +236 -0
- package/src/bridge/sessionIdCompat.js +56 -0
- package/src/bridge/sessionRunner.js +421 -0
- package/src/bridge/trustedDevice.js +170 -0
- package/src/bridge/types.js +9 -0
- package/src/bridge/webhookSanitizer.js +6 -0
- package/src/bridge/workSecret.js +99 -0
- package/src/buddy/CompanionSprite.js +348 -0
- package/src/buddy/companion.js +107 -0
- package/src/buddy/prompt.js +33 -0
- package/src/buddy/sprites.js +488 -0
- package/src/buddy/types.js +90 -0
- package/src/buddy/useBuddyNotification.js +85 -0
- package/src/cli/bg.js +17 -0
- package/src/cli/exit.js +30 -0
- package/src/cli/handlers/agents.js +55 -0
- package/src/cli/handlers/auth.js +249 -0
- package/src/cli/handlers/autoMode.js +128 -0
- package/src/cli/handlers/mcp.js +335 -0
- package/src/cli/handlers/plugins.js +634 -0
- package/src/cli/handlers/templateJobs.js +19 -0
- package/src/cli/handlers/util.js +76 -0
- package/src/cli/ndjsonSafeStringify.js +27 -0
- package/src/cli/print.js +4294 -0
- package/src/cli/remoteIO.js +208 -0
- package/src/cli/structuredIO.js +644 -0
- package/src/cli/transports/HybridTransport.js +233 -0
- package/src/cli/transports/SSETransport.js +538 -0
- package/src/cli/transports/SerialBatchEventUploader.js +224 -0
- package/src/cli/transports/WebSocketTransport.js +613 -0
- package/src/cli/transports/WorkerStateUploader.js +88 -0
- package/src/cli/transports/ccrClient.js +711 -0
- package/src/cli/transports/transportUtils.js +39 -0
- package/src/cli/update.js +314 -0
- package/src/commandCenter/launch.js +39 -0
- package/src/commandCenter/phoneApi.js +168 -0
- package/src/commandCenter/phoneStore.js +159 -0
- package/src/commandCenter/reactorBus.js +130 -0
- package/src/commandCenter/server.js +288 -0
- package/src/commandCenter/server.ts +42 -7
- package/src/commandCenter/tunnel.js +199 -0
- package/src/commands/add-dir/add-dir.js +121 -0
- package/src/commands/add-dir/index.js +8 -0
- package/src/commands/add-dir/validation.js +76 -0
- package/src/commands/advisor.js +88 -0
- package/src/commands/agents/agents.js +10 -0
- package/src/commands/agents/index.js +7 -0
- package/src/commands/agents-platform/index.js +2 -0
- package/src/commands/assistant/index.js +86 -0
- package/src/commands/backup/index.js +31 -0
- package/src/commands/branch/branch.js +205 -0
- package/src/commands/branch/index.js +11 -0
- package/src/commands/bridge/bridge.js +513 -0
- package/src/commands/bridge/index.js +22 -0
- package/src/commands/bridge-kick.js +179 -0
- package/src/commands/brief.js +89 -0
- package/src/commands/btw/btw.js +235 -0
- package/src/commands/btw/index.js +9 -0
- package/src/commands/buddy/buddy.js +100 -0
- package/src/commands/buddy/index.js +11 -0
- package/src/commands/chrome/chrome.js +291 -0
- package/src/commands/chrome/index.js +10 -0
- package/src/commands/clear/caches.js +116 -0
- package/src/commands/clear/clear.js +5 -0
- package/src/commands/clear/conversation.js +189 -0
- package/src/commands/clear/index.js +9 -0
- package/src/commands/color/color.js +58 -0
- package/src/commands/color/index.js +9 -0
- package/src/commands/commit-push-pr.js +137 -0
- package/src/commands/commit.js +80 -0
- package/src/commands/compact/compact.js +194 -0
- package/src/commands/compact/index.js +11 -0
- package/src/commands/config/config.js +6 -0
- package/src/commands/config/index.js +8 -0
- package/src/commands/context/context-noninteractive.js +219 -0
- package/src/commands/context/context.js +45 -0
- package/src/commands/context/index.js +21 -0
- package/src/commands/coordinator.js +34 -0
- package/src/commands/copy/copy.js +366 -0
- package/src/commands/copy/index.js +7 -0
- package/src/commands/cost/cost.js +21 -0
- package/src/commands/cost/index.js +16 -0
- package/src/commands/createMovedToPluginCommand.js +33 -0
- package/src/commands/desktop/desktop.js +6 -0
- package/src/commands/desktop/index.js +22 -0
- package/src/commands/diff/diff.js +6 -0
- package/src/commands/diff/index.js +6 -0
- package/src/commands/doctor/doctor.js +6 -0
- package/src/commands/doctor/index.js +9 -0
- package/src/commands/effort/effort.js +166 -0
- package/src/commands/effort/index.js +11 -0
- package/src/commands/exit/exit.js +32 -0
- package/src/commands/exit/index.js +9 -0
- package/src/commands/export/export.js +87 -0
- package/src/commands/export/index.js +8 -0
- package/src/commands/extra-usage/extra-usage-core.js +99 -0
- package/src/commands/extra-usage/extra-usage-noninteractive.js +13 -0
- package/src/commands/extra-usage/extra-usage.js +15 -0
- package/src/commands/extra-usage/index.js +29 -0
- package/src/commands/fast/fast.js +276 -0
- package/src/commands/fast/index.js +19 -0
- package/src/commands/feedback/feedback.js +11 -0
- package/src/commands/feedback/index.js +20 -0
- package/src/commands/files/files.js +11 -0
- package/src/commands/files/index.js +9 -0
- package/src/commands/force-snip.js +19 -0
- package/src/commands/fork/index.js +67 -0
- package/src/commands/heapdump/heapdump.js +14 -0
- package/src/commands/heapdump/index.js +9 -0
- package/src/commands/help/help.js +6 -0
- package/src/commands/help/index.js +7 -0
- package/src/commands/hooks/hooks.js +12 -0
- package/src/commands/hooks/index.js +8 -0
- package/src/commands/ide/ide.js +615 -0
- package/src/commands/ide/index.js +8 -0
- package/src/commands/init-verifiers.js +258 -0
- package/src/commands/init.js +248 -0
- package/src/commands/insights.js +2554 -0
- package/src/commands/install-github-app/ApiKeyStep.js +230 -0
- package/src/commands/install-github-app/CheckExistingSecretStep.js +194 -0
- package/src/commands/install-github-app/CheckGitHubStep.js +16 -0
- package/src/commands/install-github-app/ChooseRepoStep.js +211 -0
- package/src/commands/install-github-app/CreatingStep.js +53 -0
- package/src/commands/install-github-app/ErrorStep.js +84 -0
- package/src/commands/install-github-app/ExistingWorkflowStep.js +105 -0
- package/src/commands/install-github-app/InstallAppStep.js +97 -0
- package/src/commands/install-github-app/OAuthFlowStep.js +190 -0
- package/src/commands/install-github-app/SuccessStep.js +94 -0
- package/src/commands/install-github-app/WarningsStep.js +71 -0
- package/src/commands/install-github-app/index.js +10 -0
- package/src/commands/install-github-app/install-github-app.js +593 -0
- package/src/commands/install-github-app/setupGitHubActions.js +227 -0
- package/src/commands/install-slack-app/index.js +9 -0
- package/src/commands/install-slack-app/install-slack-app.js +25 -0
- package/src/commands/install.js +198 -0
- package/src/commands/keybindings/index.js +10 -0
- package/src/commands/keybindings/keybindings.js +47 -0
- package/src/commands/login/index.js +21 -0
- package/src/commands/login/login.js +135 -0
- package/src/commands/logout/index.js +11 -0
- package/src/commands/logout/logout.js +75 -0
- package/src/commands/mcp/addCommand.js +183 -0
- package/src/commands/mcp/index.js +9 -0
- package/src/commands/mcp/mcp.js +78 -0
- package/src/commands/mcp/xaaIdpCommand.js +193 -0
- package/src/commands/memories/index.js +9 -0
- package/src/commands/memories/index.ts +12 -0
- package/src/commands/memories/memories.tsx +950 -0
- package/src/commands/memory/index.js +7 -0
- package/src/commands/memory/memory.js +71 -0
- package/src/commands/mobile/index.js +9 -0
- package/src/commands/mobile/mobile.js +279 -0
- package/src/commands/model/index.js +14 -0
- package/src/commands/model/model.js +284 -0
- package/src/commands/output-style/index.js +8 -0
- package/src/commands/output-style/output-style.js +6 -0
- package/src/commands/passes/index.js +17 -0
- package/src/commands/passes/passes.js +23 -0
- package/src/commands/peers/index.js +68 -0
- package/src/commands/permissions/index.js +8 -0
- package/src/commands/permissions/permissions.js +9 -0
- package/src/commands/plan/index.js +8 -0
- package/src/commands/plan/plan.js +116 -0
- package/src/commands/plugin/AddMarketplace.js +96 -0
- package/src/commands/plugin/BrowseMarketplace.js +582 -0
- package/src/commands/plugin/DiscoverPlugins.js +613 -0
- package/src/commands/plugin/ManageMarketplaces.js +583 -0
- package/src/commands/plugin/ManagePlugins.js +1783 -0
- package/src/commands/plugin/PluginErrors.js +124 -0
- package/src/commands/plugin/PluginOptionsDialog.js +367 -0
- package/src/commands/plugin/PluginOptionsFlow.js +97 -0
- package/src/commands/plugin/PluginSettings.js +1041 -0
- package/src/commands/plugin/PluginTrustWarning.js +35 -0
- package/src/commands/plugin/UnifiedInstalledCell.js +616 -0
- package/src/commands/plugin/ValidatePlugin.js +96 -0
- package/src/commands/plugin/index.js +10 -0
- package/src/commands/plugin/parseArgs.js +71 -0
- package/src/commands/plugin/plugin.js +6 -0
- package/src/commands/plugin/pluginDetailsHelpers.js +95 -0
- package/src/commands/plugin/usePagination.js +89 -0
- package/src/commands/pr_comments/index.js +49 -0
- package/src/commands/privacy-settings/index.js +11 -0
- package/src/commands/privacy-settings/privacy-settings.js +55 -0
- package/src/commands/proactive.js +29 -0
- package/src/commands/rate-limit-options/index.js +15 -0
- package/src/commands/rate-limit-options/rate-limit-options.js +213 -0
- package/src/commands/release-notes/index.js +8 -0
- package/src/commands/release-notes/release-notes.js +38 -0
- package/src/commands/reload-plugins/index.js +11 -0
- package/src/commands/reload-plugins/reload-plugins.js +52 -0
- package/src/commands/remote-env/index.js +12 -0
- package/src/commands/remote-env/remote-env.js +6 -0
- package/src/commands/remote-setup/api.js +155 -0
- package/src/commands/remote-setup/index.js +15 -0
- package/src/commands/remote-setup/remote-setup.js +150 -0
- package/src/commands/remoteControlServer/index.js +58 -0
- package/src/commands/rename/generateSessionName.js +58 -0
- package/src/commands/rename/index.js +9 -0
- package/src/commands/rename/rename.js +52 -0
- package/src/commands/resume/index.js +9 -0
- package/src/commands/resume/resume.js +239 -0
- package/src/commands/review/UltrareviewOverageDialog.js +97 -0
- package/src/commands/review/reviewRemote.js +259 -0
- package/src/commands/review/ultrareviewCommand.js +58 -0
- package/src/commands/review/ultrareviewEnabled.js +10 -0
- package/src/commands/review.js +53 -0
- package/src/commands/rewind/index.js +10 -0
- package/src/commands/rewind/rewind.js +7 -0
- package/src/commands/sandbox-toggle/index.js +41 -0
- package/src/commands/sandbox-toggle/sandbox-toggle.js +73 -0
- package/src/commands/security-review.js +231 -0
- package/src/commands/session/index.js +13 -0
- package/src/commands/session/session.js +143 -0
- package/src/commands/skills/index.js +7 -0
- package/src/commands/skills/skills.js +6 -0
- package/src/commands/speak.js +21 -0
- package/src/commands/start-business.js +1575 -0
- package/src/commands/start-business.ts +1581 -0
- package/src/commands/stats/index.js +7 -0
- package/src/commands/stats/stats.js +6 -0
- package/src/commands/status/index.js +8 -0
- package/src/commands/status/status.js +6 -0
- package/src/commands/statusline.js +22 -0
- package/src/commands/stickers/index.js +8 -0
- package/src/commands/stickers/stickers.js +14 -0
- package/src/commands/subscribe-pr.js +131 -0
- package/src/commands/tag/index.js +9 -0
- package/src/commands/tag/tag.js +215 -0
- package/src/commands/tasks/index.js +8 -0
- package/src/commands/tasks/tasks.js +6 -0
- package/src/commands/terminalSetup/index.js +18 -0
- package/src/commands/terminalSetup/terminalSetup.js +491 -0
- package/src/commands/thaddeus-usage/index.js +17 -0
- package/src/commands/theme/index.js +7 -0
- package/src/commands/theme/theme.js +51 -0
- package/src/commands/thinkback/index.js +9 -0
- package/src/commands/thinkback/thinkback.js +528 -0
- package/src/commands/thinkback-play/index.js +13 -0
- package/src/commands/thinkback-play/thinkback-play.js +34 -0
- package/src/commands/torch.js +122 -0
- package/src/commands/ultraplan.js +416 -0
- package/src/commands/upgrade/index.js +12 -0
- package/src/commands/upgrade/upgrade.js +38 -0
- package/src/commands/usage/index.js +7 -0
- package/src/commands/usage/usage.js +6 -0
- package/src/commands/version.js +17 -0
- package/src/commands/vim/index.js +8 -0
- package/src/commands/vim/vim.js +25 -0
- package/src/commands/voice/index.js +13 -0
- package/src/commands/voice/voice.js +44 -0
- package/src/commands/workflows/index.js +123 -0
- package/src/commands.js +614 -0
- package/src/commands.ts +4 -0
- package/src/components/AgentProgressLine.js +112 -0
- package/src/components/AntModelSwitchCallout.js +8 -0
- package/src/components/App.js +46 -0
- package/src/components/ApproveApiKey.js +125 -0
- package/src/components/AutoModeOptInDialog.js +140 -0
- package/src/components/AutoUpdater.js +156 -0
- package/src/components/AutoUpdaterWrapper.js +78 -0
- package/src/components/AwsAuthStatusBox.js +88 -0
- package/src/components/BaseTextInput.js +105 -0
- package/src/components/BashModeProgress.js +49 -0
- package/src/components/BridgeDialog.js +415 -0
- package/src/components/BypassPermissionsModeDialog.js +87 -0
- package/src/components/ChannelDowngradeDialog.js +101 -0
- package/src/components/ClaudeInChromeOnboarding.js +126 -0
- package/src/components/ClaudeMdExternalIncludesDialog.js +137 -0
- package/src/components/ClickableImageRef.js +65 -0
- package/src/components/CompactSummary.js +120 -0
- package/src/components/ConfigurableShortcutHint.js +35 -0
- package/src/components/ConsoleOAuthFlow.js +554 -0
- package/src/components/ContextSuggestions.js +44 -0
- package/src/components/ContextVisualization.js +482 -0
- package/src/components/CoordinatorAgentStatus.js +261 -0
- package/src/components/CostThresholdDialog.js +49 -0
- package/src/components/CtrlOToExpand.js +50 -0
- package/src/components/CustomSelect/SelectMulti.js +150 -0
- package/src/components/CustomSelect/index.js +2 -0
- package/src/components/CustomSelect/option-map.js +32 -0
- package/src/components/CustomSelect/select-input-option.js +426 -0
- package/src/components/CustomSelect/select-option.js +24 -0
- package/src/components/CustomSelect/select.js +518 -0
- package/src/components/CustomSelect/use-multi-select-state.js +214 -0
- package/src/components/CustomSelect/use-select-input.js +170 -0
- package/src/components/CustomSelect/use-select-navigation.js +366 -0
- package/src/components/CustomSelect/use-select-state.js +22 -0
- package/src/components/DesktopHandoff.js +195 -0
- package/src/components/DesktopUpsell/DesktopUpsellStartup.js +174 -0
- package/src/components/DevBar.js +51 -0
- package/src/components/DevChannelsDialog.js +104 -0
- package/src/components/DiagnosticsDisplay.js +91 -0
- package/src/components/EffortCallout.js +264 -0
- package/src/components/EffortIndicator.js +28 -0
- package/src/components/ExitFlow.js +41 -0
- package/src/components/ExportDialog.js +101 -0
- package/src/components/FallbackToolUseErrorMessage.js +116 -0
- package/src/components/FallbackToolUseRejectedMessage.js +17 -0
- package/src/components/FastIcon.js +43 -0
- package/src/components/Feedback.js +369 -0
- package/src/components/FeedbackSurvey/FeedbackSurvey.js +151 -0
- package/src/components/FeedbackSurvey/FeedbackSurveyView.js +104 -0
- package/src/components/FeedbackSurvey/TranscriptSharePrompt.js +84 -0
- package/src/components/FeedbackSurvey/submitTranscriptShare.js +10 -0
- package/src/components/FeedbackSurvey/useDebouncedDigitInput.js +51 -0
- package/src/components/FeedbackSurvey/useFeedbackSurvey.js +258 -0
- package/src/components/FeedbackSurvey/useFrustrationDetection.js +8 -0
- package/src/components/FeedbackSurvey/useMemorySurvey.js +191 -0
- package/src/components/FeedbackSurvey/usePostCompactSurvey.js +202 -0
- package/src/components/FeedbackSurvey/useSurveyState.js +80 -0
- package/src/components/FileEditToolDiff.js +167 -0
- package/src/components/FileEditToolUpdatedMessage.js +112 -0
- package/src/components/FileEditToolUseRejectedMessage.js +158 -0
- package/src/components/FilePathLink.js +35 -0
- package/src/components/FullscreenLayout.js +578 -0
- package/src/components/GlobalSearchDialog.js +340 -0
- package/src/components/HelpV2/Commands.js +66 -0
- package/src/components/HelpV2/General.js +25 -0
- package/src/components/HelpV2/HelpV2.js +186 -0
- package/src/components/HighlightedCode/Fallback.js +193 -0
- package/src/components/HighlightedCode.js +185 -0
- package/src/components/HistorySearchDialog.js +93 -0
- package/src/components/IdeAutoConnectDialog.js +154 -0
- package/src/components/IdeOnboardingDialog.js +175 -0
- package/src/components/IdeStatusIndicator.js +50 -0
- package/src/components/IdleReturnDialog.js +117 -0
- package/src/components/InterruptedByUser.js +16 -0
- package/src/components/InvalidConfigDialog.js +135 -0
- package/src/components/InvalidSettingsDialog.js +85 -0
- package/src/components/KeybindingWarnings.js +55 -0
- package/src/components/LanguagePicker.js +84 -0
- package/src/components/LogSelector.js +1579 -0
- package/src/components/LogoV2/AnimatedAsterisk.js +43 -0
- package/src/components/LogoV2/AnimatedClawd.js +64 -0
- package/src/components/LogoV2/ChannelsNotice.js +262 -0
- package/src/components/LogoV2/Clawd.js +33 -0
- package/src/components/LogoV2/CondensedLogo.js +160 -0
- package/src/components/LogoV2/EmergencyTip.js +48 -0
- package/src/components/LogoV2/Feed.js +85 -0
- package/src/components/LogoV2/FeedColumn.js +55 -0
- package/src/components/LogoV2/GuestPassesUpsell.js +71 -0
- package/src/components/LogoV2/LogoV2.js +565 -0
- package/src/components/LogoV2/Opus1mMergeNotice.js +57 -0
- package/src/components/LogoV2/OverageCreditUpsell.js +161 -0
- package/src/components/LogoV2/VoiceModeNotice.js +71 -0
- package/src/components/LogoV2/WelcomeV2.js +14 -0
- package/src/components/LogoV2/feedConfigs.js +79 -0
- package/src/components/LspRecommendation/LspRecommendationMenu.js +46 -0
- package/src/components/MCPServerApprovalDialog.js +114 -0
- package/src/components/MCPServerDesktopImportDialog.js +206 -0
- package/src/components/MCPServerDialogCopy.js +16 -0
- package/src/components/MCPServerMultiselectDialog.js +134 -0
- package/src/components/ManagedSettingsSecurityDialog/ManagedSettingsSecurityDialog.js +150 -0
- package/src/components/ManagedSettingsSecurityDialog/utils.js +105 -0
- package/src/components/Markdown.js +233 -0
- package/src/components/MarkdownTable.js +280 -0
- package/src/components/MemoryUsageIndicator.js +28 -0
- package/src/components/Message.js +564 -0
- package/src/components/MessageModel.js +37 -0
- package/src/components/MessageResponse.js +73 -0
- package/src/components/MessageRow.js +346 -0
- package/src/components/MessageSelector.js +744 -0
- package/src/components/MessageTimestamp.js +58 -0
- package/src/components/Messages.js +645 -0
- package/src/components/ModelPicker.js +452 -0
- package/src/components/NativeAutoUpdater.js +152 -0
- package/src/components/NotebookEditToolUseRejectedMessage.js +84 -0
- package/src/components/OffscreenFreeze.js +35 -0
- package/src/components/Onboarding.js +174 -0
- package/src/components/OutputStylePicker.js +103 -0
- package/src/components/PackageManagerAutoUpdater.js +99 -0
- package/src/components/Passes/Passes.js +114 -0
- package/src/components/PrBadge.js +91 -0
- package/src/components/PressEnterToContinue.js +16 -0
- package/src/components/PromptInput/HistorySearchInput.js +45 -0
- package/src/components/PromptInput/IssueFlagBanner.js +8 -0
- package/src/components/PromptInput/Notifications.js +220 -0
- package/src/components/PromptInput/PromptInput.js +2014 -0
- package/src/components/PromptInput/PromptInputFooter.js +85 -0
- package/src/components/PromptInput/PromptInputFooterLeftSide.js +408 -0
- package/src/components/PromptInput/PromptInputFooterSuggestions.js +281 -0
- package/src/components/PromptInput/PromptInputHelpMenu.js +380 -0
- package/src/components/PromptInput/PromptInputModeIndicator.js +73 -0
- package/src/components/PromptInput/PromptInputQueuedCommands.js +105 -0
- package/src/components/PromptInput/PromptInputStashNotice.js +21 -0
- package/src/components/PromptInput/SandboxPromptFooterHint.js +66 -0
- package/src/components/PromptInput/ShimmeredInput.js +133 -0
- package/src/components/PromptInput/VoiceIndicator.js +137 -0
- package/src/components/PromptInput/inputModes.js +24 -0
- package/src/components/PromptInput/inputPaste.js +62 -0
- package/src/components/PromptInput/useMaybeTruncateInput.js +33 -0
- package/src/components/PromptInput/usePromptInputPlaceholder.js +53 -0
- package/src/components/PromptInput/useShowFastIconHint.js +23 -0
- package/src/components/PromptInput/useSwarmBanner.js +112 -0
- package/src/components/PromptInput/utils.js +50 -0
- package/src/components/QuickOpenDialog.js +244 -0
- package/src/components/RemoteCallout.js +53 -0
- package/src/components/RemoteEnvironmentDialog.js +346 -0
- package/src/components/ResumeTask.js +173 -0
- package/src/components/SandboxViolationExpandedView.js +106 -0
- package/src/components/SandboxViolationExpandedView.tsx +3 -0
- package/src/components/ScrollKeybindingHandler.js +982 -0
- package/src/components/SearchBox.js +56 -0
- package/src/components/SentryErrorBoundary.js +16 -0
- package/src/components/SessionBackgroundHint.js +105 -0
- package/src/components/SessionPreview.js +200 -0
- package/src/components/Settings/Config.js +1626 -0
- package/src/components/Settings/Settings.js +131 -0
- package/src/components/Settings/Status.js +230 -0
- package/src/components/Settings/Usage.js +341 -0
- package/src/components/ShowInIDEPrompt.js +152 -0
- package/src/components/SkillImprovementSurvey.js +130 -0
- package/src/components/Spinner/FlashingChar.js +52 -0
- package/src/components/Spinner/GlimmerMessage.js +329 -0
- package/src/components/Spinner/ShimmerChar.js +23 -0
- package/src/components/Spinner/SpinnerAnimationRow.js +170 -0
- package/src/components/Spinner/SpinnerGlyph.js +70 -0
- package/src/components/Spinner/TeammateSpinnerLine.js +171 -0
- package/src/components/Spinner/TeammateSpinnerTree.js +269 -0
- package/src/components/Spinner/index.js +9 -0
- package/src/components/Spinner/teammateSelectHint.js +1 -0
- package/src/components/Spinner/useShimmerAnimation.js +22 -0
- package/src/components/Spinner/useStalledAnimation.js +63 -0
- package/src/components/Spinner/utils.js +78 -0
- package/src/components/Spinner.js +474 -0
- package/src/components/Stats.js +1000 -0
- package/src/components/StatusLine.js +286 -0
- package/src/components/StatusNotices.js +50 -0
- package/src/components/StructuredDiff/Fallback.js +336 -0
- package/src/components/StructuredDiff/colorDiff.js +37 -0
- package/src/components/StructuredDiff.js +153 -0
- package/src/components/StructuredDiffList.js +9 -0
- package/src/components/TagTabs.js +101 -0
- package/src/components/TaskListV2.js +333 -0
- package/src/components/TeammateViewHeader.js +88 -0
- package/src/components/TeleportError.js +191 -0
- package/src/components/TeleportProgress.js +131 -0
- package/src/components/TeleportRepoMismatchDialog.js +98 -0
- package/src/components/TeleportResumeWrapper.js +158 -0
- package/src/components/TeleportStash.js +82 -0
- package/src/components/TextInput.js +108 -0
- package/src/components/ThaddeusHint/PluginHintMenu.js +37 -0
- package/src/components/ThemePicker.js +331 -0
- package/src/components/ThinkingToggle.js +154 -0
- package/src/components/TokenWarning.js +171 -0
- package/src/components/ToolUseLoader.js +35 -0
- package/src/components/TrustDialog/TrustDialog.js +301 -0
- package/src/components/TrustDialog/utils.js +199 -0
- package/src/components/UndercoverAutoCallout.js +5 -0
- package/src/components/ValidationErrorsList.js +147 -0
- package/src/components/VimTextInput.js +136 -0
- package/src/components/VirtualMessageList.js +893 -0
- package/src/components/WorkflowMultiselectDialog.js +118 -0
- package/src/components/WorktreeExitDialog.js +220 -0
- package/src/components/agents/AgentDetail.js +227 -0
- package/src/components/agents/AgentEditor.js +147 -0
- package/src/components/agents/AgentNavigationFooter.js +22 -0
- package/src/components/agents/AgentsList.js +436 -0
- package/src/components/agents/AgentsMenu.js +849 -0
- package/src/components/agents/ColorPicker.js +110 -0
- package/src/components/agents/ModelSelector.js +63 -0
- package/src/components/agents/SnapshotUpdateDialog.js +14 -0
- package/src/components/agents/ToolSelector.js +557 -0
- package/src/components/agents/agentFileUtils.js +179 -0
- package/src/components/agents/generateAgent.js +161 -0
- package/src/components/agents/new-agent-creation/CreateAgentWizard.js +89 -0
- package/src/components/agents/new-agent-creation/wizard-steps/ColorStep.js +81 -0
- package/src/components/agents/new-agent-creation/wizard-steps/ConfirmStep.js +387 -0
- package/src/components/agents/new-agent-creation/wizard-steps/ConfirmStepWrapper.js +63 -0
- package/src/components/agents/new-agent-creation/wizard-steps/DescriptionStep.js +126 -0
- package/src/components/agents/new-agent-creation/wizard-steps/GenerateStep.js +118 -0
- package/src/components/agents/new-agent-creation/wizard-steps/LocationStep.js +80 -0
- package/src/components/agents/new-agent-creation/wizard-steps/MemoryStep.js +108 -0
- package/src/components/agents/new-agent-creation/wizard-steps/MethodStep.js +80 -0
- package/src/components/agents/new-agent-creation/wizard-steps/ModelStep.js +49 -0
- package/src/components/agents/new-agent-creation/wizard-steps/PromptStep.js +131 -0
- package/src/components/agents/new-agent-creation/wizard-steps/ToolsStep.js +52 -0
- package/src/components/agents/new-agent-creation/wizard-steps/TypeStep.js +100 -0
- package/src/components/agents/types.js +4 -0
- package/src/components/agents/utils.js +14 -0
- package/src/components/agents/validateAgent.js +79 -0
- package/src/components/design-system/Byline.js +72 -0
- package/src/components/design-system/Dialog.js +117 -0
- package/src/components/design-system/Divider.js +110 -0
- package/src/components/design-system/FuzzyPicker.js +191 -0
- package/src/components/design-system/KeyboardShortcutHint.js +68 -0
- package/src/components/design-system/ListItem.js +184 -0
- package/src/components/design-system/LoadingState.js +69 -0
- package/src/components/design-system/Pane.js +69 -0
- package/src/components/design-system/ProgressBar.js +63 -0
- package/src/components/design-system/Ratchet.js +71 -0
- package/src/components/design-system/StatusIcon.js +70 -0
- package/src/components/design-system/Tabs.js +269 -0
- package/src/components/design-system/ThemeProvider.js +137 -0
- package/src/components/design-system/ThemedBox.js +126 -0
- package/src/components/design-system/ThemedText.js +60 -0
- package/src/components/design-system/color.js +22 -0
- package/src/components/diff/DiffDetailView.js +285 -0
- package/src/components/diff/DiffDialog.js +387 -0
- package/src/components/diff/DiffFileList.js +292 -0
- package/src/components/grove/Grove.js +483 -0
- package/src/components/hooks/HooksConfigMenu.js +583 -0
- package/src/components/hooks/PromptDialog.js +82 -0
- package/src/components/hooks/SelectEventMode.js +118 -0
- package/src/components/hooks/SelectHookMode.js +101 -0
- package/src/components/hooks/SelectMatcherMode.js +131 -0
- package/src/components/hooks/ViewHookMode.js +204 -0
- package/src/components/mcp/CapabilitiesSection.js +56 -0
- package/src/components/mcp/ElicitationDialog.js +945 -0
- package/src/components/mcp/MCPAgentServerMenu.js +95 -0
- package/src/components/mcp/MCPListPanel.js +505 -0
- package/src/components/mcp/MCPReconnect.js +168 -0
- package/src/components/mcp/MCPRemoteServerMenu.js +460 -0
- package/src/components/mcp/MCPSettings.js +414 -0
- package/src/components/mcp/MCPStdioServerMenu.js +95 -0
- package/src/components/mcp/MCPToolDetailView.js +219 -0
- package/src/components/mcp/MCPToolListView.js +137 -0
- package/src/components/mcp/McpParsingWarnings.js +212 -0
- package/src/components/mcp/index.js +8 -0
- package/src/components/mcp/utils/reconnectHelpers.js +35 -0
- package/src/components/memory/MemoryFileSelector.js +454 -0
- package/src/components/memory/MemoryUpdateNotification.js +43 -0
- package/src/components/messageActions.js +418 -0
- package/src/components/messages/AdvisorMessage.js +152 -0
- package/src/components/messages/AssistantRedactedThinkingMessage.js +28 -0
- package/src/components/messages/AssistantTextMessage.js +287 -0
- package/src/components/messages/AssistantThinkingMessage.js +70 -0
- package/src/components/messages/AssistantToolUseMessage.js +324 -0
- package/src/components/messages/AttachmentMessage.js +418 -0
- package/src/components/messages/CollapsedReadSearchContent.js +363 -0
- package/src/components/messages/CompactBoundaryMessage.js +19 -0
- package/src/components/messages/GroupedToolUseContent.js +37 -0
- package/src/components/messages/HighlightedThinkingText.js +165 -0
- package/src/components/messages/HookProgressMessage.js +111 -0
- package/src/components/messages/PlanApprovalMessage.js +213 -0
- package/src/components/messages/RateLimitMessage.js +149 -0
- package/src/components/messages/ShutdownMessage.js +124 -0
- package/src/components/messages/SnipBoundaryMessage.js +7 -0
- package/src/components/messages/SystemAPIErrorMessage.js +136 -0
- package/src/components/messages/SystemTextMessage.js +842 -0
- package/src/components/messages/TaskAssignmentMessage.js +72 -0
- package/src/components/messages/UserAgentNotificationMessage.js +78 -0
- package/src/components/messages/UserBashInputMessage.js +52 -0
- package/src/components/messages/UserBashOutputMessage.js +55 -0
- package/src/components/messages/UserChannelMessage.js +130 -0
- package/src/components/messages/UserCommandMessage.js +107 -0
- package/src/components/messages/UserCrossSessionMessage.js +11 -0
- package/src/components/messages/UserForkBoilerplateMessage.js +11 -0
- package/src/components/messages/UserGitHubWebhookMessage.js +12 -0
- package/src/components/messages/UserImageMessage.js +54 -0
- package/src/components/messages/UserLocalCommandOutputMessage.js +170 -0
- package/src/components/messages/UserMemoryInputMessage.js +73 -0
- package/src/components/messages/UserPlanMessage.js +38 -0
- package/src/components/messages/UserPromptMessage.js +63 -0
- package/src/components/messages/UserResourceUpdateMessage.js +102 -0
- package/src/components/messages/UserTeammateMessage.js +156 -0
- package/src/components/messages/UserTextMessage.js +270 -0
- package/src/components/messages/UserToolResultMessage/RejectedPlanMessage.js +28 -0
- package/src/components/messages/UserToolResultMessage/RejectedToolUseMessage.js +17 -0
- package/src/components/messages/UserToolResultMessage/UserToolCanceledMessage.js +17 -0
- package/src/components/messages/UserToolResultMessage/UserToolErrorMessage.js +92 -0
- package/src/components/messages/UserToolResultMessage/UserToolRejectMessage.js +74 -0
- package/src/components/messages/UserToolResultMessage/UserToolResultMessage.js +84 -0
- package/src/components/messages/UserToolResultMessage/UserToolSuccessMessage.js +58 -0
- package/src/components/messages/UserToolResultMessage/utils.js +43 -0
- package/src/components/messages/nullRenderingAttachments.js +58 -0
- package/src/components/messages/teamMemCollapsed.js +142 -0
- package/src/components/messages/teamMemSaved.js +16 -0
- package/src/components/permissions/AskUserQuestionPermissionRequest/AskUserQuestionPermissionRequest.js +659 -0
- package/src/components/permissions/AskUserQuestionPermissionRequest/PreviewBox.js +219 -0
- package/src/components/permissions/AskUserQuestionPermissionRequest/PreviewQuestionView.js +227 -0
- package/src/components/permissions/AskUserQuestionPermissionRequest/QuestionNavigationBar.js +175 -0
- package/src/components/permissions/AskUserQuestionPermissionRequest/QuestionView.js +444 -0
- package/src/components/permissions/AskUserQuestionPermissionRequest/SubmitQuestionsView.js +137 -0
- package/src/components/permissions/AskUserQuestionPermissionRequest/use-multiple-choice-state.js +100 -0
- package/src/components/permissions/BashPermissionRequest/BashPermissionRequest.js +404 -0
- package/src/components/permissions/BashPermissionRequest/bashToolUseOptions.js +110 -0
- package/src/components/permissions/ComputerUseApproval/ComputerUseApproval.js +449 -0
- package/src/components/permissions/EnterPlanModePermissionRequest/EnterPlanModePermissionRequest.js +126 -0
- package/src/components/permissions/ExitPlanModePermissionRequest/ExitPlanModePermissionRequest.js +653 -0
- package/src/components/permissions/FallbackPermissionRequest.js +349 -0
- package/src/components/permissions/FileEditPermissionRequest/FileEditPermissionRequest.js +185 -0
- package/src/components/permissions/FilePermissionDialog/FilePermissionDialog.js +108 -0
- package/src/components/permissions/FilePermissionDialog/ideDiffConfig.js +13 -0
- package/src/components/permissions/FilePermissionDialog/permissionOptions.js +137 -0
- package/src/components/permissions/FilePermissionDialog/useFilePermissionDialog.js +131 -0
- package/src/components/permissions/FilePermissionDialog/usePermissionHandler.js +86 -0
- package/src/components/permissions/FileWritePermissionRequest/FileWritePermissionRequest.js +164 -0
- package/src/components/permissions/FileWritePermissionRequest/FileWriteToolDiff.js +79 -0
- package/src/components/permissions/FilesystemPermissionRequest/FilesystemPermissionRequest.js +113 -0
- package/src/components/permissions/MonitorPermissionRequest/MonitorPermissionRequest.js +7 -0
- package/src/components/permissions/NotebookEditPermissionRequest/NotebookEditPermissionRequest.js +164 -0
- package/src/components/permissions/NotebookEditPermissionRequest/NotebookEditToolDiff.js +218 -0
- package/src/components/permissions/PermissionDecisionDebugInfo.js +467 -0
- package/src/components/permissions/PermissionDialog.js +55 -0
- package/src/components/permissions/PermissionExplanation.js +269 -0
- package/src/components/permissions/PermissionPrompt.js +316 -0
- package/src/components/permissions/PermissionRequest.js +159 -0
- package/src/components/permissions/PermissionRequestTitle.js +58 -0
- package/src/components/permissions/PermissionRuleExplanation.js +110 -0
- package/src/components/permissions/PowerShellPermissionRequest/PowerShellPermissionRequest.js +178 -0
- package/src/components/permissions/PowerShellPermissionRequest/powershellToolUseOptions.js +73 -0
- package/src/components/permissions/ReviewArtifactPermissionRequest/ReviewArtifactPermissionRequest.js +7 -0
- package/src/components/permissions/SandboxPermissionRequest.js +162 -0
- package/src/components/permissions/SedEditPermissionRequest/SedEditPermissionRequest.js +228 -0
- package/src/components/permissions/SkillPermissionRequest/SkillPermissionRequest.js +385 -0
- package/src/components/permissions/WebFetchPermissionRequest/WebFetchPermissionRequest.js +259 -0
- package/src/components/permissions/WorkerBadge.js +44 -0
- package/src/components/permissions/WorkerPendingPermission.js +107 -0
- package/src/components/permissions/hooks.js +163 -0
- package/src/components/permissions/rules/AddPermissionRules.js +171 -0
- package/src/components/permissions/rules/AddWorkspaceDirectory.js +335 -0
- package/src/components/permissions/rules/PermissionRuleDescription.js +78 -0
- package/src/components/permissions/rules/PermissionRuleInput.js +136 -0
- package/src/components/permissions/rules/PermissionRuleList.js +1190 -0
- package/src/components/permissions/rules/RecentDenialsTab.js +205 -0
- package/src/components/permissions/rules/RemoveWorkspaceDirectory.js +103 -0
- package/src/components/permissions/rules/WorkspaceTab.js +133 -0
- package/src/components/permissions/shellPermissionHelpers.js +112 -0
- package/src/components/permissions/useShellPermissionFeedback.js +108 -0
- package/src/components/permissions/utils.js +14 -0
- package/src/components/sandbox/SandboxConfigTab.js +48 -0
- package/src/components/sandbox/SandboxDependenciesTab.js +123 -0
- package/src/components/sandbox/SandboxDoctorSection.js +47 -0
- package/src/components/sandbox/SandboxOverridesTab.js +193 -0
- package/src/components/sandbox/SandboxSettings.js +297 -0
- package/src/components/shell/ExpandShellOutputContext.js +33 -0
- package/src/components/shell/OutputLine.js +110 -0
- package/src/components/shell/ShellProgressMessage.js +144 -0
- package/src/components/shell/ShellTimeDisplay.js +72 -0
- package/src/components/skills/SkillsMenu.js +239 -0
- package/src/components/tasks/AsyncAgentDetailDialog.js +235 -0
- package/src/components/tasks/BackgroundTask.js +364 -0
- package/src/components/tasks/BackgroundTaskStatus.js +419 -0
- package/src/components/tasks/BackgroundTasksDialog.js +494 -0
- package/src/components/tasks/DreamDetailDialog.js +251 -0
- package/src/components/tasks/InProcessTeammateDetailDialog.js +275 -0
- package/src/components/tasks/MonitorMcpDetailDialog.js +7 -0
- package/src/components/tasks/RemoteSessionDetailDialog.js +868 -0
- package/src/components/tasks/RemoteSessionProgress.js +249 -0
- package/src/components/tasks/ShellDetailDialog.js +403 -0
- package/src/components/tasks/ShellProgress.js +77 -0
- package/src/components/tasks/WorkflowDetailDialog.js +7 -0
- package/src/components/tasks/renderToolActivity.js +29 -0
- package/src/components/tasks/taskStatusUtils.js +94 -0
- package/src/components/teams/TeamStatus.js +77 -0
- package/src/components/teams/TeamsDialog.js +673 -0
- package/src/components/ui/OrderedList.js +66 -0
- package/src/components/ui/OrderedListItem.js +41 -0
- package/src/components/ui/TreeSelect.js +300 -0
- package/src/components/wizard/WizardDialogLayout.js +48 -0
- package/src/components/wizard/WizardNavigationFooter.js +11 -0
- package/src/components/wizard/WizardProvider.js +217 -0
- package/src/components/wizard/index.js +4 -0
- package/src/components/wizard/useWizard.js +9 -0
- package/src/constants/apiLimits.js +81 -0
- package/src/constants/betas.js +45 -0
- package/src/constants/common.js +29 -0
- package/src/constants/cyberRiskInstruction.js +23 -0
- package/src/constants/errorIds.js +14 -0
- package/src/constants/figures.js +38 -0
- package/src/constants/files.js +150 -0
- package/src/constants/github-app.js +139 -0
- package/src/constants/identity.js +112 -0
- package/src/constants/keys.js +10 -0
- package/src/constants/messages.js +1 -0
- package/src/constants/oauth.js +175 -0
- package/src/constants/outputStyles.js +162 -0
- package/src/constants/product.js +54 -0
- package/src/constants/prompts.js +994 -0
- package/src/constants/spinnerVerbs.js +98 -0
- package/src/constants/system.js +77 -0
- package/src/constants/systemPromptSections.js +39 -0
- package/src/constants/toolLimits.js +50 -0
- package/src/constants/tools.js +103 -0
- package/src/constants/turnCompletionVerbs.js +12 -0
- package/src/constants/xml.js +73 -0
- package/src/context/QueuedMessageContext.js +51 -0
- package/src/context/fpsMetrics.js +22 -0
- package/src/context/mailbox.js +35 -0
- package/src/context/modalContext.js +34 -0
- package/src/context/notifications.js +199 -0
- package/src/context/overlayContext.js +149 -0
- package/src/context/promptOverlayContext.js +118 -0
- package/src/context/stats.js +207 -0
- package/src/context/voice.js +74 -0
- package/src/context.js +146 -0
- package/src/coordinator/coordinatorMode.js +345 -0
- package/src/coordinator/workerAgent.js +24 -0
- package/src/cost-tracker.js +208 -0
- package/src/costHook.js +17 -0
- package/src/daemon/main.js +19 -0
- package/src/dialogLaunchers.js +77 -0
- package/src/entrypoints/agentSdkTypes.js +202 -0
- package/src/entrypoints/cli.js +226 -0
- package/src/entrypoints/init.js +265 -0
- package/src/entrypoints/mcp.js +141 -0
- package/src/entrypoints/sandboxTypes.js +112 -0
- package/src/entrypoints/sdk/controlSchemas.js +452 -0
- package/src/entrypoints/sdk/controlTypes.js +1 -0
- package/src/entrypoints/sdk/coreSchemas.js +1331 -0
- package/src/entrypoints/sdk/coreTypes.generated.js +3 -0
- package/src/entrypoints/sdk/coreTypes.js +49 -0
- package/src/entrypoints/sdk/runtimeTypes.js +1 -0
- package/src/entrypoints/sdk/sdkUtilityTypes.js +1 -0
- package/src/entrypoints/sdk/settingsTypes.generated.js +1 -0
- package/src/entrypoints/sdk/toolTypes.js +1 -0
- package/src/environment-runner/main.js +8 -0
- package/src/history.js +386 -0
- package/src/hooks/fileSuggestions.js +635 -0
- package/src/hooks/notifs/useAntOrgWarningNotification.js +5 -0
- package/src/hooks/notifs/useAutoModeUnavailableNotification.js +47 -0
- package/src/hooks/notifs/useCanSwitchToExistingSubscription.js +58 -0
- package/src/hooks/notifs/useDeprecationWarningNotification.js +43 -0
- package/src/hooks/notifs/useFastModeNotification.js +164 -0
- package/src/hooks/notifs/useIDEStatusIndicator.js +174 -0
- package/src/hooks/notifs/useInstallMessages.js +27 -0
- package/src/hooks/notifs/useLspInitializationNotification.js +144 -0
- package/src/hooks/notifs/useMcpConnectivityStatus.js +81 -0
- package/src/hooks/notifs/useModelMigrationNotifications.js +53 -0
- package/src/hooks/notifs/useNpmDeprecationNotification.js +25 -0
- package/src/hooks/notifs/usePluginAutoupdateNotification.js +83 -0
- package/src/hooks/notifs/usePluginInstallationStatus.js +128 -0
- package/src/hooks/notifs/useRateLimitWarningNotification.js +119 -0
- package/src/hooks/notifs/useSettingsErrors.js +64 -0
- package/src/hooks/notifs/useStartupNotification.js +33 -0
- package/src/hooks/notifs/useTeammateShutdownNotification.js +64 -0
- package/src/hooks/renderPlaceholder.js +26 -0
- package/src/hooks/toolPermission/PermissionContext.js +211 -0
- package/src/hooks/toolPermission/handlers/coordinatorHandler.js +44 -0
- package/src/hooks/toolPermission/handlers/interactiveHandler.js +397 -0
- package/src/hooks/toolPermission/handlers/swarmWorkerHandler.js +108 -0
- package/src/hooks/toolPermission/permissionLogging.js +145 -0
- package/src/hooks/unifiedSuggestions.js +130 -0
- package/src/hooks/useAfterFirstRender.js +12 -0
- package/src/hooks/useApiKeyVerification.js +63 -0
- package/src/hooks/useArrowKeyHistory.js +203 -0
- package/src/hooks/useAssistantHistory.js +193 -0
- package/src/hooks/useAwaySummary.js +105 -0
- package/src/hooks/useBackgroundTaskNavigation.js +204 -0
- package/src/hooks/useBlink.js +28 -0
- package/src/hooks/useCanUseTool.js +193 -0
- package/src/hooks/useCancelRequest.js +195 -0
- package/src/hooks/useChromeExtensionNotification.js +50 -0
- package/src/hooks/useClipboardImageHint.js +59 -0
- package/src/hooks/useCommandKeybindings.js +87 -0
- package/src/hooks/useCommandQueue.js +10 -0
- package/src/hooks/useCopyOnSelect.js +88 -0
- package/src/hooks/useDeferredHookMessages.js +43 -0
- package/src/hooks/useDiffData.js +69 -0
- package/src/hooks/useDiffInIDE.js +252 -0
- package/src/hooks/useDirectConnect.js +150 -0
- package/src/hooks/useDoublePress.js +44 -0
- package/src/hooks/useDynamicConfig.js +17 -0
- package/src/hooks/useElapsedTime.js +25 -0
- package/src/hooks/useExitOnCtrlCD.js +57 -0
- package/src/hooks/useExitOnCtrlCDWithKeybindings.js +17 -0
- package/src/hooks/useFileHistorySnapshotInit.js +14 -0
- package/src/hooks/useGlobalKeybindings.js +213 -0
- package/src/hooks/useHistorySearch.js +241 -0
- package/src/hooks/useIDEIntegration.js +56 -0
- package/src/hooks/useIdeAtMentioned.js +51 -0
- package/src/hooks/useIdeConnectionStatus.js +21 -0
- package/src/hooks/useIdeLogging.js +29 -0
- package/src/hooks/useIdeSelection.js +106 -0
- package/src/hooks/useInboxPoller.js +709 -0
- package/src/hooks/useInputBuffer.js +73 -0
- package/src/hooks/useIssueFlagBanner.js +115 -0
- package/src/hooks/useLogMessages.js +98 -0
- package/src/hooks/useLspPluginRecommendation.js +176 -0
- package/src/hooks/useMailboxBridge.js +15 -0
- package/src/hooks/useMainLoopModel.js +25 -0
- package/src/hooks/useManagePlugins.js +261 -0
- package/src/hooks/useMemoryUsage.js +28 -0
- package/src/hooks/useMergedClients.js +11 -0
- package/src/hooks/useMergedCommands.js +10 -0
- package/src/hooks/useMergedTools.js +32 -0
- package/src/hooks/useMinDisplayTime.js +26 -0
- package/src/hooks/useNotifyAfterTimeout.js +51 -0
- package/src/hooks/useOfficialMarketplaceNotification.js +47 -0
- package/src/hooks/usePasteHandler.js +195 -0
- package/src/hooks/usePluginRecommendationBase.js +101 -0
- package/src/hooks/usePrStatus.js +91 -0
- package/src/hooks/usePromptSuggestion.js +128 -0
- package/src/hooks/usePromptsFromClaudeInChrome.js +66 -0
- package/src/hooks/useQueueProcessor.js +46 -0
- package/src/hooks/useRemoteSession.js +431 -0
- package/src/hooks/useReplBridge.js +715 -0
- package/src/hooks/useSSHSession.js +167 -0
- package/src/hooks/useScheduledTasks.js +104 -0
- package/src/hooks/useSearchInput.js +302 -0
- package/src/hooks/useSessionBackgrounding.js +132 -0
- package/src/hooks/useSettings.js +10 -0
- package/src/hooks/useSettingsChange.js +13 -0
- package/src/hooks/useSkillImprovementSurvey.js +69 -0
- package/src/hooks/useSkillsChange.js +51 -0
- package/src/hooks/useSwarmInitialization.js +67 -0
- package/src/hooks/useSwarmPermissionPoller.js +215 -0
- package/src/hooks/useTaskListWatcher.js +157 -0
- package/src/hooks/useTasksV2.js +220 -0
- package/src/hooks/useTeammateViewAutoExit.js +55 -0
- package/src/hooks/useTeleportResume.js +81 -0
- package/src/hooks/useTerminalSize.js +9 -0
- package/src/hooks/useTextInput.js +397 -0
- package/src/hooks/useThaddeusHintRecommendation.js +117 -0
- package/src/hooks/useTimeout.js +10 -0
- package/src/hooks/useTurnDiffs.js +160 -0
- package/src/hooks/useTypeahead.js +1250 -0
- package/src/hooks/useUpdateNotification.js +21 -0
- package/src/hooks/useVimInput.js +232 -0
- package/src/hooks/useVirtualScroll.js +627 -0
- package/src/hooks/useVoice.js +952 -0
- package/src/hooks/useVoiceEnabled.js +21 -0
- package/src/hooks/useVoiceIntegration.js +629 -0
- package/src/infrastructure/audit.js +210 -0
- package/src/infrastructure/guardrails.js +513 -0
- package/src/infrastructure/index.js +11 -0
- package/src/ink/Ansi.js +269 -0
- package/src/ink/bidi.js +117 -0
- package/src/ink/clearTerminal.js +58 -0
- package/src/ink/colorize.js +198 -0
- package/src/ink/components/AlternateScreen.js +74 -0
- package/src/ink/components/App.js +562 -0
- package/src/ink/components/AppContext.js +11 -0
- package/src/ink/components/Box.js +155 -0
- package/src/ink/components/Button.js +166 -0
- package/src/ink/components/ClockContext.js +108 -0
- package/src/ink/components/CursorDeclarationContext.js +3 -0
- package/src/ink/components/ErrorOverview.js +50 -0
- package/src/ink/components/Link.js +34 -0
- package/src/ink/components/Newline.js +30 -0
- package/src/ink/components/NoSelect.js +57 -0
- package/src/ink/components/RawAnsi.js +46 -0
- package/src/ink/components/ScrollBox.js +171 -0
- package/src/ink/components/Spacer.js +20 -0
- package/src/ink/components/StdinContext.js +16 -0
- package/src/ink/components/TerminalFocusContext.js +45 -0
- package/src/ink/components/TerminalSizeContext.js +3 -0
- package/src/ink/components/Text.js +195 -0
- package/src/ink/constants.js +2 -0
- package/src/ink/dom.js +298 -0
- package/src/ink/events/click-event.js +36 -0
- package/src/ink/events/dispatcher.js +172 -0
- package/src/ink/events/emitter.js +31 -0
- package/src/ink/events/event-handlers.js +30 -0
- package/src/ink/events/event.js +9 -0
- package/src/ink/events/focus-event.js +16 -0
- package/src/ink/events/input-event.js +161 -0
- package/src/ink/events/keyboard-event.js +46 -0
- package/src/ink/events/terminal-event.js +78 -0
- package/src/ink/events/terminal-focus-event.js +15 -0
- package/src/ink/focus.js +158 -0
- package/src/ink/frame.js +30 -0
- package/src/ink/get-max-width.js +23 -0
- package/src/ink/hit-test.js +113 -0
- package/src/ink/hooks/use-animation-frame.js +48 -0
- package/src/ink/hooks/use-app.js +7 -0
- package/src/ink/hooks/use-declared-cursor.js +60 -0
- package/src/ink/hooks/use-input.js +70 -0
- package/src/ink/hooks/use-interval.js +54 -0
- package/src/ink/hooks/use-search-highlight.js +32 -0
- package/src/ink/hooks/use-selection.js +60 -0
- package/src/ink/hooks/use-stdin.js +7 -0
- package/src/ink/hooks/use-tab-status.js +57 -0
- package/src/ink/hooks/use-terminal-focus.js +15 -0
- package/src/ink/hooks/use-terminal-title.js +29 -0
- package/src/ink/hooks/use-terminal-viewport.js +77 -0
- package/src/ink/ink.js +1645 -0
- package/src/ink/instances.js +7 -0
- package/src/ink/layout/engine.js +4 -0
- package/src/ink/layout/geometry.js +61 -0
- package/src/ink/layout/node.js +62 -0
- package/src/ink/layout/yoga.js +237 -0
- package/src/ink/line-width-cache.js +19 -0
- package/src/ink/log-update.js +583 -0
- package/src/ink/measure-element.js +8 -0
- package/src/ink/measure-text.js +35 -0
- package/src/ink/node-cache.js +30 -0
- package/src/ink/optimizer.js +81 -0
- package/src/ink/output.js +556 -0
- package/src/ink/parse-keypress.js +695 -0
- package/src/ink/reconciler.js +384 -0
- package/src/ink/render-border.js +134 -0
- package/src/ink/render-node-to-output.js +1216 -0
- package/src/ink/render-to-screen.js +171 -0
- package/src/ink/renderer.js +129 -0
- package/src/ink/root.js +80 -0
- package/src/ink/screen.js +1132 -0
- package/src/ink/searchHighlight.js +78 -0
- package/src/ink/selection.js +792 -0
- package/src/ink/squash-text-nodes.js +56 -0
- package/src/ink/stringWidth.js +200 -0
- package/src/ink/styles.js +299 -0
- package/src/ink/supports-hyperlinks.js +40 -0
- package/src/ink/tabstops.js +39 -0
- package/src/ink/terminal-focus-state.js +35 -0
- package/src/ink/terminal-querier.js +173 -0
- package/src/ink/terminal.js +208 -0
- package/src/ink/termio/ansi.js +70 -0
- package/src/ink/termio/csi.js +260 -0
- package/src/ink/termio/dec.js +53 -0
- package/src/ink/termio/esc.js +55 -0
- package/src/ink/termio/osc.js +432 -0
- package/src/ink/termio/parser.js +356 -0
- package/src/ink/termio/sgr.js +292 -0
- package/src/ink/termio/tokenize.js +264 -0
- package/src/ink/termio/types.js +55 -0
- package/src/ink/termio.js +24 -0
- package/src/ink/useTerminalNotification.js +57 -0
- package/src/ink/warn.js +10 -0
- package/src/ink/widest-line.js +14 -0
- package/src/ink/wrap-text.js +54 -0
- package/src/ink/wrapAnsi.js +6 -0
- package/src/ink.js +50 -0
- package/src/integrations/credentialStore.js +176 -0
- package/src/integrations/index.js +5 -0
- package/src/integrations/integrationManager.js +180 -0
- package/src/integrations/providers/BaseProvider.js +180 -0
- package/src/integrations/providers/GitHubProvider.js +217 -0
- package/src/integrations/providers/GmailProvider.js +204 -0
- package/src/integrations/providers/GoogleCalendarProvider.js +113 -0
- package/src/integrations/providers/HubSpotProvider.js +159 -0
- package/src/integrations/providers/JiraProvider.js +216 -0
- package/src/integrations/providers/NotionProvider.js +221 -0
- package/src/integrations/providers/QuickBooksProvider.js +176 -0
- package/src/integrations/providers/SlackProvider.js +174 -0
- package/src/integrations/providers/StripeProvider.js +206 -0
- package/src/integrations/providers/TwilioProvider.js +239 -0
- package/src/integrations/providers/_template.js +112 -0
- package/src/integrations/types.js +7 -0
- package/src/interactiveHelpers.js +308 -0
- package/src/jobs/classifier.js +6 -0
- package/src/keybindings/KeybindingContext.js +184 -0
- package/src/keybindings/KeybindingProviderSetup.js +259 -0
- package/src/keybindings/defaultBindings.js +333 -0
- package/src/keybindings/loadUserBindings.js +393 -0
- package/src/keybindings/match.js +111 -0
- package/src/keybindings/parser.js +184 -0
- package/src/keybindings/reservedShortcuts.js +109 -0
- package/src/keybindings/resolver.js +182 -0
- package/src/keybindings/schema.js +205 -0
- package/src/keybindings/shortcutFormat.js +48 -0
- package/src/keybindings/template.js +40 -0
- package/src/keybindings/useKeybinding.js +161 -0
- package/src/keybindings/useShortcutDisplay.js +43 -0
- package/src/keybindings/validate.js +395 -0
- package/src/main.js +4128 -0
- package/src/memdir/findRelevantMemories.js +99 -0
- package/src/memdir/memdir.js +406 -0
- package/src/memdir/memoryAge.js +52 -0
- package/src/memdir/memoryScan.js +65 -0
- package/src/memdir/memoryShapeTelemetry.js +8 -0
- package/src/memdir/memoryTypes.js +260 -0
- package/src/memdir/paths.js +235 -0
- package/src/memdir/teamMemPaths.js +261 -0
- package/src/memdir/teamMemPrompts.js +82 -0
- package/src/migrations/migrateAutoUpdatesToSettings.js +47 -0
- package/src/migrations/migrateBypassPermissionsAcceptedToSettings.js +32 -0
- package/src/migrations/migrateEnableAllProjectMcpServersToSettings.js +83 -0
- package/src/migrations/migrateFennecToOpus.js +39 -0
- package/src/migrations/migrateLegacyOpusToCurrent.js +44 -0
- package/src/migrations/migrateOpusToOpus1m.js +31 -0
- package/src/migrations/migrateReplBridgeEnabledToRemoteControlAtStartup.js +23 -0
- package/src/migrations/migrateSonnet1mToSonnet45.js +38 -0
- package/src/migrations/migrateSonnet45ToSonnet46.js +48 -0
- package/src/migrations/resetAutoModeOptInForDefaultOffer.js +47 -0
- package/src/migrations/resetProToOpusDefault.js +46 -0
- package/src/moreright/useMoreRight.js +13 -0
- package/src/native-ts/color-diff/index.js +819 -0
- package/src/native-ts/file-index/index.js +328 -0
- package/src/native-ts/yoga-layout/enums.js +101 -0
- package/src/native-ts/yoga-layout/index.js +2113 -0
- package/src/outputStyles/loadOutputStylesDir.js +71 -0
- package/src/plugins/builtinPlugins.js +132 -0
- package/src/plugins/bundled/index.js +22 -0
- package/src/proactive/index.js +138 -0
- package/src/proactive/useProactive.js +82 -0
- package/src/projectOnboardingState.js +61 -0
- package/src/query/config.js +17 -0
- package/src/query/deps.js +12 -0
- package/src/query/stopHooks.js +332 -0
- package/src/query/tokenBudget.js +49 -0
- package/src/query.js +1264 -0
- package/src/remote/RemoteSessionManager.js +172 -0
- package/src/remote/SessionsWebSocket.js +308 -0
- package/src/remote/remotePermissionBridge.js +70 -0
- package/src/remote/sdkMessageAdapter.js +227 -0
- package/src/replLauncher.js +7 -0
- package/src/schemas/hooks.js +174 -0
- package/src/screens/Doctor.js +580 -0
- package/src/screens/REPL.js +4500 -0
- package/src/screens/ResumeConversation.js +339 -0
- package/src/self-hosted-runner/main.js +8 -0
- package/src/server/backends/dangerousBackend.js +8 -0
- package/src/server/connectHeadless.js +6 -0
- package/src/server/createDirectConnectSession.js +62 -0
- package/src/server/directConnectManager.js +153 -0
- package/src/server/lockfile.js +11 -0
- package/src/server/parseConnectUrl.js +20 -0
- package/src/server/server.js +12 -0
- package/src/server/serverBanner.js +9 -0
- package/src/server/serverLog.js +11 -0
- package/src/server/sessionManager.js +19 -0
- package/src/server/types.js +7 -0
- package/src/services/AgentSummary/agentSummary.js +147 -0
- package/src/services/MagicDocs/magicDocs.js +193 -0
- package/src/services/MagicDocs/prompts.js +110 -0
- package/src/services/PromptSuggestion/promptSuggestion.js +402 -0
- package/src/services/PromptSuggestion/speculation.js +643 -0
- package/src/services/SessionMemory/prompts.js +254 -0
- package/src/services/SessionMemory/sessionMemory.js +358 -0
- package/src/services/SessionMemory/sessionMemoryUtils.js +157 -0
- package/src/services/analytics/config.js +27 -0
- package/src/services/analytics/datadog.js +26 -0
- package/src/services/analytics/firstPartyEventLogger.js +65 -0
- package/src/services/analytics/firstPartyEventLoggingExporter.js +595 -0
- package/src/services/analytics/growthbook.js +103 -0
- package/src/services/analytics/index.js +91 -0
- package/src/services/analytics/metadata.js +696 -0
- package/src/services/analytics/sink.js +19 -0
- package/src/services/analytics/sinkKillswitch.js +19 -0
- package/src/services/api/adminRequests.js +57 -0
- package/src/services/api/bootstrap.js +118 -0
- package/src/services/api/claude.js +2466 -0
- package/src/services/api/client.js +335 -0
- package/src/services/api/dumpPrompts.js +174 -0
- package/src/services/api/emptyUsage.js +20 -0
- package/src/services/api/errorUtils.js +203 -0
- package/src/services/api/errors.js +926 -0
- package/src/services/api/filesApi.js +523 -0
- package/src/services/api/firstTokenDate.js +49 -0
- package/src/services/api/grove.js +44 -0
- package/src/services/api/logging.js +484 -0
- package/src/services/api/metricsOptOut.js +15 -0
- package/src/services/api/overageCreditGrant.js +123 -0
- package/src/services/api/promptCacheBreakDetection.js +510 -0
- package/src/services/api/referral.js +219 -0
- package/src/services/api/sessionIngress.js +358 -0
- package/src/services/api/ultrareviewQuota.js +29 -0
- package/src/services/api/usage.js +31 -0
- package/src/services/api/withRetry.js +587 -0
- package/src/services/api/xai/anthropic-shim.js +885 -0
- package/src/services/api/xai/brightDataSearch.js +161 -0
- package/src/services/api/xai/thaddeus-engine.js +605 -0
- package/src/services/api/xai/xai-client.js +276 -0
- package/src/services/autoDream/autoDream.js +244 -0
- package/src/services/autoDream/config.js +17 -0
- package/src/services/autoDream/consolidationLock.js +122 -0
- package/src/services/autoDream/consolidationPrompt.js +55 -0
- package/src/services/awaySummary.js +61 -0
- package/src/services/claudeAiLimits.js +331 -0
- package/src/services/claudeAiLimitsHook.js +15 -0
- package/src/services/compact/apiMicrocompact.js +97 -0
- package/src/services/compact/autoCompact.js +234 -0
- package/src/services/compact/cachedMCConfig.js +5 -0
- package/src/services/compact/compact.js +1256 -0
- package/src/services/compact/compactWarningHook.js +12 -0
- package/src/services/compact/compactWarningState.js +15 -0
- package/src/services/compact/grouping.js +58 -0
- package/src/services/compact/microCompact.js +414 -0
- package/src/services/compact/postCompactCleanup.js +70 -0
- package/src/services/compact/prompt.js +325 -0
- package/src/services/compact/reactiveCompact.js +20 -0
- package/src/services/compact/sessionMemoryCompact.js +467 -0
- package/src/services/compact/snipCompact.js +23 -0
- package/src/services/compact/snipProjection.js +11 -0
- package/src/services/compact/timeBasedMCConfig.js +11 -0
- package/src/services/contextCollapse/index.js +33 -0
- package/src/services/contextCollapse/operations.js +5 -0
- package/src/services/contextCollapse/persist.js +5 -0
- package/src/services/diagnosticTracking.js +282 -0
- package/src/services/elevenlabsTTS.js +245 -0
- package/src/services/extractMemories/extractMemories.js +442 -0
- package/src/services/extractMemories/prompts.js +129 -0
- package/src/services/internalLogging.js +68 -0
- package/src/services/lsp/LSPClient.js +306 -0
- package/src/services/lsp/LSPDiagnosticRegistry.js +277 -0
- package/src/services/lsp/LSPServerInstance.js +388 -0
- package/src/services/lsp/LSPServerManager.js +305 -0
- package/src/services/lsp/config.js +57 -0
- package/src/services/lsp/manager.js +246 -0
- package/src/services/lsp/passiveFeedback.js +226 -0
- package/src/services/mcp/InProcessTransport.js +54 -0
- package/src/services/mcp/MCPConnectionManager.js +50 -0
- package/src/services/mcp/SdkControlTransport.js +115 -0
- package/src/services/mcp/auth.js +1882 -0
- package/src/services/mcp/channelAllowlist.js +57 -0
- package/src/services/mcp/channelNotification.js +235 -0
- package/src/services/mcp/channelPermissions.js +192 -0
- package/src/services/mcp/claudeai.js +123 -0
- package/src/services/mcp/client.js +2478 -0
- package/src/services/mcp/config.js +1271 -0
- package/src/services/mcp/elicitationHandler.js +192 -0
- package/src/services/mcp/envExpansion.js +30 -0
- package/src/services/mcp/headersHelper.js +93 -0
- package/src/services/mcp/mcpStringUtils.js +85 -0
- package/src/services/mcp/normalization.js +21 -0
- package/src/services/mcp/oauthPort.js +69 -0
- package/src/services/mcp/officialRegistry.js +20 -0
- package/src/services/mcp/types.js +94 -0
- package/src/services/mcp/useManageMCPConnections.js +818 -0
- package/src/services/mcp/utils.js +433 -0
- package/src/services/mcp/vscodeSdkMcp.js +69 -0
- package/src/services/mcp/xaa.js +342 -0
- package/src/services/mcp/xaaIdpLogin.js +377 -0
- package/src/services/mcpServerApproval.js +30 -0
- package/src/services/mockRateLimits.js +666 -0
- package/src/services/notifier.js +114 -0
- package/src/services/oauth/auth-code-listener.js +165 -0
- package/src/services/oauth/client.js +397 -0
- package/src/services/oauth/crypto.js +19 -0
- package/src/services/oauth/getOauthProfile.js +48 -0
- package/src/services/oauth/index.js +133 -0
- package/src/services/plugins/PluginInstallationManager.js +139 -0
- package/src/services/plugins/pluginCliCommands.js +230 -0
- package/src/services/plugins/pluginOperations.js +826 -0
- package/src/services/policyLimits/index.js +547 -0
- package/src/services/policyLimits/types.js +9 -0
- package/src/services/preventSleep.js +143 -0
- package/src/services/rateLimitMessages.js +271 -0
- package/src/services/rateLimitMocking.js +91 -0
- package/src/services/remoteManagedSettings/index.js +534 -0
- package/src/services/remoteManagedSettings/securityCheck.js +60 -0
- package/src/services/remoteManagedSettings/syncCache.js +90 -0
- package/src/services/remoteManagedSettings/syncCacheState.js +89 -0
- package/src/services/remoteManagedSettings/types.js +12 -0
- package/src/services/sessionTranscript/sessionTranscript.js +5 -0
- package/src/services/settingsSync/index.js +478 -0
- package/src/services/settingsSync/types.js +35 -0
- package/src/services/skillSearch/featureCheck.js +8 -0
- package/src/services/skillSearch/localSearch.js +5 -0
- package/src/services/skillSearch/prefetch.js +8 -0
- package/src/services/skillSearch/remoteSkillLoader.js +8 -0
- package/src/services/skillSearch/remoteSkillState.js +11 -0
- package/src/services/skillSearch/signals.js +3 -0
- package/src/services/skillSearch/telemetry.js +8 -0
- package/src/services/teamMemorySync/index.js +976 -0
- package/src/services/teamMemorySync/secretScanner.js +275 -0
- package/src/services/teamMemorySync/teamMemSecretGuard.js +33 -0
- package/src/services/teamMemorySync/types.js +47 -0
- package/src/services/teamMemorySync/watcher.js +326 -0
- package/src/services/thaddeusAuth.js +485 -0
- package/src/services/thaddeusAuthTypes.js +9 -0
- package/src/services/thaddeusLoginFlow.js +236 -0
- package/src/services/tips/tipHistory.js +17 -0
- package/src/services/tips/tipRegistry.js +593 -0
- package/src/services/tips/tipScheduler.js +40 -0
- package/src/services/tokenEstimation.js +365 -0
- package/src/services/toolUseSummary/toolUseSummaryGenerator.js +87 -0
- package/src/services/tools/StreamingToolExecutor.js +413 -0
- package/src/services/tools/toolExecution.js +1309 -0
- package/src/services/tools/toolHooks.js +454 -0
- package/src/services/tools/toolOrchestration.js +110 -0
- package/src/services/vcr.js +291 -0
- package/src/services/voice.js +392 -0
- package/src/services/voiceKeyterms.js +94 -0
- package/src/services/voiceStreamSTT.js +405 -0
- package/src/setup.js +310 -0
- package/src/skills/bundled/batch.js +114 -0
- package/src/skills/bundled/claudeApi.js +145 -0
- package/src/skills/bundled/claudeApiContent.js +71 -0
- package/src/skills/bundled/claudeInChrome.js +27 -0
- package/src/skills/bundled/debug.js +99 -0
- package/src/skills/bundled/dream.js +49 -0
- package/src/skills/bundled/emailSetup.js +196 -0
- package/src/skills/bundled/hunter.js +28 -0
- package/src/skills/bundled/index.js +80 -0
- package/src/skills/bundled/keybindings.js +292 -0
- package/src/skills/bundled/loop.js +81 -0
- package/src/skills/bundled/loremIpsum.js +264 -0
- package/src/skills/bundled/reactor.js +31 -0
- package/src/skills/bundled/remember.js +73 -0
- package/src/skills/bundled/runSkillGenerator.js +12 -0
- package/src/skills/bundled/scheduleRemoteAgents.js +373 -0
- package/src/skills/bundled/simplify.js +66 -0
- package/src/skills/bundled/skillify.js +182 -0
- package/src/skills/bundled/stuck.js +69 -0
- package/src/skills/bundled/updateConfig.js +463 -0
- package/src/skills/bundled/verify.js +23 -0
- package/src/skills/bundled/verifyContent.js +10 -0
- package/src/skills/bundledSkills.js +159 -0
- package/src/skills/loadSkillsDir.js +736 -0
- package/src/skills/mcpSkillBuilders.js +10 -0
- package/src/skills/mcpSkills.js +5 -0
- package/src/state/AppState.js +182 -0
- package/src/state/AppStateStore.js +117 -0
- package/src/state/onChangeAppState.js +132 -0
- package/src/state/selectors.js +51 -0
- package/src/state/store.js +21 -0
- package/src/state/teammateViewHelpers.js +124 -0
- package/src/stubs/ant-chrome-mcp/index.js +4 -0
- package/src/stubs/ant-computer-use-input/index.js +2 -0
- package/src/stubs/ant-computer-use-mcp/index.js +7 -0
- package/src/stubs/ant-computer-use-mcp/sentinelApps.js +2 -0
- package/src/stubs/ant-computer-use-mcp/types.js +3 -0
- package/src/stubs/ant-computer-use-swift/index.js +1 -0
- package/src/stubs/anthropic-sandbox/index.js +34 -0
- package/src/tasks/DreamTask/DreamTask.js +99 -0
- package/src/tasks/InProcessTeammateTask/InProcessTeammateTask.js +116 -0
- package/src/tasks/InProcessTeammateTask/types.js +35 -0
- package/src/tasks/LocalAgentTask/LocalAgentTask.js +507 -0
- package/src/tasks/LocalMainSessionTask.js +338 -0
- package/src/tasks/LocalShellTask/LocalShellTask.js +475 -0
- package/src/tasks/LocalShellTask/guards.js +9 -0
- package/src/tasks/LocalShellTask/killShellTasks.js +59 -0
- package/src/tasks/LocalWorkflowTask/LocalWorkflowTask.js +7 -0
- package/src/tasks/MonitorMcpTask/MonitorMcpTask.js +20 -0
- package/src/tasks/RemoteAgentTask/RemoteAgentTask.js +742 -0
- package/src/tasks/pillLabel.js +69 -0
- package/src/tasks/stopTask.js +67 -0
- package/src/tasks/types.js +18 -0
- package/src/tasks.js +37 -0
- package/src/tools/AIEmployeesTool/AIEmployeesTool.js +674 -0
- package/src/tools/AIEmployeesTool/constants.js +1 -0
- package/src/tools/AIEmployeesTool/prompt.js +56 -0
- package/src/tools/AgentTool/AgentTool.js +1221 -0
- package/src/tools/AgentTool/UI.js +593 -0
- package/src/tools/AgentTool/agentColorManager.js +43 -0
- package/src/tools/AgentTool/agentDisplay.js +72 -0
- package/src/tools/AgentTool/agentMemory.js +125 -0
- package/src/tools/AgentTool/agentMemorySnapshot.js +136 -0
- package/src/tools/AgentTool/agentToolUtils.js +456 -0
- package/src/tools/AgentTool/built-in/exploreAgent.js +76 -0
- package/src/tools/AgentTool/built-in/generalPurposeAgent.js +28 -0
- package/src/tools/AgentTool/built-in/planAgent.js +87 -0
- package/src/tools/AgentTool/built-in/statuslineSetup.js +140 -0
- package/src/tools/AgentTool/built-in/thaddeusGuideAgent.js +174 -0
- package/src/tools/AgentTool/built-in/verificationAgent.js +146 -0
- package/src/tools/AgentTool/builtInAgents.js +56 -0
- package/src/tools/AgentTool/constants.js +11 -0
- package/src/tools/AgentTool/forkSubagent.js +177 -0
- package/src/tools/AgentTool/loadAgentsDir.js +497 -0
- package/src/tools/AgentTool/prompt.js +260 -0
- package/src/tools/AgentTool/resumeAgent.js +182 -0
- package/src/tools/AgentTool/runAgent.js +627 -0
- package/src/tools/AppointmentsTool/AppointmentsTool.js +628 -0
- package/src/tools/AppointmentsTool/constants.js +1 -0
- package/src/tools/AppointmentsTool/prompt.js +15 -0
- package/src/tools/AskUserQuestionTool/AskUserQuestionTool.js +238 -0
- package/src/tools/AskUserQuestionTool/prompt.js +38 -0
- package/src/tools/BashTool/BashTool.js +1009 -0
- package/src/tools/BashTool/BashToolResultMessage.js +169 -0
- package/src/tools/BashTool/UI.js +134 -0
- package/src/tools/BashTool/bashCommandHelpers.js +184 -0
- package/src/tools/BashTool/bashPermissions.js +2023 -0
- package/src/tools/BashTool/bashSecurity.js +2267 -0
- package/src/tools/BashTool/commandSemantics.js +105 -0
- package/src/tools/BashTool/commentLabel.js +14 -0
- package/src/tools/BashTool/destructiveCommandWarning.js +88 -0
- package/src/tools/BashTool/modeValidation.js +86 -0
- package/src/tools/BashTool/pathValidation.js +1079 -0
- package/src/tools/BashTool/prompt.js +333 -0
- package/src/tools/BashTool/readOnlyValidation.js +1794 -0
- package/src/tools/BashTool/sedEditParser.js +282 -0
- package/src/tools/BashTool/sedValidation.js +580 -0
- package/src/tools/BashTool/shouldUseSandbox.js +125 -0
- package/src/tools/BashTool/toolName.js +2 -0
- package/src/tools/BashTool/utils.js +180 -0
- package/src/tools/BriefTool/BriefTool.js +173 -0
- package/src/tools/BriefTool/UI.js +67 -0
- package/src/tools/BriefTool/attachments.js +86 -0
- package/src/tools/BriefTool/prompt.js +19 -0
- package/src/tools/BriefTool/upload.js +136 -0
- package/src/tools/CalendarTool/CalendarTool.js +498 -0
- package/src/tools/CalendarTool/constants.js +1 -0
- package/src/tools/CalendarTool/prompt.js +11 -0
- package/src/tools/ConfigTool/ConfigTool.js +398 -0
- package/src/tools/ConfigTool/UI.js +25 -0
- package/src/tools/ConfigTool/constants.js +1 -0
- package/src/tools/ConfigTool/prompt.js +82 -0
- package/src/tools/ConfigTool/supportedSettings.js +180 -0
- package/src/tools/ContactsTool/ContactsTool.js +648 -0
- package/src/tools/ContactsTool/constants.js +1 -0
- package/src/tools/ContactsTool/prompt.js +15 -0
- package/src/tools/CtxInspectTool/CtxInspectTool.js +44 -0
- package/src/tools/DiscoverSkillsTool/prompt.js +4 -0
- package/src/tools/EmailReadTool/index.js +410 -0
- package/src/tools/EmailSendTool/index.js +178 -0
- package/src/tools/EnterPlanModeTool/EnterPlanModeTool.js +98 -0
- package/src/tools/EnterPlanModeTool/UI.js +14 -0
- package/src/tools/EnterPlanModeTool/constants.js +1 -0
- package/src/tools/EnterPlanModeTool/prompt.js +164 -0
- package/src/tools/EnterWorktreeTool/EnterWorktreeTool.js +104 -0
- package/src/tools/EnterWorktreeTool/UI.js +9 -0
- package/src/tools/EnterWorktreeTool/constants.js +1 -0
- package/src/tools/EnterWorktreeTool/prompt.js +30 -0
- package/src/tools/ExitPlanModeTool/ExitPlanModeV2Tool.js +383 -0
- package/src/tools/ExitPlanModeTool/UI.js +32 -0
- package/src/tools/ExitPlanModeTool/constants.js +2 -0
- package/src/tools/ExitPlanModeTool/prompt.js +27 -0
- package/src/tools/ExitWorktreeTool/ExitWorktreeTool.js +257 -0
- package/src/tools/ExitWorktreeTool/UI.js +10 -0
- package/src/tools/ExitWorktreeTool/constants.js +1 -0
- package/src/tools/ExitWorktreeTool/prompt.js +32 -0
- package/src/tools/FileEditTool/FileEditTool.js +480 -0
- package/src/tools/FileEditTool/UI.js +202 -0
- package/src/tools/FileEditTool/constants.js +7 -0
- package/src/tools/FileEditTool/prompt.js +24 -0
- package/src/tools/FileEditTool/types.js +50 -0
- package/src/tools/FileEditTool/utils.js +579 -0
- package/src/tools/FileReadTool/FileReadTool.js +889 -0
- package/src/tools/FileReadTool/UI.js +126 -0
- package/src/tools/FileReadTool/imageProcessor.js +46 -0
- package/src/tools/FileReadTool/limits.js +70 -0
- package/src/tools/FileReadTool/prompt.js +31 -0
- package/src/tools/FileWriteTool/FileWriteTool.js +341 -0
- package/src/tools/FileWriteTool/UI.js +339 -0
- package/src/tools/FileWriteTool/prompt.js +15 -0
- package/src/tools/GlobTool/GlobTool.js +161 -0
- package/src/tools/GlobTool/UI.js +40 -0
- package/src/tools/GlobTool/prompt.js +6 -0
- package/src/tools/GrepTool/GrepTool.js +439 -0
- package/src/tools/GrepTool/UI.js +155 -0
- package/src/tools/GrepTool/prompt.js +16 -0
- package/src/tools/IntegrationsTool/IntegrationsTool.js +217 -0
- package/src/tools/IntegrationsTool/constants.js +1 -0
- package/src/tools/IntegrationsTool/prompt.js +41 -0
- package/src/tools/InteractionsTool/InteractionsTool.js +525 -0
- package/src/tools/InteractionsTool/constants.js +1 -0
- package/src/tools/InteractionsTool/prompt.js +14 -0
- package/src/tools/InvoicesTool/InvoicesTool.js +581 -0
- package/src/tools/InvoicesTool/constants.js +1 -0
- package/src/tools/InvoicesTool/prompt.js +15 -0
- package/src/tools/LSPTool/LSPTool.js +660 -0
- package/src/tools/LSPTool/UI.js +205 -0
- package/src/tools/LSPTool/formatters.js +445 -0
- package/src/tools/LSPTool/prompt.js +20 -0
- package/src/tools/LSPTool/schemas.js +197 -0
- package/src/tools/LSPTool/symbolContext.js +75 -0
- package/src/tools/LeadScorerTool/LeadScorerTool.js +509 -0
- package/src/tools/LeadScorerTool/constants.js +1 -0
- package/src/tools/LeadScorerTool/prompt.js +11 -0
- package/src/tools/ListMcpResourcesTool/ListMcpResourcesTool.js +100 -0
- package/src/tools/ListMcpResourcesTool/UI.js +17 -0
- package/src/tools/ListMcpResourcesTool/prompt.js +18 -0
- package/src/tools/ListPeersTool/ListPeersTool.js +45 -0
- package/src/tools/MCPTool/MCPTool.js +60 -0
- package/src/tools/MCPTool/UI.js +343 -0
- package/src/tools/MCPTool/classifyForCollapse.js +597 -0
- package/src/tools/MCPTool/prompt.js +3 -0
- package/src/tools/McpAuthTool/McpAuthTool.js +162 -0
- package/src/tools/MonitorTool/MonitorTool.js +55 -0
- package/src/tools/NotebookEditTool/NotebookEditTool.js +421 -0
- package/src/tools/NotebookEditTool/UI.js +41 -0
- package/src/tools/NotebookEditTool/constants.js +2 -0
- package/src/tools/NotebookEditTool/prompt.js +2 -0
- package/src/tools/OverflowTestTool/OverflowTestTool.js +51 -0
- package/src/tools/PhoneBridgeTool/PhoneBridgeTool.js +301 -0
- package/src/tools/PhoneBridgeTool/constants.js +1 -0
- package/src/tools/PhoneBridgeTool/prompt.js +26 -0
- package/src/tools/PowerShellTool/PowerShellTool.js +900 -0
- package/src/tools/PowerShellTool/UI.js +58 -0
- package/src/tools/PowerShellTool/clmTypes.js +207 -0
- package/src/tools/PowerShellTool/commandSemantics.js +115 -0
- package/src/tools/PowerShellTool/commonParameters.js +27 -0
- package/src/tools/PowerShellTool/destructiveCommandWarning.js +92 -0
- package/src/tools/PowerShellTool/gitSafety.js +185 -0
- package/src/tools/PowerShellTool/modeValidation.js +357 -0
- package/src/tools/PowerShellTool/pathValidation.js +1712 -0
- package/src/tools/PowerShellTool/powershellPermissions.js +1351 -0
- package/src/tools/PowerShellTool/powershellSecurity.js +942 -0
- package/src/tools/PowerShellTool/prompt.js +132 -0
- package/src/tools/PowerShellTool/readOnlyValidation.js +1633 -0
- package/src/tools/PowerShellTool/toolName.js +2 -0
- package/src/tools/PushNotificationTool/PushNotificationTool.js +35 -0
- package/src/tools/REPLTool/REPLTool.js +44 -0
- package/src/tools/REPLTool/constants.js +43 -0
- package/src/tools/REPLTool/primitiveTools.js +36 -0
- package/src/tools/ReadMcpResourceTool/ReadMcpResourceTool.js +112 -0
- package/src/tools/ReadMcpResourceTool/UI.js +24 -0
- package/src/tools/ReadMcpResourceTool/prompt.js +15 -0
- package/src/tools/RemoteTriggerTool/RemoteTriggerTool.js +142 -0
- package/src/tools/RemoteTriggerTool/UI.js +12 -0
- package/src/tools/RemoteTriggerTool/prompt.js +12 -0
- package/src/tools/ReviewArtifactTool/ReviewArtifactTool.js +51 -0
- package/src/tools/ScheduleCronTool/CronCreateTool.js +120 -0
- package/src/tools/ScheduleCronTool/CronDeleteTool.js +74 -0
- package/src/tools/ScheduleCronTool/CronListTool.js +77 -0
- package/src/tools/ScheduleCronTool/UI.js +29 -0
- package/src/tools/ScheduleCronTool/prompt.js +115 -0
- package/src/tools/SendMessageTool/SendMessageTool.js +673 -0
- package/src/tools/SendMessageTool/UI.js +24 -0
- package/src/tools/SendMessageTool/constants.js +1 -0
- package/src/tools/SendMessageTool/prompt.js +47 -0
- package/src/tools/SendUserFileTool/SendUserFileTool.js +35 -0
- package/src/tools/SendUserFileTool/prompt.js +5 -0
- package/src/tools/SkillTool/SkillTool.js +825 -0
- package/src/tools/SkillTool/UI.js +61 -0
- package/src/tools/SkillTool/constants.js +1 -0
- package/src/tools/SkillTool/prompt.js +184 -0
- package/src/tools/SleepTool/SleepTool.js +42 -0
- package/src/tools/SleepTool/prompt.js +14 -0
- package/src/tools/SnipTool/SnipTool.js +47 -0
- package/src/tools/SnipTool/prompt.js +5 -0
- package/src/tools/SubscribePRTool/SubscribePRTool.js +49 -0
- package/src/tools/SuggestBackgroundPRTool/SuggestBackgroundPRTool.js +44 -0
- package/src/tools/SyntheticOutputTool/SyntheticOutputTool.js +138 -0
- package/src/tools/SyntheticOutputTool/SyntheticOutputTool.ts +1 -1
- package/src/tools/TaskCreateTool/TaskCreateTool.js +104 -0
- package/src/tools/TaskCreateTool/constants.js +1 -0
- package/src/tools/TaskCreateTool/prompt.js +52 -0
- package/src/tools/TaskGetTool/TaskGetTool.js +106 -0
- package/src/tools/TaskGetTool/constants.js +1 -0
- package/src/tools/TaskGetTool/prompt.js +23 -0
- package/src/tools/TaskListTool/TaskListTool.js +89 -0
- package/src/tools/TaskListTool/constants.js +1 -0
- package/src/tools/TaskListTool/prompt.js +44 -0
- package/src/tools/TaskOutputTool/TaskOutputTool.js +536 -0
- package/src/tools/TaskOutputTool/constants.js +1 -0
- package/src/tools/TaskStopTool/TaskStopTool.js +110 -0
- package/src/tools/TaskStopTool/UI.js +31 -0
- package/src/tools/TaskStopTool/prompt.js +7 -0
- package/src/tools/TaskUpdateTool/TaskUpdateTool.js +301 -0
- package/src/tools/TaskUpdateTool/constants.js +1 -0
- package/src/tools/TaskUpdateTool/prompt.js +76 -0
- package/src/tools/TeamCreateTool/TeamCreateTool.js +177 -0
- package/src/tools/TeamCreateTool/UI.js +4 -0
- package/src/tools/TeamCreateTool/constants.js +1 -0
- package/src/tools/TeamCreateTool/prompt.js +113 -0
- package/src/tools/TeamDeleteTool/TeamDeleteTool.js +102 -0
- package/src/tools/TeamDeleteTool/UI.js +13 -0
- package/src/tools/TeamDeleteTool/constants.js +1 -0
- package/src/tools/TeamDeleteTool/prompt.js +16 -0
- package/src/tools/TerminalCaptureTool/TerminalCaptureTool.js +47 -0
- package/src/tools/TerminalCaptureTool/prompt.js +11 -0
- package/src/tools/TodoWriteTool/TodoWriteTool.js +99 -0
- package/src/tools/TodoWriteTool/constants.js +1 -0
- package/src/tools/TodoWriteTool/prompt.js +181 -0
- package/src/tools/ToolSearchTool/ToolSearchTool.js +357 -0
- package/src/tools/ToolSearchTool/constants.js +1 -0
- package/src/tools/ToolSearchTool/prompt.js +97 -0
- package/src/tools/TungstenTool/TungstenLiveMonitor.js +7 -0
- package/src/tools/TungstenTool/TungstenTool.js +3 -0
- package/src/tools/VerifyPlanExecutionTool/VerifyPlanExecutionTool.js +45 -0
- package/src/tools/VerifyPlanExecutionTool/constants.js +2 -0
- package/src/tools/WebBrowserTool/WebBrowserPanel.js +5 -0
- package/src/tools/WebBrowserTool/WebBrowserTool.js +58 -0
- package/src/tools/WebFetchTool/UI.js +31 -0
- package/src/tools/WebFetchTool/WebFetchTool.js +246 -0
- package/src/tools/WebFetchTool/preapproved.js +154 -0
- package/src/tools/WebFetchTool/prompt.js +39 -0
- package/src/tools/WebFetchTool/utils.js +368 -0
- package/src/tools/WebSearchTool/UI.js +67 -0
- package/src/tools/WebSearchTool/WebSearchTool.js +396 -0
- package/src/tools/WebSearchTool/prompt.js +32 -0
- package/src/tools/WorkflowTool/WorkflowPermissionRequest.js +7 -0
- package/src/tools/WorkflowTool/WorkflowTool.js +51 -0
- package/src/tools/WorkflowTool/bundled/index.js +5 -0
- package/src/tools/WorkflowTool/constants.js +1 -0
- package/src/tools/WorkflowTool/createWorkflowCommand.js +5 -0
- package/src/tools/shared/gitOperationTracking.js +220 -0
- package/src/tools/shared/spawnMultiAgent.js +805 -0
- package/src/tools/testing/TestingPermissionTool.js +72 -0
- package/src/tools/utils.js +24 -0
- package/src/tools.js +365 -0
- package/src/types/command.js +8 -0
- package/src/types/connectorText.js +3 -0
- package/src/types/generated/events_mono/claude_code/v1/claude_code_internal_event.js +673 -0
- package/src/types/generated/events_mono/common/v1/auth.js +49 -0
- package/src/types/generated/events_mono/growthbook/v1/growthbook_experiment_event.js +147 -0
- package/src/types/generated/google/protobuf/timestamp.js +38 -0
- package/src/types/hooks.js +153 -0
- package/src/types/ids.js +27 -0
- package/src/types/logs.js +11 -0
- package/src/types/permissions.js +25 -0
- package/src/types/plugin.js +72 -0
- package/src/types/textInputTypes.js +20 -0
- package/src/upstreamproxy/relay.js +346 -0
- package/src/upstreamproxy/upstreamproxy.js +234 -0
- package/src/utils/CircularBuffer.js +75 -0
- package/src/utils/Cursor.js +1229 -0
- package/src/utils/QueryGuard.js +115 -0
- package/src/utils/Shell.js +374 -0
- package/src/utils/ShellCommand.js +336 -0
- package/src/utils/abortController.js +74 -0
- package/src/utils/activityManager.js +127 -0
- package/src/utils/advisor.js +77 -0
- package/src/utils/agentContext.js +91 -0
- package/src/utils/agentId.js +83 -0
- package/src/utils/agentSwarmsEnabled.js +37 -0
- package/src/utils/agenticSessionSearch.js +255 -0
- package/src/utils/analyzeContext.js +846 -0
- package/src/utils/ansiToPng.js +259 -0
- package/src/utils/ansiToSvg.js +207 -0
- package/src/utils/api.js +555 -0
- package/src/utils/apiPreconnect.js +62 -0
- package/src/utils/appleTerminalBackup.js +95 -0
- package/src/utils/argumentSubstitution.js +114 -0
- package/src/utils/array.js +12 -0
- package/src/utils/asciicast.js +200 -0
- package/src/utils/attachments.js +2518 -0
- package/src/utils/attribution.js +308 -0
- package/src/utils/auth.js +1598 -0
- package/src/utils/authFileDescriptor.js +152 -0
- package/src/utils/authPortable.js +14 -0
- package/src/utils/autoModeDenials.js +15 -0
- package/src/utils/autoRunIssue.js +113 -0
- package/src/utils/autoUpdater.js +457 -0
- package/src/utils/aws.js +44 -0
- package/src/utils/awsAuthStatusManager.js +66 -0
- package/src/utils/background/remote/preconditions.js +175 -0
- package/src/utils/background/remote/remoteSession.js +53 -0
- package/src/utils/backgroundHousekeeping.js +64 -0
- package/src/utils/bash/ParsedCommand.js +241 -0
- package/src/utils/bash/ShellSnapshot.js +489 -0
- package/src/utils/bash/ast.js +2590 -0
- package/src/utils/bash/bashParser.js +4355 -0
- package/src/utils/bash/bashPipeCommand.js +249 -0
- package/src/utils/bash/commands.js +1131 -0
- package/src/utils/bash/heredoc.js +647 -0
- package/src/utils/bash/parser.js +195 -0
- package/src/utils/bash/prefix.js +154 -0
- package/src/utils/bash/registry.js +23 -0
- package/src/utils/bash/shellCompletion.js +196 -0
- package/src/utils/bash/shellPrefix.js +25 -0
- package/src/utils/bash/shellQuote.js +253 -0
- package/src/utils/bash/shellQuoting.js +106 -0
- package/src/utils/bash/specs/alias.js +11 -0
- package/src/utils/bash/specs/index.js +16 -0
- package/src/utils/bash/specs/nohup.js +10 -0
- package/src/utils/bash/specs/pyright.js +88 -0
- package/src/utils/bash/specs/sleep.js +10 -0
- package/src/utils/bash/specs/srun.js +28 -0
- package/src/utils/bash/specs/time.js +10 -0
- package/src/utils/bash/specs/timeout.js +17 -0
- package/src/utils/bash/treeSitterAnalysis.js +407 -0
- package/src/utils/betas.js +331 -0
- package/src/utils/billing.js +54 -0
- package/src/utils/binaryCheck.js +40 -0
- package/src/utils/browser.js +58 -0
- package/src/utils/bufferedWriter.js +77 -0
- package/src/utils/bundledMode.js +19 -0
- package/src/utils/businessDb.js +390 -0
- package/src/utils/caCerts.js +91 -0
- package/src/utils/caCertsConfig.js +77 -0
- package/src/utils/cachePaths.js +28 -0
- package/src/utils/classifierApprovals.js +66 -0
- package/src/utils/classifierApprovalsHook.js +10 -0
- package/src/utils/claudeDesktop.js +108 -0
- package/src/utils/claudeInChrome/chromeNativeHost.js +416 -0
- package/src/utils/claudeInChrome/common.js +466 -0
- package/src/utils/claudeInChrome/mcpServer.js +237 -0
- package/src/utils/claudeInChrome/prompt.js +79 -0
- package/src/utils/claudeInChrome/setup.js +304 -0
- package/src/utils/claudeInChrome/setupPortable.js +172 -0
- package/src/utils/claudeInChrome/toolRendering.js +235 -0
- package/src/utils/claudemd.js +1052 -0
- package/src/utils/cleanup.js +514 -0
- package/src/utils/cleanupRegistry.js +22 -0
- package/src/utils/cliArgs.js +53 -0
- package/src/utils/cliHighlight.js +45 -0
- package/src/utils/codeIndexing.js +149 -0
- package/src/utils/collapseBackgroundBashNotifications.js +70 -0
- package/src/utils/collapseHookSummaries.js +48 -0
- package/src/utils/collapseReadSearch.js +869 -0
- package/src/utils/collapseTeammateShutdowns.js +44 -0
- package/src/utils/combinedAbortSignal.js +40 -0
- package/src/utils/commandLifecycle.js +7 -0
- package/src/utils/commitAttribution.js +718 -0
- package/src/utils/completionCache.js +138 -0
- package/src/utils/computerUse/appNames.js +170 -0
- package/src/utils/computerUse/cleanup.js +65 -0
- package/src/utils/computerUse/common.js +56 -0
- package/src/utils/computerUse/computerUseLock.js +183 -0
- package/src/utils/computerUse/drainRunLoop.js +71 -0
- package/src/utils/computerUse/escHotkey.js +53 -0
- package/src/utils/computerUse/executor.js +480 -0
- package/src/utils/computerUse/gates.js +55 -0
- package/src/utils/computerUse/hostAdapter.js +62 -0
- package/src/utils/computerUse/inputLoader.js +25 -0
- package/src/utils/computerUse/mcpServer.js +84 -0
- package/src/utils/computerUse/setup.js +42 -0
- package/src/utils/computerUse/swiftLoader.js +18 -0
- package/src/utils/computerUse/toolRendering.js +101 -0
- package/src/utils/computerUse/wrapper.js +317 -0
- package/src/utils/concurrentSessions.js +179 -0
- package/src/utils/config.js +1078 -0
- package/src/utils/configConstants.js +18 -0
- package/src/utils/contentArray.js +45 -0
- package/src/utils/context.js +185 -0
- package/src/utils/contextAnalysis.js +171 -0
- package/src/utils/contextSuggestions.js +158 -0
- package/src/utils/controlMessageCompat.js +31 -0
- package/src/utils/conversationRecovery.js +434 -0
- package/src/utils/cron.js +260 -0
- package/src/utils/cronJitterConfig.js +62 -0
- package/src/utils/cronScheduler.js +388 -0
- package/src/utils/cronTasks.js +328 -0
- package/src/utils/cronTasksLock.js +159 -0
- package/src/utils/crossProjectResume.js +46 -0
- package/src/utils/crypto.js +13 -0
- package/src/utils/cwd.js +29 -0
- package/src/utils/debug.js +220 -0
- package/src/utils/debugFilter.js +125 -0
- package/src/utils/deepLink/banner.js +103 -0
- package/src/utils/deepLink/parseDeepLink.js +138 -0
- package/src/utils/deepLink/protocolHandler.js +119 -0
- package/src/utils/deepLink/registerProtocol.js +291 -0
- package/src/utils/deepLink/terminalLauncher.js +455 -0
- package/src/utils/deepLink/terminalPreference.js +51 -0
- package/src/utils/desktopDeepLink.js +208 -0
- package/src/utils/detectRepository.js +157 -0
- package/src/utils/diagLogs.js +74 -0
- package/src/utils/diff.js +108 -0
- package/src/utils/directMemberMessage.js +34 -0
- package/src/utils/displayTags.js +46 -0
- package/src/utils/doctorContextWarnings.js +179 -0
- package/src/utils/doctorDiagnostic.js +494 -0
- package/src/utils/dxt/helpers.js +64 -0
- package/src/utils/dxt/zip.js +167 -0
- package/src/utils/earlyInput.js +166 -0
- package/src/utils/editor.js +163 -0
- package/src/utils/effort.js +271 -0
- package/src/utils/embeddedTools.js +26 -0
- package/src/utils/employeeChat.js +271 -0
- package/src/utils/employeeDb.js +326 -0
- package/src/utils/env.js +358 -0
- package/src/utils/envDynamic.js +130 -0
- package/src/utils/envUtils.js +161 -0
- package/src/utils/envValidation.js +26 -0
- package/src/utils/errorLogSink.js +196 -0
- package/src/utils/errors.js +207 -0
- package/src/utils/exampleCommands.js +165 -0
- package/src/utils/execFileNoThrow.js +93 -0
- package/src/utils/execFileNoThrowPortable.js +49 -0
- package/src/utils/execSyncWrapper.js +6 -0
- package/src/utils/exportRenderer.js +71 -0
- package/src/utils/extraUsage.js +19 -0
- package/src/utils/fastMode.js +393 -0
- package/src/utils/file.js +467 -0
- package/src/utils/fileHistory.js +851 -0
- package/src/utils/fileOperationAnalytics.js +45 -0
- package/src/utils/filePersistence/filePersistence.js +212 -0
- package/src/utils/filePersistence/outputsScanner.js +104 -0
- package/src/utils/filePersistence/types.js +4 -0
- package/src/utils/fileRead.js +81 -0
- package/src/utils/fileReadCache.js +78 -0
- package/src/utils/fileStateCache.js +99 -0
- package/src/utils/findExecutable.js +13 -0
- package/src/utils/fingerprint.js +58 -0
- package/src/utils/forkedAgent.js +410 -0
- package/src/utils/format.js +238 -0
- package/src/utils/formatBriefTimestamp.js +72 -0
- package/src/utils/fpsTracker.js +34 -0
- package/src/utils/frontmatterParser.js +260 -0
- package/src/utils/fsOperations.js +555 -0
- package/src/utils/fullscreen.js +194 -0
- package/src/utils/generatedFiles.js +122 -0
- package/src/utils/generators.js +67 -0
- package/src/utils/genericProcessUtils.js +155 -0
- package/src/utils/getWorktreePaths.js +56 -0
- package/src/utils/getWorktreePathsPortable.js +23 -0
- package/src/utils/ghPrStatus.js +71 -0
- package/src/utils/git/gitConfigParser.js +226 -0
- package/src/utils/git/gitFilesystem.js +606 -0
- package/src/utils/git/gitignore.js +84 -0
- package/src/utils/git.js +725 -0
- package/src/utils/gitDiff.js +395 -0
- package/src/utils/gitSettings.js +18 -0
- package/src/utils/github/ghAuthStatus.js +23 -0
- package/src/utils/githubRepoPathMapping.js +135 -0
- package/src/utils/glob.js +90 -0
- package/src/utils/gracefulShutdown.js +447 -0
- package/src/utils/groupToolUses.js +126 -0
- package/src/utils/handlePromptSubmit.js +398 -0
- package/src/utils/hash.js +44 -0
- package/src/utils/headlessProfiler.js +147 -0
- package/src/utils/heapDumpService.js +201 -0
- package/src/utils/heatmap.js +151 -0
- package/src/utils/highlightMatch.js +29 -0
- package/src/utils/hooks/AsyncHookRegistry.js +187 -0
- package/src/utils/hooks/apiQueryHookHelper.js +77 -0
- package/src/utils/hooks/execAgentHook.js +257 -0
- package/src/utils/hooks/execHttpHook.js +184 -0
- package/src/utils/hooks/execPromptHook.js +171 -0
- package/src/utils/hooks/fileChangedWatcher.js +161 -0
- package/src/utils/hooks/hookEvents.js +111 -0
- package/src/utils/hooks/hookHelpers.js +60 -0
- package/src/utils/hooks/hooksConfigManager.js +323 -0
- package/src/utils/hooks/hooksConfigSnapshot.js +114 -0
- package/src/utils/hooks/hooksSettings.js +204 -0
- package/src/utils/hooks/postSamplingHooks.js +39 -0
- package/src/utils/hooks/registerFrontmatterHooks.js +47 -0
- package/src/utils/hooks/registerSkillHooks.js +40 -0
- package/src/utils/hooks/sessionHooks.js +252 -0
- package/src/utils/hooks/skillImprovement.js +211 -0
- package/src/utils/hooks/ssrfGuard.js +258 -0
- package/src/utils/hooks.js +3668 -0
- package/src/utils/horizontalScroll.js +108 -0
- package/src/utils/http.js +120 -0
- package/src/utils/hyperlink.js +28 -0
- package/src/utils/iTermBackup.js +48 -0
- package/src/utils/ide.js +1195 -0
- package/src/utils/idePathConversion.js +66 -0
- package/src/utils/idleTimeout.js +44 -0
- package/src/utils/imagePaste.js +343 -0
- package/src/utils/imageResizer.js +664 -0
- package/src/utils/imageStore.js +150 -0
- package/src/utils/imageValidation.js +92 -0
- package/src/utils/immediateCommand.js +12 -0
- package/src/utils/inProcessTeammateHelpers.js +71 -0
- package/src/utils/ink.js +20 -0
- package/src/utils/intl.js +83 -0
- package/src/utils/jetbrains.js +152 -0
- package/src/utils/json.js +231 -0
- package/src/utils/jsonRead.js +14 -0
- package/src/utils/keyboardShortcuts.js +11 -0
- package/src/utils/lazySchema.js +8 -0
- package/src/utils/listSessionsImpl.js +332 -0
- package/src/utils/localInstaller.js +130 -0
- package/src/utils/lockfile.js +30 -0
- package/src/utils/log.js +280 -0
- package/src/utils/logoV2Utils.js +256 -0
- package/src/utils/mailbox.js +50 -0
- package/src/utils/managedEnv.js +160 -0
- package/src/utils/managedEnvConstants.js +185 -0
- package/src/utils/markdown.js +315 -0
- package/src/utils/markdownConfigLoader.js +480 -0
- package/src/utils/mcp/dateTimeParser.js +102 -0
- package/src/utils/mcp/elicitationValidation.js +259 -0
- package/src/utils/mcpInstructionsDelta.js +97 -0
- package/src/utils/mcpOutputStorage.js +159 -0
- package/src/utils/mcpValidation.js +165 -0
- package/src/utils/mcpWebSocketTransport.js +180 -0
- package/src/utils/memoize.js +205 -0
- package/src/utils/memory/types.js +9 -0
- package/src/utils/memory/versions.js +7 -0
- package/src/utils/memoryFileDetection.js +245 -0
- package/src/utils/messagePredicates.js +6 -0
- package/src/utils/messageQueueManager.js +430 -0
- package/src/utils/messages/mappers.js +240 -0
- package/src/utils/messages/systemInit.js +72 -0
- package/src/utils/messages.js +4286 -0
- package/src/utils/model/agent.js +128 -0
- package/src/utils/model/aliases.js +21 -0
- package/src/utils/model/antModels.js +25 -0
- package/src/utils/model/bedrock.js +220 -0
- package/src/utils/model/check1mAccess.js +64 -0
- package/src/utils/model/configs.js +86 -0
- package/src/utils/model/contextWindowUpgradeCheck.js +41 -0
- package/src/utils/model/deprecation.js +72 -0
- package/src/utils/model/model.js +533 -0
- package/src/utils/model/modelAllowlist.js +148 -0
- package/src/utils/model/modelCapabilities.js +105 -0
- package/src/utils/model/modelOptions.js +450 -0
- package/src/utils/model/modelStrings.js +144 -0
- package/src/utils/model/modelSupportOverrides.js +40 -0
- package/src/utils/model/providers.js +35 -0
- package/src/utils/model/validateModel.js +131 -0
- package/src/utils/modelCost.js +160 -0
- package/src/utils/modifiers.js +39 -0
- package/src/utils/mtls.js +132 -0
- package/src/utils/nativeInstaller/download.js +370 -0
- package/src/utils/nativeInstaller/index.js +8 -0
- package/src/utils/nativeInstaller/installer.js +1395 -0
- package/src/utils/nativeInstaller/packageManagers.js +258 -0
- package/src/utils/nativeInstaller/pidLock.js +347 -0
- package/src/utils/notebook.js +176 -0
- package/src/utils/objectGroupBy.js +15 -0
- package/src/utils/pasteStore.js +93 -0
- package/src/utils/path.js +140 -0
- package/src/utils/pdf.js +236 -0
- package/src/utils/pdfUtils.js +61 -0
- package/src/utils/peerAddress.js +20 -0
- package/src/utils/permissions/PermissionMode.js +95 -0
- package/src/utils/permissions/PermissionPromptToolResultSchema.js +85 -0
- package/src/utils/permissions/PermissionResult.js +11 -0
- package/src/utils/permissions/PermissionRule.js +19 -0
- package/src/utils/permissions/PermissionUpdate.js +268 -0
- package/src/utils/permissions/PermissionUpdateSchema.js +61 -0
- package/src/utils/permissions/autoModeState.js +31 -0
- package/src/utils/permissions/bashClassifier.js +30 -0
- package/src/utils/permissions/bypassPermissionsKillswitch.js +115 -0
- package/src/utils/permissions/classifierDecision.js +86 -0
- package/src/utils/permissions/classifierShared.js +28 -0
- package/src/utils/permissions/dangerousPatterns.js +78 -0
- package/src/utils/permissions/denialTracking.js +34 -0
- package/src/utils/permissions/filesystem.js +1411 -0
- package/src/utils/permissions/getNextPermissionMode.js +74 -0
- package/src/utils/permissions/pathValidation.js +351 -0
- package/src/utils/permissions/permissionExplainer.js +188 -0
- package/src/utils/permissions/permissionRuleParser.js +175 -0
- package/src/utils/permissions/permissionSetup.js +1162 -0
- package/src/utils/permissions/permissions.js +1063 -0
- package/src/utils/permissions/permissionsLoader.js +217 -0
- package/src/utils/permissions/shadowedRuleDetection.js +149 -0
- package/src/utils/permissions/shellRuleMatching.js +174 -0
- package/src/utils/permissions/yoloClassifier.js +1193 -0
- package/src/utils/planModeV2.js +75 -0
- package/src/utils/plans.js +334 -0
- package/src/utils/platform.js +122 -0
- package/src/utils/plugins/addDirPluginSettings.js +53 -0
- package/src/utils/plugins/cacheUtils.js +174 -0
- package/src/utils/plugins/dependencyResolver.js +244 -0
- package/src/utils/plugins/fetchTelemetry.js +108 -0
- package/src/utils/plugins/gitAvailability.js +65 -0
- package/src/utils/plugins/headlessPluginInstall.js +136 -0
- package/src/utils/plugins/hintRecommendation.js +136 -0
- package/src/utils/plugins/installCounts.js +221 -0
- package/src/utils/plugins/installedPluginsManager.js +1003 -0
- package/src/utils/plugins/loadPluginAgents.js +219 -0
- package/src/utils/plugins/loadPluginCommands.js +595 -0
- package/src/utils/plugins/loadPluginHooks.js +239 -0
- package/src/utils/plugins/loadPluginOutputStyles.js +112 -0
- package/src/utils/plugins/lspPluginIntegration.js +293 -0
- package/src/utils/plugins/lspRecommendation.js +278 -0
- package/src/utils/plugins/managedPlugins.js +26 -0
- package/src/utils/plugins/marketplaceHelpers.js +470 -0
- package/src/utils/plugins/marketplaceManager.js +1939 -0
- package/src/utils/plugins/mcpPluginIntegration.js +465 -0
- package/src/utils/plugins/mcpbHandler.js +708 -0
- package/src/utils/plugins/officialMarketplace.js +19 -0
- package/src/utils/plugins/officialMarketplaceGcs.js +202 -0
- package/src/utils/plugins/officialMarketplaceStartupCheck.js +344 -0
- package/src/utils/plugins/orphanedPluginFilter.js +96 -0
- package/src/utils/plugins/parseMarketplaceInput.js +143 -0
- package/src/utils/plugins/performStartupChecks.js +66 -0
- package/src/utils/plugins/pluginAutoupdate.js +210 -0
- package/src/utils/plugins/pluginBlocklist.js +93 -0
- package/src/utils/plugins/pluginDirectories.js +170 -0
- package/src/utils/plugins/pluginFlagging.js +173 -0
- package/src/utils/plugins/pluginIdentifier.js +78 -0
- package/src/utils/plugins/pluginInstallationHelpers.js +400 -0
- package/src/utils/plugins/pluginLoader.js +2426 -0
- package/src/utils/plugins/pluginOptionsStorage.js +311 -0
- package/src/utils/plugins/pluginPolicy.js +18 -0
- package/src/utils/plugins/pluginStartupCheck.js +261 -0
- package/src/utils/plugins/pluginVersioning.js +128 -0
- package/src/utils/plugins/reconciler.js +181 -0
- package/src/utils/plugins/refresh.js +162 -0
- package/src/utils/plugins/schemas.js +1283 -0
- package/src/utils/plugins/validatePlugin.js +765 -0
- package/src/utils/plugins/walkPluginMarkdown.js +49 -0
- package/src/utils/plugins/zipCache.js +346 -0
- package/src/utils/plugins/zipCacheAdapters.js +133 -0
- package/src/utils/powershell/dangerousCmdlets.js +174 -0
- package/src/utils/powershell/parser.js +1357 -0
- package/src/utils/powershell/staticPrefix.js +277 -0
- package/src/utils/preflightChecks.js +147 -0
- package/src/utils/privacyLevel.js +49 -0
- package/src/utils/process.js +56 -0
- package/src/utils/processUserInput/processBashCommand.js +118 -0
- package/src/utils/processUserInput/processSlashCommand.js +845 -0
- package/src/utils/processUserInput/processTextPrompt.js +68 -0
- package/src/utils/processUserInput/processUserInput.js +344 -0
- package/src/utils/profilerBase.js +32 -0
- package/src/utils/promptCategory.js +39 -0
- package/src/utils/promptEditor.js +151 -0
- package/src/utils/promptShellExecution.js +117 -0
- package/src/utils/protectedNamespace.js +4 -0
- package/src/utils/proxy.js +345 -0
- package/src/utils/queryContext.js +110 -0
- package/src/utils/queryHelpers.js +436 -0
- package/src/utils/queryProfiler.js +242 -0
- package/src/utils/queueProcessor.js +70 -0
- package/src/utils/readEditContext.js +176 -0
- package/src/utils/readFileInRange.js +278 -0
- package/src/utils/releaseNotes.js +307 -0
- package/src/utils/renderOptions.js +67 -0
- package/src/utils/ripgrep.js +521 -0
- package/src/utils/sandbox/sandbox-adapter.js +750 -0
- package/src/utils/sandbox/sandbox-ui-utils.js +11 -0
- package/src/utils/sanitization.js +72 -0
- package/src/utils/screenshotClipboard.js +89 -0
- package/src/utils/sdkEventQueue.js +49 -0
- package/src/utils/secureStorage/fallbackStorage.js +59 -0
- package/src/utils/secureStorage/index.js +13 -0
- package/src/utils/secureStorage/keychainPrefetch.js +91 -0
- package/src/utils/secureStorage/macOsKeychainHelpers.js +91 -0
- package/src/utils/secureStorage/macOsKeychainStorage.js +192 -0
- package/src/utils/secureStorage/plainTextStorage.js +81 -0
- package/src/utils/semanticBoolean.js +23 -0
- package/src/utils/semanticNumber.js +34 -0
- package/src/utils/semver.js +51 -0
- package/src/utils/sequential.js +43 -0
- package/src/utils/sessionActivity.js +120 -0
- package/src/utils/sessionEnvVars.js +18 -0
- package/src/utils/sessionEnvironment.js +131 -0
- package/src/utils/sessionFileAccessHooks.js +205 -0
- package/src/utils/sessionIngressAuth.js +113 -0
- package/src/utils/sessionRestore.js +357 -0
- package/src/utils/sessionStart.js +165 -0
- package/src/utils/sessionState.js +76 -0
- package/src/utils/sessionStorage.js +4162 -0
- package/src/utils/sessionStoragePortable.js +665 -0
- package/src/utils/sessionTitle.js +120 -0
- package/src/utils/sessionUrl.js +50 -0
- package/src/utils/set.js +50 -0
- package/src/utils/settings/allErrors.js +29 -0
- package/src/utils/settings/applySettingsChange.js +65 -0
- package/src/utils/settings/changeDetector.js +409 -0
- package/src/utils/settings/constants.js +166 -0
- package/src/utils/settings/internalWrites.js +33 -0
- package/src/utils/settings/managedPath.js +29 -0
- package/src/utils/settings/mdm/constants.js +62 -0
- package/src/utils/settings/mdm/rawRead.js +97 -0
- package/src/utils/settings/mdm/settings.js +254 -0
- package/src/utils/settings/permissionValidation.js +224 -0
- package/src/utils/settings/pluginOnlyPolicy.js +53 -0
- package/src/utils/settings/schemaOutput.js +7 -0
- package/src/utils/settings/settings.js +791 -0
- package/src/utils/settings/settingsCache.js +47 -0
- package/src/utils/settings/toolValidationConfig.js +76 -0
- package/src/utils/settings/types.js +846 -0
- package/src/utils/settings/validateEditTool.js +34 -0
- package/src/utils/settings/validation.js +192 -0
- package/src/utils/settings/validationTips.js +111 -0
- package/src/utils/shell/bashProvider.js +202 -0
- package/src/utils/shell/outputLimits.js +7 -0
- package/src/utils/shell/powershellDetection.js +96 -0
- package/src/utils/shell/powershellProvider.js +104 -0
- package/src/utils/shell/prefix.js +246 -0
- package/src/utils/shell/readOnlyCommandValidation.js +1776 -0
- package/src/utils/shell/resolveDefaultShell.js +13 -0
- package/src/utils/shell/shellProvider.js +2 -0
- package/src/utils/shell/shellToolUtils.js +21 -0
- package/src/utils/shell/specPrefix.js +198 -0
- package/src/utils/shellConfig.js +136 -0
- package/src/utils/sideQuery.js +134 -0
- package/src/utils/sideQuestion.js +121 -0
- package/src/utils/signal.js +34 -0
- package/src/utils/sinks.js +15 -0
- package/src/utils/skills/skillChangeDetector.js +264 -0
- package/src/utils/slashCommandParsing.js +46 -0
- package/src/utils/sleep.js +72 -0
- package/src/utils/sliceAnsi.js +74 -0
- package/src/utils/slowOperations.js +216 -0
- package/src/utils/standaloneAgent.js +20 -0
- package/src/utils/startupProfiler.js +149 -0
- package/src/utils/staticRender.js +104 -0
- package/src/utils/stats.js +802 -0
- package/src/utils/statsCache.js +330 -0
- package/src/utils/status.js +359 -0
- package/src/utils/statusNoticeDefinitions.js +123 -0
- package/src/utils/statusNoticeHelpers.js +15 -0
- package/src/utils/stream.js +73 -0
- package/src/utils/streamJsonStdoutGuard.js +107 -0
- package/src/utils/streamlinedTransform.js +162 -0
- package/src/utils/stringUtils.js +202 -0
- package/src/utils/subprocessEnv.js +87 -0
- package/src/utils/suggestions/commandSuggestions.js +458 -0
- package/src/utils/suggestions/directoryCompletion.js +191 -0
- package/src/utils/suggestions/shellHistoryCompletion.js +95 -0
- package/src/utils/suggestions/skillUsageTracking.js +50 -0
- package/src/utils/suggestions/slackChannelSuggestions.js +169 -0
- package/src/utils/swarm/It2SetupPrompt.js +386 -0
- package/src/utils/swarm/backends/ITermBackend.js +276 -0
- package/src/utils/swarm/backends/InProcessBackend.js +237 -0
- package/src/utils/swarm/backends/PaneBackendExecutor.js +250 -0
- package/src/utils/swarm/backends/TmuxBackend.js +574 -0
- package/src/utils/swarm/backends/detection.js +112 -0
- package/src/utils/swarm/backends/it2Setup.js +185 -0
- package/src/utils/swarm/backends/registry.js +369 -0
- package/src/utils/swarm/backends/teammateModeSnapshot.js +68 -0
- package/src/utils/swarm/backends/types.js +9 -0
- package/src/utils/swarm/constants.js +29 -0
- package/src/utils/swarm/inProcessRunner.js +1021 -0
- package/src/utils/swarm/leaderPermissionBridge.js +31 -0
- package/src/utils/swarm/permissionSync.js +667 -0
- package/src/utils/swarm/reconnection.js +82 -0
- package/src/utils/swarm/spawnInProcess.js +218 -0
- package/src/utils/swarm/spawnUtils.js +123 -0
- package/src/utils/swarm/teamHelpers.js +484 -0
- package/src/utils/swarm/teammateInit.js +87 -0
- package/src/utils/swarm/teammateLayoutManager.js +82 -0
- package/src/utils/swarm/teammateModel.js +9 -0
- package/src/utils/swarm/teammatePromptAddendum.js +17 -0
- package/src/utils/systemDirectories.js +51 -0
- package/src/utils/systemPrompt.js +88 -0
- package/src/utils/systemPromptType.js +9 -0
- package/src/utils/systemTheme.js +108 -0
- package/src/utils/taggedId.js +49 -0
- package/src/utils/task/TaskOutput.js +320 -0
- package/src/utils/task/diskOutput.js +387 -0
- package/src/utils/task/framework.js +236 -0
- package/src/utils/task/outputFormatting.js +24 -0
- package/src/utils/task/sdkProgress.js +24 -0
- package/src/utils/taskSummary.js +3 -0
- package/src/utils/tasks.js +672 -0
- package/src/utils/teamDiscovery.js +48 -0
- package/src/utils/teamMemoryOps.js +67 -0
- package/src/utils/teammate.js +237 -0
- package/src/utils/teammateContext.js +56 -0
- package/src/utils/teammateMailbox.js +793 -0
- package/src/utils/telemetry/betaSessionTracing.js +25 -0
- package/src/utils/telemetry/bigqueryExporter.js +17 -0
- package/src/utils/telemetry/events.js +7 -0
- package/src/utils/telemetry/instrumentation.js +16 -0
- package/src/utils/telemetry/logger.js +25 -0
- package/src/utils/telemetry/perfettoTracing.js +882 -0
- package/src/utils/telemetry/pluginTelemetry.js +76 -0
- package/src/utils/telemetry/sessionTracing.js +62 -0
- package/src/utils/telemetry/skillLoadedEvent.js +4 -0
- package/src/utils/telemetryAttributes.js +56 -0
- package/src/utils/teleport/api.js +299 -0
- package/src/utils/teleport/environmentSelection.js +55 -0
- package/src/utils/teleport/environments.js +84 -0
- package/src/utils/teleport/gitBundle.js +192 -0
- package/src/utils/teleport.js +1047 -0
- package/src/utils/tempfile.js +26 -0
- package/src/utils/terminal.js +105 -0
- package/src/utils/terminalPanel.js +155 -0
- package/src/utils/textHighlighting.js +113 -0
- package/src/utils/thaddeusHints.js +142 -0
- package/src/utils/theme.js +525 -0
- package/src/utils/thinking.js +130 -0
- package/src/utils/timeouts.js +35 -0
- package/src/utils/tmuxSocket.js +373 -0
- package/src/utils/todo/types.js +9 -0
- package/src/utils/tokenBudget.js +62 -0
- package/src/utils/tokens.js +223 -0
- package/src/utils/toolErrors.js +101 -0
- package/src/utils/toolPool.js +61 -0
- package/src/utils/toolResultStorage.js +768 -0
- package/src/utils/toolSchemaCache.js +7 -0
- package/src/utils/toolSearch.js +551 -0
- package/src/utils/transcriptSearch.js +200 -0
- package/src/utils/treeify.js +111 -0
- package/src/utils/truncate.js +164 -0
- package/src/utils/udsClient.js +5 -0
- package/src/utils/udsMessaging.js +23 -0
- package/src/utils/ultraplan/ccrSession.js +264 -0
- package/src/utils/ultraplan/keyword.js +122 -0
- package/src/utils/unaryLogging.js +16 -0
- package/src/utils/undercover.js +89 -0
- package/src/utils/user.js +137 -0
- package/src/utils/userAgent.js +9 -0
- package/src/utils/userPromptKeywords.js +21 -0
- package/src/utils/uuid.js +22 -0
- package/src/utils/warningHandler.js +97 -0
- package/src/utils/which.js +75 -0
- package/src/utils/windowsPaths.js +146 -0
- package/src/utils/withResolvers.js +13 -0
- package/src/utils/words.js +793 -0
- package/src/utils/workforceIntent.js +192 -0
- package/src/utils/workloadContext.js +42 -0
- package/src/utils/worktree.js +1142 -0
- package/src/utils/worktreeModeEnabled.js +11 -0
- package/src/utils/xdg.js +52 -0
- package/src/utils/xml.js +15 -0
- package/src/utils/yaml.js +14 -0
- package/src/utils/zodToJsonSchema.js +19 -0
- package/src/vim/motions.js +73 -0
- package/src/vim/operators.js +401 -0
- package/src/vim/textObjects.js +153 -0
- package/src/vim/transitions.js +340 -0
- package/src/vim/types.js +93 -0
- package/src/voice/voiceModeEnabled.js +20 -0
- package/thaddeus-terminal.ts +401 -3
- package/thaddeus.command +1 -1
|
@@ -0,0 +1,4355 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pure-TypeScript bash parser producing tree-sitter-bash-compatible ASTs.
|
|
3
|
+
*
|
|
4
|
+
* Downstream code in parser.ts, ast.ts, prefix.ts, ParsedCommand.ts walks this
|
|
5
|
+
* by field name. startIndex/endIndex are UTF-8 BYTE offsets (not JS string
|
|
6
|
+
* indices).
|
|
7
|
+
*
|
|
8
|
+
* Grammar reference: tree-sitter-bash. Validated against a 3449-input golden
|
|
9
|
+
* corpus generated from the WASM parser.
|
|
10
|
+
*/
|
|
11
|
+
/**
|
|
12
|
+
* 50ms wall-clock cap — bails out on pathological/adversarial input.
|
|
13
|
+
* Pass `Infinity` via `parse(src, Infinity)` to disable (e.g. correctness
|
|
14
|
+
* tests, where CI jitter would otherwise cause spurious null returns).
|
|
15
|
+
*/
|
|
16
|
+
const PARSE_TIMEOUT_MS = 50;
|
|
17
|
+
/** Node budget cap — bails out before OOM on deeply nested input. */
|
|
18
|
+
const MAX_NODES = 50_000;
|
|
19
|
+
const MODULE = { parse: parseSource };
|
|
20
|
+
const READY = Promise.resolve();
|
|
21
|
+
/** No-op: pure-TS parser needs no async init. Kept for API compatibility. */
|
|
22
|
+
export function ensureParserInitialized() {
|
|
23
|
+
return READY;
|
|
24
|
+
}
|
|
25
|
+
/** Always succeeds — pure-TS needs no init. */
|
|
26
|
+
export function getParserModule() {
|
|
27
|
+
return MODULE;
|
|
28
|
+
}
|
|
29
|
+
const SPECIAL_VARS = new Set(['?', '$', '@', '*', '#', '-', '!', '_']);
|
|
30
|
+
const DECL_KEYWORDS = new Set([
|
|
31
|
+
'export',
|
|
32
|
+
'declare',
|
|
33
|
+
'typeset',
|
|
34
|
+
'readonly',
|
|
35
|
+
'local',
|
|
36
|
+
]);
|
|
37
|
+
export const SHELL_KEYWORDS = new Set([
|
|
38
|
+
'if',
|
|
39
|
+
'then',
|
|
40
|
+
'elif',
|
|
41
|
+
'else',
|
|
42
|
+
'fi',
|
|
43
|
+
'while',
|
|
44
|
+
'until',
|
|
45
|
+
'for',
|
|
46
|
+
'in',
|
|
47
|
+
'do',
|
|
48
|
+
'done',
|
|
49
|
+
'case',
|
|
50
|
+
'esac',
|
|
51
|
+
'function',
|
|
52
|
+
'select',
|
|
53
|
+
]);
|
|
54
|
+
function makeLexer(src) {
|
|
55
|
+
return {
|
|
56
|
+
src,
|
|
57
|
+
len: src.length,
|
|
58
|
+
i: 0,
|
|
59
|
+
b: 0,
|
|
60
|
+
heredocs: [],
|
|
61
|
+
byteTable: null,
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
/** Advance one JS char, updating byte offset for UTF-8. */
|
|
65
|
+
function advance(L) {
|
|
66
|
+
const c = L.src.charCodeAt(L.i);
|
|
67
|
+
L.i++;
|
|
68
|
+
if (c < 0x80) {
|
|
69
|
+
L.b++;
|
|
70
|
+
}
|
|
71
|
+
else if (c < 0x800) {
|
|
72
|
+
L.b += 2;
|
|
73
|
+
}
|
|
74
|
+
else if (c >= 0xd800 && c <= 0xdbff) {
|
|
75
|
+
// High surrogate — next char completes the pair, total 4 UTF-8 bytes
|
|
76
|
+
L.b += 4;
|
|
77
|
+
L.i++;
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
L.b += 3;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
function peek(L, off = 0) {
|
|
84
|
+
return L.i + off < L.len ? L.src[L.i + off] : '';
|
|
85
|
+
}
|
|
86
|
+
function byteAt(L, charIdx) {
|
|
87
|
+
// Fast path: ASCII-only prefix means char idx == byte idx
|
|
88
|
+
if (L.byteTable)
|
|
89
|
+
return L.byteTable[charIdx];
|
|
90
|
+
// Build table on first non-trivial lookup
|
|
91
|
+
const t = new Uint32Array(L.len + 1);
|
|
92
|
+
let b = 0;
|
|
93
|
+
let i = 0;
|
|
94
|
+
while (i < L.len) {
|
|
95
|
+
t[i] = b;
|
|
96
|
+
const c = L.src.charCodeAt(i);
|
|
97
|
+
if (c < 0x80) {
|
|
98
|
+
b++;
|
|
99
|
+
i++;
|
|
100
|
+
}
|
|
101
|
+
else if (c < 0x800) {
|
|
102
|
+
b += 2;
|
|
103
|
+
i++;
|
|
104
|
+
}
|
|
105
|
+
else if (c >= 0xd800 && c <= 0xdbff) {
|
|
106
|
+
t[i + 1] = b + 2;
|
|
107
|
+
b += 4;
|
|
108
|
+
i += 2;
|
|
109
|
+
}
|
|
110
|
+
else {
|
|
111
|
+
b += 3;
|
|
112
|
+
i++;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
t[L.len] = b;
|
|
116
|
+
L.byteTable = t;
|
|
117
|
+
return t[charIdx];
|
|
118
|
+
}
|
|
119
|
+
function isWordChar(c) {
|
|
120
|
+
// Bash word chars: alphanumeric + various punctuation that doesn't start operators
|
|
121
|
+
return ((c >= 'a' && c <= 'z') ||
|
|
122
|
+
(c >= 'A' && c <= 'Z') ||
|
|
123
|
+
(c >= '0' && c <= '9') ||
|
|
124
|
+
c === '_' ||
|
|
125
|
+
c === '/' ||
|
|
126
|
+
c === '.' ||
|
|
127
|
+
c === '-' ||
|
|
128
|
+
c === '+' ||
|
|
129
|
+
c === ':' ||
|
|
130
|
+
c === '@' ||
|
|
131
|
+
c === '%' ||
|
|
132
|
+
c === ',' ||
|
|
133
|
+
c === '~' ||
|
|
134
|
+
c === '^' ||
|
|
135
|
+
c === '?' ||
|
|
136
|
+
c === '*' ||
|
|
137
|
+
c === '!' ||
|
|
138
|
+
c === '=' ||
|
|
139
|
+
c === '[' ||
|
|
140
|
+
c === ']');
|
|
141
|
+
}
|
|
142
|
+
function isWordStart(c) {
|
|
143
|
+
return isWordChar(c) || c === '\\';
|
|
144
|
+
}
|
|
145
|
+
function isIdentStart(c) {
|
|
146
|
+
return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || c === '_';
|
|
147
|
+
}
|
|
148
|
+
function isIdentChar(c) {
|
|
149
|
+
return isIdentStart(c) || (c >= '0' && c <= '9');
|
|
150
|
+
}
|
|
151
|
+
function isDigit(c) {
|
|
152
|
+
return c >= '0' && c <= '9';
|
|
153
|
+
}
|
|
154
|
+
function isHexDigit(c) {
|
|
155
|
+
return isDigit(c) || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F');
|
|
156
|
+
}
|
|
157
|
+
function isBaseDigit(c) {
|
|
158
|
+
// Bash BASE#DIGITS: digits, letters, @ and _ (up to base 64)
|
|
159
|
+
return isIdentChar(c) || c === '@';
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Unquoted heredoc delimiter chars. Bash accepts most non-metacharacters —
|
|
163
|
+
* not just identifiers. Stop at whitespace, redirects, pipe/list operators,
|
|
164
|
+
* and structural tokens. Allows !, -, ., +, etc. (e.g. <<!HEREDOC!).
|
|
165
|
+
*/
|
|
166
|
+
function isHeredocDelimChar(c) {
|
|
167
|
+
return (c !== '' &&
|
|
168
|
+
c !== ' ' &&
|
|
169
|
+
c !== '\t' &&
|
|
170
|
+
c !== '\n' &&
|
|
171
|
+
c !== '<' &&
|
|
172
|
+
c !== '>' &&
|
|
173
|
+
c !== '|' &&
|
|
174
|
+
c !== '&' &&
|
|
175
|
+
c !== ';' &&
|
|
176
|
+
c !== '(' &&
|
|
177
|
+
c !== ')' &&
|
|
178
|
+
c !== "'" &&
|
|
179
|
+
c !== '"' &&
|
|
180
|
+
c !== '`' &&
|
|
181
|
+
c !== '\\');
|
|
182
|
+
}
|
|
183
|
+
function skipBlanks(L) {
|
|
184
|
+
while (L.i < L.len) {
|
|
185
|
+
const c = L.src[L.i];
|
|
186
|
+
if (c === ' ' || c === '\t' || c === '\r') {
|
|
187
|
+
// \r is whitespace per tree-sitter-bash extras /\s/ — handles CRLF inputs
|
|
188
|
+
advance(L);
|
|
189
|
+
}
|
|
190
|
+
else if (c === '\\') {
|
|
191
|
+
const nx = L.src[L.i + 1];
|
|
192
|
+
if (nx === '\n' || (nx === '\r' && L.src[L.i + 2] === '\n')) {
|
|
193
|
+
// Line continuation — tree-sitter extras: /\\\r?\n/
|
|
194
|
+
advance(L);
|
|
195
|
+
advance(L);
|
|
196
|
+
if (nx === '\r')
|
|
197
|
+
advance(L);
|
|
198
|
+
}
|
|
199
|
+
else if (nx === ' ' || nx === '\t') {
|
|
200
|
+
// \<space> or \<tab> — tree-sitter's _whitespace is /\\?[ \t\v]+/
|
|
201
|
+
advance(L);
|
|
202
|
+
advance(L);
|
|
203
|
+
}
|
|
204
|
+
else {
|
|
205
|
+
break;
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
else {
|
|
209
|
+
break;
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
/**
|
|
214
|
+
* Scan next token. Context-sensitive: `cmd` mode treats [ as operator (test
|
|
215
|
+
* command start), `arg` mode treats [ as word char (glob/subscript).
|
|
216
|
+
*/
|
|
217
|
+
function nextToken(L, ctx = 'arg') {
|
|
218
|
+
skipBlanks(L);
|
|
219
|
+
const start = L.b;
|
|
220
|
+
if (L.i >= L.len)
|
|
221
|
+
return { type: 'EOF', value: '', start, end: start };
|
|
222
|
+
const c = L.src[L.i];
|
|
223
|
+
const c1 = peek(L, 1);
|
|
224
|
+
const c2 = peek(L, 2);
|
|
225
|
+
if (c === '\n') {
|
|
226
|
+
advance(L);
|
|
227
|
+
return { type: 'NEWLINE', value: '\n', start, end: L.b };
|
|
228
|
+
}
|
|
229
|
+
if (c === '#') {
|
|
230
|
+
const si = L.i;
|
|
231
|
+
while (L.i < L.len && L.src[L.i] !== '\n')
|
|
232
|
+
advance(L);
|
|
233
|
+
return {
|
|
234
|
+
type: 'COMMENT',
|
|
235
|
+
value: L.src.slice(si, L.i),
|
|
236
|
+
start,
|
|
237
|
+
end: L.b,
|
|
238
|
+
};
|
|
239
|
+
}
|
|
240
|
+
// Multi-char operators (longest match first)
|
|
241
|
+
if (c === '&' && c1 === '&') {
|
|
242
|
+
advance(L);
|
|
243
|
+
advance(L);
|
|
244
|
+
return { type: 'OP', value: '&&', start, end: L.b };
|
|
245
|
+
}
|
|
246
|
+
if (c === '|' && c1 === '|') {
|
|
247
|
+
advance(L);
|
|
248
|
+
advance(L);
|
|
249
|
+
return { type: 'OP', value: '||', start, end: L.b };
|
|
250
|
+
}
|
|
251
|
+
if (c === '|' && c1 === '&') {
|
|
252
|
+
advance(L);
|
|
253
|
+
advance(L);
|
|
254
|
+
return { type: 'OP', value: '|&', start, end: L.b };
|
|
255
|
+
}
|
|
256
|
+
if (c === ';' && c1 === ';' && c2 === '&') {
|
|
257
|
+
advance(L);
|
|
258
|
+
advance(L);
|
|
259
|
+
advance(L);
|
|
260
|
+
return { type: 'OP', value: ';;&', start, end: L.b };
|
|
261
|
+
}
|
|
262
|
+
if (c === ';' && c1 === ';') {
|
|
263
|
+
advance(L);
|
|
264
|
+
advance(L);
|
|
265
|
+
return { type: 'OP', value: ';;', start, end: L.b };
|
|
266
|
+
}
|
|
267
|
+
if (c === ';' && c1 === '&') {
|
|
268
|
+
advance(L);
|
|
269
|
+
advance(L);
|
|
270
|
+
return { type: 'OP', value: ';&', start, end: L.b };
|
|
271
|
+
}
|
|
272
|
+
if (c === '>' && c1 === '>') {
|
|
273
|
+
advance(L);
|
|
274
|
+
advance(L);
|
|
275
|
+
return { type: 'OP', value: '>>', start, end: L.b };
|
|
276
|
+
}
|
|
277
|
+
if (c === '>' && c1 === '&' && c2 === '-') {
|
|
278
|
+
advance(L);
|
|
279
|
+
advance(L);
|
|
280
|
+
advance(L);
|
|
281
|
+
return { type: 'OP', value: '>&-', start, end: L.b };
|
|
282
|
+
}
|
|
283
|
+
if (c === '>' && c1 === '&') {
|
|
284
|
+
advance(L);
|
|
285
|
+
advance(L);
|
|
286
|
+
return { type: 'OP', value: '>&', start, end: L.b };
|
|
287
|
+
}
|
|
288
|
+
if (c === '>' && c1 === '|') {
|
|
289
|
+
advance(L);
|
|
290
|
+
advance(L);
|
|
291
|
+
return { type: 'OP', value: '>|', start, end: L.b };
|
|
292
|
+
}
|
|
293
|
+
if (c === '&' && c1 === '>' && c2 === '>') {
|
|
294
|
+
advance(L);
|
|
295
|
+
advance(L);
|
|
296
|
+
advance(L);
|
|
297
|
+
return { type: 'OP', value: '&>>', start, end: L.b };
|
|
298
|
+
}
|
|
299
|
+
if (c === '&' && c1 === '>') {
|
|
300
|
+
advance(L);
|
|
301
|
+
advance(L);
|
|
302
|
+
return { type: 'OP', value: '&>', start, end: L.b };
|
|
303
|
+
}
|
|
304
|
+
if (c === '<' && c1 === '<' && c2 === '<') {
|
|
305
|
+
advance(L);
|
|
306
|
+
advance(L);
|
|
307
|
+
advance(L);
|
|
308
|
+
return { type: 'OP', value: '<<<', start, end: L.b };
|
|
309
|
+
}
|
|
310
|
+
if (c === '<' && c1 === '<' && c2 === '-') {
|
|
311
|
+
advance(L);
|
|
312
|
+
advance(L);
|
|
313
|
+
advance(L);
|
|
314
|
+
return { type: 'OP', value: '<<-', start, end: L.b };
|
|
315
|
+
}
|
|
316
|
+
if (c === '<' && c1 === '<') {
|
|
317
|
+
advance(L);
|
|
318
|
+
advance(L);
|
|
319
|
+
return { type: 'OP', value: '<<', start, end: L.b };
|
|
320
|
+
}
|
|
321
|
+
if (c === '<' && c1 === '&' && c2 === '-') {
|
|
322
|
+
advance(L);
|
|
323
|
+
advance(L);
|
|
324
|
+
advance(L);
|
|
325
|
+
return { type: 'OP', value: '<&-', start, end: L.b };
|
|
326
|
+
}
|
|
327
|
+
if (c === '<' && c1 === '&') {
|
|
328
|
+
advance(L);
|
|
329
|
+
advance(L);
|
|
330
|
+
return { type: 'OP', value: '<&', start, end: L.b };
|
|
331
|
+
}
|
|
332
|
+
if (c === '<' && c1 === '(') {
|
|
333
|
+
advance(L);
|
|
334
|
+
advance(L);
|
|
335
|
+
return { type: 'LT_PAREN', value: '<(', start, end: L.b };
|
|
336
|
+
}
|
|
337
|
+
if (c === '>' && c1 === '(') {
|
|
338
|
+
advance(L);
|
|
339
|
+
advance(L);
|
|
340
|
+
return { type: 'GT_PAREN', value: '>(', start, end: L.b };
|
|
341
|
+
}
|
|
342
|
+
if (c === '(' && c1 === '(') {
|
|
343
|
+
advance(L);
|
|
344
|
+
advance(L);
|
|
345
|
+
return { type: 'OP', value: '((', start, end: L.b };
|
|
346
|
+
}
|
|
347
|
+
if (c === ')' && c1 === ')') {
|
|
348
|
+
advance(L);
|
|
349
|
+
advance(L);
|
|
350
|
+
return { type: 'OP', value: '))', start, end: L.b };
|
|
351
|
+
}
|
|
352
|
+
if (c === '|' || c === '&' || c === ';' || c === '>' || c === '<') {
|
|
353
|
+
advance(L);
|
|
354
|
+
return { type: 'OP', value: c, start, end: L.b };
|
|
355
|
+
}
|
|
356
|
+
if (c === '(' || c === ')') {
|
|
357
|
+
advance(L);
|
|
358
|
+
return { type: 'OP', value: c, start, end: L.b };
|
|
359
|
+
}
|
|
360
|
+
// In cmd position, [ [[ { start test/group; in arg position they're word chars
|
|
361
|
+
if (ctx === 'cmd') {
|
|
362
|
+
if (c === '[' && c1 === '[') {
|
|
363
|
+
advance(L);
|
|
364
|
+
advance(L);
|
|
365
|
+
return { type: 'OP', value: '[[', start, end: L.b };
|
|
366
|
+
}
|
|
367
|
+
if (c === '[') {
|
|
368
|
+
advance(L);
|
|
369
|
+
return { type: 'OP', value: '[', start, end: L.b };
|
|
370
|
+
}
|
|
371
|
+
if (c === '{' && (c1 === ' ' || c1 === '\t' || c1 === '\n')) {
|
|
372
|
+
advance(L);
|
|
373
|
+
return { type: 'OP', value: '{', start, end: L.b };
|
|
374
|
+
}
|
|
375
|
+
if (c === '}') {
|
|
376
|
+
advance(L);
|
|
377
|
+
return { type: 'OP', value: '}', start, end: L.b };
|
|
378
|
+
}
|
|
379
|
+
if (c === '!' && (c1 === ' ' || c1 === '\t')) {
|
|
380
|
+
advance(L);
|
|
381
|
+
return { type: 'OP', value: '!', start, end: L.b };
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
if (c === '"') {
|
|
385
|
+
advance(L);
|
|
386
|
+
return { type: 'DQUOTE', value: '"', start, end: L.b };
|
|
387
|
+
}
|
|
388
|
+
if (c === "'") {
|
|
389
|
+
const si = L.i;
|
|
390
|
+
advance(L);
|
|
391
|
+
while (L.i < L.len && L.src[L.i] !== "'")
|
|
392
|
+
advance(L);
|
|
393
|
+
if (L.i < L.len)
|
|
394
|
+
advance(L);
|
|
395
|
+
return {
|
|
396
|
+
type: 'SQUOTE',
|
|
397
|
+
value: L.src.slice(si, L.i),
|
|
398
|
+
start,
|
|
399
|
+
end: L.b,
|
|
400
|
+
};
|
|
401
|
+
}
|
|
402
|
+
if (c === '$') {
|
|
403
|
+
if (c1 === '(' && c2 === '(') {
|
|
404
|
+
advance(L);
|
|
405
|
+
advance(L);
|
|
406
|
+
advance(L);
|
|
407
|
+
return { type: 'DOLLAR_DPAREN', value: '$((', start, end: L.b };
|
|
408
|
+
}
|
|
409
|
+
if (c1 === '(') {
|
|
410
|
+
advance(L);
|
|
411
|
+
advance(L);
|
|
412
|
+
return { type: 'DOLLAR_PAREN', value: '$(', start, end: L.b };
|
|
413
|
+
}
|
|
414
|
+
if (c1 === '{') {
|
|
415
|
+
advance(L);
|
|
416
|
+
advance(L);
|
|
417
|
+
return { type: 'DOLLAR_BRACE', value: '${', start, end: L.b };
|
|
418
|
+
}
|
|
419
|
+
if (c1 === "'") {
|
|
420
|
+
// ANSI-C string $'...'
|
|
421
|
+
const si = L.i;
|
|
422
|
+
advance(L);
|
|
423
|
+
advance(L);
|
|
424
|
+
while (L.i < L.len && L.src[L.i] !== "'") {
|
|
425
|
+
if (L.src[L.i] === '\\' && L.i + 1 < L.len)
|
|
426
|
+
advance(L);
|
|
427
|
+
advance(L);
|
|
428
|
+
}
|
|
429
|
+
if (L.i < L.len)
|
|
430
|
+
advance(L);
|
|
431
|
+
return {
|
|
432
|
+
type: 'ANSI_C',
|
|
433
|
+
value: L.src.slice(si, L.i),
|
|
434
|
+
start,
|
|
435
|
+
end: L.b,
|
|
436
|
+
};
|
|
437
|
+
}
|
|
438
|
+
advance(L);
|
|
439
|
+
return { type: 'DOLLAR', value: '$', start, end: L.b };
|
|
440
|
+
}
|
|
441
|
+
if (c === '`') {
|
|
442
|
+
advance(L);
|
|
443
|
+
return { type: 'BACKTICK', value: '`', start, end: L.b };
|
|
444
|
+
}
|
|
445
|
+
// File descriptor before redirect: digit+ immediately followed by > or <
|
|
446
|
+
if (isDigit(c)) {
|
|
447
|
+
let j = L.i;
|
|
448
|
+
while (j < L.len && isDigit(L.src[j]))
|
|
449
|
+
j++;
|
|
450
|
+
const after = j < L.len ? L.src[j] : '';
|
|
451
|
+
if (after === '>' || after === '<') {
|
|
452
|
+
const si = L.i;
|
|
453
|
+
while (L.i < j)
|
|
454
|
+
advance(L);
|
|
455
|
+
return {
|
|
456
|
+
type: 'WORD',
|
|
457
|
+
value: L.src.slice(si, L.i),
|
|
458
|
+
start,
|
|
459
|
+
end: L.b,
|
|
460
|
+
};
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
// Word / number
|
|
464
|
+
if (isWordStart(c) || c === '{' || c === '}') {
|
|
465
|
+
const si = L.i;
|
|
466
|
+
while (L.i < L.len) {
|
|
467
|
+
const ch = L.src[L.i];
|
|
468
|
+
if (ch === '\\') {
|
|
469
|
+
if (L.i + 1 >= L.len) {
|
|
470
|
+
// Trailing `\` at EOF — tree-sitter excludes it from the word and
|
|
471
|
+
// emits a sibling ERROR. Stop here so the word ends before `\`.
|
|
472
|
+
break;
|
|
473
|
+
}
|
|
474
|
+
// Escape next char (including \n for line continuation mid-word)
|
|
475
|
+
if (L.src[L.i + 1] === '\n') {
|
|
476
|
+
advance(L);
|
|
477
|
+
advance(L);
|
|
478
|
+
continue;
|
|
479
|
+
}
|
|
480
|
+
advance(L);
|
|
481
|
+
advance(L);
|
|
482
|
+
continue;
|
|
483
|
+
}
|
|
484
|
+
if (!isWordChar(ch) && ch !== '{' && ch !== '}') {
|
|
485
|
+
break;
|
|
486
|
+
}
|
|
487
|
+
advance(L);
|
|
488
|
+
}
|
|
489
|
+
if (L.i > si) {
|
|
490
|
+
const v = L.src.slice(si, L.i);
|
|
491
|
+
// Number: optional sign then digits only
|
|
492
|
+
if (/^-?\d+$/.test(v)) {
|
|
493
|
+
return { type: 'NUMBER', value: v, start, end: L.b };
|
|
494
|
+
}
|
|
495
|
+
return { type: 'WORD', value: v, start, end: L.b };
|
|
496
|
+
}
|
|
497
|
+
// Empty word (lone `\` at EOF) — fall through to single-char consumer
|
|
498
|
+
}
|
|
499
|
+
// Unknown char — consume as single-char word
|
|
500
|
+
advance(L);
|
|
501
|
+
return { type: 'WORD', value: c, start, end: L.b };
|
|
502
|
+
}
|
|
503
|
+
function parseSource(source, timeoutMs) {
|
|
504
|
+
const L = makeLexer(source);
|
|
505
|
+
const srcBytes = byteLengthUtf8(source);
|
|
506
|
+
const P = {
|
|
507
|
+
L,
|
|
508
|
+
src: source,
|
|
509
|
+
srcBytes,
|
|
510
|
+
isAscii: srcBytes === source.length,
|
|
511
|
+
nodeCount: 0,
|
|
512
|
+
deadline: performance.now() + (timeoutMs ?? PARSE_TIMEOUT_MS),
|
|
513
|
+
aborted: false,
|
|
514
|
+
inBacktick: 0,
|
|
515
|
+
stopToken: null,
|
|
516
|
+
};
|
|
517
|
+
try {
|
|
518
|
+
const program = parseProgram(P);
|
|
519
|
+
if (P.aborted)
|
|
520
|
+
return null;
|
|
521
|
+
return program;
|
|
522
|
+
}
|
|
523
|
+
catch {
|
|
524
|
+
return null;
|
|
525
|
+
}
|
|
526
|
+
}
|
|
527
|
+
function byteLengthUtf8(s) {
|
|
528
|
+
let b = 0;
|
|
529
|
+
for (let i = 0; i < s.length; i++) {
|
|
530
|
+
const c = s.charCodeAt(i);
|
|
531
|
+
if (c < 0x80)
|
|
532
|
+
b++;
|
|
533
|
+
else if (c < 0x800)
|
|
534
|
+
b += 2;
|
|
535
|
+
else if (c >= 0xd800 && c <= 0xdbff) {
|
|
536
|
+
b += 4;
|
|
537
|
+
i++;
|
|
538
|
+
}
|
|
539
|
+
else
|
|
540
|
+
b += 3;
|
|
541
|
+
}
|
|
542
|
+
return b;
|
|
543
|
+
}
|
|
544
|
+
function checkBudget(P) {
|
|
545
|
+
P.nodeCount++;
|
|
546
|
+
if (P.nodeCount > MAX_NODES) {
|
|
547
|
+
P.aborted = true;
|
|
548
|
+
throw new Error('budget');
|
|
549
|
+
}
|
|
550
|
+
if ((P.nodeCount & 0x7f) === 0 && performance.now() > P.deadline) {
|
|
551
|
+
P.aborted = true;
|
|
552
|
+
throw new Error('timeout');
|
|
553
|
+
}
|
|
554
|
+
}
|
|
555
|
+
/** Build a node. Slices text from source by byte range via char-index lookup. */
|
|
556
|
+
function mk(P, type, start, end, children) {
|
|
557
|
+
checkBudget(P);
|
|
558
|
+
return {
|
|
559
|
+
type,
|
|
560
|
+
text: sliceBytes(P, start, end),
|
|
561
|
+
startIndex: start,
|
|
562
|
+
endIndex: end,
|
|
563
|
+
children,
|
|
564
|
+
};
|
|
565
|
+
}
|
|
566
|
+
function sliceBytes(P, startByte, endByte) {
|
|
567
|
+
if (P.isAscii)
|
|
568
|
+
return P.src.slice(startByte, endByte);
|
|
569
|
+
// Find char indices for byte offsets. Build byte table if needed.
|
|
570
|
+
const L = P.L;
|
|
571
|
+
if (!L.byteTable)
|
|
572
|
+
byteAt(L, 0);
|
|
573
|
+
const t = L.byteTable;
|
|
574
|
+
// Binary search for char index where byte offset matches
|
|
575
|
+
let lo = 0;
|
|
576
|
+
let hi = P.src.length;
|
|
577
|
+
while (lo < hi) {
|
|
578
|
+
const m = (lo + hi) >>> 1;
|
|
579
|
+
if (t[m] < startByte)
|
|
580
|
+
lo = m + 1;
|
|
581
|
+
else
|
|
582
|
+
hi = m;
|
|
583
|
+
}
|
|
584
|
+
const sc = lo;
|
|
585
|
+
lo = sc;
|
|
586
|
+
hi = P.src.length;
|
|
587
|
+
while (lo < hi) {
|
|
588
|
+
const m = (lo + hi) >>> 1;
|
|
589
|
+
if (t[m] < endByte)
|
|
590
|
+
lo = m + 1;
|
|
591
|
+
else
|
|
592
|
+
hi = m;
|
|
593
|
+
}
|
|
594
|
+
return P.src.slice(sc, lo);
|
|
595
|
+
}
|
|
596
|
+
function leaf(P, type, tok) {
|
|
597
|
+
return mk(P, type, tok.start, tok.end, []);
|
|
598
|
+
}
|
|
599
|
+
function parseProgram(P) {
|
|
600
|
+
const children = [];
|
|
601
|
+
// Skip leading whitespace & newlines — program start is first content byte
|
|
602
|
+
skipBlanks(P.L);
|
|
603
|
+
while (true) {
|
|
604
|
+
const save = saveLex(P.L);
|
|
605
|
+
const t = nextToken(P.L, 'cmd');
|
|
606
|
+
if (t.type === 'NEWLINE') {
|
|
607
|
+
skipBlanks(P.L);
|
|
608
|
+
continue;
|
|
609
|
+
}
|
|
610
|
+
restoreLex(P.L, save);
|
|
611
|
+
break;
|
|
612
|
+
}
|
|
613
|
+
const progStart = P.L.b;
|
|
614
|
+
while (P.L.i < P.L.len) {
|
|
615
|
+
const save = saveLex(P.L);
|
|
616
|
+
const t = nextToken(P.L, 'cmd');
|
|
617
|
+
if (t.type === 'EOF')
|
|
618
|
+
break;
|
|
619
|
+
if (t.type === 'NEWLINE')
|
|
620
|
+
continue;
|
|
621
|
+
if (t.type === 'COMMENT') {
|
|
622
|
+
children.push(leaf(P, 'comment', t));
|
|
623
|
+
continue;
|
|
624
|
+
}
|
|
625
|
+
restoreLex(P.L, save);
|
|
626
|
+
const stmts = parseStatements(P, null);
|
|
627
|
+
for (const s of stmts)
|
|
628
|
+
children.push(s);
|
|
629
|
+
if (stmts.length === 0) {
|
|
630
|
+
// Couldn't parse — emit ERROR and skip one token
|
|
631
|
+
const errTok = nextToken(P.L, 'cmd');
|
|
632
|
+
if (errTok.type === 'EOF')
|
|
633
|
+
break;
|
|
634
|
+
// Stray `;;` at program level (e.g., `var=;;` outside case) — tree-sitter
|
|
635
|
+
// silently elides. Keep leading `;` as ERROR (security: paste artifact).
|
|
636
|
+
if (errTok.type === 'OP' &&
|
|
637
|
+
errTok.value === ';;' &&
|
|
638
|
+
children.length > 0) {
|
|
639
|
+
continue;
|
|
640
|
+
}
|
|
641
|
+
children.push(mk(P, 'ERROR', errTok.start, errTok.end, []));
|
|
642
|
+
}
|
|
643
|
+
}
|
|
644
|
+
// tree-sitter includes trailing whitespace in program extent
|
|
645
|
+
const progEnd = children.length > 0 ? P.srcBytes : progStart;
|
|
646
|
+
return mk(P, 'program', progStart, progEnd, children);
|
|
647
|
+
}
|
|
648
|
+
function saveLex(L) {
|
|
649
|
+
return L.b * 0x10000 + L.i;
|
|
650
|
+
}
|
|
651
|
+
function restoreLex(L, s) {
|
|
652
|
+
L.i = s & 0xffff;
|
|
653
|
+
L.b = s >>> 16;
|
|
654
|
+
}
|
|
655
|
+
/**
|
|
656
|
+
* Parse a sequence of statements separated by ; & newline. Returns a flat list
|
|
657
|
+
* where ; and & are sibling leaves (NOT wrapped in 'list' — only && || get
|
|
658
|
+
* that). Stops at terminator or EOF.
|
|
659
|
+
*/
|
|
660
|
+
function parseStatements(P, terminator) {
|
|
661
|
+
const out = [];
|
|
662
|
+
while (true) {
|
|
663
|
+
skipBlanks(P.L);
|
|
664
|
+
const save = saveLex(P.L);
|
|
665
|
+
const t = nextToken(P.L, 'cmd');
|
|
666
|
+
if (t.type === 'EOF') {
|
|
667
|
+
restoreLex(P.L, save);
|
|
668
|
+
break;
|
|
669
|
+
}
|
|
670
|
+
if (t.type === 'NEWLINE') {
|
|
671
|
+
// Process pending heredocs
|
|
672
|
+
if (P.L.heredocs.length > 0) {
|
|
673
|
+
scanHeredocBodies(P);
|
|
674
|
+
}
|
|
675
|
+
continue;
|
|
676
|
+
}
|
|
677
|
+
if (t.type === 'COMMENT') {
|
|
678
|
+
out.push(leaf(P, 'comment', t));
|
|
679
|
+
continue;
|
|
680
|
+
}
|
|
681
|
+
if (terminator && t.type === 'OP' && t.value === terminator) {
|
|
682
|
+
restoreLex(P.L, save);
|
|
683
|
+
break;
|
|
684
|
+
}
|
|
685
|
+
if (t.type === 'OP' &&
|
|
686
|
+
(t.value === ')' ||
|
|
687
|
+
t.value === '}' ||
|
|
688
|
+
t.value === ';;' ||
|
|
689
|
+
t.value === ';&' ||
|
|
690
|
+
t.value === ';;&' ||
|
|
691
|
+
t.value === '))' ||
|
|
692
|
+
t.value === ']]' ||
|
|
693
|
+
t.value === ']')) {
|
|
694
|
+
restoreLex(P.L, save);
|
|
695
|
+
break;
|
|
696
|
+
}
|
|
697
|
+
if (t.type === 'BACKTICK' && P.inBacktick > 0) {
|
|
698
|
+
restoreLex(P.L, save);
|
|
699
|
+
break;
|
|
700
|
+
}
|
|
701
|
+
if (t.type === 'WORD' &&
|
|
702
|
+
(t.value === 'then' ||
|
|
703
|
+
t.value === 'elif' ||
|
|
704
|
+
t.value === 'else' ||
|
|
705
|
+
t.value === 'fi' ||
|
|
706
|
+
t.value === 'do' ||
|
|
707
|
+
t.value === 'done' ||
|
|
708
|
+
t.value === 'esac')) {
|
|
709
|
+
restoreLex(P.L, save);
|
|
710
|
+
break;
|
|
711
|
+
}
|
|
712
|
+
restoreLex(P.L, save);
|
|
713
|
+
const stmt = parseAndOr(P);
|
|
714
|
+
if (!stmt)
|
|
715
|
+
break;
|
|
716
|
+
out.push(stmt);
|
|
717
|
+
// Look for separator
|
|
718
|
+
skipBlanks(P.L);
|
|
719
|
+
const save2 = saveLex(P.L);
|
|
720
|
+
const sep = nextToken(P.L, 'cmd');
|
|
721
|
+
if (sep.type === 'OP' && (sep.value === ';' || sep.value === '&')) {
|
|
722
|
+
// Check if terminator follows — if so, emit separator but stop
|
|
723
|
+
const save3 = saveLex(P.L);
|
|
724
|
+
const after = nextToken(P.L, 'cmd');
|
|
725
|
+
restoreLex(P.L, save3);
|
|
726
|
+
out.push(leaf(P, sep.value, sep));
|
|
727
|
+
if (after.type === 'EOF' ||
|
|
728
|
+
(after.type === 'OP' &&
|
|
729
|
+
(after.value === ')' ||
|
|
730
|
+
after.value === '}' ||
|
|
731
|
+
after.value === ';;' ||
|
|
732
|
+
after.value === ';&' ||
|
|
733
|
+
after.value === ';;&')) ||
|
|
734
|
+
(after.type === 'WORD' &&
|
|
735
|
+
(after.value === 'then' ||
|
|
736
|
+
after.value === 'elif' ||
|
|
737
|
+
after.value === 'else' ||
|
|
738
|
+
after.value === 'fi' ||
|
|
739
|
+
after.value === 'do' ||
|
|
740
|
+
after.value === 'done' ||
|
|
741
|
+
after.value === 'esac'))) {
|
|
742
|
+
// Trailing separator — don't include it at program level unless
|
|
743
|
+
// there's content after. But at inner levels we keep it.
|
|
744
|
+
continue;
|
|
745
|
+
}
|
|
746
|
+
}
|
|
747
|
+
else if (sep.type === 'NEWLINE') {
|
|
748
|
+
if (P.L.heredocs.length > 0) {
|
|
749
|
+
scanHeredocBodies(P);
|
|
750
|
+
}
|
|
751
|
+
continue;
|
|
752
|
+
}
|
|
753
|
+
else {
|
|
754
|
+
restoreLex(P.L, save2);
|
|
755
|
+
}
|
|
756
|
+
}
|
|
757
|
+
// Trim trailing separator if at program level
|
|
758
|
+
return out;
|
|
759
|
+
}
|
|
760
|
+
/**
|
|
761
|
+
* Parse pipeline chains joined by && ||. Left-associative nesting.
|
|
762
|
+
* tree-sitter quirk: trailing redirect on the last pipeline wraps the ENTIRE
|
|
763
|
+
* list in a redirected_statement — `a > x && b > y` becomes
|
|
764
|
+
* redirected_statement(list(redirected_statement(a,>x), &&, b), >y).
|
|
765
|
+
*/
|
|
766
|
+
function parseAndOr(P) {
|
|
767
|
+
let left = parsePipeline(P);
|
|
768
|
+
if (!left)
|
|
769
|
+
return null;
|
|
770
|
+
while (true) {
|
|
771
|
+
const save = saveLex(P.L);
|
|
772
|
+
const t = nextToken(P.L, 'cmd');
|
|
773
|
+
if (t.type === 'OP' && (t.value === '&&' || t.value === '||')) {
|
|
774
|
+
const op = leaf(P, t.value, t);
|
|
775
|
+
skipNewlines(P);
|
|
776
|
+
const right = parsePipeline(P);
|
|
777
|
+
if (!right) {
|
|
778
|
+
left = mk(P, 'list', left.startIndex, op.endIndex, [left, op]);
|
|
779
|
+
break;
|
|
780
|
+
}
|
|
781
|
+
// If right is a redirected_statement, hoist its redirects to wrap the list.
|
|
782
|
+
if (right.type === 'redirected_statement' && right.children.length >= 2) {
|
|
783
|
+
const inner = right.children[0];
|
|
784
|
+
const redirs = right.children.slice(1);
|
|
785
|
+
const listNode = mk(P, 'list', left.startIndex, inner.endIndex, [
|
|
786
|
+
left,
|
|
787
|
+
op,
|
|
788
|
+
inner,
|
|
789
|
+
]);
|
|
790
|
+
const lastR = redirs[redirs.length - 1];
|
|
791
|
+
left = mk(P, 'redirected_statement', listNode.startIndex, lastR.endIndex, [listNode, ...redirs]);
|
|
792
|
+
}
|
|
793
|
+
else {
|
|
794
|
+
left = mk(P, 'list', left.startIndex, right.endIndex, [left, op, right]);
|
|
795
|
+
}
|
|
796
|
+
}
|
|
797
|
+
else {
|
|
798
|
+
restoreLex(P.L, save);
|
|
799
|
+
break;
|
|
800
|
+
}
|
|
801
|
+
}
|
|
802
|
+
return left;
|
|
803
|
+
}
|
|
804
|
+
function skipNewlines(P) {
|
|
805
|
+
while (true) {
|
|
806
|
+
const save = saveLex(P.L);
|
|
807
|
+
const t = nextToken(P.L, 'cmd');
|
|
808
|
+
if (t.type !== 'NEWLINE') {
|
|
809
|
+
restoreLex(P.L, save);
|
|
810
|
+
break;
|
|
811
|
+
}
|
|
812
|
+
}
|
|
813
|
+
}
|
|
814
|
+
/**
|
|
815
|
+
* Parse commands joined by | or |&. Flat children with operator leaves.
|
|
816
|
+
* tree-sitter quirk: `a | b 2>nul | c` hoists the redirect on `b` to wrap
|
|
817
|
+
* the preceding pipeline fragment — pipeline(redirected_statement(
|
|
818
|
+
* pipeline(a,|,b), 2>nul), |, c).
|
|
819
|
+
*/
|
|
820
|
+
function parsePipeline(P) {
|
|
821
|
+
let first = parseCommand(P);
|
|
822
|
+
if (!first)
|
|
823
|
+
return null;
|
|
824
|
+
const parts = [first];
|
|
825
|
+
while (true) {
|
|
826
|
+
const save = saveLex(P.L);
|
|
827
|
+
const t = nextToken(P.L, 'cmd');
|
|
828
|
+
if (t.type === 'OP' && (t.value === '|' || t.value === '|&')) {
|
|
829
|
+
const op = leaf(P, t.value, t);
|
|
830
|
+
skipNewlines(P);
|
|
831
|
+
const next = parseCommand(P);
|
|
832
|
+
if (!next) {
|
|
833
|
+
parts.push(op);
|
|
834
|
+
break;
|
|
835
|
+
}
|
|
836
|
+
// Hoist trailing redirect on `next` to wrap current pipeline fragment
|
|
837
|
+
if (next.type === 'redirected_statement' &&
|
|
838
|
+
next.children.length >= 2 &&
|
|
839
|
+
parts.length >= 1) {
|
|
840
|
+
const inner = next.children[0];
|
|
841
|
+
const redirs = next.children.slice(1);
|
|
842
|
+
// Wrap existing parts + op + inner as a pipeline
|
|
843
|
+
const pipeKids = [...parts, op, inner];
|
|
844
|
+
const pipeNode = mk(P, 'pipeline', pipeKids[0].startIndex, inner.endIndex, pipeKids);
|
|
845
|
+
const lastR = redirs[redirs.length - 1];
|
|
846
|
+
const wrapped = mk(P, 'redirected_statement', pipeNode.startIndex, lastR.endIndex, [pipeNode, ...redirs]);
|
|
847
|
+
parts.length = 0;
|
|
848
|
+
parts.push(wrapped);
|
|
849
|
+
first = wrapped;
|
|
850
|
+
continue;
|
|
851
|
+
}
|
|
852
|
+
parts.push(op, next);
|
|
853
|
+
}
|
|
854
|
+
else {
|
|
855
|
+
restoreLex(P.L, save);
|
|
856
|
+
break;
|
|
857
|
+
}
|
|
858
|
+
}
|
|
859
|
+
if (parts.length === 1)
|
|
860
|
+
return parts[0];
|
|
861
|
+
const last = parts[parts.length - 1];
|
|
862
|
+
return mk(P, 'pipeline', parts[0].startIndex, last.endIndex, parts);
|
|
863
|
+
}
|
|
864
|
+
/** Parse a single command: simple, compound, or control structure. */
|
|
865
|
+
function parseCommand(P) {
|
|
866
|
+
skipBlanks(P.L);
|
|
867
|
+
const save = saveLex(P.L);
|
|
868
|
+
const t = nextToken(P.L, 'cmd');
|
|
869
|
+
if (t.type === 'EOF') {
|
|
870
|
+
restoreLex(P.L, save);
|
|
871
|
+
return null;
|
|
872
|
+
}
|
|
873
|
+
// Negation — tree-sitter wraps just the command, redirects go outside.
|
|
874
|
+
// `! cmd > out` → redirected_statement(negated_command(!, cmd), >out)
|
|
875
|
+
if (t.type === 'OP' && t.value === '!') {
|
|
876
|
+
const bang = leaf(P, '!', t);
|
|
877
|
+
const inner = parseCommand(P);
|
|
878
|
+
if (!inner) {
|
|
879
|
+
restoreLex(P.L, save);
|
|
880
|
+
return null;
|
|
881
|
+
}
|
|
882
|
+
// If inner is a redirected_statement, hoist redirects outside negation
|
|
883
|
+
if (inner.type === 'redirected_statement' && inner.children.length >= 2) {
|
|
884
|
+
const cmd = inner.children[0];
|
|
885
|
+
const redirs = inner.children.slice(1);
|
|
886
|
+
const neg = mk(P, 'negated_command', bang.startIndex, cmd.endIndex, [
|
|
887
|
+
bang,
|
|
888
|
+
cmd,
|
|
889
|
+
]);
|
|
890
|
+
const lastR = redirs[redirs.length - 1];
|
|
891
|
+
return mk(P, 'redirected_statement', neg.startIndex, lastR.endIndex, [
|
|
892
|
+
neg,
|
|
893
|
+
...redirs,
|
|
894
|
+
]);
|
|
895
|
+
}
|
|
896
|
+
return mk(P, 'negated_command', bang.startIndex, inner.endIndex, [
|
|
897
|
+
bang,
|
|
898
|
+
inner,
|
|
899
|
+
]);
|
|
900
|
+
}
|
|
901
|
+
if (t.type === 'OP' && t.value === '(') {
|
|
902
|
+
const open = leaf(P, '(', t);
|
|
903
|
+
const body = parseStatements(P, ')');
|
|
904
|
+
const closeTok = nextToken(P.L, 'cmd');
|
|
905
|
+
const close = closeTok.type === 'OP' && closeTok.value === ')'
|
|
906
|
+
? leaf(P, ')', closeTok)
|
|
907
|
+
: mk(P, ')', open.endIndex, open.endIndex, []);
|
|
908
|
+
const node = mk(P, 'subshell', open.startIndex, close.endIndex, [
|
|
909
|
+
open,
|
|
910
|
+
...body,
|
|
911
|
+
close,
|
|
912
|
+
]);
|
|
913
|
+
return maybeRedirect(P, node);
|
|
914
|
+
}
|
|
915
|
+
if (t.type === 'OP' && t.value === '((') {
|
|
916
|
+
const open = leaf(P, '((', t);
|
|
917
|
+
const exprs = parseArithCommaList(P, '))', 'var');
|
|
918
|
+
const closeTok = nextToken(P.L, 'cmd');
|
|
919
|
+
const close = closeTok.value === '))'
|
|
920
|
+
? leaf(P, '))', closeTok)
|
|
921
|
+
: mk(P, '))', open.endIndex, open.endIndex, []);
|
|
922
|
+
return mk(P, 'compound_statement', open.startIndex, close.endIndex, [
|
|
923
|
+
open,
|
|
924
|
+
...exprs,
|
|
925
|
+
close,
|
|
926
|
+
]);
|
|
927
|
+
}
|
|
928
|
+
if (t.type === 'OP' && t.value === '{') {
|
|
929
|
+
const open = leaf(P, '{', t);
|
|
930
|
+
const body = parseStatements(P, '}');
|
|
931
|
+
const closeTok = nextToken(P.L, 'cmd');
|
|
932
|
+
const close = closeTok.type === 'OP' && closeTok.value === '}'
|
|
933
|
+
? leaf(P, '}', closeTok)
|
|
934
|
+
: mk(P, '}', open.endIndex, open.endIndex, []);
|
|
935
|
+
const node = mk(P, 'compound_statement', open.startIndex, close.endIndex, [
|
|
936
|
+
open,
|
|
937
|
+
...body,
|
|
938
|
+
close,
|
|
939
|
+
]);
|
|
940
|
+
return maybeRedirect(P, node);
|
|
941
|
+
}
|
|
942
|
+
if (t.type === 'OP' && (t.value === '[' || t.value === '[[')) {
|
|
943
|
+
const open = leaf(P, t.value, t);
|
|
944
|
+
const closer = t.value === '[' ? ']' : ']]';
|
|
945
|
+
// Grammar: `[` can contain choice(_expression, redirected_statement).
|
|
946
|
+
// Try _expression first; if we don't reach `]`, backtrack and parse as
|
|
947
|
+
// redirected_statement (handles `[ ! cmd -v go &>/dev/null ]`).
|
|
948
|
+
const exprSave = saveLex(P.L);
|
|
949
|
+
let expr = parseTestExpr(P, closer);
|
|
950
|
+
skipBlanks(P.L);
|
|
951
|
+
if (t.value === '[' && peek(P.L) !== ']') {
|
|
952
|
+
// Expression parse didn't reach `]` — try as redirected_statement.
|
|
953
|
+
// Thread `]` stop-token so parseSimpleCommand doesn't eat it as arg.
|
|
954
|
+
restoreLex(P.L, exprSave);
|
|
955
|
+
const prevStop = P.stopToken;
|
|
956
|
+
P.stopToken = ']';
|
|
957
|
+
const rstmt = parseCommand(P);
|
|
958
|
+
P.stopToken = prevStop;
|
|
959
|
+
if (rstmt && rstmt.type === 'redirected_statement') {
|
|
960
|
+
expr = rstmt;
|
|
961
|
+
}
|
|
962
|
+
else {
|
|
963
|
+
// Neither worked — restore and keep the expression result
|
|
964
|
+
restoreLex(P.L, exprSave);
|
|
965
|
+
expr = parseTestExpr(P, closer);
|
|
966
|
+
}
|
|
967
|
+
skipBlanks(P.L);
|
|
968
|
+
}
|
|
969
|
+
const closeTok = nextToken(P.L, 'arg');
|
|
970
|
+
let close;
|
|
971
|
+
if (closeTok.value === closer) {
|
|
972
|
+
close = leaf(P, closer, closeTok);
|
|
973
|
+
}
|
|
974
|
+
else {
|
|
975
|
+
close = mk(P, closer, open.endIndex, open.endIndex, []);
|
|
976
|
+
}
|
|
977
|
+
const kids = expr ? [open, expr, close] : [open, close];
|
|
978
|
+
return mk(P, 'test_command', open.startIndex, close.endIndex, kids);
|
|
979
|
+
}
|
|
980
|
+
if (t.type === 'WORD') {
|
|
981
|
+
if (t.value === 'if')
|
|
982
|
+
return maybeRedirect(P, parseIf(P, t), true);
|
|
983
|
+
if (t.value === 'while' || t.value === 'until')
|
|
984
|
+
return maybeRedirect(P, parseWhile(P, t), true);
|
|
985
|
+
if (t.value === 'for')
|
|
986
|
+
return maybeRedirect(P, parseFor(P, t), true);
|
|
987
|
+
if (t.value === 'select')
|
|
988
|
+
return maybeRedirect(P, parseFor(P, t), true);
|
|
989
|
+
if (t.value === 'case')
|
|
990
|
+
return maybeRedirect(P, parseCase(P, t), true);
|
|
991
|
+
if (t.value === 'function')
|
|
992
|
+
return parseFunction(P, t);
|
|
993
|
+
if (DECL_KEYWORDS.has(t.value))
|
|
994
|
+
return maybeRedirect(P, parseDeclaration(P, t));
|
|
995
|
+
if (t.value === 'unset' || t.value === 'unsetenv') {
|
|
996
|
+
return maybeRedirect(P, parseUnset(P, t));
|
|
997
|
+
}
|
|
998
|
+
}
|
|
999
|
+
restoreLex(P.L, save);
|
|
1000
|
+
return parseSimpleCommand(P);
|
|
1001
|
+
}
|
|
1002
|
+
/**
|
|
1003
|
+
* Parse a simple command: [assignment]* word [arg|redirect]*
|
|
1004
|
+
* Returns variable_assignment if only one assignment and no command.
|
|
1005
|
+
*/
|
|
1006
|
+
function parseSimpleCommand(P) {
|
|
1007
|
+
const start = P.L.b;
|
|
1008
|
+
const assignments = [];
|
|
1009
|
+
const preRedirects = [];
|
|
1010
|
+
while (true) {
|
|
1011
|
+
skipBlanks(P.L);
|
|
1012
|
+
const a = tryParseAssignment(P);
|
|
1013
|
+
if (a) {
|
|
1014
|
+
assignments.push(a);
|
|
1015
|
+
continue;
|
|
1016
|
+
}
|
|
1017
|
+
const r = tryParseRedirect(P);
|
|
1018
|
+
if (r) {
|
|
1019
|
+
preRedirects.push(r);
|
|
1020
|
+
continue;
|
|
1021
|
+
}
|
|
1022
|
+
break;
|
|
1023
|
+
}
|
|
1024
|
+
skipBlanks(P.L);
|
|
1025
|
+
const save = saveLex(P.L);
|
|
1026
|
+
const nameTok = nextToken(P.L, 'cmd');
|
|
1027
|
+
if (nameTok.type === 'EOF' ||
|
|
1028
|
+
nameTok.type === 'NEWLINE' ||
|
|
1029
|
+
nameTok.type === 'COMMENT' ||
|
|
1030
|
+
(nameTok.type === 'OP' &&
|
|
1031
|
+
nameTok.value !== '{' &&
|
|
1032
|
+
nameTok.value !== '[' &&
|
|
1033
|
+
nameTok.value !== '[[') ||
|
|
1034
|
+
(nameTok.type === 'WORD' &&
|
|
1035
|
+
SHELL_KEYWORDS.has(nameTok.value) &&
|
|
1036
|
+
nameTok.value !== 'in')) {
|
|
1037
|
+
restoreLex(P.L, save);
|
|
1038
|
+
// No command — standalone assignment(s) or redirect
|
|
1039
|
+
if (assignments.length === 1 && preRedirects.length === 0) {
|
|
1040
|
+
return assignments[0];
|
|
1041
|
+
}
|
|
1042
|
+
if (preRedirects.length > 0 && assignments.length === 0) {
|
|
1043
|
+
// Bare redirect → redirected_statement with just file_redirect children
|
|
1044
|
+
const last = preRedirects[preRedirects.length - 1];
|
|
1045
|
+
return mk(P, 'redirected_statement', preRedirects[0].startIndex, last.endIndex, preRedirects);
|
|
1046
|
+
}
|
|
1047
|
+
if (assignments.length > 1 && preRedirects.length === 0) {
|
|
1048
|
+
// `A=1 B=2` with no command → variable_assignments (plural)
|
|
1049
|
+
const last = assignments[assignments.length - 1];
|
|
1050
|
+
return mk(P, 'variable_assignments', assignments[0].startIndex, last.endIndex, assignments);
|
|
1051
|
+
}
|
|
1052
|
+
if (assignments.length > 0 || preRedirects.length > 0) {
|
|
1053
|
+
const all = [...assignments, ...preRedirects];
|
|
1054
|
+
const last = all[all.length - 1];
|
|
1055
|
+
return mk(P, 'command', start, last.endIndex, all);
|
|
1056
|
+
}
|
|
1057
|
+
return null;
|
|
1058
|
+
}
|
|
1059
|
+
restoreLex(P.L, save);
|
|
1060
|
+
// Check for function definition: name() { ... }
|
|
1061
|
+
const fnSave = saveLex(P.L);
|
|
1062
|
+
const nm = parseWord(P, 'cmd');
|
|
1063
|
+
if (nm && nm.type === 'word') {
|
|
1064
|
+
skipBlanks(P.L);
|
|
1065
|
+
if (peek(P.L) === '(' && peek(P.L, 1) === ')') {
|
|
1066
|
+
const oTok = nextToken(P.L, 'cmd');
|
|
1067
|
+
const cTok = nextToken(P.L, 'cmd');
|
|
1068
|
+
const oParen = leaf(P, '(', oTok);
|
|
1069
|
+
const cParen = leaf(P, ')', cTok);
|
|
1070
|
+
skipBlanks(P.L);
|
|
1071
|
+
skipNewlines(P);
|
|
1072
|
+
const body = parseCommand(P);
|
|
1073
|
+
if (body) {
|
|
1074
|
+
// If body is redirected_statement(compound_statement, file_redirect...),
|
|
1075
|
+
// hoist redirects to function_definition level per tree-sitter grammar
|
|
1076
|
+
let bodyKids = [body];
|
|
1077
|
+
if (body.type === 'redirected_statement' &&
|
|
1078
|
+
body.children.length >= 2 &&
|
|
1079
|
+
body.children[0].type === 'compound_statement') {
|
|
1080
|
+
bodyKids = body.children;
|
|
1081
|
+
}
|
|
1082
|
+
const last = bodyKids[bodyKids.length - 1];
|
|
1083
|
+
return mk(P, 'function_definition', nm.startIndex, last.endIndex, [
|
|
1084
|
+
nm,
|
|
1085
|
+
oParen,
|
|
1086
|
+
cParen,
|
|
1087
|
+
...bodyKids,
|
|
1088
|
+
]);
|
|
1089
|
+
}
|
|
1090
|
+
}
|
|
1091
|
+
}
|
|
1092
|
+
restoreLex(P.L, fnSave);
|
|
1093
|
+
const nameArg = parseWord(P, 'cmd');
|
|
1094
|
+
if (!nameArg) {
|
|
1095
|
+
if (assignments.length === 1)
|
|
1096
|
+
return assignments[0];
|
|
1097
|
+
return null;
|
|
1098
|
+
}
|
|
1099
|
+
const cmdName = mk(P, 'command_name', nameArg.startIndex, nameArg.endIndex, [
|
|
1100
|
+
nameArg,
|
|
1101
|
+
]);
|
|
1102
|
+
const args = [];
|
|
1103
|
+
const redirects = [];
|
|
1104
|
+
let heredocRedirect = null;
|
|
1105
|
+
while (true) {
|
|
1106
|
+
skipBlanks(P.L);
|
|
1107
|
+
// Post-command redirects are greedy (repeat1 $._literal) — once a redirect
|
|
1108
|
+
// appears after command_name, subsequent literals attach to it per grammar's
|
|
1109
|
+
// prec.left. `grep 2>/dev/null -q foo` → file_redirect eats `-q foo`.
|
|
1110
|
+
// Args parsed BEFORE the first redirect still go to command (cat a b > out).
|
|
1111
|
+
const r = tryParseRedirect(P, true);
|
|
1112
|
+
if (r) {
|
|
1113
|
+
if (r.type === 'heredoc_redirect') {
|
|
1114
|
+
heredocRedirect = r;
|
|
1115
|
+
}
|
|
1116
|
+
else if (r.type === 'herestring_redirect') {
|
|
1117
|
+
args.push(r);
|
|
1118
|
+
}
|
|
1119
|
+
else {
|
|
1120
|
+
redirects.push(r);
|
|
1121
|
+
}
|
|
1122
|
+
continue;
|
|
1123
|
+
}
|
|
1124
|
+
// Once a file_redirect has been seen, command args are done — grammar's
|
|
1125
|
+
// command rule doesn't allow file_redirect in its post-name choice, so
|
|
1126
|
+
// anything after belongs to redirected_statement's file_redirect children.
|
|
1127
|
+
if (redirects.length > 0)
|
|
1128
|
+
break;
|
|
1129
|
+
// `[` test_command backtrack — stop at `]` so outer handler can consume it
|
|
1130
|
+
if (P.stopToken === ']' && peek(P.L) === ']')
|
|
1131
|
+
break;
|
|
1132
|
+
const save2 = saveLex(P.L);
|
|
1133
|
+
const pk = nextToken(P.L, 'arg');
|
|
1134
|
+
if (pk.type === 'EOF' ||
|
|
1135
|
+
pk.type === 'NEWLINE' ||
|
|
1136
|
+
pk.type === 'COMMENT' ||
|
|
1137
|
+
(pk.type === 'OP' &&
|
|
1138
|
+
(pk.value === '|' ||
|
|
1139
|
+
pk.value === '|&' ||
|
|
1140
|
+
pk.value === '&&' ||
|
|
1141
|
+
pk.value === '||' ||
|
|
1142
|
+
pk.value === ';' ||
|
|
1143
|
+
pk.value === ';;' ||
|
|
1144
|
+
pk.value === ';&' ||
|
|
1145
|
+
pk.value === ';;&' ||
|
|
1146
|
+
pk.value === '&' ||
|
|
1147
|
+
pk.value === ')' ||
|
|
1148
|
+
pk.value === '}' ||
|
|
1149
|
+
pk.value === '))'))) {
|
|
1150
|
+
restoreLex(P.L, save2);
|
|
1151
|
+
break;
|
|
1152
|
+
}
|
|
1153
|
+
restoreLex(P.L, save2);
|
|
1154
|
+
const arg = parseWord(P, 'arg');
|
|
1155
|
+
if (!arg) {
|
|
1156
|
+
// Lone `(` in arg position — tree-sitter parses this as subshell arg
|
|
1157
|
+
// e.g., `echo =(cmd)` → command has ERROR(=), subshell(cmd) as args
|
|
1158
|
+
if (peek(P.L) === '(') {
|
|
1159
|
+
const oTok = nextToken(P.L, 'cmd');
|
|
1160
|
+
const open = leaf(P, '(', oTok);
|
|
1161
|
+
const body = parseStatements(P, ')');
|
|
1162
|
+
const cTok = nextToken(P.L, 'cmd');
|
|
1163
|
+
const close = cTok.type === 'OP' && cTok.value === ')'
|
|
1164
|
+
? leaf(P, ')', cTok)
|
|
1165
|
+
: mk(P, ')', open.endIndex, open.endIndex, []);
|
|
1166
|
+
args.push(mk(P, 'subshell', open.startIndex, close.endIndex, [
|
|
1167
|
+
open,
|
|
1168
|
+
...body,
|
|
1169
|
+
close,
|
|
1170
|
+
]));
|
|
1171
|
+
continue;
|
|
1172
|
+
}
|
|
1173
|
+
break;
|
|
1174
|
+
}
|
|
1175
|
+
// Lone `=` in arg position is a parse error in bash — tree-sitter wraps
|
|
1176
|
+
// it in ERROR for recovery. Happens in `echo =(cmd)` (zsh process-sub).
|
|
1177
|
+
if (arg.type === 'word' && arg.text === '=') {
|
|
1178
|
+
args.push(mk(P, 'ERROR', arg.startIndex, arg.endIndex, [arg]));
|
|
1179
|
+
continue;
|
|
1180
|
+
}
|
|
1181
|
+
// Word immediately followed by `(` (no whitespace) is a parse error —
|
|
1182
|
+
// bash doesn't allow glob-then-subshell adjacency. tree-sitter wraps the
|
|
1183
|
+
// word in ERROR. Catches zsh glob qualifiers like `*.(e:'cmd':)`.
|
|
1184
|
+
if ((arg.type === 'word' || arg.type === 'concatenation') &&
|
|
1185
|
+
peek(P.L) === '(' &&
|
|
1186
|
+
P.L.b === arg.endIndex) {
|
|
1187
|
+
args.push(mk(P, 'ERROR', arg.startIndex, arg.endIndex, [arg]));
|
|
1188
|
+
continue;
|
|
1189
|
+
}
|
|
1190
|
+
args.push(arg);
|
|
1191
|
+
}
|
|
1192
|
+
// preRedirects (e.g., `2>&1 cat`, `<<<str cmd`) go INSIDE the command node
|
|
1193
|
+
// before command_name per tree-sitter grammar, not in redirected_statement
|
|
1194
|
+
const cmdChildren = [...assignments, ...preRedirects, cmdName, ...args];
|
|
1195
|
+
const cmdEnd = cmdChildren.length > 0
|
|
1196
|
+
? cmdChildren[cmdChildren.length - 1].endIndex
|
|
1197
|
+
: cmdName.endIndex;
|
|
1198
|
+
const cmdStart = cmdChildren[0].startIndex;
|
|
1199
|
+
const cmd = mk(P, 'command', cmdStart, cmdEnd, cmdChildren);
|
|
1200
|
+
if (heredocRedirect) {
|
|
1201
|
+
// Scan heredoc body now
|
|
1202
|
+
scanHeredocBodies(P);
|
|
1203
|
+
const hd = P.L.heredocs.shift();
|
|
1204
|
+
if (hd && heredocRedirect.children.length >= 2) {
|
|
1205
|
+
const bodyNode = mk(P, 'heredoc_body', hd.bodyStart, hd.bodyEnd, hd.quoted ? [] : parseHeredocBodyContent(P, hd.bodyStart, hd.bodyEnd));
|
|
1206
|
+
const endNode = mk(P, 'heredoc_end', hd.endStart, hd.endEnd, []);
|
|
1207
|
+
heredocRedirect.children.push(bodyNode, endNode);
|
|
1208
|
+
heredocRedirect.endIndex = hd.endEnd;
|
|
1209
|
+
heredocRedirect.text = sliceBytes(P, heredocRedirect.startIndex, hd.endEnd);
|
|
1210
|
+
}
|
|
1211
|
+
const allR = [...preRedirects, heredocRedirect, ...redirects];
|
|
1212
|
+
const rStart = preRedirects.length > 0
|
|
1213
|
+
? Math.min(cmd.startIndex, preRedirects[0].startIndex)
|
|
1214
|
+
: cmd.startIndex;
|
|
1215
|
+
return mk(P, 'redirected_statement', rStart, heredocRedirect.endIndex, [
|
|
1216
|
+
cmd,
|
|
1217
|
+
...allR,
|
|
1218
|
+
]);
|
|
1219
|
+
}
|
|
1220
|
+
if (redirects.length > 0) {
|
|
1221
|
+
const last = redirects[redirects.length - 1];
|
|
1222
|
+
return mk(P, 'redirected_statement', cmd.startIndex, last.endIndex, [
|
|
1223
|
+
cmd,
|
|
1224
|
+
...redirects,
|
|
1225
|
+
]);
|
|
1226
|
+
}
|
|
1227
|
+
return cmd;
|
|
1228
|
+
}
|
|
1229
|
+
function maybeRedirect(P, node, allowHerestring = false) {
|
|
1230
|
+
const redirects = [];
|
|
1231
|
+
while (true) {
|
|
1232
|
+
skipBlanks(P.L);
|
|
1233
|
+
const save = saveLex(P.L);
|
|
1234
|
+
const r = tryParseRedirect(P);
|
|
1235
|
+
if (!r)
|
|
1236
|
+
break;
|
|
1237
|
+
if (r.type === 'herestring_redirect' && !allowHerestring) {
|
|
1238
|
+
restoreLex(P.L, save);
|
|
1239
|
+
break;
|
|
1240
|
+
}
|
|
1241
|
+
redirects.push(r);
|
|
1242
|
+
}
|
|
1243
|
+
if (redirects.length === 0)
|
|
1244
|
+
return node;
|
|
1245
|
+
const last = redirects[redirects.length - 1];
|
|
1246
|
+
return mk(P, 'redirected_statement', node.startIndex, last.endIndex, [
|
|
1247
|
+
node,
|
|
1248
|
+
...redirects,
|
|
1249
|
+
]);
|
|
1250
|
+
}
|
|
1251
|
+
function tryParseAssignment(P) {
|
|
1252
|
+
const save = saveLex(P.L);
|
|
1253
|
+
skipBlanks(P.L);
|
|
1254
|
+
const startB = P.L.b;
|
|
1255
|
+
// Must start with identifier
|
|
1256
|
+
if (!isIdentStart(peek(P.L))) {
|
|
1257
|
+
restoreLex(P.L, save);
|
|
1258
|
+
return null;
|
|
1259
|
+
}
|
|
1260
|
+
while (isIdentChar(peek(P.L)))
|
|
1261
|
+
advance(P.L);
|
|
1262
|
+
const nameEnd = P.L.b;
|
|
1263
|
+
// Optional subscript
|
|
1264
|
+
let subEnd = nameEnd;
|
|
1265
|
+
if (peek(P.L) === '[') {
|
|
1266
|
+
advance(P.L);
|
|
1267
|
+
let depth = 1;
|
|
1268
|
+
while (P.L.i < P.L.len && depth > 0) {
|
|
1269
|
+
const c = peek(P.L);
|
|
1270
|
+
if (c === '[')
|
|
1271
|
+
depth++;
|
|
1272
|
+
else if (c === ']')
|
|
1273
|
+
depth--;
|
|
1274
|
+
advance(P.L);
|
|
1275
|
+
}
|
|
1276
|
+
subEnd = P.L.b;
|
|
1277
|
+
}
|
|
1278
|
+
const c = peek(P.L);
|
|
1279
|
+
const c1 = peek(P.L, 1);
|
|
1280
|
+
let op;
|
|
1281
|
+
if (c === '=' && c1 !== '=') {
|
|
1282
|
+
op = '=';
|
|
1283
|
+
}
|
|
1284
|
+
else if (c === '+' && c1 === '=') {
|
|
1285
|
+
op = '+=';
|
|
1286
|
+
}
|
|
1287
|
+
else {
|
|
1288
|
+
restoreLex(P.L, save);
|
|
1289
|
+
return null;
|
|
1290
|
+
}
|
|
1291
|
+
const nameNode = mk(P, 'variable_name', startB, nameEnd, []);
|
|
1292
|
+
// Subscript handling: wrap in subscript node if present
|
|
1293
|
+
let lhs = nameNode;
|
|
1294
|
+
if (subEnd > nameEnd) {
|
|
1295
|
+
const brOpen = mk(P, '[', nameEnd, nameEnd + 1, []);
|
|
1296
|
+
const idx = parseSubscriptIndex(P, nameEnd + 1, subEnd - 1);
|
|
1297
|
+
const brClose = mk(P, ']', subEnd - 1, subEnd, []);
|
|
1298
|
+
lhs = mk(P, 'subscript', startB, subEnd, [nameNode, brOpen, idx, brClose]);
|
|
1299
|
+
}
|
|
1300
|
+
const opStart = P.L.b;
|
|
1301
|
+
advance(P.L);
|
|
1302
|
+
if (op === '+=')
|
|
1303
|
+
advance(P.L);
|
|
1304
|
+
const opEnd = P.L.b;
|
|
1305
|
+
const opNode = mk(P, op, opStart, opEnd, []);
|
|
1306
|
+
let val = null;
|
|
1307
|
+
if (peek(P.L) === '(') {
|
|
1308
|
+
// Array
|
|
1309
|
+
const aoTok = nextToken(P.L, 'cmd');
|
|
1310
|
+
const aOpen = leaf(P, '(', aoTok);
|
|
1311
|
+
const elems = [aOpen];
|
|
1312
|
+
while (true) {
|
|
1313
|
+
skipBlanks(P.L);
|
|
1314
|
+
if (peek(P.L) === ')')
|
|
1315
|
+
break;
|
|
1316
|
+
const e = parseWord(P, 'arg');
|
|
1317
|
+
if (!e)
|
|
1318
|
+
break;
|
|
1319
|
+
elems.push(e);
|
|
1320
|
+
}
|
|
1321
|
+
const acTok = nextToken(P.L, 'cmd');
|
|
1322
|
+
const aClose = acTok.value === ')'
|
|
1323
|
+
? leaf(P, ')', acTok)
|
|
1324
|
+
: mk(P, ')', aOpen.endIndex, aOpen.endIndex, []);
|
|
1325
|
+
elems.push(aClose);
|
|
1326
|
+
val = mk(P, 'array', aOpen.startIndex, aClose.endIndex, elems);
|
|
1327
|
+
}
|
|
1328
|
+
else {
|
|
1329
|
+
const c2 = peek(P.L);
|
|
1330
|
+
if (c2 &&
|
|
1331
|
+
c2 !== ' ' &&
|
|
1332
|
+
c2 !== '\t' &&
|
|
1333
|
+
c2 !== '\n' &&
|
|
1334
|
+
c2 !== ';' &&
|
|
1335
|
+
c2 !== '&' &&
|
|
1336
|
+
c2 !== '|' &&
|
|
1337
|
+
c2 !== ')' &&
|
|
1338
|
+
c2 !== '}') {
|
|
1339
|
+
val = parseWord(P, 'arg');
|
|
1340
|
+
}
|
|
1341
|
+
}
|
|
1342
|
+
const kids = val ? [lhs, opNode, val] : [lhs, opNode];
|
|
1343
|
+
const end = val ? val.endIndex : opEnd;
|
|
1344
|
+
return mk(P, 'variable_assignment', startB, end, kids);
|
|
1345
|
+
}
|
|
1346
|
+
/**
|
|
1347
|
+
* Parse subscript index content. Parsed arithmetically per tree-sitter grammar:
|
|
1348
|
+
* `${a[1+2]}` → binary_expression; `${a[++i]}` → unary_expression(word);
|
|
1349
|
+
* `${a[(($n+1))]}` → compound_statement(binary_expression). Falls back to
|
|
1350
|
+
* simple patterns (@, *) as word.
|
|
1351
|
+
*/
|
|
1352
|
+
function parseSubscriptIndexInline(P) {
|
|
1353
|
+
skipBlanks(P.L);
|
|
1354
|
+
const c = peek(P.L);
|
|
1355
|
+
// @ or * alone → word (associative array all-keys)
|
|
1356
|
+
if ((c === '@' || c === '*') && peek(P.L, 1) === ']') {
|
|
1357
|
+
const s = P.L.b;
|
|
1358
|
+
advance(P.L);
|
|
1359
|
+
return mk(P, 'word', s, P.L.b, []);
|
|
1360
|
+
}
|
|
1361
|
+
// ((expr)) → compound_statement wrapping the inner arithmetic
|
|
1362
|
+
if (c === '(' && peek(P.L, 1) === '(') {
|
|
1363
|
+
const oStart = P.L.b;
|
|
1364
|
+
advance(P.L);
|
|
1365
|
+
advance(P.L);
|
|
1366
|
+
const open = mk(P, '((', oStart, P.L.b, []);
|
|
1367
|
+
const inner = parseArithExpr(P, '))', 'var');
|
|
1368
|
+
skipBlanks(P.L);
|
|
1369
|
+
let close;
|
|
1370
|
+
if (peek(P.L) === ')' && peek(P.L, 1) === ')') {
|
|
1371
|
+
const cs = P.L.b;
|
|
1372
|
+
advance(P.L);
|
|
1373
|
+
advance(P.L);
|
|
1374
|
+
close = mk(P, '))', cs, P.L.b, []);
|
|
1375
|
+
}
|
|
1376
|
+
else {
|
|
1377
|
+
close = mk(P, '))', P.L.b, P.L.b, []);
|
|
1378
|
+
}
|
|
1379
|
+
const kids = inner ? [open, inner, close] : [open, close];
|
|
1380
|
+
return mk(P, 'compound_statement', open.startIndex, close.endIndex, kids);
|
|
1381
|
+
}
|
|
1382
|
+
// Arithmetic — but bare identifiers in subscript use 'word' mode per
|
|
1383
|
+
// tree-sitter (${words[++counter]} → unary_expression(word)).
|
|
1384
|
+
return parseArithExpr(P, ']', 'word');
|
|
1385
|
+
}
|
|
1386
|
+
/** Legacy byte-range subscript index parser — kept for callers that pre-scan. */
|
|
1387
|
+
function parseSubscriptIndex(P, startB, endB) {
|
|
1388
|
+
const text = sliceBytes(P, startB, endB);
|
|
1389
|
+
if (/^\d+$/.test(text))
|
|
1390
|
+
return mk(P, 'number', startB, endB, []);
|
|
1391
|
+
const m = /^\$([a-zA-Z_]\w*)$/.exec(text);
|
|
1392
|
+
if (m) {
|
|
1393
|
+
const dollar = mk(P, '$', startB, startB + 1, []);
|
|
1394
|
+
const vn = mk(P, 'variable_name', startB + 1, endB, []);
|
|
1395
|
+
return mk(P, 'simple_expansion', startB, endB, [dollar, vn]);
|
|
1396
|
+
}
|
|
1397
|
+
if (text.length === 2 && text[0] === '$' && SPECIAL_VARS.has(text[1])) {
|
|
1398
|
+
const dollar = mk(P, '$', startB, startB + 1, []);
|
|
1399
|
+
const vn = mk(P, 'special_variable_name', startB + 1, endB, []);
|
|
1400
|
+
return mk(P, 'simple_expansion', startB, endB, [dollar, vn]);
|
|
1401
|
+
}
|
|
1402
|
+
return mk(P, 'word', startB, endB, []);
|
|
1403
|
+
}
|
|
1404
|
+
/**
|
|
1405
|
+
* Can the current position start a redirect destination literal?
|
|
1406
|
+
* Returns false at redirect ops, terminators, or file-descriptor-prefixed ops
|
|
1407
|
+
* so file_redirect's repeat1($._literal) stops at the right boundary.
|
|
1408
|
+
*/
|
|
1409
|
+
function isRedirectLiteralStart(P) {
|
|
1410
|
+
const c = peek(P.L);
|
|
1411
|
+
if (c === '' || c === '\n')
|
|
1412
|
+
return false;
|
|
1413
|
+
// Shell terminators and operators
|
|
1414
|
+
if (c === '|' || c === '&' || c === ';' || c === '(' || c === ')')
|
|
1415
|
+
return false;
|
|
1416
|
+
// Redirect operators (< > with any suffix; <( >( handled by caller)
|
|
1417
|
+
if (c === '<' || c === '>') {
|
|
1418
|
+
// <( >( are process substitutions — those ARE literals
|
|
1419
|
+
return peek(P.L, 1) === '(';
|
|
1420
|
+
}
|
|
1421
|
+
// N< N> file descriptor prefix — starts a new redirect, not a literal
|
|
1422
|
+
if (isDigit(c)) {
|
|
1423
|
+
let j = P.L.i;
|
|
1424
|
+
while (j < P.L.len && isDigit(P.L.src[j]))
|
|
1425
|
+
j++;
|
|
1426
|
+
const after = j < P.L.len ? P.L.src[j] : '';
|
|
1427
|
+
if (after === '>' || after === '<')
|
|
1428
|
+
return false;
|
|
1429
|
+
}
|
|
1430
|
+
// `}` only terminates if we're in a context where it's a closer — but
|
|
1431
|
+
// file_redirect sees `}` as word char (e.g., `>$HOME}` is valid path char).
|
|
1432
|
+
// Actually `}` at top level terminates compound_statement — need to stop.
|
|
1433
|
+
if (c === '}')
|
|
1434
|
+
return false;
|
|
1435
|
+
// Test command closer — when parseSimpleCommand is called from `[` context,
|
|
1436
|
+
// `]` must terminate so parseCommand can return and `[` handler consume it.
|
|
1437
|
+
if (P.stopToken === ']' && c === ']')
|
|
1438
|
+
return false;
|
|
1439
|
+
return true;
|
|
1440
|
+
}
|
|
1441
|
+
/**
|
|
1442
|
+
* Parse a redirect operator + destination(s).
|
|
1443
|
+
* @param greedy When true, file_redirect consumes repeat1($._literal) per
|
|
1444
|
+
* grammar's prec.left — `cmd >f a b c` attaches `a b c` to the redirect.
|
|
1445
|
+
* When false (preRedirect context), takes only 1 destination because
|
|
1446
|
+
* command's dynamic precedence beats redirected_statement's prec(-1).
|
|
1447
|
+
*/
|
|
1448
|
+
function tryParseRedirect(P, greedy = false) {
|
|
1449
|
+
const save = saveLex(P.L);
|
|
1450
|
+
skipBlanks(P.L);
|
|
1451
|
+
// File descriptor prefix?
|
|
1452
|
+
let fd = null;
|
|
1453
|
+
if (isDigit(peek(P.L))) {
|
|
1454
|
+
const startB = P.L.b;
|
|
1455
|
+
let j = P.L.i;
|
|
1456
|
+
while (j < P.L.len && isDigit(P.L.src[j]))
|
|
1457
|
+
j++;
|
|
1458
|
+
const after = j < P.L.len ? P.L.src[j] : '';
|
|
1459
|
+
if (after === '>' || after === '<') {
|
|
1460
|
+
while (P.L.i < j)
|
|
1461
|
+
advance(P.L);
|
|
1462
|
+
fd = mk(P, 'file_descriptor', startB, P.L.b, []);
|
|
1463
|
+
}
|
|
1464
|
+
}
|
|
1465
|
+
const t = nextToken(P.L, 'arg');
|
|
1466
|
+
if (t.type !== 'OP') {
|
|
1467
|
+
restoreLex(P.L, save);
|
|
1468
|
+
return null;
|
|
1469
|
+
}
|
|
1470
|
+
const v = t.value;
|
|
1471
|
+
if (v === '<<<') {
|
|
1472
|
+
const op = leaf(P, '<<<', t);
|
|
1473
|
+
skipBlanks(P.L);
|
|
1474
|
+
const target = parseWord(P, 'arg');
|
|
1475
|
+
const end = target ? target.endIndex : op.endIndex;
|
|
1476
|
+
const kids = target ? [op, target] : [op];
|
|
1477
|
+
return mk(P, 'herestring_redirect', fd ? fd.startIndex : op.startIndex, end, fd ? [fd, ...kids] : kids);
|
|
1478
|
+
}
|
|
1479
|
+
if (v === '<<' || v === '<<-') {
|
|
1480
|
+
const op = leaf(P, v, t);
|
|
1481
|
+
// Heredoc start — delimiter word (may be quoted)
|
|
1482
|
+
skipBlanks(P.L);
|
|
1483
|
+
const dStart = P.L.b;
|
|
1484
|
+
let quoted = false;
|
|
1485
|
+
let delim = '';
|
|
1486
|
+
const dc = peek(P.L);
|
|
1487
|
+
if (dc === "'" || dc === '"') {
|
|
1488
|
+
quoted = true;
|
|
1489
|
+
advance(P.L);
|
|
1490
|
+
while (P.L.i < P.L.len && peek(P.L) !== dc) {
|
|
1491
|
+
delim += peek(P.L);
|
|
1492
|
+
advance(P.L);
|
|
1493
|
+
}
|
|
1494
|
+
if (P.L.i < P.L.len)
|
|
1495
|
+
advance(P.L);
|
|
1496
|
+
}
|
|
1497
|
+
else if (dc === '\\') {
|
|
1498
|
+
// Backslash-escaped delimiter: \X — exactly one escaped char, body is
|
|
1499
|
+
// quoted (literal). Covers <<\EOF <<\' <<\\ etc.
|
|
1500
|
+
quoted = true;
|
|
1501
|
+
advance(P.L);
|
|
1502
|
+
if (P.L.i < P.L.len && peek(P.L) !== '\n') {
|
|
1503
|
+
delim += peek(P.L);
|
|
1504
|
+
advance(P.L);
|
|
1505
|
+
}
|
|
1506
|
+
// May be followed by more ident chars (e.g. <<\EOF → delim "EOF")
|
|
1507
|
+
while (P.L.i < P.L.len && isIdentChar(peek(P.L))) {
|
|
1508
|
+
delim += peek(P.L);
|
|
1509
|
+
advance(P.L);
|
|
1510
|
+
}
|
|
1511
|
+
}
|
|
1512
|
+
else {
|
|
1513
|
+
// Unquoted delimiter: bash accepts most non-metacharacters (not just
|
|
1514
|
+
// identifiers). Allow !, -, ., etc. — stop at shell metachars.
|
|
1515
|
+
while (P.L.i < P.L.len && isHeredocDelimChar(peek(P.L))) {
|
|
1516
|
+
delim += peek(P.L);
|
|
1517
|
+
advance(P.L);
|
|
1518
|
+
}
|
|
1519
|
+
}
|
|
1520
|
+
const dEnd = P.L.b;
|
|
1521
|
+
const startNode = mk(P, 'heredoc_start', dStart, dEnd, []);
|
|
1522
|
+
// Register pending heredoc — body scanned at next newline
|
|
1523
|
+
P.L.heredocs.push({
|
|
1524
|
+
delim,
|
|
1525
|
+
stripTabs: v === '<<-',
|
|
1526
|
+
quoted,
|
|
1527
|
+
bodyStart: 0,
|
|
1528
|
+
bodyEnd: 0,
|
|
1529
|
+
endStart: 0,
|
|
1530
|
+
endEnd: 0,
|
|
1531
|
+
});
|
|
1532
|
+
const kids = fd ? [fd, op, startNode] : [op, startNode];
|
|
1533
|
+
const startIdx = fd ? fd.startIndex : op.startIndex;
|
|
1534
|
+
// SECURITY: tree-sitter nests any pipeline/list/file_redirect appearing
|
|
1535
|
+
// between heredoc_start and the newline as a CHILD of heredoc_redirect.
|
|
1536
|
+
// `ls <<'EOF' | rm -rf /tmp/evil` must not silently drop the rm. Parse
|
|
1537
|
+
// trailing words and file_redirects properly (ast.ts walkHeredocRedirect
|
|
1538
|
+
// fails closed on any unrecognized child via tooComplex). Pipeline / list
|
|
1539
|
+
// operators (| && || ;) are structurally complex — emit ERROR so the same
|
|
1540
|
+
// fail-closed path rejects them.
|
|
1541
|
+
while (true) {
|
|
1542
|
+
skipBlanks(P.L);
|
|
1543
|
+
const tc = peek(P.L);
|
|
1544
|
+
if (tc === '\n' || tc === '' || P.L.i >= P.L.len)
|
|
1545
|
+
break;
|
|
1546
|
+
// File redirect after delimiter: cat <<EOF > out.txt
|
|
1547
|
+
if (tc === '>' || tc === '<' || isDigit(tc)) {
|
|
1548
|
+
const rSave = saveLex(P.L);
|
|
1549
|
+
const r = tryParseRedirect(P);
|
|
1550
|
+
if (r && r.type === 'file_redirect') {
|
|
1551
|
+
kids.push(r);
|
|
1552
|
+
continue;
|
|
1553
|
+
}
|
|
1554
|
+
restoreLex(P.L, rSave);
|
|
1555
|
+
}
|
|
1556
|
+
// Pipeline after heredoc_start: `one <<EOF | grep two` — tree-sitter
|
|
1557
|
+
// nests the pipeline as a child of heredoc_redirect. ast.ts
|
|
1558
|
+
// walkHeredocRedirect fails closed on pipeline/command via tooComplex.
|
|
1559
|
+
if (tc === '|' && peek(P.L, 1) !== '|') {
|
|
1560
|
+
advance(P.L);
|
|
1561
|
+
skipBlanks(P.L);
|
|
1562
|
+
const pipeCmds = [];
|
|
1563
|
+
while (true) {
|
|
1564
|
+
const cmd = parseCommand(P);
|
|
1565
|
+
if (!cmd)
|
|
1566
|
+
break;
|
|
1567
|
+
pipeCmds.push(cmd);
|
|
1568
|
+
skipBlanks(P.L);
|
|
1569
|
+
if (peek(P.L) === '|' && peek(P.L, 1) !== '|') {
|
|
1570
|
+
const ps = P.L.b;
|
|
1571
|
+
advance(P.L);
|
|
1572
|
+
pipeCmds.push(mk(P, '|', ps, P.L.b, []));
|
|
1573
|
+
skipBlanks(P.L);
|
|
1574
|
+
continue;
|
|
1575
|
+
}
|
|
1576
|
+
break;
|
|
1577
|
+
}
|
|
1578
|
+
if (pipeCmds.length > 0) {
|
|
1579
|
+
const pl = pipeCmds[pipeCmds.length - 1];
|
|
1580
|
+
// tree-sitter always wraps in pipeline after `|`, even single command
|
|
1581
|
+
kids.push(mk(P, 'pipeline', pipeCmds[0].startIndex, pl.endIndex, pipeCmds));
|
|
1582
|
+
}
|
|
1583
|
+
continue;
|
|
1584
|
+
}
|
|
1585
|
+
// && / || after heredoc_start: `cat <<-EOF || die "..."` — tree-sitter
|
|
1586
|
+
// nests just the RHS command (not a list) as a child of heredoc_redirect.
|
|
1587
|
+
if ((tc === '&' && peek(P.L, 1) === '&') ||
|
|
1588
|
+
(tc === '|' && peek(P.L, 1) === '|')) {
|
|
1589
|
+
advance(P.L);
|
|
1590
|
+
advance(P.L);
|
|
1591
|
+
skipBlanks(P.L);
|
|
1592
|
+
const rhs = parseCommand(P);
|
|
1593
|
+
if (rhs)
|
|
1594
|
+
kids.push(rhs);
|
|
1595
|
+
continue;
|
|
1596
|
+
}
|
|
1597
|
+
// Terminator / unhandled metachar — consume rest of line as ERROR so
|
|
1598
|
+
// ast.ts rejects it. Covers ; & ( )
|
|
1599
|
+
if (tc === '&' || tc === ';' || tc === '(' || tc === ')') {
|
|
1600
|
+
const eStart = P.L.b;
|
|
1601
|
+
while (P.L.i < P.L.len && peek(P.L) !== '\n')
|
|
1602
|
+
advance(P.L);
|
|
1603
|
+
kids.push(mk(P, 'ERROR', eStart, P.L.b, []));
|
|
1604
|
+
break;
|
|
1605
|
+
}
|
|
1606
|
+
// Trailing word argument: newins <<-EOF - org.freedesktop.service
|
|
1607
|
+
const w = parseWord(P, 'arg');
|
|
1608
|
+
if (w) {
|
|
1609
|
+
kids.push(w);
|
|
1610
|
+
continue;
|
|
1611
|
+
}
|
|
1612
|
+
// Unrecognized — consume rest of line as ERROR
|
|
1613
|
+
const eStart = P.L.b;
|
|
1614
|
+
while (P.L.i < P.L.len && peek(P.L) !== '\n')
|
|
1615
|
+
advance(P.L);
|
|
1616
|
+
if (P.L.b > eStart)
|
|
1617
|
+
kids.push(mk(P, 'ERROR', eStart, P.L.b, []));
|
|
1618
|
+
break;
|
|
1619
|
+
}
|
|
1620
|
+
return mk(P, 'heredoc_redirect', startIdx, P.L.b, kids);
|
|
1621
|
+
}
|
|
1622
|
+
// Close-fd variants: `<&-` `>&-` have OPTIONAL destination (0 or 1)
|
|
1623
|
+
if (v === '<&-' || v === '>&-') {
|
|
1624
|
+
const op = leaf(P, v, t);
|
|
1625
|
+
const kids = [];
|
|
1626
|
+
if (fd)
|
|
1627
|
+
kids.push(fd);
|
|
1628
|
+
kids.push(op);
|
|
1629
|
+
// Optional single destination — only consume if next is a literal
|
|
1630
|
+
skipBlanks(P.L);
|
|
1631
|
+
const dSave = saveLex(P.L);
|
|
1632
|
+
const dest = isRedirectLiteralStart(P) ? parseWord(P, 'arg') : null;
|
|
1633
|
+
if (dest) {
|
|
1634
|
+
kids.push(dest);
|
|
1635
|
+
}
|
|
1636
|
+
else {
|
|
1637
|
+
restoreLex(P.L, dSave);
|
|
1638
|
+
}
|
|
1639
|
+
const startIdx = fd ? fd.startIndex : op.startIndex;
|
|
1640
|
+
const end = dest ? dest.endIndex : op.endIndex;
|
|
1641
|
+
return mk(P, 'file_redirect', startIdx, end, kids);
|
|
1642
|
+
}
|
|
1643
|
+
if (v === '>' ||
|
|
1644
|
+
v === '>>' ||
|
|
1645
|
+
v === '>&' ||
|
|
1646
|
+
v === '>|' ||
|
|
1647
|
+
v === '&>' ||
|
|
1648
|
+
v === '&>>' ||
|
|
1649
|
+
v === '<' ||
|
|
1650
|
+
v === '<&') {
|
|
1651
|
+
const op = leaf(P, v, t);
|
|
1652
|
+
const kids = [];
|
|
1653
|
+
if (fd)
|
|
1654
|
+
kids.push(fd);
|
|
1655
|
+
kids.push(op);
|
|
1656
|
+
// Grammar: destination is repeat1($._literal) — greedily consume literals
|
|
1657
|
+
// until a non-literal (redirect op, terminator, etc). tree-sitter's
|
|
1658
|
+
// prec.left makes `cmd >f a b c` attach `a b c` to the file_redirect,
|
|
1659
|
+
// NOT to the command. Structural quirk but required for corpus parity.
|
|
1660
|
+
// In preRedirect context (greedy=false), take only 1 literal because
|
|
1661
|
+
// command's dynamic precedence beats redirected_statement's prec(-1).
|
|
1662
|
+
let end = op.endIndex;
|
|
1663
|
+
let taken = 0;
|
|
1664
|
+
while (true) {
|
|
1665
|
+
skipBlanks(P.L);
|
|
1666
|
+
if (!isRedirectLiteralStart(P))
|
|
1667
|
+
break;
|
|
1668
|
+
if (!greedy && taken >= 1)
|
|
1669
|
+
break;
|
|
1670
|
+
const tc = peek(P.L);
|
|
1671
|
+
const tc1 = peek(P.L, 1);
|
|
1672
|
+
let target = null;
|
|
1673
|
+
if ((tc === '<' || tc === '>') && tc1 === '(') {
|
|
1674
|
+
target = parseProcessSub(P);
|
|
1675
|
+
}
|
|
1676
|
+
else {
|
|
1677
|
+
target = parseWord(P, 'arg');
|
|
1678
|
+
}
|
|
1679
|
+
if (!target)
|
|
1680
|
+
break;
|
|
1681
|
+
kids.push(target);
|
|
1682
|
+
end = target.endIndex;
|
|
1683
|
+
taken++;
|
|
1684
|
+
}
|
|
1685
|
+
const startIdx = fd ? fd.startIndex : op.startIndex;
|
|
1686
|
+
return mk(P, 'file_redirect', startIdx, end, kids);
|
|
1687
|
+
}
|
|
1688
|
+
restoreLex(P.L, save);
|
|
1689
|
+
return null;
|
|
1690
|
+
}
|
|
1691
|
+
function parseProcessSub(P) {
|
|
1692
|
+
const c = peek(P.L);
|
|
1693
|
+
if ((c !== '<' && c !== '>') || peek(P.L, 1) !== '(')
|
|
1694
|
+
return null;
|
|
1695
|
+
const start = P.L.b;
|
|
1696
|
+
advance(P.L);
|
|
1697
|
+
advance(P.L);
|
|
1698
|
+
const open = mk(P, c + '(', start, P.L.b, []);
|
|
1699
|
+
const body = parseStatements(P, ')');
|
|
1700
|
+
skipBlanks(P.L);
|
|
1701
|
+
let close;
|
|
1702
|
+
if (peek(P.L) === ')') {
|
|
1703
|
+
const cs = P.L.b;
|
|
1704
|
+
advance(P.L);
|
|
1705
|
+
close = mk(P, ')', cs, P.L.b, []);
|
|
1706
|
+
}
|
|
1707
|
+
else {
|
|
1708
|
+
close = mk(P, ')', P.L.b, P.L.b, []);
|
|
1709
|
+
}
|
|
1710
|
+
return mk(P, 'process_substitution', start, close.endIndex, [
|
|
1711
|
+
open,
|
|
1712
|
+
...body,
|
|
1713
|
+
close,
|
|
1714
|
+
]);
|
|
1715
|
+
}
|
|
1716
|
+
function scanHeredocBodies(P) {
|
|
1717
|
+
// Skip to newline if not already there
|
|
1718
|
+
while (P.L.i < P.L.len && P.L.src[P.L.i] !== '\n')
|
|
1719
|
+
advance(P.L);
|
|
1720
|
+
if (P.L.i < P.L.len)
|
|
1721
|
+
advance(P.L);
|
|
1722
|
+
for (const hd of P.L.heredocs) {
|
|
1723
|
+
hd.bodyStart = P.L.b;
|
|
1724
|
+
const delimLen = hd.delim.length;
|
|
1725
|
+
while (P.L.i < P.L.len) {
|
|
1726
|
+
const lineStart = P.L.i;
|
|
1727
|
+
const lineStartB = P.L.b;
|
|
1728
|
+
// Skip leading tabs if <<-
|
|
1729
|
+
let checkI = lineStart;
|
|
1730
|
+
if (hd.stripTabs) {
|
|
1731
|
+
while (checkI < P.L.len && P.L.src[checkI] === '\t')
|
|
1732
|
+
checkI++;
|
|
1733
|
+
}
|
|
1734
|
+
// Check if this line is the delimiter
|
|
1735
|
+
if (P.L.src.startsWith(hd.delim, checkI) &&
|
|
1736
|
+
(checkI + delimLen >= P.L.len ||
|
|
1737
|
+
P.L.src[checkI + delimLen] === '\n' ||
|
|
1738
|
+
P.L.src[checkI + delimLen] === '\r')) {
|
|
1739
|
+
hd.bodyEnd = lineStartB;
|
|
1740
|
+
// Advance past tabs
|
|
1741
|
+
while (P.L.i < checkI)
|
|
1742
|
+
advance(P.L);
|
|
1743
|
+
hd.endStart = P.L.b;
|
|
1744
|
+
// Advance past delimiter
|
|
1745
|
+
for (let k = 0; k < delimLen; k++)
|
|
1746
|
+
advance(P.L);
|
|
1747
|
+
hd.endEnd = P.L.b;
|
|
1748
|
+
// Skip trailing newline
|
|
1749
|
+
if (P.L.i < P.L.len && P.L.src[P.L.i] === '\n')
|
|
1750
|
+
advance(P.L);
|
|
1751
|
+
return;
|
|
1752
|
+
}
|
|
1753
|
+
// Consume line
|
|
1754
|
+
while (P.L.i < P.L.len && P.L.src[P.L.i] !== '\n')
|
|
1755
|
+
advance(P.L);
|
|
1756
|
+
if (P.L.i < P.L.len)
|
|
1757
|
+
advance(P.L);
|
|
1758
|
+
}
|
|
1759
|
+
// Unterminated
|
|
1760
|
+
hd.bodyEnd = P.L.b;
|
|
1761
|
+
hd.endStart = P.L.b;
|
|
1762
|
+
hd.endEnd = P.L.b;
|
|
1763
|
+
}
|
|
1764
|
+
}
|
|
1765
|
+
function parseHeredocBodyContent(P, start, end) {
|
|
1766
|
+
// Parse expansions inside an unquoted heredoc body.
|
|
1767
|
+
const saved = saveLex(P.L);
|
|
1768
|
+
// Position lexer at body start
|
|
1769
|
+
restoreLexToByte(P, start);
|
|
1770
|
+
const out = [];
|
|
1771
|
+
let contentStart = P.L.b;
|
|
1772
|
+
// tree-sitter-bash's heredoc_body rule hides the initial text segment
|
|
1773
|
+
// (_heredoc_body_beginning) — only content AFTER the first expansion is
|
|
1774
|
+
// emitted as heredoc_content. Track whether we've seen an expansion yet.
|
|
1775
|
+
let sawExpansion = false;
|
|
1776
|
+
while (P.L.b < end) {
|
|
1777
|
+
const c = peek(P.L);
|
|
1778
|
+
// Backslash escapes suppress expansion: \$ \` stay literal in heredoc.
|
|
1779
|
+
if (c === '\\') {
|
|
1780
|
+
const nxt = peek(P.L, 1);
|
|
1781
|
+
if (nxt === '$' || nxt === '`' || nxt === '\\') {
|
|
1782
|
+
advance(P.L);
|
|
1783
|
+
advance(P.L);
|
|
1784
|
+
continue;
|
|
1785
|
+
}
|
|
1786
|
+
advance(P.L);
|
|
1787
|
+
continue;
|
|
1788
|
+
}
|
|
1789
|
+
if (c === '$' || c === '`') {
|
|
1790
|
+
const preB = P.L.b;
|
|
1791
|
+
const exp = parseDollarLike(P);
|
|
1792
|
+
// Bare `$` followed by non-name (e.g. `$'` in a regex) returns a lone
|
|
1793
|
+
// '$' leaf, not an expansion — treat as literal content, don't split.
|
|
1794
|
+
if (exp &&
|
|
1795
|
+
(exp.type === 'simple_expansion' ||
|
|
1796
|
+
exp.type === 'expansion' ||
|
|
1797
|
+
exp.type === 'command_substitution' ||
|
|
1798
|
+
exp.type === 'arithmetic_expansion')) {
|
|
1799
|
+
if (sawExpansion && preB > contentStart) {
|
|
1800
|
+
out.push(mk(P, 'heredoc_content', contentStart, preB, []));
|
|
1801
|
+
}
|
|
1802
|
+
out.push(exp);
|
|
1803
|
+
contentStart = P.L.b;
|
|
1804
|
+
sawExpansion = true;
|
|
1805
|
+
}
|
|
1806
|
+
continue;
|
|
1807
|
+
}
|
|
1808
|
+
advance(P.L);
|
|
1809
|
+
}
|
|
1810
|
+
// Only emit heredoc_content children if there were expansions — otherwise
|
|
1811
|
+
// the heredoc_body is a leaf node (tree-sitter convention).
|
|
1812
|
+
if (sawExpansion) {
|
|
1813
|
+
out.push(mk(P, 'heredoc_content', contentStart, end, []));
|
|
1814
|
+
}
|
|
1815
|
+
restoreLex(P.L, saved);
|
|
1816
|
+
return out;
|
|
1817
|
+
}
|
|
1818
|
+
function restoreLexToByte(P, targetByte) {
|
|
1819
|
+
if (!P.L.byteTable)
|
|
1820
|
+
byteAt(P.L, 0);
|
|
1821
|
+
const t = P.L.byteTable;
|
|
1822
|
+
let lo = 0;
|
|
1823
|
+
let hi = P.src.length;
|
|
1824
|
+
while (lo < hi) {
|
|
1825
|
+
const m = (lo + hi) >>> 1;
|
|
1826
|
+
if (t[m] < targetByte)
|
|
1827
|
+
lo = m + 1;
|
|
1828
|
+
else
|
|
1829
|
+
hi = m;
|
|
1830
|
+
}
|
|
1831
|
+
P.L.i = lo;
|
|
1832
|
+
P.L.b = targetByte;
|
|
1833
|
+
}
|
|
1834
|
+
/**
|
|
1835
|
+
* Parse a word-position element: bare word, string, expansion, or concatenation
|
|
1836
|
+
* thereof. Returns a single node; if multiple adjacent fragments, wraps in
|
|
1837
|
+
* concatenation.
|
|
1838
|
+
*/
|
|
1839
|
+
function parseWord(P, _ctx) {
|
|
1840
|
+
skipBlanks(P.L);
|
|
1841
|
+
const parts = [];
|
|
1842
|
+
while (P.L.i < P.L.len) {
|
|
1843
|
+
const c = peek(P.L);
|
|
1844
|
+
if (c === ' ' ||
|
|
1845
|
+
c === '\t' ||
|
|
1846
|
+
c === '\n' ||
|
|
1847
|
+
c === '\r' ||
|
|
1848
|
+
c === '' ||
|
|
1849
|
+
c === '|' ||
|
|
1850
|
+
c === '&' ||
|
|
1851
|
+
c === ';' ||
|
|
1852
|
+
c === '(' ||
|
|
1853
|
+
c === ')') {
|
|
1854
|
+
break;
|
|
1855
|
+
}
|
|
1856
|
+
// < > are redirect operators unless <( >( (process substitution)
|
|
1857
|
+
if (c === '<' || c === '>') {
|
|
1858
|
+
if (peek(P.L, 1) === '(') {
|
|
1859
|
+
const ps = parseProcessSub(P);
|
|
1860
|
+
if (ps)
|
|
1861
|
+
parts.push(ps);
|
|
1862
|
+
continue;
|
|
1863
|
+
}
|
|
1864
|
+
break;
|
|
1865
|
+
}
|
|
1866
|
+
if (c === '"') {
|
|
1867
|
+
parts.push(parseDoubleQuoted(P));
|
|
1868
|
+
continue;
|
|
1869
|
+
}
|
|
1870
|
+
if (c === "'") {
|
|
1871
|
+
const tok = nextToken(P.L, 'arg');
|
|
1872
|
+
parts.push(leaf(P, 'raw_string', tok));
|
|
1873
|
+
continue;
|
|
1874
|
+
}
|
|
1875
|
+
if (c === '$') {
|
|
1876
|
+
const c1 = peek(P.L, 1);
|
|
1877
|
+
if (c1 === "'") {
|
|
1878
|
+
const tok = nextToken(P.L, 'arg');
|
|
1879
|
+
parts.push(leaf(P, 'ansi_c_string', tok));
|
|
1880
|
+
continue;
|
|
1881
|
+
}
|
|
1882
|
+
if (c1 === '"') {
|
|
1883
|
+
// Translated string: emit $ leaf + string node
|
|
1884
|
+
const dTok = {
|
|
1885
|
+
type: 'DOLLAR',
|
|
1886
|
+
value: '$',
|
|
1887
|
+
start: P.L.b,
|
|
1888
|
+
end: P.L.b + 1,
|
|
1889
|
+
};
|
|
1890
|
+
advance(P.L);
|
|
1891
|
+
parts.push(leaf(P, '$', dTok));
|
|
1892
|
+
parts.push(parseDoubleQuoted(P));
|
|
1893
|
+
continue;
|
|
1894
|
+
}
|
|
1895
|
+
if (c1 === '`') {
|
|
1896
|
+
// `$` followed by backtick — tree-sitter elides the $ entirely
|
|
1897
|
+
// and emits just (command_substitution). Consume $ and let next
|
|
1898
|
+
// iteration handle the backtick.
|
|
1899
|
+
advance(P.L);
|
|
1900
|
+
continue;
|
|
1901
|
+
}
|
|
1902
|
+
const exp = parseDollarLike(P);
|
|
1903
|
+
if (exp)
|
|
1904
|
+
parts.push(exp);
|
|
1905
|
+
continue;
|
|
1906
|
+
}
|
|
1907
|
+
if (c === '`') {
|
|
1908
|
+
if (P.inBacktick > 0)
|
|
1909
|
+
break;
|
|
1910
|
+
const bt = parseBacktick(P);
|
|
1911
|
+
if (bt)
|
|
1912
|
+
parts.push(bt);
|
|
1913
|
+
continue;
|
|
1914
|
+
}
|
|
1915
|
+
// Brace expression {1..5} or {a,b,c} — only if looks like one
|
|
1916
|
+
if (c === '{') {
|
|
1917
|
+
const be = tryParseBraceExpr(P);
|
|
1918
|
+
if (be) {
|
|
1919
|
+
parts.push(be);
|
|
1920
|
+
continue;
|
|
1921
|
+
}
|
|
1922
|
+
// SECURITY: if `{` is immediately followed by a command terminator
|
|
1923
|
+
// (; | & newline or EOF), it's a standalone word — don't slurp the
|
|
1924
|
+
// rest of the line via tryParseBraceLikeCat. `echo {;touch /tmp/evil`
|
|
1925
|
+
// must split on `;` so the security walker sees `touch`.
|
|
1926
|
+
const nc = peek(P.L, 1);
|
|
1927
|
+
if (nc === ';' ||
|
|
1928
|
+
nc === '|' ||
|
|
1929
|
+
nc === '&' ||
|
|
1930
|
+
nc === '\n' ||
|
|
1931
|
+
nc === '' ||
|
|
1932
|
+
nc === ')' ||
|
|
1933
|
+
nc === ' ' ||
|
|
1934
|
+
nc === '\t') {
|
|
1935
|
+
const bStart = P.L.b;
|
|
1936
|
+
advance(P.L);
|
|
1937
|
+
parts.push(mk(P, 'word', bStart, P.L.b, []));
|
|
1938
|
+
continue;
|
|
1939
|
+
}
|
|
1940
|
+
// Otherwise treat { and } as word fragments
|
|
1941
|
+
const cat = tryParseBraceLikeCat(P);
|
|
1942
|
+
if (cat) {
|
|
1943
|
+
for (const p of cat)
|
|
1944
|
+
parts.push(p);
|
|
1945
|
+
continue;
|
|
1946
|
+
}
|
|
1947
|
+
}
|
|
1948
|
+
// Standalone `}` in arg position is a word (e.g., `echo }foo`).
|
|
1949
|
+
// parseBareWord breaks on `}` so handle it here.
|
|
1950
|
+
if (c === '}') {
|
|
1951
|
+
const bStart = P.L.b;
|
|
1952
|
+
advance(P.L);
|
|
1953
|
+
parts.push(mk(P, 'word', bStart, P.L.b, []));
|
|
1954
|
+
continue;
|
|
1955
|
+
}
|
|
1956
|
+
// `[` and `]` are single-char word fragments (tree-sitter splits at
|
|
1957
|
+
// brackets: `[:lower:]` → `[` `:lower:` `]`, `{o[k]}` → 6 words).
|
|
1958
|
+
if (c === '[' || c === ']') {
|
|
1959
|
+
const bStart = P.L.b;
|
|
1960
|
+
advance(P.L);
|
|
1961
|
+
parts.push(mk(P, 'word', bStart, P.L.b, []));
|
|
1962
|
+
continue;
|
|
1963
|
+
}
|
|
1964
|
+
// Bare word fragment
|
|
1965
|
+
const frag = parseBareWord(P);
|
|
1966
|
+
if (!frag)
|
|
1967
|
+
break;
|
|
1968
|
+
// `NN#${...}` or `NN#$(...)` → (number (expansion|command_substitution)).
|
|
1969
|
+
// Grammar: number can be seq(/-?(0x)?[0-9]+#/, choice(expansion, cmd_sub)).
|
|
1970
|
+
// `10#${cmd}` must NOT be concatenation — it's a single number node with
|
|
1971
|
+
// the expansion as child. Detect here: frag ends with `#`, next is $ {/(.
|
|
1972
|
+
if (frag.type === 'word' &&
|
|
1973
|
+
/^-?(0x)?[0-9]+#$/.test(frag.text) &&
|
|
1974
|
+
peek(P.L) === '$' &&
|
|
1975
|
+
(peek(P.L, 1) === '{' || peek(P.L, 1) === '(')) {
|
|
1976
|
+
const exp = parseDollarLike(P);
|
|
1977
|
+
if (exp) {
|
|
1978
|
+
// Prefix `NN#` is an anonymous pattern in grammar — only the
|
|
1979
|
+
// expansion/cmd_sub is a named child.
|
|
1980
|
+
parts.push(mk(P, 'number', frag.startIndex, exp.endIndex, [exp]));
|
|
1981
|
+
continue;
|
|
1982
|
+
}
|
|
1983
|
+
}
|
|
1984
|
+
parts.push(frag);
|
|
1985
|
+
}
|
|
1986
|
+
if (parts.length === 0)
|
|
1987
|
+
return null;
|
|
1988
|
+
if (parts.length === 1)
|
|
1989
|
+
return parts[0];
|
|
1990
|
+
// Concatenation
|
|
1991
|
+
const first = parts[0];
|
|
1992
|
+
const last = parts[parts.length - 1];
|
|
1993
|
+
return mk(P, 'concatenation', first.startIndex, last.endIndex, parts);
|
|
1994
|
+
}
|
|
1995
|
+
function parseBareWord(P) {
|
|
1996
|
+
const start = P.L.b;
|
|
1997
|
+
const startI = P.L.i;
|
|
1998
|
+
while (P.L.i < P.L.len) {
|
|
1999
|
+
const c = peek(P.L);
|
|
2000
|
+
if (c === '\\') {
|
|
2001
|
+
if (P.L.i + 1 >= P.L.len) {
|
|
2002
|
+
// Trailing unpaired `\` at true EOF — tree-sitter emits word WITHOUT
|
|
2003
|
+
// the `\` plus a sibling ERROR node. Stop here; caller emits ERROR.
|
|
2004
|
+
break;
|
|
2005
|
+
}
|
|
2006
|
+
const nx = P.L.src[P.L.i + 1];
|
|
2007
|
+
if (nx === '\n' || (nx === '\r' && P.L.src[P.L.i + 2] === '\n')) {
|
|
2008
|
+
// Line continuation BREAKS the word (tree-sitter quirk) — handles \r?\n
|
|
2009
|
+
break;
|
|
2010
|
+
}
|
|
2011
|
+
advance(P.L);
|
|
2012
|
+
advance(P.L);
|
|
2013
|
+
continue;
|
|
2014
|
+
}
|
|
2015
|
+
if (c === ' ' ||
|
|
2016
|
+
c === '\t' ||
|
|
2017
|
+
c === '\n' ||
|
|
2018
|
+
c === '\r' ||
|
|
2019
|
+
c === '' ||
|
|
2020
|
+
c === '|' ||
|
|
2021
|
+
c === '&' ||
|
|
2022
|
+
c === ';' ||
|
|
2023
|
+
c === '(' ||
|
|
2024
|
+
c === ')' ||
|
|
2025
|
+
c === '<' ||
|
|
2026
|
+
c === '>' ||
|
|
2027
|
+
c === '"' ||
|
|
2028
|
+
c === "'" ||
|
|
2029
|
+
c === '$' ||
|
|
2030
|
+
c === '`' ||
|
|
2031
|
+
c === '{' ||
|
|
2032
|
+
c === '}' ||
|
|
2033
|
+
c === '[' ||
|
|
2034
|
+
c === ']') {
|
|
2035
|
+
break;
|
|
2036
|
+
}
|
|
2037
|
+
advance(P.L);
|
|
2038
|
+
}
|
|
2039
|
+
if (P.L.b === start)
|
|
2040
|
+
return null;
|
|
2041
|
+
const text = P.src.slice(startI, P.L.i);
|
|
2042
|
+
const type = /^-?\d+$/.test(text) ? 'number' : 'word';
|
|
2043
|
+
return mk(P, type, start, P.L.b, []);
|
|
2044
|
+
}
|
|
2045
|
+
function tryParseBraceExpr(P) {
|
|
2046
|
+
// {N..M} where N, M are numbers or single chars
|
|
2047
|
+
const save = saveLex(P.L);
|
|
2048
|
+
if (peek(P.L) !== '{')
|
|
2049
|
+
return null;
|
|
2050
|
+
const oStart = P.L.b;
|
|
2051
|
+
advance(P.L);
|
|
2052
|
+
const oEnd = P.L.b;
|
|
2053
|
+
// First part
|
|
2054
|
+
const p1Start = P.L.b;
|
|
2055
|
+
while (isDigit(peek(P.L)) || isIdentStart(peek(P.L)))
|
|
2056
|
+
advance(P.L);
|
|
2057
|
+
const p1End = P.L.b;
|
|
2058
|
+
if (p1End === p1Start || peek(P.L) !== '.' || peek(P.L, 1) !== '.') {
|
|
2059
|
+
restoreLex(P.L, save);
|
|
2060
|
+
return null;
|
|
2061
|
+
}
|
|
2062
|
+
const dotStart = P.L.b;
|
|
2063
|
+
advance(P.L);
|
|
2064
|
+
advance(P.L);
|
|
2065
|
+
const dotEnd = P.L.b;
|
|
2066
|
+
const p2Start = P.L.b;
|
|
2067
|
+
while (isDigit(peek(P.L)) || isIdentStart(peek(P.L)))
|
|
2068
|
+
advance(P.L);
|
|
2069
|
+
const p2End = P.L.b;
|
|
2070
|
+
if (p2End === p2Start || peek(P.L) !== '}') {
|
|
2071
|
+
restoreLex(P.L, save);
|
|
2072
|
+
return null;
|
|
2073
|
+
}
|
|
2074
|
+
const cStart = P.L.b;
|
|
2075
|
+
advance(P.L);
|
|
2076
|
+
const cEnd = P.L.b;
|
|
2077
|
+
const p1Text = sliceBytes(P, p1Start, p1End);
|
|
2078
|
+
const p2Text = sliceBytes(P, p2Start, p2End);
|
|
2079
|
+
const p1IsNum = /^\d+$/.test(p1Text);
|
|
2080
|
+
const p2IsNum = /^\d+$/.test(p2Text);
|
|
2081
|
+
// Valid brace expression: both numbers OR both single chars. Mixed = reject.
|
|
2082
|
+
if (p1IsNum !== p2IsNum) {
|
|
2083
|
+
restoreLex(P.L, save);
|
|
2084
|
+
return null;
|
|
2085
|
+
}
|
|
2086
|
+
if (!p1IsNum && (p1Text.length !== 1 || p2Text.length !== 1)) {
|
|
2087
|
+
restoreLex(P.L, save);
|
|
2088
|
+
return null;
|
|
2089
|
+
}
|
|
2090
|
+
const p1Type = p1IsNum ? 'number' : 'word';
|
|
2091
|
+
const p2Type = p2IsNum ? 'number' : 'word';
|
|
2092
|
+
return mk(P, 'brace_expression', oStart, cEnd, [
|
|
2093
|
+
mk(P, '{', oStart, oEnd, []),
|
|
2094
|
+
mk(P, p1Type, p1Start, p1End, []),
|
|
2095
|
+
mk(P, '..', dotStart, dotEnd, []),
|
|
2096
|
+
mk(P, p2Type, p2Start, p2End, []),
|
|
2097
|
+
mk(P, '}', cStart, cEnd, []),
|
|
2098
|
+
]);
|
|
2099
|
+
}
|
|
2100
|
+
function tryParseBraceLikeCat(P) {
|
|
2101
|
+
// {a,b,c} or {} → split into word fragments like tree-sitter does
|
|
2102
|
+
if (peek(P.L) !== '{')
|
|
2103
|
+
return null;
|
|
2104
|
+
const oStart = P.L.b;
|
|
2105
|
+
advance(P.L);
|
|
2106
|
+
const oEnd = P.L.b;
|
|
2107
|
+
const inner = [mk(P, 'word', oStart, oEnd, [])];
|
|
2108
|
+
while (P.L.i < P.L.len) {
|
|
2109
|
+
const bc = peek(P.L);
|
|
2110
|
+
// SECURITY: stop at command terminators so `{foo;rm x` splits correctly.
|
|
2111
|
+
if (bc === '}' ||
|
|
2112
|
+
bc === '\n' ||
|
|
2113
|
+
bc === ';' ||
|
|
2114
|
+
bc === '|' ||
|
|
2115
|
+
bc === '&' ||
|
|
2116
|
+
bc === ' ' ||
|
|
2117
|
+
bc === '\t' ||
|
|
2118
|
+
bc === '<' ||
|
|
2119
|
+
bc === '>' ||
|
|
2120
|
+
bc === '(' ||
|
|
2121
|
+
bc === ')') {
|
|
2122
|
+
break;
|
|
2123
|
+
}
|
|
2124
|
+
// `[` and `]` are single-char words: {o[k]} → { o [ k ] }
|
|
2125
|
+
if (bc === '[' || bc === ']') {
|
|
2126
|
+
const bStart = P.L.b;
|
|
2127
|
+
advance(P.L);
|
|
2128
|
+
inner.push(mk(P, 'word', bStart, P.L.b, []));
|
|
2129
|
+
continue;
|
|
2130
|
+
}
|
|
2131
|
+
const midStart = P.L.b;
|
|
2132
|
+
while (P.L.i < P.L.len) {
|
|
2133
|
+
const mc = peek(P.L);
|
|
2134
|
+
if (mc === '}' ||
|
|
2135
|
+
mc === '\n' ||
|
|
2136
|
+
mc === ';' ||
|
|
2137
|
+
mc === '|' ||
|
|
2138
|
+
mc === '&' ||
|
|
2139
|
+
mc === ' ' ||
|
|
2140
|
+
mc === '\t' ||
|
|
2141
|
+
mc === '<' ||
|
|
2142
|
+
mc === '>' ||
|
|
2143
|
+
mc === '(' ||
|
|
2144
|
+
mc === ')' ||
|
|
2145
|
+
mc === '[' ||
|
|
2146
|
+
mc === ']') {
|
|
2147
|
+
break;
|
|
2148
|
+
}
|
|
2149
|
+
advance(P.L);
|
|
2150
|
+
}
|
|
2151
|
+
const midEnd = P.L.b;
|
|
2152
|
+
if (midEnd > midStart) {
|
|
2153
|
+
const midText = sliceBytes(P, midStart, midEnd);
|
|
2154
|
+
const midType = /^-?\d+$/.test(midText) ? 'number' : 'word';
|
|
2155
|
+
inner.push(mk(P, midType, midStart, midEnd, []));
|
|
2156
|
+
}
|
|
2157
|
+
else {
|
|
2158
|
+
break;
|
|
2159
|
+
}
|
|
2160
|
+
}
|
|
2161
|
+
if (peek(P.L) === '}') {
|
|
2162
|
+
const cStart = P.L.b;
|
|
2163
|
+
advance(P.L);
|
|
2164
|
+
inner.push(mk(P, 'word', cStart, P.L.b, []));
|
|
2165
|
+
}
|
|
2166
|
+
return inner;
|
|
2167
|
+
}
|
|
2168
|
+
function parseDoubleQuoted(P) {
|
|
2169
|
+
const qStart = P.L.b;
|
|
2170
|
+
advance(P.L);
|
|
2171
|
+
const qEnd = P.L.b;
|
|
2172
|
+
const openQ = mk(P, '"', qStart, qEnd, []);
|
|
2173
|
+
const parts = [openQ];
|
|
2174
|
+
let contentStart = P.L.b;
|
|
2175
|
+
let contentStartI = P.L.i;
|
|
2176
|
+
const flushContent = () => {
|
|
2177
|
+
if (P.L.b > contentStart) {
|
|
2178
|
+
// Tree-sitter's extras rule /\s/ has higher precedence than
|
|
2179
|
+
// string_content (prec -1), so whitespace-only segments are elided.
|
|
2180
|
+
// `" ${x} "` → (string (expansion)) not (string (string_content)(expansion)(string_content)).
|
|
2181
|
+
// Note: this intentionally diverges from preserving all content — cc
|
|
2182
|
+
// tests relying on whitespace-only string_content need updating
|
|
2183
|
+
// (CCReconcile).
|
|
2184
|
+
const txt = P.src.slice(contentStartI, P.L.i);
|
|
2185
|
+
if (!/^[ \t]+$/.test(txt)) {
|
|
2186
|
+
parts.push(mk(P, 'string_content', contentStart, P.L.b, []));
|
|
2187
|
+
}
|
|
2188
|
+
}
|
|
2189
|
+
};
|
|
2190
|
+
while (P.L.i < P.L.len) {
|
|
2191
|
+
const c = peek(P.L);
|
|
2192
|
+
if (c === '"')
|
|
2193
|
+
break;
|
|
2194
|
+
if (c === '\\' && P.L.i + 1 < P.L.len) {
|
|
2195
|
+
advance(P.L);
|
|
2196
|
+
advance(P.L);
|
|
2197
|
+
continue;
|
|
2198
|
+
}
|
|
2199
|
+
if (c === '\n') {
|
|
2200
|
+
// Split string_content at newline
|
|
2201
|
+
flushContent();
|
|
2202
|
+
advance(P.L);
|
|
2203
|
+
contentStart = P.L.b;
|
|
2204
|
+
contentStartI = P.L.i;
|
|
2205
|
+
continue;
|
|
2206
|
+
}
|
|
2207
|
+
if (c === '$') {
|
|
2208
|
+
const c1 = peek(P.L, 1);
|
|
2209
|
+
if (c1 === '(' ||
|
|
2210
|
+
c1 === '{' ||
|
|
2211
|
+
isIdentStart(c1) ||
|
|
2212
|
+
SPECIAL_VARS.has(c1) ||
|
|
2213
|
+
isDigit(c1)) {
|
|
2214
|
+
flushContent();
|
|
2215
|
+
const exp = parseDollarLike(P);
|
|
2216
|
+
if (exp)
|
|
2217
|
+
parts.push(exp);
|
|
2218
|
+
contentStart = P.L.b;
|
|
2219
|
+
contentStartI = P.L.i;
|
|
2220
|
+
continue;
|
|
2221
|
+
}
|
|
2222
|
+
// Bare $ not at end-of-string: tree-sitter emits it as an anonymous
|
|
2223
|
+
// '$' token, which splits string_content. $ immediately before the
|
|
2224
|
+
// closing " is absorbed into the preceding string_content.
|
|
2225
|
+
if (c1 !== '"' && c1 !== '') {
|
|
2226
|
+
flushContent();
|
|
2227
|
+
const dS = P.L.b;
|
|
2228
|
+
advance(P.L);
|
|
2229
|
+
parts.push(mk(P, '$', dS, P.L.b, []));
|
|
2230
|
+
contentStart = P.L.b;
|
|
2231
|
+
contentStartI = P.L.i;
|
|
2232
|
+
continue;
|
|
2233
|
+
}
|
|
2234
|
+
}
|
|
2235
|
+
if (c === '`') {
|
|
2236
|
+
flushContent();
|
|
2237
|
+
const bt = parseBacktick(P);
|
|
2238
|
+
if (bt)
|
|
2239
|
+
parts.push(bt);
|
|
2240
|
+
contentStart = P.L.b;
|
|
2241
|
+
contentStartI = P.L.i;
|
|
2242
|
+
continue;
|
|
2243
|
+
}
|
|
2244
|
+
advance(P.L);
|
|
2245
|
+
}
|
|
2246
|
+
flushContent();
|
|
2247
|
+
let close;
|
|
2248
|
+
if (peek(P.L) === '"') {
|
|
2249
|
+
const cStart = P.L.b;
|
|
2250
|
+
advance(P.L);
|
|
2251
|
+
close = mk(P, '"', cStart, P.L.b, []);
|
|
2252
|
+
}
|
|
2253
|
+
else {
|
|
2254
|
+
close = mk(P, '"', P.L.b, P.L.b, []);
|
|
2255
|
+
}
|
|
2256
|
+
parts.push(close);
|
|
2257
|
+
return mk(P, 'string', qStart, close.endIndex, parts);
|
|
2258
|
+
}
|
|
2259
|
+
function parseDollarLike(P) {
|
|
2260
|
+
const c1 = peek(P.L, 1);
|
|
2261
|
+
const dStart = P.L.b;
|
|
2262
|
+
if (c1 === '(' && peek(P.L, 2) === '(') {
|
|
2263
|
+
// $(( arithmetic ))
|
|
2264
|
+
advance(P.L);
|
|
2265
|
+
advance(P.L);
|
|
2266
|
+
advance(P.L);
|
|
2267
|
+
const open = mk(P, '$((', dStart, P.L.b, []);
|
|
2268
|
+
const exprs = parseArithCommaList(P, '))', 'var');
|
|
2269
|
+
skipBlanks(P.L);
|
|
2270
|
+
let close;
|
|
2271
|
+
if (peek(P.L) === ')' && peek(P.L, 1) === ')') {
|
|
2272
|
+
const cStart = P.L.b;
|
|
2273
|
+
advance(P.L);
|
|
2274
|
+
advance(P.L);
|
|
2275
|
+
close = mk(P, '))', cStart, P.L.b, []);
|
|
2276
|
+
}
|
|
2277
|
+
else {
|
|
2278
|
+
close = mk(P, '))', P.L.b, P.L.b, []);
|
|
2279
|
+
}
|
|
2280
|
+
return mk(P, 'arithmetic_expansion', dStart, close.endIndex, [
|
|
2281
|
+
open,
|
|
2282
|
+
...exprs,
|
|
2283
|
+
close,
|
|
2284
|
+
]);
|
|
2285
|
+
}
|
|
2286
|
+
if (c1 === '[') {
|
|
2287
|
+
// $[ arithmetic ] — legacy bash syntax, same as $((...))
|
|
2288
|
+
advance(P.L);
|
|
2289
|
+
advance(P.L);
|
|
2290
|
+
const open = mk(P, '$[', dStart, P.L.b, []);
|
|
2291
|
+
const exprs = parseArithCommaList(P, ']', 'var');
|
|
2292
|
+
skipBlanks(P.L);
|
|
2293
|
+
let close;
|
|
2294
|
+
if (peek(P.L) === ']') {
|
|
2295
|
+
const cStart = P.L.b;
|
|
2296
|
+
advance(P.L);
|
|
2297
|
+
close = mk(P, ']', cStart, P.L.b, []);
|
|
2298
|
+
}
|
|
2299
|
+
else {
|
|
2300
|
+
close = mk(P, ']', P.L.b, P.L.b, []);
|
|
2301
|
+
}
|
|
2302
|
+
return mk(P, 'arithmetic_expansion', dStart, close.endIndex, [
|
|
2303
|
+
open,
|
|
2304
|
+
...exprs,
|
|
2305
|
+
close,
|
|
2306
|
+
]);
|
|
2307
|
+
}
|
|
2308
|
+
if (c1 === '(') {
|
|
2309
|
+
advance(P.L);
|
|
2310
|
+
advance(P.L);
|
|
2311
|
+
const open = mk(P, '$(', dStart, P.L.b, []);
|
|
2312
|
+
let body = parseStatements(P, ')');
|
|
2313
|
+
skipBlanks(P.L);
|
|
2314
|
+
let close;
|
|
2315
|
+
if (peek(P.L) === ')') {
|
|
2316
|
+
const cStart = P.L.b;
|
|
2317
|
+
advance(P.L);
|
|
2318
|
+
close = mk(P, ')', cStart, P.L.b, []);
|
|
2319
|
+
}
|
|
2320
|
+
else {
|
|
2321
|
+
close = mk(P, ')', P.L.b, P.L.b, []);
|
|
2322
|
+
}
|
|
2323
|
+
// $(< file) shorthand: unwrap redirected_statement → bare file_redirect
|
|
2324
|
+
// tree-sitter emits (command_substitution (file_redirect (word))) directly
|
|
2325
|
+
if (body.length === 1 &&
|
|
2326
|
+
body[0].type === 'redirected_statement' &&
|
|
2327
|
+
body[0].children.length === 1 &&
|
|
2328
|
+
body[0].children[0].type === 'file_redirect') {
|
|
2329
|
+
body = body[0].children;
|
|
2330
|
+
}
|
|
2331
|
+
return mk(P, 'command_substitution', dStart, close.endIndex, [
|
|
2332
|
+
open,
|
|
2333
|
+
...body,
|
|
2334
|
+
close,
|
|
2335
|
+
]);
|
|
2336
|
+
}
|
|
2337
|
+
if (c1 === '{') {
|
|
2338
|
+
advance(P.L);
|
|
2339
|
+
advance(P.L);
|
|
2340
|
+
const open = mk(P, '${', dStart, P.L.b, []);
|
|
2341
|
+
const inner = parseExpansionBody(P);
|
|
2342
|
+
let close;
|
|
2343
|
+
if (peek(P.L) === '}') {
|
|
2344
|
+
const cStart = P.L.b;
|
|
2345
|
+
advance(P.L);
|
|
2346
|
+
close = mk(P, '}', cStart, P.L.b, []);
|
|
2347
|
+
}
|
|
2348
|
+
else {
|
|
2349
|
+
close = mk(P, '}', P.L.b, P.L.b, []);
|
|
2350
|
+
}
|
|
2351
|
+
return mk(P, 'expansion', dStart, close.endIndex, [open, ...inner, close]);
|
|
2352
|
+
}
|
|
2353
|
+
// Simple expansion $VAR or $? $$ $@ etc
|
|
2354
|
+
advance(P.L);
|
|
2355
|
+
const dEnd = P.L.b;
|
|
2356
|
+
const dollar = mk(P, '$', dStart, dEnd, []);
|
|
2357
|
+
const nc = peek(P.L);
|
|
2358
|
+
// $_ is special_variable_name only when not followed by more ident chars
|
|
2359
|
+
if (nc === '_' && !isIdentChar(peek(P.L, 1))) {
|
|
2360
|
+
const vStart = P.L.b;
|
|
2361
|
+
advance(P.L);
|
|
2362
|
+
const vn = mk(P, 'special_variable_name', vStart, P.L.b, []);
|
|
2363
|
+
return mk(P, 'simple_expansion', dStart, P.L.b, [dollar, vn]);
|
|
2364
|
+
}
|
|
2365
|
+
if (isIdentStart(nc)) {
|
|
2366
|
+
const vStart = P.L.b;
|
|
2367
|
+
while (isIdentChar(peek(P.L)))
|
|
2368
|
+
advance(P.L);
|
|
2369
|
+
const vn = mk(P, 'variable_name', vStart, P.L.b, []);
|
|
2370
|
+
return mk(P, 'simple_expansion', dStart, P.L.b, [dollar, vn]);
|
|
2371
|
+
}
|
|
2372
|
+
if (isDigit(nc)) {
|
|
2373
|
+
const vStart = P.L.b;
|
|
2374
|
+
advance(P.L);
|
|
2375
|
+
const vn = mk(P, 'variable_name', vStart, P.L.b, []);
|
|
2376
|
+
return mk(P, 'simple_expansion', dStart, P.L.b, [dollar, vn]);
|
|
2377
|
+
}
|
|
2378
|
+
if (SPECIAL_VARS.has(nc)) {
|
|
2379
|
+
const vStart = P.L.b;
|
|
2380
|
+
advance(P.L);
|
|
2381
|
+
const vn = mk(P, 'special_variable_name', vStart, P.L.b, []);
|
|
2382
|
+
return mk(P, 'simple_expansion', dStart, P.L.b, [dollar, vn]);
|
|
2383
|
+
}
|
|
2384
|
+
// Bare $ — just a $ leaf (tree-sitter treats trailing $ as literal)
|
|
2385
|
+
return dollar;
|
|
2386
|
+
}
|
|
2387
|
+
function parseExpansionBody(P) {
|
|
2388
|
+
const out = [];
|
|
2389
|
+
skipBlanks(P.L);
|
|
2390
|
+
// Bizarre cases: ${#!} ${!#} ${!##} ${!# } ${!## } all emit empty (expansion)
|
|
2391
|
+
// — both # and ! become anonymous nodes when only combined with each other
|
|
2392
|
+
// and optional trailing space before }. Note ${!##/} does NOT match (has
|
|
2393
|
+
// content after), so it parses normally as (special_variable_name)(regex).
|
|
2394
|
+
{
|
|
2395
|
+
const c0 = peek(P.L);
|
|
2396
|
+
const c1 = peek(P.L, 1);
|
|
2397
|
+
if (c0 === '#' && c1 === '!' && peek(P.L, 2) === '}') {
|
|
2398
|
+
advance(P.L);
|
|
2399
|
+
advance(P.L);
|
|
2400
|
+
return out;
|
|
2401
|
+
}
|
|
2402
|
+
if (c0 === '!' && c1 === '#') {
|
|
2403
|
+
// ${!#} ${!##} with optional trailing space then }
|
|
2404
|
+
let j = 2;
|
|
2405
|
+
if (peek(P.L, j) === '#')
|
|
2406
|
+
j++;
|
|
2407
|
+
if (peek(P.L, j) === ' ')
|
|
2408
|
+
j++;
|
|
2409
|
+
if (peek(P.L, j) === '}') {
|
|
2410
|
+
while (j-- > 0)
|
|
2411
|
+
advance(P.L);
|
|
2412
|
+
return out;
|
|
2413
|
+
}
|
|
2414
|
+
}
|
|
2415
|
+
}
|
|
2416
|
+
// Optional # prefix for length
|
|
2417
|
+
if (peek(P.L) === '#') {
|
|
2418
|
+
const s = P.L.b;
|
|
2419
|
+
advance(P.L);
|
|
2420
|
+
out.push(mk(P, '#', s, P.L.b, []));
|
|
2421
|
+
}
|
|
2422
|
+
// Optional ! prefix for indirect expansion: ${!varname} ${!prefix*} ${!prefix@}
|
|
2423
|
+
// Only when followed by an identifier — ${!} alone is special var $!
|
|
2424
|
+
// Also = ~ prefixes (zsh-style ${=var} ${~var})
|
|
2425
|
+
const pc = peek(P.L);
|
|
2426
|
+
if ((pc === '!' || pc === '=' || pc === '~') &&
|
|
2427
|
+
(isIdentStart(peek(P.L, 1)) || isDigit(peek(P.L, 1)))) {
|
|
2428
|
+
const s = P.L.b;
|
|
2429
|
+
advance(P.L);
|
|
2430
|
+
out.push(mk(P, pc, s, P.L.b, []));
|
|
2431
|
+
}
|
|
2432
|
+
skipBlanks(P.L);
|
|
2433
|
+
// Variable name
|
|
2434
|
+
if (isIdentStart(peek(P.L))) {
|
|
2435
|
+
const s = P.L.b;
|
|
2436
|
+
while (isIdentChar(peek(P.L)))
|
|
2437
|
+
advance(P.L);
|
|
2438
|
+
out.push(mk(P, 'variable_name', s, P.L.b, []));
|
|
2439
|
+
}
|
|
2440
|
+
else if (isDigit(peek(P.L))) {
|
|
2441
|
+
const s = P.L.b;
|
|
2442
|
+
while (isDigit(peek(P.L)))
|
|
2443
|
+
advance(P.L);
|
|
2444
|
+
out.push(mk(P, 'variable_name', s, P.L.b, []));
|
|
2445
|
+
}
|
|
2446
|
+
else if (SPECIAL_VARS.has(peek(P.L))) {
|
|
2447
|
+
const s = P.L.b;
|
|
2448
|
+
advance(P.L);
|
|
2449
|
+
out.push(mk(P, 'special_variable_name', s, P.L.b, []));
|
|
2450
|
+
}
|
|
2451
|
+
// Optional subscript [idx] — parsed arithmetically
|
|
2452
|
+
if (peek(P.L) === '[') {
|
|
2453
|
+
const varNode = out[out.length - 1];
|
|
2454
|
+
const brOpen = P.L.b;
|
|
2455
|
+
advance(P.L);
|
|
2456
|
+
const brOpenNode = mk(P, '[', brOpen, P.L.b, []);
|
|
2457
|
+
const idx = parseSubscriptIndexInline(P);
|
|
2458
|
+
skipBlanks(P.L);
|
|
2459
|
+
const brClose = P.L.b;
|
|
2460
|
+
if (peek(P.L) === ']')
|
|
2461
|
+
advance(P.L);
|
|
2462
|
+
const brCloseNode = mk(P, ']', brClose, P.L.b, []);
|
|
2463
|
+
if (varNode) {
|
|
2464
|
+
const kids = idx
|
|
2465
|
+
? [varNode, brOpenNode, idx, brCloseNode]
|
|
2466
|
+
: [varNode, brOpenNode, brCloseNode];
|
|
2467
|
+
out[out.length - 1] = mk(P, 'subscript', varNode.startIndex, P.L.b, kids);
|
|
2468
|
+
}
|
|
2469
|
+
}
|
|
2470
|
+
skipBlanks(P.L);
|
|
2471
|
+
// Trailing * or @ for indirect expansion (${!prefix*} ${!prefix@}) or
|
|
2472
|
+
// @operator for parameter transformation (${var@U} ${var@Q}) — anonymous
|
|
2473
|
+
const tc = peek(P.L);
|
|
2474
|
+
if ((tc === '*' || tc === '@') && peek(P.L, 1) === '}') {
|
|
2475
|
+
const s = P.L.b;
|
|
2476
|
+
advance(P.L);
|
|
2477
|
+
out.push(mk(P, tc, s, P.L.b, []));
|
|
2478
|
+
return out;
|
|
2479
|
+
}
|
|
2480
|
+
if (tc === '@' && isIdentStart(peek(P.L, 1))) {
|
|
2481
|
+
// ${var@U} transformation — @ is anonymous, consume op char(s)
|
|
2482
|
+
const s = P.L.b;
|
|
2483
|
+
advance(P.L);
|
|
2484
|
+
out.push(mk(P, '@', s, P.L.b, []));
|
|
2485
|
+
while (isIdentChar(peek(P.L)))
|
|
2486
|
+
advance(P.L);
|
|
2487
|
+
return out;
|
|
2488
|
+
}
|
|
2489
|
+
// Operator :- := :? :+ - = ? + # ## % %% / // ^ ^^ , ,, etc.
|
|
2490
|
+
const c = peek(P.L);
|
|
2491
|
+
// Bare `:` substring operator ${var:off:len} — offset and length parsed
|
|
2492
|
+
// arithmetically. Must come BEFORE the generic operator handling so `(` after
|
|
2493
|
+
// `:` goes to parenthesized_expression not the array path. `:-` `:=` `:?`
|
|
2494
|
+
// `:+` (no space) remain default-value operators; `: -1` (with space before
|
|
2495
|
+
// -1) is substring with negative offset.
|
|
2496
|
+
if (c === ':') {
|
|
2497
|
+
const c1 = peek(P.L, 1);
|
|
2498
|
+
// `:\n` or `:}` — empty substring expansion, emits nothing (variable_name only)
|
|
2499
|
+
if (c1 === '\n' || c1 === '}') {
|
|
2500
|
+
advance(P.L);
|
|
2501
|
+
while (peek(P.L) === '\n')
|
|
2502
|
+
advance(P.L);
|
|
2503
|
+
return out;
|
|
2504
|
+
}
|
|
2505
|
+
if (c1 !== '-' && c1 !== '=' && c1 !== '?' && c1 !== '+') {
|
|
2506
|
+
advance(P.L);
|
|
2507
|
+
skipBlanks(P.L);
|
|
2508
|
+
// Offset — arithmetic. `-N` at top level is a single number node per
|
|
2509
|
+
// tree-sitter; inside parens it's unary_expression(number).
|
|
2510
|
+
const offC = peek(P.L);
|
|
2511
|
+
let off;
|
|
2512
|
+
if (offC === '-' && isDigit(peek(P.L, 1))) {
|
|
2513
|
+
const ns = P.L.b;
|
|
2514
|
+
advance(P.L);
|
|
2515
|
+
while (isDigit(peek(P.L)))
|
|
2516
|
+
advance(P.L);
|
|
2517
|
+
off = mk(P, 'number', ns, P.L.b, []);
|
|
2518
|
+
}
|
|
2519
|
+
else {
|
|
2520
|
+
off = parseArithExpr(P, ':}', 'var');
|
|
2521
|
+
}
|
|
2522
|
+
if (off)
|
|
2523
|
+
out.push(off);
|
|
2524
|
+
skipBlanks(P.L);
|
|
2525
|
+
if (peek(P.L) === ':') {
|
|
2526
|
+
advance(P.L);
|
|
2527
|
+
skipBlanks(P.L);
|
|
2528
|
+
const lenC = peek(P.L);
|
|
2529
|
+
let len;
|
|
2530
|
+
if (lenC === '-' && isDigit(peek(P.L, 1))) {
|
|
2531
|
+
const ns = P.L.b;
|
|
2532
|
+
advance(P.L);
|
|
2533
|
+
while (isDigit(peek(P.L)))
|
|
2534
|
+
advance(P.L);
|
|
2535
|
+
len = mk(P, 'number', ns, P.L.b, []);
|
|
2536
|
+
}
|
|
2537
|
+
else {
|
|
2538
|
+
len = parseArithExpr(P, '}', 'var');
|
|
2539
|
+
}
|
|
2540
|
+
if (len)
|
|
2541
|
+
out.push(len);
|
|
2542
|
+
}
|
|
2543
|
+
return out;
|
|
2544
|
+
}
|
|
2545
|
+
}
|
|
2546
|
+
if (c === ':' ||
|
|
2547
|
+
c === '#' ||
|
|
2548
|
+
c === '%' ||
|
|
2549
|
+
c === '/' ||
|
|
2550
|
+
c === '^' ||
|
|
2551
|
+
c === ',' ||
|
|
2552
|
+
c === '-' ||
|
|
2553
|
+
c === '=' ||
|
|
2554
|
+
c === '?' ||
|
|
2555
|
+
c === '+') {
|
|
2556
|
+
const s = P.L.b;
|
|
2557
|
+
const c1 = peek(P.L, 1);
|
|
2558
|
+
let op = c;
|
|
2559
|
+
if (c === ':' && (c1 === '-' || c1 === '=' || c1 === '?' || c1 === '+')) {
|
|
2560
|
+
advance(P.L);
|
|
2561
|
+
advance(P.L);
|
|
2562
|
+
op = c + c1;
|
|
2563
|
+
}
|
|
2564
|
+
else if ((c === '#' || c === '%' || c === '/' || c === '^' || c === ',') &&
|
|
2565
|
+
c1 === c) {
|
|
2566
|
+
// Doubled operators: ## %% // ^^ ,,
|
|
2567
|
+
advance(P.L);
|
|
2568
|
+
advance(P.L);
|
|
2569
|
+
op = c + c;
|
|
2570
|
+
}
|
|
2571
|
+
else {
|
|
2572
|
+
advance(P.L);
|
|
2573
|
+
}
|
|
2574
|
+
out.push(mk(P, op, s, P.L.b, []));
|
|
2575
|
+
// Rest is the default/replacement — parse as word or regex until }
|
|
2576
|
+
// Pattern-matching operators (# ## % %% / // ^ ^^ , ,,) emit regex;
|
|
2577
|
+
// value-substitution operators (:- := :? :+ - = ? + :) emit word.
|
|
2578
|
+
// `/` and `//` split at next `/` into (regex)+(word) for pat/repl.
|
|
2579
|
+
const isPattern = op === '#' ||
|
|
2580
|
+
op === '##' ||
|
|
2581
|
+
op === '%' ||
|
|
2582
|
+
op === '%%' ||
|
|
2583
|
+
op === '/' ||
|
|
2584
|
+
op === '//' ||
|
|
2585
|
+
op === '^' ||
|
|
2586
|
+
op === '^^' ||
|
|
2587
|
+
op === ',' ||
|
|
2588
|
+
op === ',,';
|
|
2589
|
+
if (op === '/' || op === '//') {
|
|
2590
|
+
// Optional /# or /% anchor prefix — anonymous node
|
|
2591
|
+
const ac = peek(P.L);
|
|
2592
|
+
if (ac === '#' || ac === '%') {
|
|
2593
|
+
const aStart = P.L.b;
|
|
2594
|
+
advance(P.L);
|
|
2595
|
+
out.push(mk(P, ac, aStart, P.L.b, []));
|
|
2596
|
+
}
|
|
2597
|
+
// Pattern: per grammar _expansion_regex_replacement, pattern is
|
|
2598
|
+
// choice(regex, string, cmd_sub, seq(string, regex)). If it STARTS
|
|
2599
|
+
// with ", emit (string) and any trailing chars become (regex).
|
|
2600
|
+
// `${v//"${old}"/}` → (string(expansion)); `${v//"${c}"\//}` →
|
|
2601
|
+
// (string)(regex).
|
|
2602
|
+
if (peek(P.L) === '"') {
|
|
2603
|
+
out.push(parseDoubleQuoted(P));
|
|
2604
|
+
const tail = parseExpansionRest(P, 'regex', true);
|
|
2605
|
+
if (tail)
|
|
2606
|
+
out.push(tail);
|
|
2607
|
+
}
|
|
2608
|
+
else {
|
|
2609
|
+
const regex = parseExpansionRest(P, 'regex', true);
|
|
2610
|
+
if (regex)
|
|
2611
|
+
out.push(regex);
|
|
2612
|
+
}
|
|
2613
|
+
if (peek(P.L) === '/') {
|
|
2614
|
+
const sepStart = P.L.b;
|
|
2615
|
+
advance(P.L);
|
|
2616
|
+
out.push(mk(P, '/', sepStart, P.L.b, []));
|
|
2617
|
+
// Replacement: per grammar, choice includes `seq(cmd_sub, word)`
|
|
2618
|
+
// which emits TWO siblings (not concatenation). Also `(` at start
|
|
2619
|
+
// of replacement is a regular word char, NOT array — unlike `:-`
|
|
2620
|
+
// default-value context. `${v/(/(Gentoo ${x}, }` replacement
|
|
2621
|
+
// `(Gentoo ${x}, ` is (concatenation (word)(expansion)(word)).
|
|
2622
|
+
const repl = parseExpansionRest(P, 'replword', false);
|
|
2623
|
+
if (repl) {
|
|
2624
|
+
// seq(cmd_sub, word) special case → siblings. Detected when
|
|
2625
|
+
// replacement is a concatenation of exactly 2 parts with first
|
|
2626
|
+
// being command_substitution.
|
|
2627
|
+
if (repl.type === 'concatenation' &&
|
|
2628
|
+
repl.children.length === 2 &&
|
|
2629
|
+
repl.children[0].type === 'command_substitution') {
|
|
2630
|
+
out.push(repl.children[0]);
|
|
2631
|
+
out.push(repl.children[1]);
|
|
2632
|
+
}
|
|
2633
|
+
else {
|
|
2634
|
+
out.push(repl);
|
|
2635
|
+
}
|
|
2636
|
+
}
|
|
2637
|
+
}
|
|
2638
|
+
}
|
|
2639
|
+
else if (op === '#' || op === '##' || op === '%' || op === '%%') {
|
|
2640
|
+
// Pattern-removal: per grammar _expansion_regex, pattern is
|
|
2641
|
+
// repeat(choice(regex, string, raw_string, ')')). Each quote/string
|
|
2642
|
+
// is a SIBLING, not absorbed into one regex. `${f%'str'*}` →
|
|
2643
|
+
// (raw_string)(regex); `${f/'str'*}` (slash) stays single regex.
|
|
2644
|
+
for (const p of parseExpansionRegexSegmented(P))
|
|
2645
|
+
out.push(p);
|
|
2646
|
+
}
|
|
2647
|
+
else {
|
|
2648
|
+
const rest = parseExpansionRest(P, isPattern ? 'regex' : 'word', false);
|
|
2649
|
+
if (rest)
|
|
2650
|
+
out.push(rest);
|
|
2651
|
+
}
|
|
2652
|
+
}
|
|
2653
|
+
return out;
|
|
2654
|
+
}
|
|
2655
|
+
function parseExpansionRest(P, nodeType, stopAtSlash) {
|
|
2656
|
+
// Don't skipBlanks — `${var:- }` space IS the word. Stop at } or newline
|
|
2657
|
+
// (`${var:\n}` emits no word). stopAtSlash=true stops at `/` for pat/repl
|
|
2658
|
+
// split in ${var/pat/repl}. nodeType 'replword' is word-mode for the
|
|
2659
|
+
// replacement in `/` `//` — same as 'word' but `(` is NOT array.
|
|
2660
|
+
const start = P.L.b;
|
|
2661
|
+
// Value-substitution RHS starting with `(` parses as array: ${var:-(x)} →
|
|
2662
|
+
// (expansion (variable_name) (array (word))). Only for 'word' context (not
|
|
2663
|
+
// pattern-matching operators which emit regex, and not 'replword' where `(`
|
|
2664
|
+
// is a regular char per grammar `_expansion_regex_replacement`).
|
|
2665
|
+
if (nodeType === 'word' && peek(P.L) === '(') {
|
|
2666
|
+
advance(P.L);
|
|
2667
|
+
const open = mk(P, '(', start, P.L.b, []);
|
|
2668
|
+
const elems = [open];
|
|
2669
|
+
while (P.L.i < P.L.len) {
|
|
2670
|
+
skipBlanks(P.L);
|
|
2671
|
+
const c = peek(P.L);
|
|
2672
|
+
if (c === ')' || c === '}' || c === '\n' || c === '')
|
|
2673
|
+
break;
|
|
2674
|
+
const wStart = P.L.b;
|
|
2675
|
+
while (P.L.i < P.L.len) {
|
|
2676
|
+
const wc = peek(P.L);
|
|
2677
|
+
if (wc === ')' ||
|
|
2678
|
+
wc === '}' ||
|
|
2679
|
+
wc === ' ' ||
|
|
2680
|
+
wc === '\t' ||
|
|
2681
|
+
wc === '\n' ||
|
|
2682
|
+
wc === '') {
|
|
2683
|
+
break;
|
|
2684
|
+
}
|
|
2685
|
+
advance(P.L);
|
|
2686
|
+
}
|
|
2687
|
+
if (P.L.b > wStart)
|
|
2688
|
+
elems.push(mk(P, 'word', wStart, P.L.b, []));
|
|
2689
|
+
else
|
|
2690
|
+
break;
|
|
2691
|
+
}
|
|
2692
|
+
if (peek(P.L) === ')') {
|
|
2693
|
+
const cStart = P.L.b;
|
|
2694
|
+
advance(P.L);
|
|
2695
|
+
elems.push(mk(P, ')', cStart, P.L.b, []));
|
|
2696
|
+
}
|
|
2697
|
+
while (peek(P.L) === '\n')
|
|
2698
|
+
advance(P.L);
|
|
2699
|
+
return mk(P, 'array', start, P.L.b, elems);
|
|
2700
|
+
}
|
|
2701
|
+
// REGEX mode: flat single-span scan. Quotes are opaque (skipped past so
|
|
2702
|
+
// `/` inside them doesn't break stopAtSlash), but NOT emitted as separate
|
|
2703
|
+
// nodes — the entire range becomes one regex node.
|
|
2704
|
+
if (nodeType === 'regex') {
|
|
2705
|
+
let braceDepth = 0;
|
|
2706
|
+
while (P.L.i < P.L.len) {
|
|
2707
|
+
const c = peek(P.L);
|
|
2708
|
+
if (c === '\n')
|
|
2709
|
+
break;
|
|
2710
|
+
if (braceDepth === 0) {
|
|
2711
|
+
if (c === '}')
|
|
2712
|
+
break;
|
|
2713
|
+
if (stopAtSlash && c === '/')
|
|
2714
|
+
break;
|
|
2715
|
+
}
|
|
2716
|
+
if (c === '\\' && P.L.i + 1 < P.L.len) {
|
|
2717
|
+
advance(P.L);
|
|
2718
|
+
advance(P.L);
|
|
2719
|
+
continue;
|
|
2720
|
+
}
|
|
2721
|
+
if (c === '"' || c === "'") {
|
|
2722
|
+
advance(P.L);
|
|
2723
|
+
while (P.L.i < P.L.len && peek(P.L) !== c) {
|
|
2724
|
+
if (peek(P.L) === '\\' && P.L.i + 1 < P.L.len)
|
|
2725
|
+
advance(P.L);
|
|
2726
|
+
advance(P.L);
|
|
2727
|
+
}
|
|
2728
|
+
if (peek(P.L) === c)
|
|
2729
|
+
advance(P.L);
|
|
2730
|
+
continue;
|
|
2731
|
+
}
|
|
2732
|
+
// Skip past nested ${...} $(...) $[...] so their } / don't terminate us
|
|
2733
|
+
if (c === '$') {
|
|
2734
|
+
const c1 = peek(P.L, 1);
|
|
2735
|
+
if (c1 === '{') {
|
|
2736
|
+
let d = 0;
|
|
2737
|
+
advance(P.L);
|
|
2738
|
+
advance(P.L);
|
|
2739
|
+
d++;
|
|
2740
|
+
while (P.L.i < P.L.len && d > 0) {
|
|
2741
|
+
const nc = peek(P.L);
|
|
2742
|
+
if (nc === '{')
|
|
2743
|
+
d++;
|
|
2744
|
+
else if (nc === '}')
|
|
2745
|
+
d--;
|
|
2746
|
+
advance(P.L);
|
|
2747
|
+
}
|
|
2748
|
+
continue;
|
|
2749
|
+
}
|
|
2750
|
+
if (c1 === '(') {
|
|
2751
|
+
let d = 0;
|
|
2752
|
+
advance(P.L);
|
|
2753
|
+
advance(P.L);
|
|
2754
|
+
d++;
|
|
2755
|
+
while (P.L.i < P.L.len && d > 0) {
|
|
2756
|
+
const nc = peek(P.L);
|
|
2757
|
+
if (nc === '(')
|
|
2758
|
+
d++;
|
|
2759
|
+
else if (nc === ')')
|
|
2760
|
+
d--;
|
|
2761
|
+
advance(P.L);
|
|
2762
|
+
}
|
|
2763
|
+
continue;
|
|
2764
|
+
}
|
|
2765
|
+
}
|
|
2766
|
+
if (c === '{')
|
|
2767
|
+
braceDepth++;
|
|
2768
|
+
else if (c === '}' && braceDepth > 0)
|
|
2769
|
+
braceDepth--;
|
|
2770
|
+
advance(P.L);
|
|
2771
|
+
}
|
|
2772
|
+
const end = P.L.b;
|
|
2773
|
+
while (peek(P.L) === '\n')
|
|
2774
|
+
advance(P.L);
|
|
2775
|
+
if (end === start)
|
|
2776
|
+
return null;
|
|
2777
|
+
return mk(P, 'regex', start, end, []);
|
|
2778
|
+
}
|
|
2779
|
+
// WORD mode: segmenting parser — recognize nested ${...}, $(...), $'...',
|
|
2780
|
+
// "...", '...', $ident, <(...)/>(...); bare chars accumulate into word
|
|
2781
|
+
// segments. Multiple parts → wrapped in concatenation.
|
|
2782
|
+
const parts = [];
|
|
2783
|
+
let segStart = P.L.b;
|
|
2784
|
+
let braceDepth = 0;
|
|
2785
|
+
const flushSeg = () => {
|
|
2786
|
+
if (P.L.b > segStart) {
|
|
2787
|
+
parts.push(mk(P, 'word', segStart, P.L.b, []));
|
|
2788
|
+
}
|
|
2789
|
+
};
|
|
2790
|
+
while (P.L.i < P.L.len) {
|
|
2791
|
+
const c = peek(P.L);
|
|
2792
|
+
if (c === '\n')
|
|
2793
|
+
break;
|
|
2794
|
+
if (braceDepth === 0) {
|
|
2795
|
+
if (c === '}')
|
|
2796
|
+
break;
|
|
2797
|
+
if (stopAtSlash && c === '/')
|
|
2798
|
+
break;
|
|
2799
|
+
}
|
|
2800
|
+
if (c === '\\' && P.L.i + 1 < P.L.len) {
|
|
2801
|
+
advance(P.L);
|
|
2802
|
+
advance(P.L);
|
|
2803
|
+
continue;
|
|
2804
|
+
}
|
|
2805
|
+
const c1 = peek(P.L, 1);
|
|
2806
|
+
if (c === '$') {
|
|
2807
|
+
if (c1 === '{' || c1 === '(' || c1 === '[') {
|
|
2808
|
+
flushSeg();
|
|
2809
|
+
const exp = parseDollarLike(P);
|
|
2810
|
+
if (exp)
|
|
2811
|
+
parts.push(exp);
|
|
2812
|
+
segStart = P.L.b;
|
|
2813
|
+
continue;
|
|
2814
|
+
}
|
|
2815
|
+
if (c1 === "'") {
|
|
2816
|
+
// $'...' ANSI-C string
|
|
2817
|
+
flushSeg();
|
|
2818
|
+
const aStart = P.L.b;
|
|
2819
|
+
advance(P.L);
|
|
2820
|
+
advance(P.L);
|
|
2821
|
+
while (P.L.i < P.L.len && peek(P.L) !== "'") {
|
|
2822
|
+
if (peek(P.L) === '\\' && P.L.i + 1 < P.L.len)
|
|
2823
|
+
advance(P.L);
|
|
2824
|
+
advance(P.L);
|
|
2825
|
+
}
|
|
2826
|
+
if (peek(P.L) === "'")
|
|
2827
|
+
advance(P.L);
|
|
2828
|
+
parts.push(mk(P, 'ansi_c_string', aStart, P.L.b, []));
|
|
2829
|
+
segStart = P.L.b;
|
|
2830
|
+
continue;
|
|
2831
|
+
}
|
|
2832
|
+
if (isIdentStart(c1) || isDigit(c1) || SPECIAL_VARS.has(c1)) {
|
|
2833
|
+
flushSeg();
|
|
2834
|
+
const exp = parseDollarLike(P);
|
|
2835
|
+
if (exp)
|
|
2836
|
+
parts.push(exp);
|
|
2837
|
+
segStart = P.L.b;
|
|
2838
|
+
continue;
|
|
2839
|
+
}
|
|
2840
|
+
}
|
|
2841
|
+
if (c === '"') {
|
|
2842
|
+
flushSeg();
|
|
2843
|
+
parts.push(parseDoubleQuoted(P));
|
|
2844
|
+
segStart = P.L.b;
|
|
2845
|
+
continue;
|
|
2846
|
+
}
|
|
2847
|
+
if (c === "'") {
|
|
2848
|
+
flushSeg();
|
|
2849
|
+
const rStart = P.L.b;
|
|
2850
|
+
advance(P.L);
|
|
2851
|
+
while (P.L.i < P.L.len && peek(P.L) !== "'")
|
|
2852
|
+
advance(P.L);
|
|
2853
|
+
if (peek(P.L) === "'")
|
|
2854
|
+
advance(P.L);
|
|
2855
|
+
parts.push(mk(P, 'raw_string', rStart, P.L.b, []));
|
|
2856
|
+
segStart = P.L.b;
|
|
2857
|
+
continue;
|
|
2858
|
+
}
|
|
2859
|
+
if ((c === '<' || c === '>') && c1 === '(') {
|
|
2860
|
+
flushSeg();
|
|
2861
|
+
const ps = parseProcessSub(P);
|
|
2862
|
+
if (ps)
|
|
2863
|
+
parts.push(ps);
|
|
2864
|
+
segStart = P.L.b;
|
|
2865
|
+
continue;
|
|
2866
|
+
}
|
|
2867
|
+
if (c === '`') {
|
|
2868
|
+
flushSeg();
|
|
2869
|
+
const bt = parseBacktick(P);
|
|
2870
|
+
if (bt)
|
|
2871
|
+
parts.push(bt);
|
|
2872
|
+
segStart = P.L.b;
|
|
2873
|
+
continue;
|
|
2874
|
+
}
|
|
2875
|
+
// Brace tracking so nested {a,b} brace-expansion chars don't prematurely
|
|
2876
|
+
// terminate (rare, but the `?` in `${cond}? (` should be treated as word).
|
|
2877
|
+
if (c === '{')
|
|
2878
|
+
braceDepth++;
|
|
2879
|
+
else if (c === '}' && braceDepth > 0)
|
|
2880
|
+
braceDepth--;
|
|
2881
|
+
advance(P.L);
|
|
2882
|
+
}
|
|
2883
|
+
flushSeg();
|
|
2884
|
+
// Consume trailing newlines before } so caller sees }
|
|
2885
|
+
while (peek(P.L) === '\n')
|
|
2886
|
+
advance(P.L);
|
|
2887
|
+
// Tree-sitter skips leading whitespace (extras) in expansion RHS when
|
|
2888
|
+
// there's content after: `${2+ ${2}}` → just (expansion). But `${v:- }`
|
|
2889
|
+
// (space-only RHS) keeps the space as (word). So drop leading whitespace-
|
|
2890
|
+
// only word segment if it's NOT the only part.
|
|
2891
|
+
if (parts.length > 1 &&
|
|
2892
|
+
parts[0].type === 'word' &&
|
|
2893
|
+
/^[ \t]+$/.test(parts[0].text)) {
|
|
2894
|
+
parts.shift();
|
|
2895
|
+
}
|
|
2896
|
+
if (parts.length === 0)
|
|
2897
|
+
return null;
|
|
2898
|
+
if (parts.length === 1)
|
|
2899
|
+
return parts[0];
|
|
2900
|
+
// Multiple parts: wrap in concatenation (word mode keeps concat wrapping;
|
|
2901
|
+
// regex mode also concats per tree-sitter for mixed quote+glob patterns).
|
|
2902
|
+
const last = parts[parts.length - 1];
|
|
2903
|
+
return mk(P, 'concatenation', parts[0].startIndex, last.endIndex, parts);
|
|
2904
|
+
}
|
|
2905
|
+
// Pattern for # ## % %% operators — per grammar _expansion_regex:
|
|
2906
|
+
// repeat(choice(regex, string, raw_string, ')', /\s+/→regex)). Each quote
|
|
2907
|
+
// becomes a SIBLING node, not absorbed. `${f%'str'*}` → (raw_string)(regex).
|
|
2908
|
+
function parseExpansionRegexSegmented(P) {
|
|
2909
|
+
const out = [];
|
|
2910
|
+
let segStart = P.L.b;
|
|
2911
|
+
const flushRegex = () => {
|
|
2912
|
+
if (P.L.b > segStart)
|
|
2913
|
+
out.push(mk(P, 'regex', segStart, P.L.b, []));
|
|
2914
|
+
};
|
|
2915
|
+
while (P.L.i < P.L.len) {
|
|
2916
|
+
const c = peek(P.L);
|
|
2917
|
+
if (c === '}' || c === '\n')
|
|
2918
|
+
break;
|
|
2919
|
+
if (c === '\\' && P.L.i + 1 < P.L.len) {
|
|
2920
|
+
advance(P.L);
|
|
2921
|
+
advance(P.L);
|
|
2922
|
+
continue;
|
|
2923
|
+
}
|
|
2924
|
+
if (c === '"') {
|
|
2925
|
+
flushRegex();
|
|
2926
|
+
out.push(parseDoubleQuoted(P));
|
|
2927
|
+
segStart = P.L.b;
|
|
2928
|
+
continue;
|
|
2929
|
+
}
|
|
2930
|
+
if (c === "'") {
|
|
2931
|
+
flushRegex();
|
|
2932
|
+
const rStart = P.L.b;
|
|
2933
|
+
advance(P.L);
|
|
2934
|
+
while (P.L.i < P.L.len && peek(P.L) !== "'")
|
|
2935
|
+
advance(P.L);
|
|
2936
|
+
if (peek(P.L) === "'")
|
|
2937
|
+
advance(P.L);
|
|
2938
|
+
out.push(mk(P, 'raw_string', rStart, P.L.b, []));
|
|
2939
|
+
segStart = P.L.b;
|
|
2940
|
+
continue;
|
|
2941
|
+
}
|
|
2942
|
+
// Nested ${...} $(...) — opaque scan so their } doesn't terminate us
|
|
2943
|
+
if (c === '$') {
|
|
2944
|
+
const c1 = peek(P.L, 1);
|
|
2945
|
+
if (c1 === '{') {
|
|
2946
|
+
let d = 1;
|
|
2947
|
+
advance(P.L);
|
|
2948
|
+
advance(P.L);
|
|
2949
|
+
while (P.L.i < P.L.len && d > 0) {
|
|
2950
|
+
const nc = peek(P.L);
|
|
2951
|
+
if (nc === '{')
|
|
2952
|
+
d++;
|
|
2953
|
+
else if (nc === '}')
|
|
2954
|
+
d--;
|
|
2955
|
+
advance(P.L);
|
|
2956
|
+
}
|
|
2957
|
+
continue;
|
|
2958
|
+
}
|
|
2959
|
+
if (c1 === '(') {
|
|
2960
|
+
let d = 1;
|
|
2961
|
+
advance(P.L);
|
|
2962
|
+
advance(P.L);
|
|
2963
|
+
while (P.L.i < P.L.len && d > 0) {
|
|
2964
|
+
const nc = peek(P.L);
|
|
2965
|
+
if (nc === '(')
|
|
2966
|
+
d++;
|
|
2967
|
+
else if (nc === ')')
|
|
2968
|
+
d--;
|
|
2969
|
+
advance(P.L);
|
|
2970
|
+
}
|
|
2971
|
+
continue;
|
|
2972
|
+
}
|
|
2973
|
+
}
|
|
2974
|
+
advance(P.L);
|
|
2975
|
+
}
|
|
2976
|
+
flushRegex();
|
|
2977
|
+
while (peek(P.L) === '\n')
|
|
2978
|
+
advance(P.L);
|
|
2979
|
+
return out;
|
|
2980
|
+
}
|
|
2981
|
+
function parseBacktick(P) {
|
|
2982
|
+
const start = P.L.b;
|
|
2983
|
+
advance(P.L);
|
|
2984
|
+
const open = mk(P, '`', start, P.L.b, []);
|
|
2985
|
+
P.inBacktick++;
|
|
2986
|
+
// Parse statements inline — stop at closing backtick
|
|
2987
|
+
const body = [];
|
|
2988
|
+
while (true) {
|
|
2989
|
+
skipBlanks(P.L);
|
|
2990
|
+
if (peek(P.L) === '`' || peek(P.L) === '')
|
|
2991
|
+
break;
|
|
2992
|
+
const save = saveLex(P.L);
|
|
2993
|
+
const t = nextToken(P.L, 'cmd');
|
|
2994
|
+
if (t.type === 'EOF' || t.type === 'BACKTICK') {
|
|
2995
|
+
restoreLex(P.L, save);
|
|
2996
|
+
break;
|
|
2997
|
+
}
|
|
2998
|
+
if (t.type === 'NEWLINE')
|
|
2999
|
+
continue;
|
|
3000
|
+
restoreLex(P.L, save);
|
|
3001
|
+
const stmt = parseAndOr(P);
|
|
3002
|
+
if (!stmt)
|
|
3003
|
+
break;
|
|
3004
|
+
body.push(stmt);
|
|
3005
|
+
skipBlanks(P.L);
|
|
3006
|
+
if (peek(P.L) === '`')
|
|
3007
|
+
break;
|
|
3008
|
+
const save2 = saveLex(P.L);
|
|
3009
|
+
const sep = nextToken(P.L, 'cmd');
|
|
3010
|
+
if (sep.type === 'OP' && (sep.value === ';' || sep.value === '&')) {
|
|
3011
|
+
body.push(leaf(P, sep.value, sep));
|
|
3012
|
+
}
|
|
3013
|
+
else if (sep.type !== 'NEWLINE') {
|
|
3014
|
+
restoreLex(P.L, save2);
|
|
3015
|
+
}
|
|
3016
|
+
}
|
|
3017
|
+
P.inBacktick--;
|
|
3018
|
+
let close;
|
|
3019
|
+
if (peek(P.L) === '`') {
|
|
3020
|
+
const cStart = P.L.b;
|
|
3021
|
+
advance(P.L);
|
|
3022
|
+
close = mk(P, '`', cStart, P.L.b, []);
|
|
3023
|
+
}
|
|
3024
|
+
else {
|
|
3025
|
+
close = mk(P, '`', P.L.b, P.L.b, []);
|
|
3026
|
+
}
|
|
3027
|
+
// Empty backticks (whitespace/newline only) are elided entirely by
|
|
3028
|
+
// tree-sitter — used as a line-continuation hack: "foo"`<newline>`"bar"
|
|
3029
|
+
// → (concatenation (string) (string)) with no command_substitution.
|
|
3030
|
+
if (body.length === 0)
|
|
3031
|
+
return null;
|
|
3032
|
+
return mk(P, 'command_substitution', start, close.endIndex, [
|
|
3033
|
+
open,
|
|
3034
|
+
...body,
|
|
3035
|
+
close,
|
|
3036
|
+
]);
|
|
3037
|
+
}
|
|
3038
|
+
function parseIf(P, ifTok) {
|
|
3039
|
+
const ifKw = leaf(P, 'if', ifTok);
|
|
3040
|
+
const kids = [ifKw];
|
|
3041
|
+
const cond = parseStatements(P, null);
|
|
3042
|
+
kids.push(...cond);
|
|
3043
|
+
consumeKeyword(P, 'then', kids);
|
|
3044
|
+
const body = parseStatements(P, null);
|
|
3045
|
+
kids.push(...body);
|
|
3046
|
+
while (true) {
|
|
3047
|
+
const save = saveLex(P.L);
|
|
3048
|
+
const t = nextToken(P.L, 'cmd');
|
|
3049
|
+
if (t.type === 'WORD' && t.value === 'elif') {
|
|
3050
|
+
const eKw = leaf(P, 'elif', t);
|
|
3051
|
+
const eCond = parseStatements(P, null);
|
|
3052
|
+
const eKids = [eKw, ...eCond];
|
|
3053
|
+
consumeKeyword(P, 'then', eKids);
|
|
3054
|
+
const eBody = parseStatements(P, null);
|
|
3055
|
+
eKids.push(...eBody);
|
|
3056
|
+
const last = eKids[eKids.length - 1];
|
|
3057
|
+
kids.push(mk(P, 'elif_clause', eKw.startIndex, last.endIndex, eKids));
|
|
3058
|
+
}
|
|
3059
|
+
else if (t.type === 'WORD' && t.value === 'else') {
|
|
3060
|
+
const elKw = leaf(P, 'else', t);
|
|
3061
|
+
const elBody = parseStatements(P, null);
|
|
3062
|
+
const last = elBody.length > 0 ? elBody[elBody.length - 1] : elKw;
|
|
3063
|
+
kids.push(mk(P, 'else_clause', elKw.startIndex, last.endIndex, [elKw, ...elBody]));
|
|
3064
|
+
}
|
|
3065
|
+
else {
|
|
3066
|
+
restoreLex(P.L, save);
|
|
3067
|
+
break;
|
|
3068
|
+
}
|
|
3069
|
+
}
|
|
3070
|
+
consumeKeyword(P, 'fi', kids);
|
|
3071
|
+
const last = kids[kids.length - 1];
|
|
3072
|
+
return mk(P, 'if_statement', ifKw.startIndex, last.endIndex, kids);
|
|
3073
|
+
}
|
|
3074
|
+
function parseWhile(P, kwTok) {
|
|
3075
|
+
const kw = leaf(P, kwTok.value, kwTok);
|
|
3076
|
+
const kids = [kw];
|
|
3077
|
+
const cond = parseStatements(P, null);
|
|
3078
|
+
kids.push(...cond);
|
|
3079
|
+
const dg = parseDoGroup(P);
|
|
3080
|
+
if (dg)
|
|
3081
|
+
kids.push(dg);
|
|
3082
|
+
const last = kids[kids.length - 1];
|
|
3083
|
+
return mk(P, 'while_statement', kw.startIndex, last.endIndex, kids);
|
|
3084
|
+
}
|
|
3085
|
+
function parseFor(P, forTok) {
|
|
3086
|
+
const forKw = leaf(P, forTok.value, forTok);
|
|
3087
|
+
skipBlanks(P.L);
|
|
3088
|
+
// C-style for (( ; ; )) — only for `for`, not `select`
|
|
3089
|
+
if (forTok.value === 'for' && peek(P.L) === '(' && peek(P.L, 1) === '(') {
|
|
3090
|
+
const oStart = P.L.b;
|
|
3091
|
+
advance(P.L);
|
|
3092
|
+
advance(P.L);
|
|
3093
|
+
const open = mk(P, '((', oStart, P.L.b, []);
|
|
3094
|
+
const kids = [forKw, open];
|
|
3095
|
+
// init; cond; update — all three use 'assign' mode so `c = expr` emits
|
|
3096
|
+
// variable_assignment, while bare idents (c in `c<=5`) → word. Each
|
|
3097
|
+
// clause may be a comma-separated list.
|
|
3098
|
+
for (let k = 0; k < 3; k++) {
|
|
3099
|
+
skipBlanks(P.L);
|
|
3100
|
+
const es = parseArithCommaList(P, k < 2 ? ';' : '))', 'assign');
|
|
3101
|
+
kids.push(...es);
|
|
3102
|
+
if (k < 2) {
|
|
3103
|
+
if (peek(P.L) === ';') {
|
|
3104
|
+
const s = P.L.b;
|
|
3105
|
+
advance(P.L);
|
|
3106
|
+
kids.push(mk(P, ';', s, P.L.b, []));
|
|
3107
|
+
}
|
|
3108
|
+
}
|
|
3109
|
+
}
|
|
3110
|
+
skipBlanks(P.L);
|
|
3111
|
+
if (peek(P.L) === ')' && peek(P.L, 1) === ')') {
|
|
3112
|
+
const cStart = P.L.b;
|
|
3113
|
+
advance(P.L);
|
|
3114
|
+
advance(P.L);
|
|
3115
|
+
kids.push(mk(P, '))', cStart, P.L.b, []));
|
|
3116
|
+
}
|
|
3117
|
+
// Optional ; or newline
|
|
3118
|
+
const save = saveLex(P.L);
|
|
3119
|
+
const sep = nextToken(P.L, 'cmd');
|
|
3120
|
+
if (sep.type === 'OP' && sep.value === ';') {
|
|
3121
|
+
kids.push(leaf(P, ';', sep));
|
|
3122
|
+
}
|
|
3123
|
+
else if (sep.type !== 'NEWLINE') {
|
|
3124
|
+
restoreLex(P.L, save);
|
|
3125
|
+
}
|
|
3126
|
+
const dg = parseDoGroup(P);
|
|
3127
|
+
if (dg) {
|
|
3128
|
+
kids.push(dg);
|
|
3129
|
+
}
|
|
3130
|
+
else {
|
|
3131
|
+
// C-style for can also use `{ ... }` body instead of `do ... done`
|
|
3132
|
+
skipNewlines(P);
|
|
3133
|
+
skipBlanks(P.L);
|
|
3134
|
+
if (peek(P.L) === '{') {
|
|
3135
|
+
const bOpen = P.L.b;
|
|
3136
|
+
advance(P.L);
|
|
3137
|
+
const brace = mk(P, '{', bOpen, P.L.b, []);
|
|
3138
|
+
const body = parseStatements(P, '}');
|
|
3139
|
+
let bClose;
|
|
3140
|
+
if (peek(P.L) === '}') {
|
|
3141
|
+
const cs = P.L.b;
|
|
3142
|
+
advance(P.L);
|
|
3143
|
+
bClose = mk(P, '}', cs, P.L.b, []);
|
|
3144
|
+
}
|
|
3145
|
+
else {
|
|
3146
|
+
bClose = mk(P, '}', P.L.b, P.L.b, []);
|
|
3147
|
+
}
|
|
3148
|
+
kids.push(mk(P, 'compound_statement', brace.startIndex, bClose.endIndex, [
|
|
3149
|
+
brace,
|
|
3150
|
+
...body,
|
|
3151
|
+
bClose,
|
|
3152
|
+
]));
|
|
3153
|
+
}
|
|
3154
|
+
}
|
|
3155
|
+
const last = kids[kids.length - 1];
|
|
3156
|
+
return mk(P, 'c_style_for_statement', forKw.startIndex, last.endIndex, kids);
|
|
3157
|
+
}
|
|
3158
|
+
// Regular for VAR in words; do ... done
|
|
3159
|
+
const kids = [forKw];
|
|
3160
|
+
const varTok = nextToken(P.L, 'arg');
|
|
3161
|
+
kids.push(mk(P, 'variable_name', varTok.start, varTok.end, []));
|
|
3162
|
+
skipBlanks(P.L);
|
|
3163
|
+
const save = saveLex(P.L);
|
|
3164
|
+
const inTok = nextToken(P.L, 'arg');
|
|
3165
|
+
if (inTok.type === 'WORD' && inTok.value === 'in') {
|
|
3166
|
+
kids.push(leaf(P, 'in', inTok));
|
|
3167
|
+
while (true) {
|
|
3168
|
+
skipBlanks(P.L);
|
|
3169
|
+
const c = peek(P.L);
|
|
3170
|
+
if (c === ';' || c === '\n' || c === '')
|
|
3171
|
+
break;
|
|
3172
|
+
const w = parseWord(P, 'arg');
|
|
3173
|
+
if (!w)
|
|
3174
|
+
break;
|
|
3175
|
+
kids.push(w);
|
|
3176
|
+
}
|
|
3177
|
+
}
|
|
3178
|
+
else {
|
|
3179
|
+
restoreLex(P.L, save);
|
|
3180
|
+
}
|
|
3181
|
+
// Separator
|
|
3182
|
+
const save2 = saveLex(P.L);
|
|
3183
|
+
const sep = nextToken(P.L, 'cmd');
|
|
3184
|
+
if (sep.type === 'OP' && sep.value === ';') {
|
|
3185
|
+
kids.push(leaf(P, ';', sep));
|
|
3186
|
+
}
|
|
3187
|
+
else if (sep.type !== 'NEWLINE') {
|
|
3188
|
+
restoreLex(P.L, save2);
|
|
3189
|
+
}
|
|
3190
|
+
const dg = parseDoGroup(P);
|
|
3191
|
+
if (dg)
|
|
3192
|
+
kids.push(dg);
|
|
3193
|
+
const last = kids[kids.length - 1];
|
|
3194
|
+
return mk(P, 'for_statement', forKw.startIndex, last.endIndex, kids);
|
|
3195
|
+
}
|
|
3196
|
+
function parseDoGroup(P) {
|
|
3197
|
+
skipNewlines(P);
|
|
3198
|
+
const save = saveLex(P.L);
|
|
3199
|
+
const doTok = nextToken(P.L, 'cmd');
|
|
3200
|
+
if (doTok.type !== 'WORD' || doTok.value !== 'do') {
|
|
3201
|
+
restoreLex(P.L, save);
|
|
3202
|
+
return null;
|
|
3203
|
+
}
|
|
3204
|
+
const doKw = leaf(P, 'do', doTok);
|
|
3205
|
+
const body = parseStatements(P, null);
|
|
3206
|
+
const kids = [doKw, ...body];
|
|
3207
|
+
consumeKeyword(P, 'done', kids);
|
|
3208
|
+
const last = kids[kids.length - 1];
|
|
3209
|
+
return mk(P, 'do_group', doKw.startIndex, last.endIndex, kids);
|
|
3210
|
+
}
|
|
3211
|
+
function parseCase(P, caseTok) {
|
|
3212
|
+
const caseKw = leaf(P, 'case', caseTok);
|
|
3213
|
+
const kids = [caseKw];
|
|
3214
|
+
skipBlanks(P.L);
|
|
3215
|
+
const word = parseWord(P, 'arg');
|
|
3216
|
+
if (word)
|
|
3217
|
+
kids.push(word);
|
|
3218
|
+
skipBlanks(P.L);
|
|
3219
|
+
consumeKeyword(P, 'in', kids);
|
|
3220
|
+
skipNewlines(P);
|
|
3221
|
+
while (true) {
|
|
3222
|
+
skipBlanks(P.L);
|
|
3223
|
+
skipNewlines(P);
|
|
3224
|
+
const save = saveLex(P.L);
|
|
3225
|
+
const t = nextToken(P.L, 'arg');
|
|
3226
|
+
if (t.type === 'WORD' && t.value === 'esac') {
|
|
3227
|
+
kids.push(leaf(P, 'esac', t));
|
|
3228
|
+
break;
|
|
3229
|
+
}
|
|
3230
|
+
if (t.type === 'EOF')
|
|
3231
|
+
break;
|
|
3232
|
+
restoreLex(P.L, save);
|
|
3233
|
+
const item = parseCaseItem(P);
|
|
3234
|
+
if (!item)
|
|
3235
|
+
break;
|
|
3236
|
+
kids.push(item);
|
|
3237
|
+
}
|
|
3238
|
+
const last = kids[kids.length - 1];
|
|
3239
|
+
return mk(P, 'case_statement', caseKw.startIndex, last.endIndex, kids);
|
|
3240
|
+
}
|
|
3241
|
+
function parseCaseItem(P) {
|
|
3242
|
+
skipBlanks(P.L);
|
|
3243
|
+
const start = P.L.b;
|
|
3244
|
+
const kids = [];
|
|
3245
|
+
// Optional leading '(' before pattern — bash allows (pattern) syntax
|
|
3246
|
+
if (peek(P.L) === '(') {
|
|
3247
|
+
const s = P.L.b;
|
|
3248
|
+
advance(P.L);
|
|
3249
|
+
kids.push(mk(P, '(', s, P.L.b, []));
|
|
3250
|
+
}
|
|
3251
|
+
// Pattern(s)
|
|
3252
|
+
let isFirstAlt = true;
|
|
3253
|
+
while (true) {
|
|
3254
|
+
skipBlanks(P.L);
|
|
3255
|
+
const c = peek(P.L);
|
|
3256
|
+
if (c === ')' || c === '')
|
|
3257
|
+
break;
|
|
3258
|
+
const pats = parseCasePattern(P);
|
|
3259
|
+
if (pats.length === 0)
|
|
3260
|
+
break;
|
|
3261
|
+
// tree-sitter quirk: first alternative with quotes is inlined as flat
|
|
3262
|
+
// siblings; subsequent alternatives are wrapped in (concatenation) with
|
|
3263
|
+
// `word` instead of `extglob_pattern` for bare segments.
|
|
3264
|
+
if (!isFirstAlt && pats.length > 1) {
|
|
3265
|
+
const rewritten = pats.map(p => p.type === 'extglob_pattern'
|
|
3266
|
+
? mk(P, 'word', p.startIndex, p.endIndex, [])
|
|
3267
|
+
: p);
|
|
3268
|
+
const first = rewritten[0];
|
|
3269
|
+
const last = rewritten[rewritten.length - 1];
|
|
3270
|
+
kids.push(mk(P, 'concatenation', first.startIndex, last.endIndex, rewritten));
|
|
3271
|
+
}
|
|
3272
|
+
else {
|
|
3273
|
+
kids.push(...pats);
|
|
3274
|
+
}
|
|
3275
|
+
isFirstAlt = false;
|
|
3276
|
+
skipBlanks(P.L);
|
|
3277
|
+
// \<newline> line continuation between alternatives
|
|
3278
|
+
if (peek(P.L) === '\\' && peek(P.L, 1) === '\n') {
|
|
3279
|
+
advance(P.L);
|
|
3280
|
+
advance(P.L);
|
|
3281
|
+
skipBlanks(P.L);
|
|
3282
|
+
}
|
|
3283
|
+
if (peek(P.L) === '|') {
|
|
3284
|
+
const s = P.L.b;
|
|
3285
|
+
advance(P.L);
|
|
3286
|
+
kids.push(mk(P, '|', s, P.L.b, []));
|
|
3287
|
+
// \<newline> after | is also a line continuation
|
|
3288
|
+
if (peek(P.L) === '\\' && peek(P.L, 1) === '\n') {
|
|
3289
|
+
advance(P.L);
|
|
3290
|
+
advance(P.L);
|
|
3291
|
+
}
|
|
3292
|
+
}
|
|
3293
|
+
else {
|
|
3294
|
+
break;
|
|
3295
|
+
}
|
|
3296
|
+
}
|
|
3297
|
+
if (peek(P.L) === ')') {
|
|
3298
|
+
const s = P.L.b;
|
|
3299
|
+
advance(P.L);
|
|
3300
|
+
kids.push(mk(P, ')', s, P.L.b, []));
|
|
3301
|
+
}
|
|
3302
|
+
const body = parseStatements(P, null);
|
|
3303
|
+
kids.push(...body);
|
|
3304
|
+
const save = saveLex(P.L);
|
|
3305
|
+
const term = nextToken(P.L, 'cmd');
|
|
3306
|
+
if (term.type === 'OP' &&
|
|
3307
|
+
(term.value === ';;' || term.value === ';&' || term.value === ';;&')) {
|
|
3308
|
+
kids.push(leaf(P, term.value, term));
|
|
3309
|
+
}
|
|
3310
|
+
else {
|
|
3311
|
+
restoreLex(P.L, save);
|
|
3312
|
+
}
|
|
3313
|
+
if (kids.length === 0)
|
|
3314
|
+
return null;
|
|
3315
|
+
// tree-sitter quirk: case_item with EMPTY body and a single pattern matching
|
|
3316
|
+
// extglob-operator-char-prefix (no actual glob metachars) downgrades to word.
|
|
3317
|
+
// `-o) owner=$2 ;;` (has body) → extglob_pattern; `-g) ;;` (empty) → word.
|
|
3318
|
+
if (body.length === 0) {
|
|
3319
|
+
for (let i = 0; i < kids.length; i++) {
|
|
3320
|
+
const k = kids[i];
|
|
3321
|
+
if (k.type !== 'extglob_pattern')
|
|
3322
|
+
continue;
|
|
3323
|
+
const text = sliceBytes(P, k.startIndex, k.endIndex);
|
|
3324
|
+
if (/^[-+?*@!][a-zA-Z]/.test(text) && !/[*?(]/.test(text)) {
|
|
3325
|
+
kids[i] = mk(P, 'word', k.startIndex, k.endIndex, []);
|
|
3326
|
+
}
|
|
3327
|
+
}
|
|
3328
|
+
}
|
|
3329
|
+
const last = kids[kids.length - 1];
|
|
3330
|
+
return mk(P, 'case_item', start, last.endIndex, kids);
|
|
3331
|
+
}
|
|
3332
|
+
function parseCasePattern(P) {
|
|
3333
|
+
skipBlanks(P.L);
|
|
3334
|
+
const save = saveLex(P.L);
|
|
3335
|
+
const start = P.L.b;
|
|
3336
|
+
const startI = P.L.i;
|
|
3337
|
+
let parenDepth = 0;
|
|
3338
|
+
let hasDollar = false;
|
|
3339
|
+
let hasBracketOutsideParen = false;
|
|
3340
|
+
let hasQuote = false;
|
|
3341
|
+
while (P.L.i < P.L.len) {
|
|
3342
|
+
const c = peek(P.L);
|
|
3343
|
+
if (c === '\\' && P.L.i + 1 < P.L.len) {
|
|
3344
|
+
// Escaped char — consume both (handles `bar\ baz` as single pattern)
|
|
3345
|
+
// \<newline> is a line continuation; eat it but stay in pattern.
|
|
3346
|
+
advance(P.L);
|
|
3347
|
+
advance(P.L);
|
|
3348
|
+
continue;
|
|
3349
|
+
}
|
|
3350
|
+
if (c === '"' || c === "'") {
|
|
3351
|
+
hasQuote = true;
|
|
3352
|
+
// Skip past the quoted segment so its content (spaces, |, etc.) doesn't
|
|
3353
|
+
// break the peek-ahead scan.
|
|
3354
|
+
advance(P.L);
|
|
3355
|
+
while (P.L.i < P.L.len && peek(P.L) !== c) {
|
|
3356
|
+
if (peek(P.L) === '\\' && P.L.i + 1 < P.L.len)
|
|
3357
|
+
advance(P.L);
|
|
3358
|
+
advance(P.L);
|
|
3359
|
+
}
|
|
3360
|
+
if (peek(P.L) === c)
|
|
3361
|
+
advance(P.L);
|
|
3362
|
+
continue;
|
|
3363
|
+
}
|
|
3364
|
+
// Paren counting: any ( inside pattern opens a scope; don't break at ) or |
|
|
3365
|
+
// until balanced. Handles extglob *(a|b) and nested shapes *([0-9])([0-9]).
|
|
3366
|
+
if (c === '(') {
|
|
3367
|
+
parenDepth++;
|
|
3368
|
+
advance(P.L);
|
|
3369
|
+
continue;
|
|
3370
|
+
}
|
|
3371
|
+
if (parenDepth > 0) {
|
|
3372
|
+
if (c === ')') {
|
|
3373
|
+
parenDepth--;
|
|
3374
|
+
advance(P.L);
|
|
3375
|
+
continue;
|
|
3376
|
+
}
|
|
3377
|
+
if (c === '\n')
|
|
3378
|
+
break;
|
|
3379
|
+
advance(P.L);
|
|
3380
|
+
continue;
|
|
3381
|
+
}
|
|
3382
|
+
if (c === ')' || c === '|' || c === ' ' || c === '\t' || c === '\n')
|
|
3383
|
+
break;
|
|
3384
|
+
if (c === '$')
|
|
3385
|
+
hasDollar = true;
|
|
3386
|
+
if (c === '[')
|
|
3387
|
+
hasBracketOutsideParen = true;
|
|
3388
|
+
advance(P.L);
|
|
3389
|
+
}
|
|
3390
|
+
if (P.L.b === start)
|
|
3391
|
+
return [];
|
|
3392
|
+
const text = P.src.slice(startI, P.L.i);
|
|
3393
|
+
const hasExtglobParen = /[*?+@!]\(/.test(text);
|
|
3394
|
+
// Quoted segments in pattern: tree-sitter splits at quote boundaries into
|
|
3395
|
+
// multiple sibling nodes. `*"foo"*` → (extglob_pattern)(string)(extglob_pattern).
|
|
3396
|
+
// Re-scan with a segmenting pass.
|
|
3397
|
+
if (hasQuote && !hasExtglobParen) {
|
|
3398
|
+
restoreLex(P.L, save);
|
|
3399
|
+
return parseCasePatternSegmented(P);
|
|
3400
|
+
}
|
|
3401
|
+
// tree-sitter splits patterns with [ or $ into concatenation via word parsing
|
|
3402
|
+
// UNLESS pattern has extglob parens (those override and emit extglob_pattern).
|
|
3403
|
+
// `*.[1357]` → concat(word word number word); `${PN}.pot` → concat(expansion word);
|
|
3404
|
+
// but `*([0-9])` → extglob_pattern (has extglob paren).
|
|
3405
|
+
if (!hasExtglobParen && (hasDollar || hasBracketOutsideParen)) {
|
|
3406
|
+
restoreLex(P.L, save);
|
|
3407
|
+
const w = parseWord(P, 'arg');
|
|
3408
|
+
return w ? [w] : [];
|
|
3409
|
+
}
|
|
3410
|
+
// Patterns starting with extglob operator chars (+ - ? * @ !) followed by
|
|
3411
|
+
// identifier chars are extglob_pattern per tree-sitter, even without parens
|
|
3412
|
+
// or glob metachars. `-o)` → extglob_pattern; plain `foo)` → word.
|
|
3413
|
+
const type = hasExtglobParen || /[*?]/.test(text) || /^[-+?*@!][a-zA-Z]/.test(text)
|
|
3414
|
+
? 'extglob_pattern'
|
|
3415
|
+
: 'word';
|
|
3416
|
+
return [mk(P, type, start, P.L.b, [])];
|
|
3417
|
+
}
|
|
3418
|
+
// Segmented scan for case patterns containing quotes: `*"foo"*` →
|
|
3419
|
+
// [extglob_pattern, string, extglob_pattern]. Bare segments → extglob_pattern
|
|
3420
|
+
// if they have */?, else word. Stops at ) | space tab newline outside quotes.
|
|
3421
|
+
function parseCasePatternSegmented(P) {
|
|
3422
|
+
const parts = [];
|
|
3423
|
+
let segStart = P.L.b;
|
|
3424
|
+
let segStartI = P.L.i;
|
|
3425
|
+
const flushSeg = () => {
|
|
3426
|
+
if (P.L.i > segStartI) {
|
|
3427
|
+
const t = P.src.slice(segStartI, P.L.i);
|
|
3428
|
+
const type = /[*?]/.test(t) ? 'extglob_pattern' : 'word';
|
|
3429
|
+
parts.push(mk(P, type, segStart, P.L.b, []));
|
|
3430
|
+
}
|
|
3431
|
+
};
|
|
3432
|
+
while (P.L.i < P.L.len) {
|
|
3433
|
+
const c = peek(P.L);
|
|
3434
|
+
if (c === '\\' && P.L.i + 1 < P.L.len) {
|
|
3435
|
+
advance(P.L);
|
|
3436
|
+
advance(P.L);
|
|
3437
|
+
continue;
|
|
3438
|
+
}
|
|
3439
|
+
if (c === '"') {
|
|
3440
|
+
flushSeg();
|
|
3441
|
+
parts.push(parseDoubleQuoted(P));
|
|
3442
|
+
segStart = P.L.b;
|
|
3443
|
+
segStartI = P.L.i;
|
|
3444
|
+
continue;
|
|
3445
|
+
}
|
|
3446
|
+
if (c === "'") {
|
|
3447
|
+
flushSeg();
|
|
3448
|
+
const tok = nextToken(P.L, 'arg');
|
|
3449
|
+
parts.push(leaf(P, 'raw_string', tok));
|
|
3450
|
+
segStart = P.L.b;
|
|
3451
|
+
segStartI = P.L.i;
|
|
3452
|
+
continue;
|
|
3453
|
+
}
|
|
3454
|
+
if (c === ')' || c === '|' || c === ' ' || c === '\t' || c === '\n')
|
|
3455
|
+
break;
|
|
3456
|
+
advance(P.L);
|
|
3457
|
+
}
|
|
3458
|
+
flushSeg();
|
|
3459
|
+
return parts;
|
|
3460
|
+
}
|
|
3461
|
+
function parseFunction(P, fnTok) {
|
|
3462
|
+
const fnKw = leaf(P, 'function', fnTok);
|
|
3463
|
+
skipBlanks(P.L);
|
|
3464
|
+
const nameTok = nextToken(P.L, 'arg');
|
|
3465
|
+
const name = mk(P, 'word', nameTok.start, nameTok.end, []);
|
|
3466
|
+
const kids = [fnKw, name];
|
|
3467
|
+
skipBlanks(P.L);
|
|
3468
|
+
if (peek(P.L) === '(' && peek(P.L, 1) === ')') {
|
|
3469
|
+
const o = nextToken(P.L, 'cmd');
|
|
3470
|
+
const c = nextToken(P.L, 'cmd');
|
|
3471
|
+
kids.push(leaf(P, '(', o));
|
|
3472
|
+
kids.push(leaf(P, ')', c));
|
|
3473
|
+
}
|
|
3474
|
+
skipBlanks(P.L);
|
|
3475
|
+
skipNewlines(P);
|
|
3476
|
+
const body = parseCommand(P);
|
|
3477
|
+
if (body) {
|
|
3478
|
+
// Hoist redirects from redirected_statement(compound_statement, ...) to
|
|
3479
|
+
// function_definition level per tree-sitter grammar
|
|
3480
|
+
if (body.type === 'redirected_statement' &&
|
|
3481
|
+
body.children.length >= 2 &&
|
|
3482
|
+
body.children[0].type === 'compound_statement') {
|
|
3483
|
+
kids.push(...body.children);
|
|
3484
|
+
}
|
|
3485
|
+
else {
|
|
3486
|
+
kids.push(body);
|
|
3487
|
+
}
|
|
3488
|
+
}
|
|
3489
|
+
const last = kids[kids.length - 1];
|
|
3490
|
+
return mk(P, 'function_definition', fnKw.startIndex, last.endIndex, kids);
|
|
3491
|
+
}
|
|
3492
|
+
function parseDeclaration(P, kwTok) {
|
|
3493
|
+
const kw = leaf(P, kwTok.value, kwTok);
|
|
3494
|
+
const kids = [kw];
|
|
3495
|
+
while (true) {
|
|
3496
|
+
skipBlanks(P.L);
|
|
3497
|
+
const c = peek(P.L);
|
|
3498
|
+
if (c === '' ||
|
|
3499
|
+
c === '\n' ||
|
|
3500
|
+
c === ';' ||
|
|
3501
|
+
c === '&' ||
|
|
3502
|
+
c === '|' ||
|
|
3503
|
+
c === ')' ||
|
|
3504
|
+
c === '<' ||
|
|
3505
|
+
c === '>') {
|
|
3506
|
+
break;
|
|
3507
|
+
}
|
|
3508
|
+
const a = tryParseAssignment(P);
|
|
3509
|
+
if (a) {
|
|
3510
|
+
kids.push(a);
|
|
3511
|
+
continue;
|
|
3512
|
+
}
|
|
3513
|
+
// Quoted string or concatenation: `export "FOO=bar"`, `export 'X'`
|
|
3514
|
+
if (c === '"' || c === "'" || c === '$') {
|
|
3515
|
+
const w = parseWord(P, 'arg');
|
|
3516
|
+
if (w) {
|
|
3517
|
+
kids.push(w);
|
|
3518
|
+
continue;
|
|
3519
|
+
}
|
|
3520
|
+
break;
|
|
3521
|
+
}
|
|
3522
|
+
// Flag like -a or bare variable name
|
|
3523
|
+
const save = saveLex(P.L);
|
|
3524
|
+
const tok = nextToken(P.L, 'arg');
|
|
3525
|
+
if (tok.type === 'WORD' || tok.type === 'NUMBER') {
|
|
3526
|
+
if (tok.value.startsWith('-')) {
|
|
3527
|
+
kids.push(leaf(P, 'word', tok));
|
|
3528
|
+
}
|
|
3529
|
+
else if (isIdentStart(tok.value[0] ?? '')) {
|
|
3530
|
+
kids.push(mk(P, 'variable_name', tok.start, tok.end, []));
|
|
3531
|
+
}
|
|
3532
|
+
else {
|
|
3533
|
+
kids.push(leaf(P, 'word', tok));
|
|
3534
|
+
}
|
|
3535
|
+
}
|
|
3536
|
+
else {
|
|
3537
|
+
restoreLex(P.L, save);
|
|
3538
|
+
break;
|
|
3539
|
+
}
|
|
3540
|
+
}
|
|
3541
|
+
const last = kids[kids.length - 1];
|
|
3542
|
+
return mk(P, 'declaration_command', kw.startIndex, last.endIndex, kids);
|
|
3543
|
+
}
|
|
3544
|
+
function parseUnset(P, kwTok) {
|
|
3545
|
+
const kw = leaf(P, 'unset', kwTok);
|
|
3546
|
+
const kids = [kw];
|
|
3547
|
+
while (true) {
|
|
3548
|
+
skipBlanks(P.L);
|
|
3549
|
+
const c = peek(P.L);
|
|
3550
|
+
if (c === '' ||
|
|
3551
|
+
c === '\n' ||
|
|
3552
|
+
c === ';' ||
|
|
3553
|
+
c === '&' ||
|
|
3554
|
+
c === '|' ||
|
|
3555
|
+
c === ')' ||
|
|
3556
|
+
c === '<' ||
|
|
3557
|
+
c === '>') {
|
|
3558
|
+
break;
|
|
3559
|
+
}
|
|
3560
|
+
// SECURITY: use parseWord (not raw nextToken) so quoted strings like
|
|
3561
|
+
// `unset 'a[$(id)]'` emit a raw_string child that ast.ts can reject.
|
|
3562
|
+
// Previously `break` silently dropped non-WORD args — hiding the
|
|
3563
|
+
// arithmetic-subscript code-exec vector from the security walker.
|
|
3564
|
+
const arg = parseWord(P, 'arg');
|
|
3565
|
+
if (!arg)
|
|
3566
|
+
break;
|
|
3567
|
+
if (arg.type === 'word') {
|
|
3568
|
+
if (arg.text.startsWith('-')) {
|
|
3569
|
+
kids.push(arg);
|
|
3570
|
+
}
|
|
3571
|
+
else {
|
|
3572
|
+
kids.push(mk(P, 'variable_name', arg.startIndex, arg.endIndex, []));
|
|
3573
|
+
}
|
|
3574
|
+
}
|
|
3575
|
+
else {
|
|
3576
|
+
kids.push(arg);
|
|
3577
|
+
}
|
|
3578
|
+
}
|
|
3579
|
+
const last = kids[kids.length - 1];
|
|
3580
|
+
return mk(P, 'unset_command', kw.startIndex, last.endIndex, kids);
|
|
3581
|
+
}
|
|
3582
|
+
function consumeKeyword(P, name, kids) {
|
|
3583
|
+
skipNewlines(P);
|
|
3584
|
+
const save = saveLex(P.L);
|
|
3585
|
+
const t = nextToken(P.L, 'cmd');
|
|
3586
|
+
if (t.type === 'WORD' && t.value === name) {
|
|
3587
|
+
kids.push(leaf(P, name, t));
|
|
3588
|
+
}
|
|
3589
|
+
else {
|
|
3590
|
+
restoreLex(P.L, save);
|
|
3591
|
+
}
|
|
3592
|
+
}
|
|
3593
|
+
// ───────────────────── Test & Arithmetic Expressions ─────────────────────
|
|
3594
|
+
function parseTestExpr(P, closer) {
|
|
3595
|
+
return parseTestOr(P, closer);
|
|
3596
|
+
}
|
|
3597
|
+
function parseTestOr(P, closer) {
|
|
3598
|
+
let left = parseTestAnd(P, closer);
|
|
3599
|
+
if (!left)
|
|
3600
|
+
return null;
|
|
3601
|
+
while (true) {
|
|
3602
|
+
skipBlanks(P.L);
|
|
3603
|
+
const save = saveLex(P.L);
|
|
3604
|
+
if (peek(P.L) === '|' && peek(P.L, 1) === '|') {
|
|
3605
|
+
const s = P.L.b;
|
|
3606
|
+
advance(P.L);
|
|
3607
|
+
advance(P.L);
|
|
3608
|
+
const op = mk(P, '||', s, P.L.b, []);
|
|
3609
|
+
const right = parseTestAnd(P, closer);
|
|
3610
|
+
if (!right) {
|
|
3611
|
+
restoreLex(P.L, save);
|
|
3612
|
+
break;
|
|
3613
|
+
}
|
|
3614
|
+
left = mk(P, 'binary_expression', left.startIndex, right.endIndex, [
|
|
3615
|
+
left,
|
|
3616
|
+
op,
|
|
3617
|
+
right,
|
|
3618
|
+
]);
|
|
3619
|
+
}
|
|
3620
|
+
else {
|
|
3621
|
+
break;
|
|
3622
|
+
}
|
|
3623
|
+
}
|
|
3624
|
+
return left;
|
|
3625
|
+
}
|
|
3626
|
+
function parseTestAnd(P, closer) {
|
|
3627
|
+
let left = parseTestUnary(P, closer);
|
|
3628
|
+
if (!left)
|
|
3629
|
+
return null;
|
|
3630
|
+
while (true) {
|
|
3631
|
+
skipBlanks(P.L);
|
|
3632
|
+
if (peek(P.L) === '&' && peek(P.L, 1) === '&') {
|
|
3633
|
+
const s = P.L.b;
|
|
3634
|
+
advance(P.L);
|
|
3635
|
+
advance(P.L);
|
|
3636
|
+
const op = mk(P, '&&', s, P.L.b, []);
|
|
3637
|
+
const right = parseTestUnary(P, closer);
|
|
3638
|
+
if (!right)
|
|
3639
|
+
break;
|
|
3640
|
+
left = mk(P, 'binary_expression', left.startIndex, right.endIndex, [
|
|
3641
|
+
left,
|
|
3642
|
+
op,
|
|
3643
|
+
right,
|
|
3644
|
+
]);
|
|
3645
|
+
}
|
|
3646
|
+
else {
|
|
3647
|
+
break;
|
|
3648
|
+
}
|
|
3649
|
+
}
|
|
3650
|
+
return left;
|
|
3651
|
+
}
|
|
3652
|
+
function parseTestUnary(P, closer) {
|
|
3653
|
+
skipBlanks(P.L);
|
|
3654
|
+
const c = peek(P.L);
|
|
3655
|
+
if (c === '(') {
|
|
3656
|
+
const s = P.L.b;
|
|
3657
|
+
advance(P.L);
|
|
3658
|
+
const open = mk(P, '(', s, P.L.b, []);
|
|
3659
|
+
const inner = parseTestOr(P, closer);
|
|
3660
|
+
skipBlanks(P.L);
|
|
3661
|
+
let close;
|
|
3662
|
+
if (peek(P.L) === ')') {
|
|
3663
|
+
const cs = P.L.b;
|
|
3664
|
+
advance(P.L);
|
|
3665
|
+
close = mk(P, ')', cs, P.L.b, []);
|
|
3666
|
+
}
|
|
3667
|
+
else {
|
|
3668
|
+
close = mk(P, ')', P.L.b, P.L.b, []);
|
|
3669
|
+
}
|
|
3670
|
+
const kids = inner ? [open, inner, close] : [open, close];
|
|
3671
|
+
return mk(P, 'parenthesized_expression', open.startIndex, close.endIndex, kids);
|
|
3672
|
+
}
|
|
3673
|
+
return parseTestBinary(P, closer);
|
|
3674
|
+
}
|
|
3675
|
+
/**
|
|
3676
|
+
* Parse `!`-negated or test-operator (`-f`) or parenthesized primary — but NOT
|
|
3677
|
+
* a binary comparison. Used as LHS of binary_expression so `! x =~ y` binds
|
|
3678
|
+
* `!` to `x` only, not the whole `x =~ y`.
|
|
3679
|
+
*/
|
|
3680
|
+
function parseTestNegatablePrimary(P, closer) {
|
|
3681
|
+
skipBlanks(P.L);
|
|
3682
|
+
const c = peek(P.L);
|
|
3683
|
+
if (c === '!') {
|
|
3684
|
+
const s = P.L.b;
|
|
3685
|
+
advance(P.L);
|
|
3686
|
+
const bang = mk(P, '!', s, P.L.b, []);
|
|
3687
|
+
const inner = parseTestNegatablePrimary(P, closer);
|
|
3688
|
+
if (!inner)
|
|
3689
|
+
return bang;
|
|
3690
|
+
return mk(P, 'unary_expression', bang.startIndex, inner.endIndex, [
|
|
3691
|
+
bang,
|
|
3692
|
+
inner,
|
|
3693
|
+
]);
|
|
3694
|
+
}
|
|
3695
|
+
if (c === '-' && isIdentStart(peek(P.L, 1))) {
|
|
3696
|
+
const s = P.L.b;
|
|
3697
|
+
advance(P.L);
|
|
3698
|
+
while (isIdentChar(peek(P.L)))
|
|
3699
|
+
advance(P.L);
|
|
3700
|
+
const op = mk(P, 'test_operator', s, P.L.b, []);
|
|
3701
|
+
skipBlanks(P.L);
|
|
3702
|
+
const arg = parseTestPrimary(P, closer);
|
|
3703
|
+
if (!arg)
|
|
3704
|
+
return op;
|
|
3705
|
+
return mk(P, 'unary_expression', op.startIndex, arg.endIndex, [op, arg]);
|
|
3706
|
+
}
|
|
3707
|
+
return parseTestPrimary(P, closer);
|
|
3708
|
+
}
|
|
3709
|
+
function parseTestBinary(P, closer) {
|
|
3710
|
+
skipBlanks(P.L);
|
|
3711
|
+
// `!` in test context binds tighter than =~/==.
|
|
3712
|
+
// `[[ ! "x" =~ y ]]` → (binary_expression (unary_expression (string)) (regex))
|
|
3713
|
+
// `[[ ! -f x ]]` → (unary_expression ! (unary_expression (test_operator) (word)))
|
|
3714
|
+
const left = parseTestNegatablePrimary(P, closer);
|
|
3715
|
+
if (!left)
|
|
3716
|
+
return null;
|
|
3717
|
+
skipBlanks(P.L);
|
|
3718
|
+
// Binary comparison: == != =~ -eq -lt etc.
|
|
3719
|
+
const c = peek(P.L);
|
|
3720
|
+
const c1 = peek(P.L, 1);
|
|
3721
|
+
let op = null;
|
|
3722
|
+
const os = P.L.b;
|
|
3723
|
+
if (c === '=' && c1 === '=') {
|
|
3724
|
+
advance(P.L);
|
|
3725
|
+
advance(P.L);
|
|
3726
|
+
op = mk(P, '==', os, P.L.b, []);
|
|
3727
|
+
}
|
|
3728
|
+
else if (c === '!' && c1 === '=') {
|
|
3729
|
+
advance(P.L);
|
|
3730
|
+
advance(P.L);
|
|
3731
|
+
op = mk(P, '!=', os, P.L.b, []);
|
|
3732
|
+
}
|
|
3733
|
+
else if (c === '=' && c1 === '~') {
|
|
3734
|
+
advance(P.L);
|
|
3735
|
+
advance(P.L);
|
|
3736
|
+
op = mk(P, '=~', os, P.L.b, []);
|
|
3737
|
+
}
|
|
3738
|
+
else if (c === '=' && c1 !== '=') {
|
|
3739
|
+
advance(P.L);
|
|
3740
|
+
op = mk(P, '=', os, P.L.b, []);
|
|
3741
|
+
}
|
|
3742
|
+
else if (c === '<' && c1 !== '<') {
|
|
3743
|
+
advance(P.L);
|
|
3744
|
+
op = mk(P, '<', os, P.L.b, []);
|
|
3745
|
+
}
|
|
3746
|
+
else if (c === '>' && c1 !== '>') {
|
|
3747
|
+
advance(P.L);
|
|
3748
|
+
op = mk(P, '>', os, P.L.b, []);
|
|
3749
|
+
}
|
|
3750
|
+
else if (c === '-' && isIdentStart(c1)) {
|
|
3751
|
+
advance(P.L);
|
|
3752
|
+
while (isIdentChar(peek(P.L)))
|
|
3753
|
+
advance(P.L);
|
|
3754
|
+
op = mk(P, 'test_operator', os, P.L.b, []);
|
|
3755
|
+
}
|
|
3756
|
+
if (!op)
|
|
3757
|
+
return left;
|
|
3758
|
+
skipBlanks(P.L);
|
|
3759
|
+
// In [[ ]], RHS of ==/!=/=/=~ gets special pattern parsing: paren counting
|
|
3760
|
+
// so @(a|b|c) doesn't break on |, and segments become extglob_pattern/regex.
|
|
3761
|
+
if (closer === ']]') {
|
|
3762
|
+
const opText = op.type;
|
|
3763
|
+
if (opText === '=~') {
|
|
3764
|
+
skipBlanks(P.L);
|
|
3765
|
+
// If the ENTIRE RHS is a quoted string, emit string/raw_string not
|
|
3766
|
+
// regex: `[[ "$x" =~ "$y" ]]` → (binary_expression (string) (string)).
|
|
3767
|
+
// If there's content after the quote (`' boop '(.*)$`), the whole RHS
|
|
3768
|
+
// stays a single (regex). Peek past the quote to check.
|
|
3769
|
+
const rc = peek(P.L);
|
|
3770
|
+
let rhs = null;
|
|
3771
|
+
if (rc === '"' || rc === "'") {
|
|
3772
|
+
const save = saveLex(P.L);
|
|
3773
|
+
const quoted = rc === '"'
|
|
3774
|
+
? parseDoubleQuoted(P)
|
|
3775
|
+
: leaf(P, 'raw_string', nextToken(P.L, 'arg'));
|
|
3776
|
+
// Check if RHS ends here: only whitespace then ]] or &&/|| or newline
|
|
3777
|
+
let j = P.L.i;
|
|
3778
|
+
while (j < P.L.len && (P.src[j] === ' ' || P.src[j] === '\t'))
|
|
3779
|
+
j++;
|
|
3780
|
+
const nc = P.src[j] ?? '';
|
|
3781
|
+
const nc1 = P.src[j + 1] ?? '';
|
|
3782
|
+
if ((nc === ']' && nc1 === ']') ||
|
|
3783
|
+
(nc === '&' && nc1 === '&') ||
|
|
3784
|
+
(nc === '|' && nc1 === '|') ||
|
|
3785
|
+
nc === '\n' ||
|
|
3786
|
+
nc === '') {
|
|
3787
|
+
rhs = quoted;
|
|
3788
|
+
}
|
|
3789
|
+
else {
|
|
3790
|
+
restoreLex(P.L, save);
|
|
3791
|
+
}
|
|
3792
|
+
}
|
|
3793
|
+
if (!rhs)
|
|
3794
|
+
rhs = parseTestRegexRhs(P);
|
|
3795
|
+
if (!rhs)
|
|
3796
|
+
return left;
|
|
3797
|
+
return mk(P, 'binary_expression', left.startIndex, rhs.endIndex, [
|
|
3798
|
+
left,
|
|
3799
|
+
op,
|
|
3800
|
+
rhs,
|
|
3801
|
+
]);
|
|
3802
|
+
}
|
|
3803
|
+
// Single `=` emits (regex) per tree-sitter; `==` and `!=` emit extglob_pattern
|
|
3804
|
+
if (opText === '=') {
|
|
3805
|
+
const rhs = parseTestRegexRhs(P);
|
|
3806
|
+
if (!rhs)
|
|
3807
|
+
return left;
|
|
3808
|
+
return mk(P, 'binary_expression', left.startIndex, rhs.endIndex, [
|
|
3809
|
+
left,
|
|
3810
|
+
op,
|
|
3811
|
+
rhs,
|
|
3812
|
+
]);
|
|
3813
|
+
}
|
|
3814
|
+
if (opText === '==' || opText === '!=') {
|
|
3815
|
+
const parts = parseTestExtglobRhs(P);
|
|
3816
|
+
if (parts.length === 0)
|
|
3817
|
+
return left;
|
|
3818
|
+
const last = parts[parts.length - 1];
|
|
3819
|
+
return mk(P, 'binary_expression', left.startIndex, last.endIndex, [
|
|
3820
|
+
left,
|
|
3821
|
+
op,
|
|
3822
|
+
...parts,
|
|
3823
|
+
]);
|
|
3824
|
+
}
|
|
3825
|
+
}
|
|
3826
|
+
const right = parseTestPrimary(P, closer);
|
|
3827
|
+
if (!right)
|
|
3828
|
+
return left;
|
|
3829
|
+
return mk(P, 'binary_expression', left.startIndex, right.endIndex, [
|
|
3830
|
+
left,
|
|
3831
|
+
op,
|
|
3832
|
+
right,
|
|
3833
|
+
]);
|
|
3834
|
+
}
|
|
3835
|
+
// RHS of =~ in [[ ]] — scan as single (regex) node with paren/bracket counting
|
|
3836
|
+
// so | ( ) inside the regex don't break parsing. Stop at ]] or ws+&&/||.
|
|
3837
|
+
function parseTestRegexRhs(P) {
|
|
3838
|
+
skipBlanks(P.L);
|
|
3839
|
+
const start = P.L.b;
|
|
3840
|
+
let parenDepth = 0;
|
|
3841
|
+
let bracketDepth = 0;
|
|
3842
|
+
while (P.L.i < P.L.len) {
|
|
3843
|
+
const c = peek(P.L);
|
|
3844
|
+
if (c === '\\' && P.L.i + 1 < P.L.len) {
|
|
3845
|
+
advance(P.L);
|
|
3846
|
+
advance(P.L);
|
|
3847
|
+
continue;
|
|
3848
|
+
}
|
|
3849
|
+
if (c === '\n')
|
|
3850
|
+
break;
|
|
3851
|
+
if (parenDepth === 0 && bracketDepth === 0) {
|
|
3852
|
+
if (c === ']' && peek(P.L, 1) === ']')
|
|
3853
|
+
break;
|
|
3854
|
+
if (c === ' ' || c === '\t') {
|
|
3855
|
+
// Peek past blanks for ]] or &&/||
|
|
3856
|
+
let j = P.L.i;
|
|
3857
|
+
while (j < P.L.len && (P.L.src[j] === ' ' || P.L.src[j] === '\t'))
|
|
3858
|
+
j++;
|
|
3859
|
+
const nc = P.L.src[j] ?? '';
|
|
3860
|
+
const nc1 = P.L.src[j + 1] ?? '';
|
|
3861
|
+
if ((nc === ']' && nc1 === ']') ||
|
|
3862
|
+
(nc === '&' && nc1 === '&') ||
|
|
3863
|
+
(nc === '|' && nc1 === '|')) {
|
|
3864
|
+
break;
|
|
3865
|
+
}
|
|
3866
|
+
advance(P.L);
|
|
3867
|
+
continue;
|
|
3868
|
+
}
|
|
3869
|
+
}
|
|
3870
|
+
if (c === '(')
|
|
3871
|
+
parenDepth++;
|
|
3872
|
+
else if (c === ')' && parenDepth > 0)
|
|
3873
|
+
parenDepth--;
|
|
3874
|
+
else if (c === '[')
|
|
3875
|
+
bracketDepth++;
|
|
3876
|
+
else if (c === ']' && bracketDepth > 0)
|
|
3877
|
+
bracketDepth--;
|
|
3878
|
+
advance(P.L);
|
|
3879
|
+
}
|
|
3880
|
+
if (P.L.b === start)
|
|
3881
|
+
return null;
|
|
3882
|
+
return mk(P, 'regex', start, P.L.b, []);
|
|
3883
|
+
}
|
|
3884
|
+
// RHS of ==/!=/= in [[ ]] — returns array of parts. Bare text → extglob_pattern
|
|
3885
|
+
// (with paren counting for @(a|b)); $(...)/${}/quoted → proper node types.
|
|
3886
|
+
// Multiple parts become flat children of binary_expression per tree-sitter.
|
|
3887
|
+
function parseTestExtglobRhs(P) {
|
|
3888
|
+
skipBlanks(P.L);
|
|
3889
|
+
const parts = [];
|
|
3890
|
+
let segStart = P.L.b;
|
|
3891
|
+
let segStartI = P.L.i;
|
|
3892
|
+
let parenDepth = 0;
|
|
3893
|
+
const flushSeg = () => {
|
|
3894
|
+
if (P.L.i > segStartI) {
|
|
3895
|
+
const text = P.src.slice(segStartI, P.L.i);
|
|
3896
|
+
// Pure number stays number; everything else is extglob_pattern
|
|
3897
|
+
const type = /^\d+$/.test(text) ? 'number' : 'extglob_pattern';
|
|
3898
|
+
parts.push(mk(P, type, segStart, P.L.b, []));
|
|
3899
|
+
}
|
|
3900
|
+
};
|
|
3901
|
+
while (P.L.i < P.L.len) {
|
|
3902
|
+
const c = peek(P.L);
|
|
3903
|
+
if (c === '\\' && P.L.i + 1 < P.L.len) {
|
|
3904
|
+
advance(P.L);
|
|
3905
|
+
advance(P.L);
|
|
3906
|
+
continue;
|
|
3907
|
+
}
|
|
3908
|
+
if (c === '\n')
|
|
3909
|
+
break;
|
|
3910
|
+
if (parenDepth === 0) {
|
|
3911
|
+
if (c === ']' && peek(P.L, 1) === ']')
|
|
3912
|
+
break;
|
|
3913
|
+
if (c === ' ' || c === '\t') {
|
|
3914
|
+
let j = P.L.i;
|
|
3915
|
+
while (j < P.L.len && (P.L.src[j] === ' ' || P.L.src[j] === '\t'))
|
|
3916
|
+
j++;
|
|
3917
|
+
const nc = P.L.src[j] ?? '';
|
|
3918
|
+
const nc1 = P.L.src[j + 1] ?? '';
|
|
3919
|
+
if ((nc === ']' && nc1 === ']') ||
|
|
3920
|
+
(nc === '&' && nc1 === '&') ||
|
|
3921
|
+
(nc === '|' && nc1 === '|')) {
|
|
3922
|
+
break;
|
|
3923
|
+
}
|
|
3924
|
+
advance(P.L);
|
|
3925
|
+
continue;
|
|
3926
|
+
}
|
|
3927
|
+
}
|
|
3928
|
+
// $ " ' must be parsed even inside @( ) extglob parens — parseDollarLike
|
|
3929
|
+
// consumes matching ) so parenDepth stays consistent.
|
|
3930
|
+
if (c === '$') {
|
|
3931
|
+
const c1 = peek(P.L, 1);
|
|
3932
|
+
if (c1 === '(' ||
|
|
3933
|
+
c1 === '{' ||
|
|
3934
|
+
isIdentStart(c1) ||
|
|
3935
|
+
SPECIAL_VARS.has(c1)) {
|
|
3936
|
+
flushSeg();
|
|
3937
|
+
const exp = parseDollarLike(P);
|
|
3938
|
+
if (exp)
|
|
3939
|
+
parts.push(exp);
|
|
3940
|
+
segStart = P.L.b;
|
|
3941
|
+
segStartI = P.L.i;
|
|
3942
|
+
continue;
|
|
3943
|
+
}
|
|
3944
|
+
}
|
|
3945
|
+
if (c === '"') {
|
|
3946
|
+
flushSeg();
|
|
3947
|
+
parts.push(parseDoubleQuoted(P));
|
|
3948
|
+
segStart = P.L.b;
|
|
3949
|
+
segStartI = P.L.i;
|
|
3950
|
+
continue;
|
|
3951
|
+
}
|
|
3952
|
+
if (c === "'") {
|
|
3953
|
+
flushSeg();
|
|
3954
|
+
const tok = nextToken(P.L, 'arg');
|
|
3955
|
+
parts.push(leaf(P, 'raw_string', tok));
|
|
3956
|
+
segStart = P.L.b;
|
|
3957
|
+
segStartI = P.L.i;
|
|
3958
|
+
continue;
|
|
3959
|
+
}
|
|
3960
|
+
if (c === '(')
|
|
3961
|
+
parenDepth++;
|
|
3962
|
+
else if (c === ')' && parenDepth > 0)
|
|
3963
|
+
parenDepth--;
|
|
3964
|
+
advance(P.L);
|
|
3965
|
+
}
|
|
3966
|
+
flushSeg();
|
|
3967
|
+
return parts;
|
|
3968
|
+
}
|
|
3969
|
+
function parseTestPrimary(P, closer) {
|
|
3970
|
+
skipBlanks(P.L);
|
|
3971
|
+
// Stop at closer
|
|
3972
|
+
if (closer === ']' && peek(P.L) === ']')
|
|
3973
|
+
return null;
|
|
3974
|
+
if (closer === ']]' && peek(P.L) === ']' && peek(P.L, 1) === ']')
|
|
3975
|
+
return null;
|
|
3976
|
+
return parseWord(P, 'arg');
|
|
3977
|
+
}
|
|
3978
|
+
/** Operator precedence table (higher = tighter binding). */
|
|
3979
|
+
const ARITH_PREC = {
|
|
3980
|
+
'=': 2,
|
|
3981
|
+
'+=': 2,
|
|
3982
|
+
'-=': 2,
|
|
3983
|
+
'*=': 2,
|
|
3984
|
+
'/=': 2,
|
|
3985
|
+
'%=': 2,
|
|
3986
|
+
'<<=': 2,
|
|
3987
|
+
'>>=': 2,
|
|
3988
|
+
'&=': 2,
|
|
3989
|
+
'^=': 2,
|
|
3990
|
+
'|=': 2,
|
|
3991
|
+
'||': 4,
|
|
3992
|
+
'&&': 5,
|
|
3993
|
+
'|': 6,
|
|
3994
|
+
'^': 7,
|
|
3995
|
+
'&': 8,
|
|
3996
|
+
'==': 9,
|
|
3997
|
+
'!=': 9,
|
|
3998
|
+
'<': 10,
|
|
3999
|
+
'>': 10,
|
|
4000
|
+
'<=': 10,
|
|
4001
|
+
'>=': 10,
|
|
4002
|
+
'<<': 11,
|
|
4003
|
+
'>>': 11,
|
|
4004
|
+
'+': 12,
|
|
4005
|
+
'-': 12,
|
|
4006
|
+
'*': 13,
|
|
4007
|
+
'/': 13,
|
|
4008
|
+
'%': 13,
|
|
4009
|
+
'**': 14,
|
|
4010
|
+
};
|
|
4011
|
+
/** Right-associative operators (assignment and exponent). */
|
|
4012
|
+
const ARITH_RIGHT_ASSOC = new Set([
|
|
4013
|
+
'=',
|
|
4014
|
+
'+=',
|
|
4015
|
+
'-=',
|
|
4016
|
+
'*=',
|
|
4017
|
+
'/=',
|
|
4018
|
+
'%=',
|
|
4019
|
+
'<<=',
|
|
4020
|
+
'>>=',
|
|
4021
|
+
'&=',
|
|
4022
|
+
'^=',
|
|
4023
|
+
'|=',
|
|
4024
|
+
'**',
|
|
4025
|
+
]);
|
|
4026
|
+
function parseArithExpr(P, stop, mode = 'var') {
|
|
4027
|
+
return parseArithTernary(P, stop, mode);
|
|
4028
|
+
}
|
|
4029
|
+
/** Top-level: comma-separated list. arithmetic_expansion emits multiple children. */
|
|
4030
|
+
function parseArithCommaList(P, stop, mode = 'var') {
|
|
4031
|
+
const out = [];
|
|
4032
|
+
while (true) {
|
|
4033
|
+
const e = parseArithTernary(P, stop, mode);
|
|
4034
|
+
if (e)
|
|
4035
|
+
out.push(e);
|
|
4036
|
+
skipBlanks(P.L);
|
|
4037
|
+
if (peek(P.L) === ',' && !isArithStop(P, stop)) {
|
|
4038
|
+
advance(P.L);
|
|
4039
|
+
continue;
|
|
4040
|
+
}
|
|
4041
|
+
break;
|
|
4042
|
+
}
|
|
4043
|
+
return out;
|
|
4044
|
+
}
|
|
4045
|
+
function parseArithTernary(P, stop, mode) {
|
|
4046
|
+
const cond = parseArithBinary(P, stop, 0, mode);
|
|
4047
|
+
if (!cond)
|
|
4048
|
+
return null;
|
|
4049
|
+
skipBlanks(P.L);
|
|
4050
|
+
if (peek(P.L) === '?') {
|
|
4051
|
+
const qs = P.L.b;
|
|
4052
|
+
advance(P.L);
|
|
4053
|
+
const q = mk(P, '?', qs, P.L.b, []);
|
|
4054
|
+
const t = parseArithBinary(P, ':', 0, mode);
|
|
4055
|
+
skipBlanks(P.L);
|
|
4056
|
+
let colon;
|
|
4057
|
+
if (peek(P.L) === ':') {
|
|
4058
|
+
const cs = P.L.b;
|
|
4059
|
+
advance(P.L);
|
|
4060
|
+
colon = mk(P, ':', cs, P.L.b, []);
|
|
4061
|
+
}
|
|
4062
|
+
else {
|
|
4063
|
+
colon = mk(P, ':', P.L.b, P.L.b, []);
|
|
4064
|
+
}
|
|
4065
|
+
const f = parseArithTernary(P, stop, mode);
|
|
4066
|
+
const last = f ?? colon;
|
|
4067
|
+
const kids = [cond, q];
|
|
4068
|
+
if (t)
|
|
4069
|
+
kids.push(t);
|
|
4070
|
+
kids.push(colon);
|
|
4071
|
+
if (f)
|
|
4072
|
+
kids.push(f);
|
|
4073
|
+
return mk(P, 'ternary_expression', cond.startIndex, last.endIndex, kids);
|
|
4074
|
+
}
|
|
4075
|
+
return cond;
|
|
4076
|
+
}
|
|
4077
|
+
/** Scan next arithmetic binary operator; returns [text, length] or null. */
|
|
4078
|
+
function scanArithOp(P) {
|
|
4079
|
+
const c = peek(P.L);
|
|
4080
|
+
const c1 = peek(P.L, 1);
|
|
4081
|
+
const c2 = peek(P.L, 2);
|
|
4082
|
+
// 3-char: <<= >>=
|
|
4083
|
+
if (c === '<' && c1 === '<' && c2 === '=')
|
|
4084
|
+
return ['<<=', 3];
|
|
4085
|
+
if (c === '>' && c1 === '>' && c2 === '=')
|
|
4086
|
+
return ['>>=', 3];
|
|
4087
|
+
// 2-char
|
|
4088
|
+
if (c === '*' && c1 === '*')
|
|
4089
|
+
return ['**', 2];
|
|
4090
|
+
if (c === '<' && c1 === '<')
|
|
4091
|
+
return ['<<', 2];
|
|
4092
|
+
if (c === '>' && c1 === '>')
|
|
4093
|
+
return ['>>', 2];
|
|
4094
|
+
if (c === '=' && c1 === '=')
|
|
4095
|
+
return ['==', 2];
|
|
4096
|
+
if (c === '!' && c1 === '=')
|
|
4097
|
+
return ['!=', 2];
|
|
4098
|
+
if (c === '<' && c1 === '=')
|
|
4099
|
+
return ['<=', 2];
|
|
4100
|
+
if (c === '>' && c1 === '=')
|
|
4101
|
+
return ['>=', 2];
|
|
4102
|
+
if (c === '&' && c1 === '&')
|
|
4103
|
+
return ['&&', 2];
|
|
4104
|
+
if (c === '|' && c1 === '|')
|
|
4105
|
+
return ['||', 2];
|
|
4106
|
+
if (c === '+' && c1 === '=')
|
|
4107
|
+
return ['+=', 2];
|
|
4108
|
+
if (c === '-' && c1 === '=')
|
|
4109
|
+
return ['-=', 2];
|
|
4110
|
+
if (c === '*' && c1 === '=')
|
|
4111
|
+
return ['*=', 2];
|
|
4112
|
+
if (c === '/' && c1 === '=')
|
|
4113
|
+
return ['/=', 2];
|
|
4114
|
+
if (c === '%' && c1 === '=')
|
|
4115
|
+
return ['%=', 2];
|
|
4116
|
+
if (c === '&' && c1 === '=')
|
|
4117
|
+
return ['&=', 2];
|
|
4118
|
+
if (c === '^' && c1 === '=')
|
|
4119
|
+
return ['^=', 2];
|
|
4120
|
+
if (c === '|' && c1 === '=')
|
|
4121
|
+
return ['|=', 2];
|
|
4122
|
+
// 1-char — but NOT ++ -- (those are pre/postfix)
|
|
4123
|
+
if (c === '+' && c1 !== '+')
|
|
4124
|
+
return ['+', 1];
|
|
4125
|
+
if (c === '-' && c1 !== '-')
|
|
4126
|
+
return ['-', 1];
|
|
4127
|
+
if (c === '*')
|
|
4128
|
+
return ['*', 1];
|
|
4129
|
+
if (c === '/')
|
|
4130
|
+
return ['/', 1];
|
|
4131
|
+
if (c === '%')
|
|
4132
|
+
return ['%', 1];
|
|
4133
|
+
if (c === '<')
|
|
4134
|
+
return ['<', 1];
|
|
4135
|
+
if (c === '>')
|
|
4136
|
+
return ['>', 1];
|
|
4137
|
+
if (c === '&')
|
|
4138
|
+
return ['&', 1];
|
|
4139
|
+
if (c === '|')
|
|
4140
|
+
return ['|', 1];
|
|
4141
|
+
if (c === '^')
|
|
4142
|
+
return ['^', 1];
|
|
4143
|
+
if (c === '=')
|
|
4144
|
+
return ['=', 1];
|
|
4145
|
+
return null;
|
|
4146
|
+
}
|
|
4147
|
+
/** Precedence-climbing binary expression parser. */
|
|
4148
|
+
function parseArithBinary(P, stop, minPrec, mode) {
|
|
4149
|
+
let left = parseArithUnary(P, stop, mode);
|
|
4150
|
+
if (!left)
|
|
4151
|
+
return null;
|
|
4152
|
+
while (true) {
|
|
4153
|
+
skipBlanks(P.L);
|
|
4154
|
+
if (isArithStop(P, stop))
|
|
4155
|
+
break;
|
|
4156
|
+
if (peek(P.L) === ',')
|
|
4157
|
+
break;
|
|
4158
|
+
const opInfo = scanArithOp(P);
|
|
4159
|
+
if (!opInfo)
|
|
4160
|
+
break;
|
|
4161
|
+
const [opText, opLen] = opInfo;
|
|
4162
|
+
const prec = ARITH_PREC[opText];
|
|
4163
|
+
if (prec === undefined || prec < minPrec)
|
|
4164
|
+
break;
|
|
4165
|
+
const os = P.L.b;
|
|
4166
|
+
for (let k = 0; k < opLen; k++)
|
|
4167
|
+
advance(P.L);
|
|
4168
|
+
const op = mk(P, opText, os, P.L.b, []);
|
|
4169
|
+
const nextMin = ARITH_RIGHT_ASSOC.has(opText) ? prec : prec + 1;
|
|
4170
|
+
const right = parseArithBinary(P, stop, nextMin, mode);
|
|
4171
|
+
if (!right)
|
|
4172
|
+
break;
|
|
4173
|
+
left = mk(P, 'binary_expression', left.startIndex, right.endIndex, [
|
|
4174
|
+
left,
|
|
4175
|
+
op,
|
|
4176
|
+
right,
|
|
4177
|
+
]);
|
|
4178
|
+
}
|
|
4179
|
+
return left;
|
|
4180
|
+
}
|
|
4181
|
+
function parseArithUnary(P, stop, mode) {
|
|
4182
|
+
skipBlanks(P.L);
|
|
4183
|
+
if (isArithStop(P, stop))
|
|
4184
|
+
return null;
|
|
4185
|
+
const c = peek(P.L);
|
|
4186
|
+
const c1 = peek(P.L, 1);
|
|
4187
|
+
// Prefix ++ --
|
|
4188
|
+
if ((c === '+' && c1 === '+') || (c === '-' && c1 === '-')) {
|
|
4189
|
+
const s = P.L.b;
|
|
4190
|
+
advance(P.L);
|
|
4191
|
+
advance(P.L);
|
|
4192
|
+
const op = mk(P, c + c1, s, P.L.b, []);
|
|
4193
|
+
const inner = parseArithUnary(P, stop, mode);
|
|
4194
|
+
if (!inner)
|
|
4195
|
+
return op;
|
|
4196
|
+
return mk(P, 'unary_expression', op.startIndex, inner.endIndex, [op, inner]);
|
|
4197
|
+
}
|
|
4198
|
+
if (c === '-' || c === '+' || c === '!' || c === '~') {
|
|
4199
|
+
// In 'word'/'assign' mode (c-style for head), `-N` is a single number
|
|
4200
|
+
// literal per tree-sitter, not unary_expression. 'var' mode uses unary.
|
|
4201
|
+
if (mode !== 'var' && c === '-' && isDigit(c1)) {
|
|
4202
|
+
const s = P.L.b;
|
|
4203
|
+
advance(P.L);
|
|
4204
|
+
while (isDigit(peek(P.L)))
|
|
4205
|
+
advance(P.L);
|
|
4206
|
+
return mk(P, 'number', s, P.L.b, []);
|
|
4207
|
+
}
|
|
4208
|
+
const s = P.L.b;
|
|
4209
|
+
advance(P.L);
|
|
4210
|
+
const op = mk(P, c, s, P.L.b, []);
|
|
4211
|
+
const inner = parseArithUnary(P, stop, mode);
|
|
4212
|
+
if (!inner)
|
|
4213
|
+
return op;
|
|
4214
|
+
return mk(P, 'unary_expression', op.startIndex, inner.endIndex, [op, inner]);
|
|
4215
|
+
}
|
|
4216
|
+
return parseArithPostfix(P, stop, mode);
|
|
4217
|
+
}
|
|
4218
|
+
function parseArithPostfix(P, stop, mode) {
|
|
4219
|
+
const prim = parseArithPrimary(P, stop, mode);
|
|
4220
|
+
if (!prim)
|
|
4221
|
+
return null;
|
|
4222
|
+
const c = peek(P.L);
|
|
4223
|
+
const c1 = peek(P.L, 1);
|
|
4224
|
+
if ((c === '+' && c1 === '+') || (c === '-' && c1 === '-')) {
|
|
4225
|
+
const s = P.L.b;
|
|
4226
|
+
advance(P.L);
|
|
4227
|
+
advance(P.L);
|
|
4228
|
+
const op = mk(P, c + c1, s, P.L.b, []);
|
|
4229
|
+
return mk(P, 'postfix_expression', prim.startIndex, op.endIndex, [prim, op]);
|
|
4230
|
+
}
|
|
4231
|
+
return prim;
|
|
4232
|
+
}
|
|
4233
|
+
function parseArithPrimary(P, stop, mode) {
|
|
4234
|
+
skipBlanks(P.L);
|
|
4235
|
+
if (isArithStop(P, stop))
|
|
4236
|
+
return null;
|
|
4237
|
+
const c = peek(P.L);
|
|
4238
|
+
if (c === '(') {
|
|
4239
|
+
const s = P.L.b;
|
|
4240
|
+
advance(P.L);
|
|
4241
|
+
const open = mk(P, '(', s, P.L.b, []);
|
|
4242
|
+
// Parenthesized expression may contain comma-separated exprs
|
|
4243
|
+
const inners = parseArithCommaList(P, ')', mode);
|
|
4244
|
+
skipBlanks(P.L);
|
|
4245
|
+
let close;
|
|
4246
|
+
if (peek(P.L) === ')') {
|
|
4247
|
+
const cs = P.L.b;
|
|
4248
|
+
advance(P.L);
|
|
4249
|
+
close = mk(P, ')', cs, P.L.b, []);
|
|
4250
|
+
}
|
|
4251
|
+
else {
|
|
4252
|
+
close = mk(P, ')', P.L.b, P.L.b, []);
|
|
4253
|
+
}
|
|
4254
|
+
return mk(P, 'parenthesized_expression', open.startIndex, close.endIndex, [
|
|
4255
|
+
open,
|
|
4256
|
+
...inners,
|
|
4257
|
+
close,
|
|
4258
|
+
]);
|
|
4259
|
+
}
|
|
4260
|
+
if (c === '"') {
|
|
4261
|
+
return parseDoubleQuoted(P);
|
|
4262
|
+
}
|
|
4263
|
+
if (c === '$') {
|
|
4264
|
+
return parseDollarLike(P);
|
|
4265
|
+
}
|
|
4266
|
+
if (isDigit(c)) {
|
|
4267
|
+
const s = P.L.b;
|
|
4268
|
+
while (isDigit(peek(P.L)))
|
|
4269
|
+
advance(P.L);
|
|
4270
|
+
// Hex: 0x1f
|
|
4271
|
+
if (P.L.b - s === 1 &&
|
|
4272
|
+
c === '0' &&
|
|
4273
|
+
(peek(P.L) === 'x' || peek(P.L) === 'X')) {
|
|
4274
|
+
advance(P.L);
|
|
4275
|
+
while (isHexDigit(peek(P.L)))
|
|
4276
|
+
advance(P.L);
|
|
4277
|
+
}
|
|
4278
|
+
// Base notation: BASE#DIGITS e.g. 2#1010, 16#ff
|
|
4279
|
+
else if (peek(P.L) === '#') {
|
|
4280
|
+
advance(P.L);
|
|
4281
|
+
while (isBaseDigit(peek(P.L)))
|
|
4282
|
+
advance(P.L);
|
|
4283
|
+
}
|
|
4284
|
+
return mk(P, 'number', s, P.L.b, []);
|
|
4285
|
+
}
|
|
4286
|
+
if (isIdentStart(c)) {
|
|
4287
|
+
const s = P.L.b;
|
|
4288
|
+
while (isIdentChar(peek(P.L)))
|
|
4289
|
+
advance(P.L);
|
|
4290
|
+
const nc = peek(P.L);
|
|
4291
|
+
// Assignment in 'assign' mode (c-style for init): emit variable_assignment
|
|
4292
|
+
// so chained `a = b = c = 1` nests correctly. Other modes treat `=` as a
|
|
4293
|
+
// binary_expression operator via the precedence table.
|
|
4294
|
+
if (mode === 'assign') {
|
|
4295
|
+
skipBlanks(P.L);
|
|
4296
|
+
const ac = peek(P.L);
|
|
4297
|
+
const ac1 = peek(P.L, 1);
|
|
4298
|
+
if (ac === '=' && ac1 !== '=') {
|
|
4299
|
+
const vn = mk(P, 'variable_name', s, P.L.b, []);
|
|
4300
|
+
const es = P.L.b;
|
|
4301
|
+
advance(P.L);
|
|
4302
|
+
const eq = mk(P, '=', es, P.L.b, []);
|
|
4303
|
+
// RHS may itself be another assignment (chained)
|
|
4304
|
+
const val = parseArithTernary(P, stop, mode);
|
|
4305
|
+
const end = val ? val.endIndex : eq.endIndex;
|
|
4306
|
+
const kids = val ? [vn, eq, val] : [vn, eq];
|
|
4307
|
+
return mk(P, 'variable_assignment', s, end, kids);
|
|
4308
|
+
}
|
|
4309
|
+
}
|
|
4310
|
+
// Subscript
|
|
4311
|
+
if (nc === '[') {
|
|
4312
|
+
const vn = mk(P, 'variable_name', s, P.L.b, []);
|
|
4313
|
+
const brS = P.L.b;
|
|
4314
|
+
advance(P.L);
|
|
4315
|
+
const brOpen = mk(P, '[', brS, P.L.b, []);
|
|
4316
|
+
const idx = parseArithTernary(P, ']', 'var') ?? parseDollarLike(P);
|
|
4317
|
+
skipBlanks(P.L);
|
|
4318
|
+
let brClose;
|
|
4319
|
+
if (peek(P.L) === ']') {
|
|
4320
|
+
const cs = P.L.b;
|
|
4321
|
+
advance(P.L);
|
|
4322
|
+
brClose = mk(P, ']', cs, P.L.b, []);
|
|
4323
|
+
}
|
|
4324
|
+
else {
|
|
4325
|
+
brClose = mk(P, ']', P.L.b, P.L.b, []);
|
|
4326
|
+
}
|
|
4327
|
+
const kids = idx ? [vn, brOpen, idx, brClose] : [vn, brOpen, brClose];
|
|
4328
|
+
return mk(P, 'subscript', s, brClose.endIndex, kids);
|
|
4329
|
+
}
|
|
4330
|
+
// Bare identifier: variable_name in 'var' mode, word in 'word'/'assign' mode.
|
|
4331
|
+
// 'assign' mode falls through to word when no `=` follows (c-style for
|
|
4332
|
+
// cond/update clauses: `c<=5` → binary_expression(word, number)).
|
|
4333
|
+
const identType = mode === 'var' ? 'variable_name' : 'word';
|
|
4334
|
+
return mk(P, identType, s, P.L.b, []);
|
|
4335
|
+
}
|
|
4336
|
+
return null;
|
|
4337
|
+
}
|
|
4338
|
+
function isArithStop(P, stop) {
|
|
4339
|
+
const c = peek(P.L);
|
|
4340
|
+
if (stop === '))')
|
|
4341
|
+
return c === ')' && peek(P.L, 1) === ')';
|
|
4342
|
+
if (stop === ')')
|
|
4343
|
+
return c === ')';
|
|
4344
|
+
if (stop === ';')
|
|
4345
|
+
return c === ';';
|
|
4346
|
+
if (stop === ':')
|
|
4347
|
+
return c === ':';
|
|
4348
|
+
if (stop === ']')
|
|
4349
|
+
return c === ']';
|
|
4350
|
+
if (stop === '}')
|
|
4351
|
+
return c === '}';
|
|
4352
|
+
if (stop === ':}')
|
|
4353
|
+
return c === ':' || c === '}';
|
|
4354
|
+
return c === '' || c === '\n';
|
|
4355
|
+
}
|