├── .github ├── CONTRIBUTING.md ├── ISSUE_TEMPLATE.md ├── ISSUE_TEMPLATE │ ├── bug_report.md │ ├── custom.md │ └── feature_request.md ├── PULL_REQUEST_TEMPLATE.md └── workflows │ └── node.js.yml ├── .gitignore ├── .gitmodules ├── .prettierrc ├── .vscode ├── launch.json ├── settings.json └── tasks.json ├── .vscodeignore ├── CHANGELOG.md ├── LICENSE ├── README.md ├── Resources.md ├── build └── clean.js ├── clients └── vscode │ ├── README.md │ ├── fileicons │ └── kos-file-icon.json │ ├── images │ ├── kos-file-icon.svg │ └── kos_extension_logo.png │ ├── package-lock.json │ ├── package.json │ ├── snippets │ └── snippets.json │ ├── src │ ├── commands │ │ ├── channelRouterProvider.ts │ │ ├── commandUtilities.ts │ │ ├── kspProvider.ts │ │ ├── searchDocumentationProvider.ts │ │ ├── telnetProvider.ts │ │ ├── terminalUtilities.ts │ │ └── types.ts │ ├── extension.ts │ └── spinner.ts │ ├── tsconfig.json │ ├── types │ └── telnet-client.d.ts │ └── webpack.config.js ├── iconSupport.json ├── kerboscripts ├── .vscode │ └── settings.json ├── parser_invalid │ └── parameters │ │ ├── paramtest6_error.ks │ │ └── paramtest7_error.ks └── parser_valid │ ├── Good Files │ ├── Errors and UI │ │ ├── WIP │ │ │ ├── alarm.ks │ │ │ ├── launch.ks │ │ │ └── readout.ks │ │ ├── error0_100.ks │ │ ├── errorlist │ │ │ ├── error0_100.ks │ │ │ ├── errorlistexe.ks │ │ │ ├── lib_menu.ks │ │ │ ├── lib_menulist1.ks │ │ │ ├── lib_menutest.ks │ │ │ ├── lib_ui.ks │ │ │ └── test.ks │ │ ├── errorlistexe.ks │ │ ├── lib_menu.ks │ │ ├── lib_menulist1.ks │ │ ├── lib_menutest.ks │ │ └── lib_ui.ks │ ├── Impact │ │ ├── b.ks │ │ ├── bodylanding.ks │ │ ├── fancytti.ks │ │ ├── newtti.ks │ │ └── tti.KS │ ├── Libs │ │ ├── lib_dvcalc.ks │ │ ├── lib_filecopy.ks │ │ ├── lib_inclination.ks │ │ ├── lib_mancalc.ks │ │ ├── lib_rendezvous │ │ │ ├── completerendezvous.ks │ │ │ ├── old working stuff │ │ │ │ ├── finmain.ks │ │ │ │ ├── finsub.ks │ │ │ │ ├── inclmain.ks │ │ │ │ ├── inclstart.ks │ │ │ │ ├── inclsub.ks │ │ │ │ ├── protodock.ks │ │ │ │ ├── protodock1.ks │ │ │ │ ├── rendmain.ks │ │ │ │ ├── rendprec.ks │ │ │ │ └── replay.ks │ │ │ └── rend_functions.ks │ │ ├── lib_science.ks │ │ ├── lib_stage.ks │ │ ├── lib_steering.ks │ │ └── lib_true_anomaly.ks │ ├── Other │ │ ├── function.ks │ │ ├── orbitpopper.ks │ │ └── orbitstopper.ks │ ├── PID │ │ ├── pid1.ks │ │ ├── pid2.ks │ │ └── pidplus.ks │ ├── lib_docking.ks │ └── lib_runmodes.ks │ ├── Reusable Booster │ ├── boostback.ks │ ├── boot │ │ ├── boostback_boot.ks │ │ ├── boot_constructor.ks │ │ ├── payload.ks │ │ └── refuel_truck.ks │ ├── cam.ks │ ├── circ.ks │ ├── constructor │ ├── cpu_light.ks │ ├── exec.ks │ ├── launch.ks │ ├── lib_UI.ks │ ├── lib_list.ks │ ├── lib_menu.ks │ ├── lib_rocket_utility.ks │ └── refuel_truck.ks │ ├── addons │ └── trajectories │ │ ├── traj1.ks │ │ └── traj2.ks │ ├── ap.ks │ ├── autopilot.ks │ ├── boostback.ks │ ├── boot │ ├── boostback_boot.ks │ ├── boot_drone.ks │ ├── boot_plane.ks │ ├── boot_propeller.ks │ ├── boot_qShip.ks │ ├── boot_updater.ks │ ├── bootup_toukie.ks │ ├── junkboot.ks │ └── station.ks │ ├── boot_drone.ks │ ├── cam.ks │ ├── circ.ks │ ├── comms.ks │ ├── compile │ ├── compiletest1.ks │ ├── compiletest2.ks │ ├── compiletest3.ks │ └── testrunonce │ │ ├── testrunonce_lib1.ks │ │ ├── testrunonce_lib2.ks │ │ ├── testrunonce_p1.ks │ │ ├── testrunonce_p2.ks │ │ └── testrunonce_p3.ks │ ├── cooked_steering │ └── testwheelsteertypes1.ks │ ├── cpu_light.ks │ ├── cq.ks │ ├── debug.ks │ ├── delegates │ ├── delegatetest1.ks │ ├── delegatetest2.ks │ ├── delegatetest3.ks │ ├── delegatetest3_lib.ks │ ├── delegatetest4.ks │ ├── delegatetest5.ks │ ├── delegatetest6.ks │ └── delegatetest7.ks │ ├── demo │ ├── testrefvec.ks │ └── testskid.ks │ ├── dependencyTest │ ├── exec.ks │ └── lib.ks │ ├── dock.ks │ ├── drone_ship.ks │ ├── exe_toukie │ ├── gapapov.ks │ ├── mission_getter.ks │ └── missionscript.ks │ ├── exec.ks │ ├── funcParameterTest.ks │ ├── functest28.ks │ ├── functest29.ks │ ├── functest30.ks │ ├── functest30_inner.ks │ ├── functest31.ks │ ├── gui │ ├── gui_callback_1.ks │ └── gui_callback_2.ks │ ├── gui_template.ks │ ├── input │ └── terminal1.ks │ ├── integration │ ├── basic.ks │ ├── func.ks │ ├── func_args.ks │ ├── lock.ks │ ├── operators.ks │ ├── suffixes.ks │ └── vars.ks │ ├── ksconfig.json │ ├── launch.ks │ ├── lib │ ├── lib_physics.ks │ ├── lib_pid.ks │ └── testlibpid.ks │ ├── lib_UI.ks │ ├── lib_formation.ks │ ├── lib_geo.ks │ ├── lib_json.ks │ ├── lib_list.ks │ ├── lib_menu.ks │ ├── lib_quad.ks │ ├── lib_rocket_utility.ks │ ├── lib_toukie │ ├── Commented Files │ │ └── gapapov_remastered.ks │ ├── lib_atmos_launch.ks │ ├── lib_closest_approach.ks │ ├── lib_docking.ks │ ├── lib_gapapov_main.ks │ ├── lib_gui.ks │ ├── lib_gui_file_picker.ks │ ├── lib_hillclimb_man_exe.ks │ ├── lib_hillclimb_scoring.ks │ ├── lib_hillclimb_universal.ks │ ├── lib_inclination.ks │ ├── lib_other.ks │ ├── lib_phase_angle.ks │ ├── lib_readout.ks │ ├── lib_rendezvous.ks │ ├── lib_space_check.ks │ ├── lib_stage.ks │ ├── lib_steering.ks │ ├── lib_transfer.ks │ ├── lib_transfer_burns.ks │ ├── lib_true_anomaly.ks │ └── lib_warp.ks │ ├── linetest.ks │ ├── list │ └── testlist.ks │ ├── loop │ ├── fromthrottletest.ks │ ├── looptest1.ks │ ├── looptest2.ks │ └── looptest3.ks │ ├── menutest.ks │ ├── missions_toukie │ └── Gaia 01.ks │ ├── parameters │ ├── paramtest1.ks │ ├── paramtest2.ks │ ├── paramtest3.ks │ ├── paramtest4.ks │ ├── paramtest4_lib.ks │ ├── paramtest5.ks │ ├── paramtest6.ks │ └── paramtest7.ks │ ├── q.ks │ ├── quad.ks │ ├── quad_GUI.ks │ ├── quad_loop.ks │ ├── race.ks │ ├── resource_transfer │ ├── testtransfer1.ks │ ├── testtransfer2.ks │ └── testtransfer3.ks │ ├── rs.ks │ ├── serialization │ ├── lexicon.ks │ ├── list.ks │ ├── misc.ks │ ├── queue.ks │ ├── range.ks │ ├── stack.ks │ └── uniqueset.ks │ ├── steeringeditor.ks │ ├── steeringmanager.ks │ ├── string │ └── stringtester.ks │ ├── test_error.ks │ ├── triggers │ ├── testtrigger1.ks │ ├── testtrigger2.ks │ ├── testtrigger3.ks │ ├── testtrigger4.ks │ ├── testtrigger5.ks │ ├── testtrigger6.ks │ └── testtrigger7.ks │ ├── turret.ks │ ├── unitTests │ ├── allLanguage.ks │ ├── analysis │ │ └── test.ks │ ├── breaktest.ks │ ├── deferredtest.ks │ ├── definedtest.ks │ ├── dualTable.ks │ ├── loadFiles │ │ ├── empty │ │ │ └── empty.ks │ │ ├── example.ks │ │ ├── ksconfig.json │ │ └── other.js │ ├── preservetest.ks │ ├── returntest.ks │ ├── scannertest.ks │ ├── shadow │ │ ├── shadowLib.ks │ │ ├── shadowSrc.ks │ │ └── shadowtest.ks │ └── usedtest.ks │ └── user_functions │ ├── functest1.ks │ ├── functest10.ks │ ├── functest10_inner.ks │ ├── functest11.ks │ ├── functest12.ks │ ├── functest13.ks │ ├── functest14.ks │ ├── functest15.ks │ ├── functest16.ks │ ├── functest17.ks │ ├── functest18.ks │ ├── functest19.ks │ ├── functest2.ks │ ├── functest20.ks │ ├── functest21-inner.ks │ ├── functest21.ks │ ├── functest21_inner.ks │ ├── functest22.ks │ ├── functest23.ks │ ├── functest24.ks │ ├── functest25.ks │ ├── functest26.ks │ ├── functest27.ks │ ├── functest27_b.ks │ ├── functest28.ks │ ├── functest29.ks │ ├── functest29_lib.ks │ ├── functest3.ks │ ├── functest30.ks │ ├── functest30_lib.ks │ ├── functest32.ks │ ├── functest33.ks │ ├── functest4.ks │ ├── functest5.ks │ ├── functest6.ks │ ├── functest7.ks │ ├── functest8.ks │ ├── functest9.ks │ ├── test1.ks │ ├── test2.ks │ ├── testanonymousfunc1.ks │ ├── testclosure1.ks │ ├── testclosure2.ks │ ├── testclosure3.ks │ ├── testreturn1.ks │ └── testreturn2.ks ├── kos.configuration.json ├── package-lock.json ├── package.json ├── server ├── .npmignore ├── .vscode │ └── settings.json ├── README.md ├── benchmark.data.json ├── benchmark │ ├── controlFlow.benchmark.ts │ ├── old │ │ ├── array.benchmark2.ts │ │ ├── full.benchmark2.ts │ │ ├── parser.benchmark2.ts │ │ └── scanner2.benchmark2.ts │ ├── parser.benchmark.ts │ ├── resolver.benchmark.ts │ ├── scanner.benchmark.ts │ └── typeChecker.benchmark.ts ├── bin │ └── kos ├── jest.config.js ├── ksconfig.md ├── package-lock.json ├── package.json ├── src │ ├── @types │ │ └── jstats.d.ts │ ├── analysis │ │ ├── functionScan.ts │ │ ├── localResolver.ts │ │ ├── models │ │ │ ├── environment.ts │ │ │ ├── scopePosition.ts │ │ │ ├── setResult.ts │ │ │ ├── symbolTable.ts │ │ │ ├── symbolTableBuilder.ts │ │ │ ├── tracker.ts │ │ │ └── typeTracker.ts │ │ ├── preResolver.ts │ │ ├── resolver.ts │ │ ├── setResolver.ts │ │ ├── standardLibrary.ts │ │ └── types.ts │ ├── config │ │ ├── lintManager.ts │ │ ├── models │ │ │ ├── lintRules.ts │ │ │ ├── serverConfiguration.ts │ │ │ └── workspaceConfiguration.ts │ │ └── workspaceConfigParser.ts │ ├── controlFlow │ │ ├── controlFlow.ts │ │ ├── flowGraph.ts │ │ ├── models │ │ │ ├── basicBlock.ts │ │ │ ├── branchJump.ts │ │ │ └── narrowing.ts │ │ └── types.ts │ ├── directives │ │ ├── basicDirectives.ts │ │ ├── directiveContainer.ts │ │ ├── directiveParser.ts │ │ ├── include.ts │ │ ├── types.ts │ │ └── utils.ts │ ├── generator │ │ ├── generator.ts │ │ ├── testRun.ts │ │ └── types.ts │ ├── kls.ts │ ├── models │ │ ├── function.ts │ │ ├── graph.ts │ │ ├── grouping.ts │ │ ├── lock.ts │ │ ├── logger.ts │ │ ├── parameter.ts │ │ ├── scc.ts │ │ ├── script.ts │ │ ├── suffix.ts │ │ ├── token.ts │ │ ├── tokentypes.ts │ │ ├── types.ts │ │ └── variable.ts │ ├── parser │ │ ├── lang_spec.txt │ │ ├── models │ │ │ ├── base.ts │ │ │ ├── declare.ts │ │ │ ├── expr.ts │ │ │ ├── parserError.ts │ │ │ ├── stmt.ts │ │ │ └── suffixTerm.ts │ │ ├── parser.ts │ │ ├── scriptFind.ts │ │ ├── tokenCheck.ts │ │ ├── types.ts │ │ └── utils │ │ │ ├── grammarNodes.ts │ │ │ ├── parseResult.ts │ │ │ └── toStringUtils.ts │ ├── scanner │ │ ├── models │ │ │ └── marker.ts │ │ ├── scanner.ts │ │ └── types.ts │ ├── server.ts │ ├── services │ │ ├── analysisService.ts │ │ ├── configurationService.ts │ │ ├── documentService.ts │ │ ├── foldableService.ts │ │ ├── ioService.ts │ │ ├── resolverService.ts │ │ └── symbolService.ts │ ├── typeChecker │ │ ├── binders │ │ │ ├── binder.ts │ │ │ ├── callBinder.ts │ │ │ ├── indexerBinder.ts │ │ │ └── typeBinder.ts │ │ ├── initialize.ts │ │ ├── ksTypes │ │ │ ├── addon │ │ │ │ ├── addon.ts │ │ │ │ └── addonList.ts │ │ │ ├── bodyatmosphere.ts │ │ │ ├── career.ts │ │ │ ├── collections │ │ │ │ ├── direction.ts │ │ │ │ ├── enumerable.ts │ │ │ │ ├── enumerator.ts │ │ │ │ ├── initialize.ts │ │ │ │ ├── lexicon.ts │ │ │ │ ├── list.ts │ │ │ │ ├── queue.ts │ │ │ │ ├── range.ts │ │ │ │ ├── stack.ts │ │ │ │ ├── uniqueset.ts │ │ │ │ ├── userList.ts │ │ │ │ └── vector.ts │ │ │ ├── communication │ │ │ │ ├── connection.ts │ │ │ │ ├── controlConnection.ts │ │ │ │ ├── homeConnection.ts │ │ │ │ ├── message.ts │ │ │ │ ├── messageQueue.ts │ │ │ │ ├── processorConnection.ts │ │ │ │ └── vesselConnection.ts │ │ │ ├── config.ts │ │ │ ├── constant.ts │ │ │ ├── core.ts │ │ │ ├── craftTemplate.ts │ │ │ ├── crew.ts │ │ │ ├── deltaV.ts │ │ │ ├── flightControl.ts │ │ │ ├── geoCoordinates.ts │ │ │ ├── gui │ │ │ │ ├── box.ts │ │ │ │ ├── elements │ │ │ │ │ ├── button.ts │ │ │ │ │ ├── label.ts │ │ │ │ │ ├── popupMenu.ts │ │ │ │ │ ├── slider.ts │ │ │ │ │ └── textField.ts │ │ │ │ ├── guiWidget.ts │ │ │ │ ├── initialize.ts │ │ │ │ ├── scrollBox.ts │ │ │ │ ├── spacing.ts │ │ │ │ ├── widget.ts │ │ │ │ ├── widgetSkin.ts │ │ │ │ ├── widgetStyle.ts │ │ │ │ ├── widgetStyleRectOffset.ts │ │ │ │ └── widgetStyleState.ts │ │ │ ├── highlight.ts │ │ │ ├── hsva.ts │ │ │ ├── io │ │ │ │ ├── fileContent.ts │ │ │ │ ├── path.ts │ │ │ │ ├── volume.ts │ │ │ │ ├── volumeDirectory.ts │ │ │ │ ├── volumeItem.ts │ │ │ │ └── volumneFile.ts │ │ │ ├── kUniverse.ts │ │ │ ├── kacAlarmWrapper.ts │ │ │ ├── kosProcessorFields.ts │ │ │ ├── loadDistance.ts │ │ │ ├── node.ts │ │ │ ├── note.ts │ │ │ ├── orbitEta.ts │ │ │ ├── orbitInfo.ts │ │ │ ├── orbital │ │ │ │ ├── bodyTarget.ts │ │ │ │ ├── initialize.ts │ │ │ │ ├── orbitable.ts │ │ │ │ └── vesselTarget.ts │ │ │ ├── orbitalVelocity.ts │ │ │ ├── parts │ │ │ │ ├── activeResource.ts │ │ │ │ ├── aggregateResource.ts │ │ │ │ ├── bounds.ts │ │ │ │ ├── consumedResource.ts │ │ │ │ ├── consumedResourceRcs.ts │ │ │ │ ├── decoupler.ts │ │ │ │ ├── dockingPort.ts │ │ │ │ ├── element.ts │ │ │ │ ├── engine.ts │ │ │ │ ├── gimbal.ts │ │ │ │ ├── initialize.ts │ │ │ │ ├── part.ts │ │ │ │ ├── partModule.ts │ │ │ │ ├── rcs.ts │ │ │ │ ├── resource.ts │ │ │ │ ├── scienceContainerModule.ts │ │ │ │ ├── scienceExperimentModule.ts │ │ │ │ └── separator.ts │ │ │ ├── pidLoop.ts │ │ │ ├── primitives │ │ │ │ ├── boolean.ts │ │ │ │ ├── builtInDelegate.ts │ │ │ │ ├── delegate.ts │ │ │ │ ├── initialize.ts │ │ │ │ ├── none.ts │ │ │ │ ├── primitives.ts │ │ │ │ ├── scalar.ts │ │ │ │ ├── serializeableStructure.ts │ │ │ │ ├── string.ts │ │ │ │ └── structure.ts │ │ │ ├── resourceTransfer.ts │ │ │ ├── rgba.ts │ │ │ ├── scienceData.ts │ │ │ ├── situtationLoadDistance.ts │ │ │ ├── steeringManager.ts │ │ │ ├── terminalInput.ts │ │ │ ├── terminalStruct.ts │ │ │ ├── time │ │ │ │ ├── initalize.ts │ │ │ │ ├── timebase.ts.ts │ │ │ │ ├── timespan.ts │ │ │ │ └── timestamp.ts │ │ │ ├── timewarp.ts │ │ │ ├── userDelegate.ts │ │ │ ├── vectorRenderer.ts │ │ │ ├── versionInfo.ts │ │ │ ├── vessel │ │ │ │ ├── stage.ts │ │ │ │ ├── vesselAlt.ts │ │ │ │ ├── vesselEta.ts │ │ │ │ └── vesselSensors.ts │ │ │ ├── voice.ts │ │ │ └── waypoint.ts │ │ ├── models │ │ │ ├── parametricTypes │ │ │ │ ├── parametricCallSignature.ts │ │ │ │ ├── parametricIndexer.ts │ │ │ │ └── parametricType.ts │ │ │ ├── suffixTypeNode.ts │ │ │ ├── typeNode.ts │ │ │ └── types │ │ │ │ ├── callSignature.ts │ │ │ │ ├── constantType.ts │ │ │ │ ├── delegateType.ts │ │ │ │ ├── indexer.ts │ │ │ │ ├── operator.ts │ │ │ │ ├── type.ts │ │ │ │ ├── unionType.ts │ │ │ │ └── variadicType.ts │ │ ├── typeChecker.ts │ │ ├── types.ts │ │ └── utilities │ │ │ ├── typeCreators.ts │ │ │ ├── typeHelpers.ts │ │ │ └── typeUtilities.ts │ ├── types.ts │ └── utilities │ │ ├── arrayUtils.ts │ │ ├── clean.ts │ │ ├── constants.ts │ │ ├── debounce.ts │ │ ├── diagnosticsUtils.ts │ │ ├── entityUtils.ts │ │ ├── fsUtils.ts │ │ ├── graphUtils.ts │ │ ├── levenshtein.ts │ │ ├── mapper.ts │ │ ├── memoize.ts │ │ ├── pathUtils.ts │ │ ├── positionUtils.ts │ │ ├── randomUtils.ts │ │ ├── serverUtils.ts │ │ ├── stringUtils.ts │ │ ├── treeExecute.ts │ │ ├── treeTraverse.ts │ │ ├── typeGuards.ts │ │ └── types.ts ├── test │ ├── analysis │ │ ├── functionScan.spec.ts │ │ ├── localResolver.spec.ts │ │ ├── resolver.spec.ts │ │ ├── setResolver.spec.ts │ │ └── symbols.spec.ts │ ├── config │ │ ├── lintManger.spec.ts │ │ ├── models │ │ │ ├── serverConfiguration.spec.ts │ │ │ └── workspaceConfiguration.spec.ts │ │ └── workspaceConfigParser.spec.ts │ ├── controlFlow │ │ └── controlFlow.spec.ts │ ├── directives │ │ ├── directiveParser.spec.ts │ │ └── include.spec.ts │ ├── parser.spec.ts │ ├── scanner.spec.ts │ ├── services │ │ ├── analysisService.spec.ts │ │ ├── configurationService.spec.ts │ │ ├── documentService.spec.ts │ │ ├── foldableService.spec.ts │ │ ├── ioService.spec.ts │ │ ├── resolverService.spec.ts │ │ └── symbolService.spec.ts │ ├── typeChecking │ │ ├── typeChecking.spec.ts │ │ └── types.spec.ts │ ├── utilities │ │ ├── factories.ts │ │ ├── levenshteinDistance.spec.ts │ │ ├── mockServices.ts │ │ └── setup.ts │ └── utilitites.spec.ts ├── tsconfig.json ├── webpack.config.js └── zakzak.config.json └── tsconfig.base.json /.github/CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Example Contributing Guidelines 2 | 3 | This is an example of GitHub's contributing guidelines file. Check out GitHub's [CONTRIBUTING.md help center article](https://help.github.com/articles/setting-guidelines-for-repository-contributors/) for more information. 4 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | * **I'm submitting a ...** 2 | [ ] bug report 3 | [ ] feature request 4 | [ ] question about the decisions made in the repository 5 | [ ] question about how to use this project 6 | 7 | * **Summary** 8 | 9 | 10 | 11 | * **Other information** (e.g. detailed explanation, stacktraces, related issues, suggestions how to fix, links for us to have context, eg. StackOverflow, personal fork, etc.) 12 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve 4 | title: "[BUG] " 5 | labels: '' 6 | assignees: jonnyboyC 7 | 8 | --- 9 | 10 | **Describe the bug** 11 | A clear and concise description of what the bug is. 12 | 13 | **To Reproduce** 14 | Steps to reproduce the behavior: 15 | 1. Go to '...' 16 | 2. Click on '....' 17 | 3. Scroll down to '....' 18 | 4. See error 19 | 20 | **Expected behavior** 21 | A clear and concise description of what you expected to happen. 22 | 23 | **Screenshots** 24 | If applicable, add screenshots to help explain your problem. 25 | 26 | **Editor (please complete the following information):** 27 | - OS: [e.g. Window, Linux, Mac] 28 | - Editor [e.g. vscode atom] 29 | - Extension Version [e.g. 22] 30 | 31 | **Additional context** 32 | Add any other context about the problem here. 33 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/custom.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Custom issue template 3 | about: Describe this issue template's purpose here. 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | 11 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for this project 4 | title: "[Feature] " 5 | labels: enhancement 6 | assignees: jonnyboyC 7 | 8 | --- 9 | 10 | **Is your feature request related to a problem? Please describe.** 11 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] 12 | 13 | **Describe the solution you'd like** 14 | A clear and concise description of what you want to happen. 15 | 16 | **Describe alternatives you've considered** 17 | A clear and concise description of any alternative solutions or features you've considered. 18 | 19 | **Additional context** 20 | Add any other context or screenshots about the feature request here. 21 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | * **What kind of change does this PR introduce?** (Bug fix, feature, docs update, ...) 2 | 3 | 4 | 5 | * **What is the current behavior?** (You can also link to an open issue here) 6 | 7 | 8 | 9 | * **What is the new behavior (if this is a feature change)?** 10 | 11 | 12 | 13 | * **Other information**: 14 | -------------------------------------------------------------------------------- /.github/workflows/node.js.yml: -------------------------------------------------------------------------------- 1 | # This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node 2 | # For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-nodejs 3 | 4 | name: Node.js CI 5 | 6 | on: 7 | pull_request: 8 | branches: ['main'] 9 | 10 | jobs: 11 | build: 12 | runs-on: ubuntu-latest 13 | 14 | steps: 15 | - uses: actions/checkout@v4 16 | - name: Use Node.js 20.x 17 | uses: actions/setup-node@v4 18 | with: 19 | node-version: 20.x 20 | cache: 'npm' 21 | - run: npm ci 22 | - run: npm run bundle 23 | 24 | test: 25 | runs-on: ubuntu-latest 26 | 27 | steps: 28 | - uses: actions/checkout@v4 29 | - name: Use Node.js 20.x 30 | uses: actions/setup-node@v4 31 | with: 32 | node-version: 20.x 33 | cache: 'npm' 34 | - run: npm ci 35 | - run: npm run test 36 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | out 3 | dist 4 | server/build/* 5 | .idea/* 6 | *.vsix 7 | 8 | coverage 9 | 10 | junit.xml -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "clients/vscode/kos-grammar"] 2 | path = clients/vscode/kos-grammar 3 | url = https://github.com/jonnyboyC/kos-grammar.git 4 | branch = master 5 | -------------------------------------------------------------------------------- /.prettierrc: -------------------------------------------------------------------------------- 1 | { 2 | "trailingComma": "all", 3 | "tabWidth": 2, 4 | "semi": true, 5 | "singleQuote": true 6 | } -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "files.exclude": { 3 | "server/out": false, // set this to true to hide the "out" folder with the compiled JS files 4 | "server/dist": false, 5 | }, 6 | "search.exclude": { 7 | "server/out": true, // set this to false to include "out" folder in search results 8 | "server/dist": true 9 | }, 10 | "typescript.tsdk": "./node_modules/typescript/lib", 11 | "typescript.tsc.autoDetect": "off", 12 | "npm.exclude": ["**/clients", "**/server"], 13 | "npm.enableScriptExplorer": true, 14 | "breadcrumbs.enabled": true, 15 | } -------------------------------------------------------------------------------- /.vscodeignore: -------------------------------------------------------------------------------- 1 | .vscode/** 2 | **/*.ts 3 | **/*.map 4 | **/*.gitignore 5 | **/tsconfig.json 6 | **/tsconfig.base.json 7 | **/buildcache.json 8 | **/contributing.md 9 | **/junit.xml 10 | kerboscripts 11 | node_modules 12 | build 13 | clients/vscode/src/** 14 | clients/vscode/node_modules/** 15 | clients/atom/** 16 | server/src/** 17 | server/build/** 18 | server/out/** 19 | server/bin/** 20 | server/node_modules/** 21 | server/coverage/** -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 John Chabot 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Resources.md: -------------------------------------------------------------------------------- 1 | [Crafting Interpreters](http://craftinginterpreters.com/) 2 | [Article on Creating an infering type system](https://blog.mgechev.com/2017/08/05/typed-lambda-calculus-create-type-checker-transpiler-compiler-javascript/) 3 | [KOS Github](https://github.com/KSP-KOS/KOS) -------------------------------------------------------------------------------- /build/clean.js: -------------------------------------------------------------------------------- 1 | var fs = require('fs'); 2 | 3 | function deleteFolderRecursive(path) { 4 | if (fs.existsSync(path) && fs.lstatSync(path).isDirectory()) { 5 | fs.readdirSync(path).forEach(function(file, index) { 6 | var curPath = path + '/' + file; 7 | 8 | if (fs.lstatSync(curPath).isDirectory()) { 9 | deleteFolderRecursive(curPath); 10 | } else { 11 | fs.unlinkSync(curPath); 12 | } 13 | }); 14 | 15 | console.log(`Deleting directory "${path}"...`); 16 | fs.rmdirSync(path); 17 | } 18 | } 19 | 20 | console.log('Cleaning working tree...'); 21 | deleteFolderRecursive('./server/out'); 22 | deleteFolderRecursive('./server/dist'); 23 | deleteFolderRecursive('./clients/vscode/out'); 24 | console.log('Successfully cleaned working tree!'); 25 | -------------------------------------------------------------------------------- /clients/vscode/README.md: -------------------------------------------------------------------------------- 1 | # KOS (Kerboscript) Vscode Client 2 | 3 | This is the kos-language-server client for visual studio code. 4 | 5 | In addition to the features provided by the kos-language server this extension adds: 6 | - Syntax Highlighting 7 | - Commands to 8 | - Start KSP 9 | - Start a telnet session 10 | - Search kOS docs 11 | 12 | -------------------------------------------------------------------------------- /clients/vscode/fileicons/kos-file-icon.json: -------------------------------------------------------------------------------- 1 | { 2 | "iconDefinitions": { 3 | "kos_file": { 4 | "iconPath": "./images/kos-file-icon.svg" 5 | } 6 | }, 7 | "fileExtensions": { 8 | "ks": "kos_file" 9 | } 10 | } -------------------------------------------------------------------------------- /clients/vscode/images/kos-file-icon.svg: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | KS 7 | -------------------------------------------------------------------------------- /clients/vscode/images/kos_extension_logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jonnyboyC/kos-language-server/aff3a4743f5492a878cbfb5d2938e2e90f83cb45/clients/vscode/images/kos_extension_logo.png -------------------------------------------------------------------------------- /clients/vscode/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "kos-vscode-client", 3 | "description": "Vscode client for the KOS-language-server", 4 | "author": "John Chabot", 5 | "license": "MIT", 6 | "version": "1.1.7", 7 | "publisher": "JohnChabot", 8 | "repository": { 9 | "type": "git", 10 | "url": "https://github.com/jonnyboyC/kos-language-server" 11 | }, 12 | "engines": { 13 | "vscode": "^1.40.0" 14 | }, 15 | "keywords": [ 16 | "KOS", 17 | "language-server", 18 | "KSP" 19 | ], 20 | "scripts": { 21 | "build": "tsc -p ./tsconfig.json", 22 | "bundle": "webpack --config ./webpack.config.js --mode production" 23 | }, 24 | "dependencies": { 25 | "vscode-languageclient": "^9.0.1", 26 | "ws": "^8.18.0" 27 | }, 28 | "devDependencies": { 29 | "@types/jest": "^29.5.13", 30 | "@types/node": "^22.6.1", 31 | "@types/semver": "^7.5.8", 32 | "@types/ws": "^8.5.12", 33 | "@types/vscode": "1.93.0", 34 | "jest": "^29.7.0", 35 | "jest-junit": "^16.0.0", 36 | "npm-run-all": "^4.1.5", 37 | "ts-jest": "^29.2.5", 38 | "ts-loader": "^9.5.1", 39 | "typescript": "^5.6.2", 40 | "webpack": "^5.94.0", 41 | "webpack-cli": "^5.1.4" 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /clients/vscode/src/commands/kspProvider.ts: -------------------------------------------------------------------------------- 1 | import { IKosCommand } from './types'; 2 | import { platformKsp } from './commandUtilities'; 3 | import { spawn } from 'child_process'; 4 | import { existsSync } from 'fs'; 5 | import { window, workspace } from 'vscode'; 6 | import { resolve } from 'path'; 7 | 8 | export const kspProvider: IKosCommand = { 9 | command: 'kos.startksp', 10 | commandCallback: () => { 11 | // get configuration 12 | const configruation = workspace.getConfiguration('kos-vscode'); 13 | 14 | const configPath = configruation.get('kerbalSpaceProgramPath'); 15 | const path = configPath || platformKsp(); 16 | 17 | console.log(resolve(path)); 18 | 19 | if (existsSync(path)) { 20 | spawn(path, { 21 | detached: true, 22 | stdio: 'ignore', 23 | }).unref(); 24 | } else { 25 | window.showWarningMessage(`Unable to find Kerbal Space Program here ${path}`); 26 | } 27 | }, 28 | }; 29 | -------------------------------------------------------------------------------- /clients/vscode/src/commands/terminalUtilities.ts: -------------------------------------------------------------------------------- 1 | import { window, Terminal } from 'vscode'; 2 | 3 | /** 4 | * Check if any terminals are open 5 | */ 6 | export const isTerminalOpen = (): boolean => { 7 | return window.terminals.length > 0; 8 | }; 9 | 10 | /** 11 | * Create or select a terminal with the provided name 12 | * @param name name of the terminal to select 13 | */ 14 | export const selectOrCreateTerminal = (name: string): Terminal => { 15 | // if we don't have any terimals create and return 16 | if (!isTerminalOpen()) { 17 | return window.createTerminal(name); 18 | } 19 | 20 | // search for our terminal 21 | for (const terminal of window.terminals) { 22 | if (terminal.name === name) { 23 | return terminal; 24 | } 25 | } 26 | 27 | // if not found create 28 | return window.createTerminal(name); 29 | }; 30 | -------------------------------------------------------------------------------- /clients/vscode/src/commands/types.ts: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | * Basic interface replicating the vscode command registration 4 | */ 5 | export interface IKosCommand { 6 | /** 7 | * Name of the command 8 | */ 9 | command: string; 10 | 11 | /** 12 | * Callback to be called when command is invoked 13 | */ 14 | commandCallback: (...args: any[]) => any; 15 | } 16 | -------------------------------------------------------------------------------- /clients/vscode/src/spinner.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * A class representing a unicode spinner 3 | */ 4 | export class Spinner { 5 | /** 6 | * character frames of the spinner 7 | */ 8 | private readonly frames = ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏']; 9 | 10 | /** 11 | * Current frame 12 | */ 13 | private interval = 0; 14 | 15 | /** 16 | * Return a frame of the spinner and increment the frame 17 | */ 18 | public spin(): string { 19 | return this.frames[(this.interval = ++this.interval % this.frames.length)]; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /clients/vscode/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.base.json", 3 | "compilerOptions": { 4 | "baseUrl": ".", 5 | "module": "commonjs", 6 | "target": "es6", 7 | "outDir": "out", 8 | "rootDir": "src", 9 | "lib": ["es6", "dom"], 10 | "esModuleInterop": true, 11 | "sourceMap": true, 12 | "noEmit": false, 13 | "incremental": false 14 | // "tsBuildInfoFile": "./out/buildcache.json", 15 | }, 16 | "include": [ 17 | "src" 18 | ], 19 | "exclude": [ 20 | "node_modules", 21 | ], 22 | } 23 | -------------------------------------------------------------------------------- /iconSupport.json: -------------------------------------------------------------------------------- 1 | { 2 | "iconThemes": [ 3 | { 4 | "id": "kos-file-icon", 5 | "label": "KOS File Icon", 6 | "path": "./fileicons/kos-file-icon.json" 7 | } 8 | ] 9 | } -------------------------------------------------------------------------------- /kerboscripts/.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "kos-vscode.trace.server.verbosity": "message", 3 | "kos-vscode.trace.server.format": "text", 4 | "kos-vscode.trace.server.level": "info", 5 | "kos-vscode.lspPort": 7000, 6 | "lspInspector.port": 7000, 7 | "kos-vscode.telnetPort": 5415, 8 | "kos-vscode.completionCase": "camelcase", 9 | // "kos-vscode.trace.server.level": "info" 10 | } -------------------------------------------------------------------------------- /kerboscripts/parser_invalid/parameters/paramtest6_error.ks: -------------------------------------------------------------------------------- 1 | 2 | parameter mandatory1, default1 is 0, mandatory2. 3 | 4 | print "will never get this far - will break on compile". 5 | -------------------------------------------------------------------------------- /kerboscripts/parser_invalid/parameters/paramtest7_error.ks: -------------------------------------------------------------------------------- 1 | function will_fail_compile { 2 | parameter p1 is 0. 3 | parameter p2. // not defaulted - is an error. 4 | } 5 | -------------------------------------------------------------------------------- /kerboscripts/parser_valid/Good Files/Errors and UI/errorlist/errorlistexe.ks: -------------------------------------------------------------------------------- 1 | copypath("0:/lib/errorlist/error0_100", ""). 2 | run error0_100. 3 | -------------------------------------------------------------------------------- /kerboscripts/parser_valid/Good Files/Errors and UI/errorlistexe.ks: -------------------------------------------------------------------------------- 1 | copypath("0:/lib/errorlist/error0_100", ""). 2 | run error0_100. 3 | -------------------------------------------------------------------------------- /kerboscripts/parser_valid/Good Files/Libs/lib_filecopy.ks: -------------------------------------------------------------------------------- 1 | For filename in core:currentvolume:files:keys { 2 | if filename:startswith("lib_") { 3 | if filename:endswith(".ks") { 4 | print "Found file called: " + filename. 5 | runpath(filename). 6 | } 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /kerboscripts/parser_valid/Good Files/Libs/lib_rendezvous/old working stuff/inclmain.ks: -------------------------------------------------------------------------------- 1 | 2 | until thetachange < 0.009 { 3 | InclinationMatcher(TargetThingy). 4 | } 5 | 6 | 7 | if ship:apoapsis < TargetThingy:periapsis { 8 | Circularizer(0.0009, apoapsis). 9 | } else { 10 | Circularizer(0.0009, periapsis). 11 | } 12 | 13 | run rendmain. 14 | -------------------------------------------------------------------------------- /kerboscripts/parser_valid/Good Files/Libs/lib_rendezvous/old working stuff/inclsub.ks: -------------------------------------------------------------------------------- 1 | KillRelVel(TargetThingy, 30). 2 | FinalApproach(500). 3 | 4 | rcs on. 5 | sas off. 6 | 7 | set dockingport to ship:partstagged("port A")[0]. 8 | set targetport to TargetThingy:partstagged("port B")[0]. 9 | 10 | print "killing relative velocity...". 11 | kill_rel_vel(targetPort). 12 | print "approaching...". 13 | approach_port(targetPort, dockingPort, 100, 5). 14 | approach_port(targetPort, dockingPort, 50, 3). 15 | approach_port(targetPort, dockingPort, 40, 1). 16 | approach_port(targetPort, dockingPort, 35, 0.4). 17 | 18 | wait until not ship:messages:empty. 19 | set received to ship:messages:pop. 20 | if received:content = "Command 1" { 21 | wait 0. 22 | } 23 | 24 | print "received". 25 | 26 | wait 1. 27 | rcs on. 28 | wait 1. 29 | 30 | approach_port(targetPort, dockingPort, 20, 2). 31 | approach_port(targetPort, dockingPort, 10, 1). 32 | approach_port(targetPort, dockingPort, 0, 0.5). 33 | 34 | translate(v(0,0,0)). 35 | rcs off. 36 | sas on. 37 | -------------------------------------------------------------------------------- /kerboscripts/parser_valid/Good Files/Libs/lib_rendezvous/old working stuff/protodock.ks: -------------------------------------------------------------------------------- 1 | clearscreen. 2 | run rend_functions. 3 | print "type in other terminal: run protodock1.". 4 | 5 | wait until not ship:messages:empty. 6 | set received to ship:messages:pop. 7 | if received:content = "Command 1" { 8 | wait 0. 9 | } 10 | print "received". 11 | 12 | wait 1. 13 | rcs on. 14 | wait 1. 15 | 16 | approach_port(targetPort, dockingPort, 20, 2). 17 | approach_port(targetPort, dockingPort, 10, 1). 18 | approach_port(targetPort, dockingPort, 0, 0.5). 19 | 20 | translate(v(0,0,0)). 21 | rcs off. 22 | sas on. 23 | -------------------------------------------------------------------------------- /kerboscripts/parser_valid/Good Files/Libs/lib_rendezvous/old working stuff/protodock1.ks: -------------------------------------------------------------------------------- 1 | lock steering to -(ship:position - vessel("duck"):position). 2 | set vangdone to false. 3 | until vangdone = true { 4 | if vang(ship:facing:vector, -(ship:position - vessel("duck"):position)) < 2 { 5 | wait 5. 6 | if vang(ship:facing:vector, -(ship:position - vessel("duck"):position)) < 2 { 7 | set vangdone to true. 8 | } 9 | } 10 | } 11 | 12 | set vangdone to false. 13 | 14 | print "sending...". 15 | set message to "Command 1". 16 | set c to vessel("duck"):connection. 17 | c:sendmessage(message). 18 | print "sent...". 19 | wait until false. 20 | -------------------------------------------------------------------------------- /kerboscripts/parser_valid/Good Files/Libs/lib_rendezvous/old working stuff/rendmain.ks: -------------------------------------------------------------------------------- 1 | set oncetwice to 0. 2 | print "running rendmain.ks". 3 | 4 | until oncetwice = 2 { 5 | set aop1 to ship:orbit:argumentofperiapsis. 6 | set aop2 to TargetThingy:orbit:argumentofperiapsis. 7 | set ta1 to aop2 -aop1. 8 | 9 | ETAToTa(ship, ta1). 10 | set TimeTargetPeriapsis to ta. 11 | 12 | set SMA to ship:orbit:semimajoraxis. 13 | set Ecc to ship:orbit:eccentricity. 14 | set CurRadiusAtTargetPeriapsis to (SMA * ( (1-ecc^2) / (1+ecc*cos(ta1))))-body:radius. 15 | 16 | DeltaVCalc(CurRadiusAtTargetPeriapsis, ((TargetThingy:orbit:apoapsis+ CurRadiusAtTargetPeriapsis + 2*body:radius)/2)). 17 | EndDeltaV(DvNeeded). 18 | TimeTillManeuverBurn(TimeTargetPeriapsis, DvNeeded). 19 | 20 | warpto(StartT-40). 21 | wait until time:seconds > StartT-40. 22 | 23 | if neg = true { 24 | SteeringOrbitRet(). 25 | } else { 26 | SteeringOrbitPro(). 27 | } 28 | 29 | wait until time:seconds >= StartT. 30 | 31 | PerformBurn(EndDv). 32 | 33 | set oncetwice to oncetwice + 1. 34 | } 35 | //run rendprec. 36 | run finmain. 37 | // line 133 38 | -------------------------------------------------------------------------------- /kerboscripts/parser_valid/Good Files/Libs/lib_rendezvous/old working stuff/rendprec.ks: -------------------------------------------------------------------------------- 1 | // precision right here ! 2 | print "running rendprec.ks". 3 | 4 | set neededtime to eta:periapsis +time:seconds -60. 5 | warpto(neededtime). // add error time and burntime 6 | wait until time:seconds >= neededtime. 7 | wait 0. 8 | // dv calcing 9 | 10 | 11 | DeltaVCalc(ship:periapsis, ((TargetThingy:orbit:apoapsis+ ship:periapsis + 2*body:radius)/2)). 12 | EndDeltaV(DvNeeded). 13 | TimeTillManeuverBurn(eta:periapsis, DvNeeded). 14 | 15 | WarpTo(StartT-40). 16 | wait until time:seconds >= StartT-40. 17 | 18 | if neg = true { 19 | SteeringOrbitRet(). 20 | } else { 21 | SteeringOrbitPro(). 22 | } 23 | 24 | wait until time:seconds >= StartT. 25 | PerformBurn(EndDv). 26 | 27 | run finmain. 28 | 29 | // line 110 30 | -------------------------------------------------------------------------------- /kerboscripts/parser_valid/Good Files/Libs/lib_rendezvous/old working stuff/replay.ks: -------------------------------------------------------------------------------- 1 | run finmain. 2 | -------------------------------------------------------------------------------- /kerboscripts/parser_valid/Good Files/Libs/lib_science.ks: -------------------------------------------------------------------------------- 1 | Function ScienceCollect{ 2 | 3 | parameter KeepData is false. 4 | set ModuleList to List(). 5 | 6 | for m in ship:modulesnamed("DMModuleScienceAnimate") { 7 | if m:inoperable = false { 8 | m:deploy. 9 | wait until m:hasdata. 10 | print "Science collected!". 11 | wait 1. 12 | m:toggle. 13 | if m:inoperable = true { 14 | if KeepData = false { 15 | m:dump. 16 | } 17 | } 18 | if m:data:transmitvalue < 0.1 { 19 | m:dump. 20 | } 21 | ModuleList:Add(m). 22 | } 23 | } 24 | 25 | for m in ship:modulesnamed("ModuleScienceExperiment") { 26 | if m:inoperable = false { 27 | m:deploy. 28 | wait until m:hasdata. 29 | print "Science collected!". 30 | if m:inoperable = true { 31 | if KeepData = false { 32 | m:dump. 33 | } 34 | } 35 | if m:data:transmitvalue < 0.1 { 36 | m:dump. 37 | } 38 | ModuleList:Add(m). 39 | } 40 | } 41 | 42 | } 43 | 44 | Function TransmitData { 45 | 46 | For m in ModuleList { 47 | m:transmit. 48 | } 49 | 50 | ModuleList:clear. 51 | 52 | } 53 | -------------------------------------------------------------------------------- /kerboscripts/parser_valid/Good Files/Libs/lib_stage.ks: -------------------------------------------------------------------------------- 1 | Function StageCheck { 2 | 3 | set PrevThrust to MaxThrust. 4 | 5 | when MaxThrust < (PrevThrust - 10) then { 6 | set CurrentThrottle to Throttle. 7 | lock Throttle to 0. 8 | wait 1. 9 | stage. 10 | wait 1. 11 | lock Throttle to CurrentThrottle. 12 | set PrevThrust to MaxThrust. 13 | preserve. 14 | } 15 | 16 | when MaxThrust = 0 then { 17 | stage. 18 | preserve. 19 | } 20 | } 21 | 22 | Function EndStage { 23 | Parameter EndStage. 24 | 25 | until stage:number = EndStage { 26 | wait 2. 27 | stage. 28 | } 29 | 30 | } 31 | 32 | Function LaunchStage { 33 | until ship:availablethrust > 0 { 34 | wait 1. 35 | stage. 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /kerboscripts/parser_valid/Good Files/Other/orbitpopper.ks: -------------------------------------------------------------------------------- 1 | print "running orbitpopper.ks". 2 | PARAMETER direction. 3 | PARAMETER Trot. 4 | PARAMETER Targget. 5 | PARAMETER ORB. // Y=NO TARGET BUT ORBIT N= TARGET IS TRUE 6 | 7 | run stagechecker. 8 | Stagecheck(). 9 | lock steering to heading(direction, 0). 10 | wait 5. 11 | 12 | IF eta:apoapsis > 300 { 13 | set kuniverse:timewarp:warp to 3. 14 | } 15 | 16 | Wait until eta:apoapsis <= 180. 17 | set kuniverse:timewarp:warp to 0. 18 | 19 | wait until eta:apoapsis < 20. 20 | Lock throttle to Trot. 21 | run orbitstopper(direction, Targget, ORB). 22 | -------------------------------------------------------------------------------- /kerboscripts/parser_valid/Good Files/Other/orbitstopper.ks: -------------------------------------------------------------------------------- 1 | print "running orbitstopper.ks". 2 | PARAMETER direction. 3 | PARAMETER targget. 4 | PARAMETER ORB. // Y=NO TARGET BUT ORBIT N= TARGET IS TRUE 5 | run stagechecker. 6 | stagecheck(). 7 | set oldap to APOAPSIS. 8 | wait until eta:apoapsis>50 OR Periapsis>oldap. 9 | lock throttle to 0. 10 | if eta:apoapsis>600{ 11 | lock throttle to 1. 12 | wait until periapsis>oldap. 13 | lock throttle to 0. 14 | } 15 | 16 | If (APOAPSIS-PERIAPSIS)>5000{ 17 | Run orbitpopper(direction, 0.2, Targget). 18 | }ELSE{ 19 | run launch(Targget, N, ORB). 20 | // run orbitinstructions. 21 | } 22 | 23 | -------------------------------------------------------------------------------- /kerboscripts/parser_valid/Good Files/PID/pid1.ks: -------------------------------------------------------------------------------- 1 | SET pScale TO 0.002. 2 | 3 | FUNCTION P_LOOP { 4 | PARAMETER targget. 5 | 6 | RETURN (targget - ALTITUDE) * pScale. 7 | } 8 | 9 | LOCK STEERING TO HEADING(90, 90). 10 | STAGE. 11 | 12 | // Test our proportional function 13 | SET autoThrottle TO 0. 14 | LOCK THROTTLE TO autoThrottle. 15 | 16 | SWITCH TO 0. 17 | SET startTime TO TIME:SECONDS. 18 | 19 | UNTIL STAGE:LIQUIDFUEL < 10 { 20 | SET autoThrottlex TO P_LOOP(500). 21 | SET autoThrottle TO MAX(0, MIN(autoThrottlex, 1)). 22 | WAIT 0.001. 23 | LOG (TIME:SECONDS - startTime) + "," + ALTITUDE + "," + autoThrottle TO "testflight2.csv". 24 | } 25 | 26 | // Recover the vessel 27 | LOCK THROTTLE TO 0. 28 | STAGE. 29 | SWITCH TO 1. -------------------------------------------------------------------------------- /kerboscripts/parser_valid/Reusable Booster/boot/refuel_truck.ks: -------------------------------------------------------------------------------- 1 | clearscreen. 2 | print "Refueling script is running...". 3 | print "Waiting for a request message". 4 | 5 | wait until ship:loaded and ship:unpacked. 6 | lights off. 7 | 8 | 9 | until false { 10 | wait 0.5. 11 | if not(ship:messages:empty) { 12 | local msg is ship:messages:pop. 13 | if msg:content = "bruh" { 14 | global targetVessel is msg:sender. 15 | if targetVessel:loaded and targetVessel:unpacked { 16 | global targetPort is targetVessel:partstagged("refueling port")[0]. 17 | } 18 | else global targetPort is ship:rootpart. 19 | 20 | kuniverse:forceactive(ship). 21 | 22 | break. 23 | } 24 | } 25 | } 26 | 27 | run refuel_truck. -------------------------------------------------------------------------------- /kerboscripts/parser_valid/Reusable Booster/cam.ks: -------------------------------------------------------------------------------- 1 | // ### Functions ### 2 | // >> 3 | function vecToHdg { 4 | parameter v. 5 | set v to vxcl(up:vector,v). 6 | 7 | local ang is vang(north:vector,v). 8 | if vdot(heading(90,0):vector,v) < 0 set ang to -ang. 9 | 10 | return ang. 11 | //return ang * constant():pi / 180. //return in radians 12 | } 13 | 14 | function vecToPitch { 15 | parameter v. 16 | 17 | local ang is vang(-up:vector,v) - 90. 18 | 19 | return -ang. 20 | //return ang * constant():pi / 180. 21 | } 22 | 23 | 24 | 25 | // << 26 | 27 | 28 | 29 | global hasCamAddon is addons:available("camera"). 30 | 31 | if hasCamAddon { 32 | global extcam is addons:camera:flightcamera. 33 | //set extcam:camerafov to 70. 34 | 35 | 36 | 37 | //local ev is v(0,0,0). 38 | //global camAvgList is list(). 39 | //global camAvgFrames is 30. 40 | //global camAvgI is 0. 41 | //for i in range(camAvgFrames) camAvgList:add(ev). 42 | 43 | } -------------------------------------------------------------------------------- /kerboscripts/parser_valid/Reusable Booster/constructor/loader_constructor.ks: -------------------------------------------------------------------------------- 1 | @LAZYGLOBAL on. 2 | SET CONFIG:STAT TO false. 3 | set terminal:brightness to 1. 4 | //set terminal:charwidth to 12. 5 | //set terminal:charheight to 12. 6 | print "Preparing Constructor QUAD script files..". 7 | runoncepath("cpu_light.ksm"). 8 | setLights(0,0.5,0.5). 9 | wait 0.1. 10 | 11 | 12 | clearguis(). 13 | //runoncepath("cam.ks"). 14 | runoncepath("constructor/lib_constructor.ks"). 15 | //runoncepath("lib_json.ks"). 16 | //runoncepath("race.ks"). 17 | runoncepath("constructor/loop_constructor.ks"). 18 | //runoncepath("constructor/GUI_constructor.ks"). 19 | print "Running Quad setup..". 20 | //core:doaction("close terminal",true). 21 | runpath("constructor/main_constructor.ks"). 22 | 23 | //LOG PROFILERESULT() TO qprof.csv. -------------------------------------------------------------------------------- /kerboscripts/parser_valid/Reusable Booster/cpu_light.ks: -------------------------------------------------------------------------------- 1 | //function to set the kos cpu's light, if it has one. 2 | 3 | //find the module and store it for later 4 | local lightParts is ship:partstagged("light"). 5 | local kosLightMods is list(). 6 | local hasLights is false. 7 | getLightModule(core:part). 8 | 9 | if lightParts:length > 0 { 10 | for p in lightParts { 11 | getLightModule(p). 12 | } 13 | } 14 | 15 | function getLightModule { 16 | parameter p. 17 | for ms in p:modules { 18 | local m is p:getmodule(ms). 19 | if m:hasfield("light r") { 20 | set hasLights to true. 21 | kosLightMods:add(m). 22 | } 23 | } 24 | } 25 | 26 | function setLights { 27 | parameter r,g,b. 28 | 29 | if hasLights { 30 | for m in kosLightMods { 31 | m:setfield("light r",r). 32 | m:setfield("light g",g). 33 | m:setfield("light b",b). 34 | } 35 | } 36 | } 37 | 38 | if hasLights { 39 | setLights(1,1,1). 40 | } -------------------------------------------------------------------------------- /kerboscripts/parser_valid/addons/trajectories/traj1.ks: -------------------------------------------------------------------------------- 1 | print "Should simply print if trajectories mod is available.". 2 | print "Available should mean that the mod is installed.". 3 | print "An error thrown should mean that the addon itself is not compiled.". 4 | print "Any other deviation means that the test is not working.". 5 | if (addons:tr:available) { 6 | print "Trajectories addon is available!". 7 | } 8 | else { 9 | print "Trajectories addon not available!". 10 | } 11 | -------------------------------------------------------------------------------- /kerboscripts/parser_valid/boot/boostback_boot.ks: -------------------------------------------------------------------------------- 1 | // boostback_boot.ks 2 | clearscreen. 3 | wait 1. 4 | print "boostback boot program running, waiting for message to start.". 5 | local done is false. 6 | 7 | if altitude > 40000 and ship:messages:empty runpath("0:/boostback.ks", 0). 8 | 9 | until done { 10 | if not ship:messages:empty { 11 | local msg is ship:messages:pop. 12 | if msg:content = "boostback" { 13 | switch to 0. 14 | runpath("0:/boostback.ks", 0, msg:sender). 15 | set done to true. 16 | } 17 | else if msg:content = "good luck" { 18 | switch to 0. 19 | runpath("0:/boostback.ks", 1, msg:sender). 20 | set done to true. 21 | } 22 | } 23 | wait 0. 24 | } -------------------------------------------------------------------------------- /kerboscripts/parser_valid/boot/boot_drone.ks: -------------------------------------------------------------------------------- 1 | //drone boot 2 | ag1 off. ag2 off. ag3 off. 3 | switch to 0. 4 | set terminal:brightness to 1. 5 | set terminal:width to 30. 6 | set terminal:height to 20. 7 | clearscreen. 8 | print "In standby". 9 | print "-------------------------". 10 | print "[AG 1] START". 11 | print "[AG 2] Force compile all". 12 | print "[AG 3] Exit boot program". 13 | print "-------------------------". 14 | print " ". 15 | 16 | wait until ship:unpacked. 17 | 18 | runoncepath("cpu_light.ks"). 19 | 20 | local ascending is false. 21 | local strength is 1.1. 22 | local strengthIncr is 0.05. 23 | until ag1 or ag3 { 24 | if ag2 { 25 | ag2 off. 26 | runpath("cq.ks",0). 27 | } 28 | 29 | if ascending set strength to strength + strengthIncr. 30 | else set strength to strength - strengthIncr. 31 | if strength <= 0.3 or strength >= 1.1 toggle ascending. 32 | setLights(0,0.45 * strength,1 * strength). 33 | 34 | wait 0.08. 35 | } 36 | ag3 off. 37 | if ag1 { 38 | ag1 off. 39 | core:doevent("open terminal"). 40 | run q. 41 | } 42 | 43 | print "Program ended". -------------------------------------------------------------------------------- /kerboscripts/parser_valid/boot/boot_qShip.ks: -------------------------------------------------------------------------------- 1 | switch to 0. 2 | 3 | //runoncepath("cpu_light.ks"). 4 | runpath("drone_ship.ks"). -------------------------------------------------------------------------------- /kerboscripts/parser_valid/boot/boot_updater.ks: -------------------------------------------------------------------------------- 1 | deletepath("1:/boot/bootup_toukie"). 2 | copypath("0:/boot/bootup_toukie", "1:/boot/"). 3 | log "" to BootCheck.ks. 4 | reboot. -------------------------------------------------------------------------------- /kerboscripts/parser_valid/boot/bootup_toukie.ks: -------------------------------------------------------------------------------- 1 | { 2 | 3 | global T_Boot is lexicon( 4 | "CopyAndRunFile", CopyAndRunFile@, 5 | "CopyFile", CopyFile@ 6 | ). 7 | 8 | global BootVersion is "1.4.3". 9 | 10 | Function CopyAndRunFile { 11 | parameter TargetFile. 12 | parameter FileLocation is "0:/". 13 | set string1 to FileLocation + TargetFile. 14 | deletepath(TargetFile). 15 | copypath(string1, ""). 16 | runpath(TargetFile). 17 | } 18 | 19 | Function CopyFile { 20 | parameter TargetFile. 21 | parameter FileLocation is "0:/". 22 | set string1 to FileLocation + TargetFile. 23 | deletepath(TargetFile). 24 | copypath(string1, ""). 25 | } 26 | 27 | wait until ship:loaded. 28 | wait until ship:unpacked. 29 | wait 0. 30 | 31 | set kuniverse:timewarp:warp to 0. 32 | set PilotMainThrottle to 0. 33 | sas off. 34 | rcs off. 35 | wait 0. 36 | 37 | switch to 1. 38 | 39 | CopyFile("boot_updater", "0:/boot/"). 40 | CopyAndRunFile("missionscript", "0:/exe_toukie/"). 41 | 42 | } 43 | -------------------------------------------------------------------------------- /kerboscripts/parser_valid/boot/junkboot.ks: -------------------------------------------------------------------------------- 1 | { 2 | 3 | global T_Boot is lexicon( 4 | "CopyAndRunFile", CopyAndRunFile@, 5 | "CopyFile", CopyFile@ 6 | ). 7 | 8 | global BootVersion is "1.4.3". 9 | 10 | Function CopyAndRunFile { 11 | parameter TargetFile. 12 | parameter FileLocation is "0:/". 13 | set string1 to FileLocation + TargetFile. 14 | deletepath(TargetFile). 15 | copypath(string1, ""). 16 | runpath(TargetFile). 17 | } 18 | 19 | Function CopyFile { 20 | parameter TargetFile. 21 | parameter FileLocation is "0:/". 22 | set string1 to FileLocation + TargetFile. 23 | deletepath(TargetFile). 24 | copypath(string1, ""). 25 | } 26 | 27 | wait until ship:loaded. 28 | wait until ship:unpacked. 29 | wait 0. 30 | 31 | set kuniverse:timewarp:warp to 0. 32 | set PilotMainThrottle to 0. 33 | sas off. 34 | rcs off. 35 | wait 0. 36 | 37 | switch to 1. 38 | 39 | CopyFile("boot_updater", "0:/boot/"). 40 | CopyAndRunFile("mission_getter", "0:/exe_toukie/"). 41 | 42 | } 43 | -------------------------------------------------------------------------------- /kerboscripts/parser_valid/boot/station.ks: -------------------------------------------------------------------------------- 1 | // ### station.ks ### 2 | 3 | clearscreen. 4 | print "Station attitude and sanity control.". 5 | wait until ship:loaded and ship:unpacked. 6 | print "". 7 | print "Running.". 8 | local controlpart is ship:partstagged("control")[0]. 9 | controlpart:controlfrom(). 10 | lock throttle to 0. 11 | lock steering to st. 12 | 13 | 14 | until false { 15 | set aimVec to -body:angularvel. 16 | set topVec to vcrs(sun:position,aimVec). //sun 17 | set st to lookdirup(aimVec, topVec). 18 | 19 | wait 0. 20 | } -------------------------------------------------------------------------------- /kerboscripts/parser_valid/boot_drone.ks: -------------------------------------------------------------------------------- 1 | //drone boot 2 | ag1 off. ag2 off. ag3 off. 3 | switch to 0. 4 | set terminal:brightness to 1. 5 | //set terminal:charwidth to 12. 6 | //set terminal:charheight to 12. 7 | clearscreen. 8 | print "In standby". 9 | print "-------------------------". 10 | print "[AG 1] START". 11 | print "[AG 2] Force compile all". 12 | print "[AG 3] Exit boot program". 13 | print "-------------------------". 14 | print " ". 15 | 16 | wait until ship:unpacked. 17 | 18 | runoncepath("cpu_light.ks"). 19 | 20 | local ascending is false. 21 | local strength is 1.1. 22 | local strengthIncr is 0.05. 23 | until ag1 or ag3 { 24 | if ag2 { 25 | ag2 off. 26 | runpath("cq.ks",0). 27 | } 28 | 29 | if ascending set strength to strength + strengthIncr. 30 | else set strength to strength - strengthIncr. 31 | if strength <= 0.3 or strength >= 1.1 toggle ascending. 32 | setLights(0,0.45 * strength,1 * strength). 33 | 34 | wait 0.08. 35 | } 36 | ag3 off. 37 | if ag1 { 38 | ag1 off. 39 | core:doevent("open terminal"). 40 | run q. 41 | } 42 | 43 | print "Program ended". -------------------------------------------------------------------------------- /kerboscripts/parser_valid/cam.ks: -------------------------------------------------------------------------------- 1 | // ### Functions ### 2 | // >> 3 | function vecToHdg { 4 | parameter v. 5 | set v to vxcl(up:vector,v). 6 | 7 | local ang is vang(north:vector,v). 8 | if vdot(heading(90,0):vector,v) < 0 set ang to -ang. 9 | 10 | return ang. 11 | //return ang * constant():pi / 180. //return in radians 12 | } 13 | 14 | function vecToPitch { 15 | parameter v. 16 | 17 | local ang is vang(-up:vector,v) - 90. 18 | 19 | return -ang. 20 | //return ang * constant():pi / 180. 21 | } 22 | 23 | // << 24 | 25 | global hasCamAddon is addons:available("camera"). 26 | 27 | if hasCamAddon { 28 | global extcam is addons:camera:flightcamera. 29 | //set extcam:camerafov to 70. 30 | 31 | local ev is v(0,0,0). 32 | global camAvgList is list(). 33 | global camAvgFrames is 30. 34 | global camAvgI is 0. 35 | for i in range(camAvgFrames) camAvgList:add(ev). 36 | 37 | } -------------------------------------------------------------------------------- /kerboscripts/parser_valid/compile/compiletest1.ks: -------------------------------------------------------------------------------- 1 | // compiletest1 2 | print "Tests the case where an empty script file is run". 3 | print "from another script. It should do nothing, rather". 4 | print "than get stuck forever or error out.". 5 | print " ". 6 | print "You must 'set count to 0' before you run the test". 7 | set count to count + 1. 8 | if count > 1 { print 1/0. }. // force dump after a few runs 9 | print "program started". 10 | log "" to empty_file. 11 | delete empty_file. 12 | log "" to empty_file. 13 | run empty_file. 14 | print "If it got this far without complaint, then it passed the test.". 15 | -------------------------------------------------------------------------------- /kerboscripts/parser_valid/compile/compiletest2.ks: -------------------------------------------------------------------------------- 1 | print "this will test whether or not you can ". 2 | print "use lock inside for loop.". 3 | FOR p IN SHIP:PARTS { 4 | LOCK THROTTLE TO 0. 5 | } 6 | -------------------------------------------------------------------------------- /kerboscripts/parser_valid/compile/testrunonce/testrunonce_lib1.ks: -------------------------------------------------------------------------------- 1 | // Library to be called by testrunonce: 2 | 3 | // Lib1 runs Lib2 even though lib2 is also called by the main prog too: 4 | run once testrunonce_lib2("dummy"). 5 | 6 | function lib1 { 7 | return "lib1 value". 8 | } 9 | 10 | print "MAINLINE CODE of lib1 is running.". 11 | -------------------------------------------------------------------------------- /kerboscripts/parser_valid/compile/testrunonce/testrunonce_lib2.ks: -------------------------------------------------------------------------------- 1 | // Library to be called by testrunonce: 2 | 3 | parameter dummy. // just to test passing args not getting stack misaligned. 4 | 5 | // Lib2 runs Lib1 even though lib1 is also called by the main prog too: 6 | run once testrunonce_lib1. 7 | 8 | function lib2 { 9 | return "lib2 value". 10 | } 11 | 12 | print "MAINLINE CODE of lib2 is running.". 13 | -------------------------------------------------------------------------------- /kerboscripts/parser_valid/compile/testrunonce/testrunonce_p1.ks: -------------------------------------------------------------------------------- 1 | // Outermost level of testing the run-once system: 2 | 3 | print "Testing run without 'once' to ensure backward compatibility.". 4 | 5 | print "running lib1 and lib2 first time.". 6 | run testrunonce_lib1. 7 | run testrunonce_lib2("dummy arg"). 8 | 9 | print "Testing that the funcs exist:". 10 | print "lib1 function returns: " + lib1(). 11 | print "lib2 function returns: " + lib2(). 12 | 13 | print "running lib1 and lib2 second time.". 14 | print "Next lines SHOULD print 'MAINLINE CODE' as it runs the libs.". 15 | run testrunonce_lib1. 16 | run testrunonce_lib2("dummy arg"). 17 | 18 | print "Testing that the funcs still exist:". 19 | print "lib1 function returns: " + lib1(). 20 | print "lib2 function returns: " + lib2(). 21 | -------------------------------------------------------------------------------- /kerboscripts/parser_valid/compile/testrunonce/testrunonce_p2.ks: -------------------------------------------------------------------------------- 1 | // Outermost level of testing the run-once system: 2 | 3 | print "Testing run with 'once' to test new functionality.". 4 | 5 | print "running lib1 and lib2 first time.". 6 | run once testrunonce_lib1. 7 | run once testrunonce_lib2("dummy"). 8 | 9 | print "Testing that the funcs exist:". 10 | print "lib1 function returns: " + lib1(). 11 | print "lib2 function returns: " + lib2(). 12 | 13 | print "running lib1 and lib2 second time.". 14 | print "Next line should NOT print 'MAINLINE CODE IS RUNNING.". 15 | run once testrunonce_lib1. 16 | run once testrunonce_lib2("dummy"). 17 | 18 | print "Testing that the funcs still exist:". 19 | print "lib1 function returns: " + lib1(). 20 | print "lib2 function returns: " + lib2(). 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /kerboscripts/parser_valid/cpu_light.ks: -------------------------------------------------------------------------------- 1 | //function to set the kos cpu's light, if it has one. 2 | 3 | //find the module and store it for later 4 | local cpuPart is core:part. 5 | local lightParts is ship:partstagged("light"). 6 | local kosLightMods is list(). 7 | local hasLights is false. 8 | getLightModule(cpuPart). 9 | 10 | if lightParts:length > 0 { 11 | for p in lightParts { 12 | getLightModule(p). 13 | } 14 | } 15 | 16 | function getLightModule { 17 | parameter p. 18 | for ms in p:modules { 19 | local m is p:getmodule(ms). 20 | if m:hasfield("light r") and m:hasfield("light g") and m:hasfield("light b") { //not really necessary to check all but why not 21 | set hasLights to true. 22 | kosLightMods:add(m). 23 | } 24 | } 25 | } 26 | 27 | function setLights { 28 | parameter r,g,b. 29 | 30 | if hasLights { 31 | //only takes a value between 0 and 1 32 | //set r to max(0,min(1,r)). 33 | //set g to max(0,min(1,g)). 34 | //set b to max(0,min(1,b)). 35 | 36 | for m in kosLightMods { 37 | m:setfield("light r",r). 38 | m:setfield("light g",g). 39 | m:setfield("light b",b). 40 | } 41 | } 42 | } 43 | 44 | if hasLights { 45 | setLights(1,1,1). 46 | } -------------------------------------------------------------------------------- /kerboscripts/parser_valid/delegates/delegatetest1.ks: -------------------------------------------------------------------------------- 1 | print "ship vel = " + ship:velocity:orbit:mag(). 2 | 3 | function foo { 4 | print " -- proof I am in foo.". 5 | } 6 | 7 | function bar { 8 | parameter a, b, c. 9 | 10 | print " -- proof I am in bar("+a+", "+b+", "+c+")". 11 | return a+b+c. 12 | } 13 | 14 | print "== calling foo normally ==". 15 | foo(). 16 | print "== getting a delegate of foo ==". 17 | set foo_ref to foo@. 18 | print "== calling the delegate of foo ==". 19 | foo_ref:call(). 20 | 21 | print "== calling bar normally ==". 22 | set sum to bar(1,2,3). 23 | print "bar returned " + sum. 24 | print "== calling bar through a delegate ==". 25 | set bar_ref to bar@. 26 | set refsum to bar_ref:call(1,2,3). 27 | print "bar via a ref returned " + refsum + " which should be 6". 28 | print "== getting a bound curry of bar delegate ==". 29 | set bar_bound to bar_ref:bind(1,2). 30 | print "== calling bar through bound curry ==". 31 | set refsum to bar_bound:call(3). 32 | print "bar via a bound curry returned " + refsum + " which should be 6". 33 | -------------------------------------------------------------------------------- /kerboscripts/parser_valid/delegates/delegatetest2.ks: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jonnyboyC/kos-language-server/aff3a4743f5492a878cbfb5d2938e2e90f83cb45/kerboscripts/parser_valid/delegates/delegatetest2.ks -------------------------------------------------------------------------------- /kerboscripts/parser_valid/delegates/delegatetest3.ks: -------------------------------------------------------------------------------- 1 | print "Testing a parent program that runs a child program". 2 | print "making delegates that the parent tries calling.". 3 | 4 | { 5 | // Hide the parent delegate 6 | function triple { parameter i. return i * 3. } 7 | function announce { parameter i. print " -- Announcing " + i. } 8 | 9 | print "== Pass delegate to child, receieve delegate back ==". 10 | run delegatetest3_lib.ks(triple@, true). 11 | print " -- Ensure list(6,9,12) " + mapper_result:call(list(2,3,4)). 12 | 13 | print "== Allow delegate to run in child context". 14 | print " -- Ensure announced: 2, 3, 4 on next line:". 15 | run delegatetest3_lib.ks(announce@, false). 16 | } 17 | -------------------------------------------------------------------------------- /kerboscripts/parser_valid/delegates/delegatetest3_lib.ks: -------------------------------------------------------------------------------- 1 | 2 | parameter op, yield_results. 3 | 4 | function make_mapper { 5 | function map { 6 | parameter operation, collection. 7 | local result is list(). 8 | for item in collection result:add(operation:call(item)). 9 | return result. 10 | } 11 | return map@. 12 | } 13 | 14 | function make_eacher { 15 | function for_each { 16 | parameter operation, collection. 17 | for item in collection { 18 | operation:call(item). 19 | } 20 | } 21 | return for_each@. 22 | } 23 | 24 | if yield_results { 25 | global mapper_result is make_mapper():bind(op). 26 | } else { 27 | global mapper_result is make_eacher():bind(op). 28 | mapper_result:call(list(2,3,4)). 29 | } 30 | 31 | 32 | -------------------------------------------------------------------------------- /kerboscripts/parser_valid/delegates/delegatetest5.ks: -------------------------------------------------------------------------------- 1 | print "Testing an array of delegates.". 2 | 3 | function f1 { parameter a,b. return a+b. } 4 | 5 | local f1_curry1 is f1@:bind(1). 6 | local f1_curry2 is f1_curry1:bind(2). 7 | local mod_del is mod@:bind(8,5). // testing a delegate of a built-in too. 8 | 9 | local func_arr is LIST(f1@, f1_curry1, f1_curry2, mod_del). 10 | 11 | print "Array of functions is:". 12 | 13 | print "--- func_arr[0] -----". 14 | print func_arr[0]. 15 | print "--- func_arr[1] -----". 16 | print func_arr[1]. 17 | print "--- func_arr[2] -----". 18 | print func_arr[2]. 19 | print "--- func_arr[3] -----". 20 | print func_arr[3]. 21 | 22 | print "Calling them. These should all print 3:". 23 | print "calling func_arr[0](1,2) returns " + func_arr[0](1,2). 24 | print "calling func_arr[1](2) returns " + func_arr[1](2). 25 | print "calling func_arr[2]() returns " + func_arr[2](). 26 | print "calling func_arr[3]() returns " + func_arr[3](). 27 | -------------------------------------------------------------------------------- /kerboscripts/parser_valid/delegates/delegatetest7.ks: -------------------------------------------------------------------------------- 1 | // Tests using system callbacks with pre-bound args. 2 | // This test was added for issue #2236 3 | 4 | local vd is vecdraw(v(0,0,0), ship:north:vector * 10, white, "test vector", 1, true). 5 | function update_color { 6 | parameter base_color. 7 | return rgb(base_color:r+random()*0.2, base_color:g+random()*0.2, base_color:b+random()*0.2). 8 | } 9 | print "Now flickering vector color blue-ish-ly for 5 seconds.". 10 | set vd:colorupdater to update_color@:bind(rgb(0.2,0.2,0.7)). 11 | wait 5. 12 | print "Now flickering vector color red-ish-ly for 5 seconds.". 13 | set vd:colorupdater to update_color@:bind(rgb(0.7,0.2,0.2)). 14 | wait 5. 15 | local vd is 0. 16 | print "Done. If it got here without dying, the issue is fixed.". 17 | -------------------------------------------------------------------------------- /kerboscripts/parser_valid/demo/testrefvec.ks: -------------------------------------------------------------------------------- 1 | // A small sample script to demonstrate the reference vector 2 | // idea. 3 | 4 | clearscreen. 5 | print "Solar Prime Vector demo.". 6 | print " ". 7 | print "Use time-warp to watch things change.". 8 | print "press action group 1 to quit.". 9 | 10 | set refdraw to vecdraw(). 11 | set refdraw:color to white. 12 | set refdraw:label to "SolarPrimeVector". 13 | set refdraw:show to true. 14 | set zerodraw to vecdraw(). 15 | set zerodraw:color to yellow. 16 | set zerodraw:label to ship:body:name + "'s zero meridian". 17 | set zerodraw:show to true. 18 | 19 | until ag1 { 20 | set refdraw:start to ship:body:position. 21 | set zerodraw:start to ship:body:position. 22 | set refdraw:vec to 2500000*SOLARPRIMEVECTOR. 23 | set zerodraw:vec to 4*(latlng(0,0):position - ship:body:position). 24 | print ship:body:name + 25 | ":ROTATIONANGLE = " + 26 | round(ship:body:rotationangle,2) + " deg " 27 | at (0,1). 28 | }. 29 | 30 | set refdraw to 0. 31 | set zerodraw to 0. 32 | -------------------------------------------------------------------------------- /kerboscripts/parser_valid/dependencyTest/exec.ks: -------------------------------------------------------------------------------- 1 | runOncePath("lib.ks"). 2 | 3 | test(). 4 | -------------------------------------------------------------------------------- /kerboscripts/parser_valid/dependencyTest/lib.ks: -------------------------------------------------------------------------------- 1 | function test { 2 | print("hi"). 3 | } 4 | 5 | function blah { 6 | print("blah"). 7 | } 8 | 9 | function stuff { 10 | 11 | } -------------------------------------------------------------------------------- /kerboscripts/parser_valid/exe_toukie/gapapov.ks: -------------------------------------------------------------------------------- 1 | wait 1. 2 | T_Stage["LaunchStage"](). 3 | T_Stage["StageCheck"](). 4 | 5 | T_GUI["StatusCheck"](). 6 | local GivenParameterList is T_GUI["CompleteParameterGUI"](). 7 | T_ReadOut["InitialReadOut"](10). 8 | 9 | T_GAPAPOV["GAPAPOV"](GivenParameterList). 10 | clearguis(). 11 | 12 | wait 5. 13 | HUDtext("Script complete", 5, 2, 30, red, true). 14 | wait 0.5. 15 | HUDtext("Script complete", 5, 2, 30, rgb(1, 0.647, 0), true). 16 | wait 0.5. 17 | HUDtext("Script complete", 5, 2, 30, yellow, true). 18 | wait 0.5. 19 | HUDtext("Script complete", 5, 2, 30, green, true). 20 | wait 0.5. 21 | HUDtext("Script complete", 5, 2, 30, blue, true). 22 | wait 0.5. 23 | HUDtext("Script complete", 5, 2, 30, purple, true). 24 | -------------------------------------------------------------------------------- /kerboscripts/parser_valid/funcParameterTest.ks: -------------------------------------------------------------------------------- 1 | // local function test1 { 2 | // parameter a is 0. 3 | // print a. 4 | // } 5 | 6 | // local function test2 { 7 | // parameter a is 0. 8 | // print a. 9 | // } 10 | 11 | // local b is { parameter b is 0. print b. }. 12 | // local c is { parameter b is 0. print b. }. 13 | 14 | // function createTerrainVecdraws { 15 | // showTerrainVecdraws(false). 16 | // set vd_terrainlist to list(). 17 | // local steps is 0. 18 | // for i in range(steps) { 19 | // vd_terrainlist:add(vecdraw(v(0,0,0),v(0,0,0),rgba(1,i/steps,0,0.5),"",1,terrainVecs,2)). 20 | // } 21 | // } 22 | // function showTerrainVecdraws { 23 | // parameter p. 24 | // for i in range(vd_terrainlist:length) { set vd_terrainlist[i]:show to p. } //color to rgba(1,i/steps,0,0.5). } 25 | // } 26 | 27 | function adjust { 28 | parameter sign. 29 | local func is { print "hi". }. 30 | func(func()). 31 | } -------------------------------------------------------------------------------- /kerboscripts/parser_valid/functest28.ks: -------------------------------------------------------------------------------- 1 | function wants_three_args { 2 | parameter p1, p2, p3. 3 | 4 | print "args were: " + p1 + ", " + p2 + ", " + p3. 5 | }. 6 | 7 | print "Testing function call with too few args.". 8 | print "You should expect an error when this runs.". 9 | print " ". 10 | 11 | wants_three_args("arg1", "arg2" ). // missing arg3. 12 | -------------------------------------------------------------------------------- /kerboscripts/parser_valid/functest29.ks: -------------------------------------------------------------------------------- 1 | function wants_three_args { 2 | parameter p1, p2, p3. 3 | 4 | print "args were: " + p1 + ", " + p2 + ", " + p3. 5 | }. 6 | 7 | print "Testing function call with too many args.". 8 | print "You should expect an error when this runs.". 9 | print " ". 10 | 11 | wants_three_args("arg1", "arg2", "arg3", "arg4" ). // arg4 uncalled for. 12 | -------------------------------------------------------------------------------- /kerboscripts/parser_valid/functest30.ks: -------------------------------------------------------------------------------- 1 | print "Testing the case of a RUN in a loop.". 2 | 3 | set i to 1. 4 | until i > 4 { 5 | print "Iteration " + i. 6 | run functest30_inner(i). 7 | set i to i + 1. 8 | } 9 | -------------------------------------------------------------------------------- /kerboscripts/parser_valid/functest30_inner.ks: -------------------------------------------------------------------------------- 1 | declare parameter p1. 2 | 3 | print "functest31_inner here: I was called with arg: " + p1. 4 | -------------------------------------------------------------------------------- /kerboscripts/parser_valid/functest31.ks: -------------------------------------------------------------------------------- 1 | // 2 | // I am not too sure if this is a feature we want to advertise yet, 3 | // but it does seem to be doable: 4 | // 5 | print "Testing varying args logic". 6 | 7 | // A function that accepts varying args. 8 | // the first arg is a number: how many more args to expect. 9 | // the rest of the args are just printed for testing. 10 | function print_var_args { 11 | parameter how_many. 12 | 13 | // read parameters, filling a local string. 14 | local my_string is "". 15 | local i is 1. 16 | until i > how_many { 17 | parameter next_arg. 18 | set my_string to my_string + " " + next_arg. 19 | set i to i + 1. 20 | } 21 | 22 | print my_string. 23 | } 24 | 25 | 26 | print "This test should work and print: A B C". 27 | print_var_args(3, "A", "B", "C"). 28 | 29 | print "This test should work and print: 10 20 30 40 50 60". 30 | print_var_args(6, 10, 20, 30, 40, 50, 60). 31 | 32 | print "This test should work and print: ". 33 | print_var_args(0). 34 | 35 | print "This test should fail and complain about not enough args:". 36 | print_var_args(5, "A", "B", "C"). // it will try to read more than I sent. 37 | 38 | 39 | -------------------------------------------------------------------------------- /kerboscripts/parser_valid/input/terminal1.ks: -------------------------------------------------------------------------------- 1 | wait 1. 2 | print "Press any key to begin input test...". 3 | global input is terminal:input:getchar(). 4 | global done is false. 5 | print "Input will be echoed back to you. Press q to quit". 6 | until done { 7 | if (terminal:input:haschar) { 8 | set input to terminal:input:getchar(). 9 | if input = "q" { 10 | set done to true. 11 | } 12 | else { 13 | print "Input read was: " + input + " (ascii " + unchar(input) + ")". 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /kerboscripts/parser_valid/integration/basic.ks: -------------------------------------------------------------------------------- 1 | 2 | print("text"). -------------------------------------------------------------------------------- /kerboscripts/parser_valid/integration/func.ks: -------------------------------------------------------------------------------- 1 | 2 | function a 3 | { 4 | print("a"). 5 | } 6 | 7 | a(). -------------------------------------------------------------------------------- /kerboscripts/parser_valid/integration/func_args.ks: -------------------------------------------------------------------------------- 1 | 2 | function f 3 | { 4 | parameter a. 5 | parameter b to 3. 6 | 7 | print(a). 8 | print(b). 9 | } 10 | 11 | f(0, 1). 12 | f(2). -------------------------------------------------------------------------------- /kerboscripts/parser_valid/integration/lock.ks: -------------------------------------------------------------------------------- 1 | 2 | global a to 1. 3 | global b to 2. 4 | 5 | lock c to a + b. 6 | 7 | print(c). 8 | 9 | set b to 3. 10 | print(c). 11 | 12 | set c to 5. 13 | print(c). -------------------------------------------------------------------------------- /kerboscripts/parser_valid/integration/operators.ks: -------------------------------------------------------------------------------- 1 | 2 | set a to 0. 3 | 4 | print(+ 1). 5 | print(- (-1)). 6 | print(not false). 7 | print(defined a). 8 | 9 | print(1 + 2). 10 | print(2 * 3). 11 | print(4 / 2). 12 | print(3 ^ 2). 13 | print(2 > 1). 14 | print(2 >= 1). 15 | print(1 < 2). 16 | print(1 <= 2). 17 | print(1 = 1). 18 | print(1 <> 2). 19 | print(true and true). 20 | print(true or false). 21 | -------------------------------------------------------------------------------- /kerboscripts/parser_valid/integration/suffixes.ks: -------------------------------------------------------------------------------- 1 | 2 | set a to lexicon(). 3 | 4 | print(a:length). 5 | 6 | set a["a"] to 2. 7 | 8 | print(a:length). 9 | 10 | print(a["a"]). 11 | 12 | set a["b"] to list(1,2,3). 13 | 14 | print(a["b"]:length). 15 | 16 | set a:case to true. 17 | 18 | print(a:length). 19 | 20 | set a["a"] to 3. 21 | 22 | print(a:haskey("A")). -------------------------------------------------------------------------------- /kerboscripts/parser_valid/integration/vars.ks: -------------------------------------------------------------------------------- 1 | 2 | set a to 1. 3 | set b to a + 1. 4 | set c to a + b. 5 | 6 | print(a). 7 | print(b). 8 | print(c). 9 | -------------------------------------------------------------------------------- /kerboscripts/parser_valid/ksconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "linting": { 3 | "type-checking": "info" 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /kerboscripts/parser_valid/lib/lib_physics.ks: -------------------------------------------------------------------------------- 1 | // A library of routines to help do basic physics calculations 2 | 3 | @LAZYGLOBAL off. 4 | 5 | // Return the gravity acceleration at SHIP's current location. 6 | declare function g_here { 7 | return constant():G * ((ship:body:mass)/((ship:altitude + body:radius)^2)). 8 | }. 9 | 10 | // Return the force on SHIP due to gravity acceleration at SHIP's current location. 11 | declare function Fg_here { 12 | return ship:mass*g_here(). 13 | }. 14 | 15 | -------------------------------------------------------------------------------- /kerboscripts/parser_valid/lib_toukie/lib_stage.ks: -------------------------------------------------------------------------------- 1 | @lazyglobal off. 2 | 3 | { 4 | 5 | global T_Stage is lexicon( 6 | "StageCheck", StageCheck@, 7 | "EndStage", EndStage@, 8 | "LaunchStage", LaunchStage@ 9 | ). 10 | 11 | Function StageCheck { 12 | 13 | local PrevThrust is MaxThrust. 14 | 15 | when MaxThrust < (PrevThrust - 10) then { 16 | local CurrentThrottle is Throttle. 17 | lock Throttle to 0. 18 | wait until stage:ready. 19 | stage. 20 | wait 1. 21 | lock Throttle to CurrentThrottle. 22 | set PrevThrust to MaxThrust. 23 | preserve. 24 | } 25 | } 26 | 27 | Function EndStage { 28 | Parameter EndStage. 29 | 30 | until stage:number = EndStage { 31 | wait until stage:ready. 32 | stage. 33 | } 34 | 35 | } 36 | 37 | Function LaunchStage { 38 | local startheight is alt:radar. 39 | until ship:availablethrust > 0 { 40 | wait until stage:ready. 41 | stage. 42 | wait 1. 43 | if alt:radar < (startheight+1) { 44 | stage. 45 | } 46 | } 47 | } 48 | } 49 | print "read lib_stage". 50 | -------------------------------------------------------------------------------- /kerboscripts/parser_valid/list/testlist.ks: -------------------------------------------------------------------------------- 1 | // Test the list constructor. 2 | 3 | local l1 is list(). 4 | local l2 is list(5,10,15,20). 5 | // 2-d test: 6 | local m1 is list( list(10,20,30,40), list(15,25,35,45), list(11,22,33,44) ). 7 | 8 | print "----------------------". 9 | print "list l1 is: (should be empty)". 10 | for item in l1 { print item + " " . }. 11 | 12 | print "----------------------". 13 | print "list l2 is: (should be 4 things)". 14 | for item in l2 { print item + " " . }. 15 | 16 | print "----------------------". 17 | print "2-D list m1 is:". 18 | for row in m1 { 19 | local str is "(". 20 | for item in row { 21 | set str to str + item + " ". 22 | }. 23 | set str to str + ") ". 24 | print str. 25 | }. 26 | -------------------------------------------------------------------------------- /kerboscripts/parser_valid/loop/fromthrottletest.ks: -------------------------------------------------------------------------------- 1 | print "This test from issue #1117 excercises the". 2 | print "bug with trying to LOCK THROTTLE inside". 3 | print "a FROM loop". 4 | print "It should move the throttle at T -3 seconds.". 5 | print "--------------------------------------------". 6 | print " ". 7 | FROM { LOCAL countdown IS 10. } UNTIL countdown = 0 STEP { SET countdown TO countdown - 1. } DO { 8 | PRINT "T -" + countdown. 9 | IF countdown = 3 { 10 | print "Throttle should now become 1.". 11 | LOCK THROTTLE TO 1.0. 12 | } 13 | WAIT 1. 14 | } 15 | -------------------------------------------------------------------------------- /kerboscripts/parser_valid/loop/looptest1.ks: -------------------------------------------------------------------------------- 1 | // Test of from loop syntax: 2 | 3 | print "Simple from loop to print from 1 to 10.". 4 | 5 | from {local i is 1.} until i > 10 step {set i to i+1.} do { 6 | print i. 7 | } 8 | print "done". 9 | -------------------------------------------------------------------------------- /kerboscripts/parser_valid/loop/looptest2.ks: -------------------------------------------------------------------------------- 1 | // Test of from loop syntax: 2 | 3 | doTest(). // body of test wrapped in function to prove it's local vars. 4 | 5 | function doTest 6 | { 7 | print "Nested from loop test.". 8 | print "Fills a 2-D array from 0,0, to 3,3, and then prints the array.". 9 | 10 | local arr is List(). 11 | local count is 0. 12 | 13 | print "filling array:". 14 | from {local i is 0.} until i > 3 step {set i to i+1.} do { 15 | arr:add( list() ). 16 | from {local j is 0.} until j > 3 step {set j to j+1.} do { 17 | arr[i]:add( count ). 18 | set count to count + 1. 19 | } 20 | } 21 | 22 | print "printing array:". 23 | from {local i is 0.} until i > 3 step {set i to i+1.} do { 24 | from {local j is 0.} until j > 3 step {set j to j+1.} do { 25 | print "arr["+i+"]["+j+"] = " + arr[i][j]. 26 | } 27 | } 28 | 29 | print "Done, now trying something that should bomb out on purpose.". 30 | print "proving local scope by trying to access i,j outside the loop:". 31 | print "If the next line errors out with unknown identifier, that's CORRECT.". 32 | print "i is " + i + ", and j is " + j. 33 | print "SHOULD NOT GET THIS FAR.". 34 | } 35 | 36 | -------------------------------------------------------------------------------- /kerboscripts/parser_valid/loop/looptest3.ks: -------------------------------------------------------------------------------- 1 | // Additional test to make sure that a from loop can access a nested and an outer function in a loop 2 | set testValue to 0. 3 | doTest(). 4 | 5 | function doTest 6 | { 7 | from {local i is 0.} until i > 3 step {set i to i+1.} do { 8 | addOnce(i). 9 | addDouble(i). 10 | } 11 | 12 | function addOnce{ 13 | parameter addMe. 14 | set testValue to testValue + addMe. 15 | } 16 | } 17 | 18 | function addDouble{ 19 | parameter addMe. 20 | set testValue to testValue + addMe * 2. 21 | } 22 | 23 | if testValue <> 18 { 24 | print "failed: testValue should be 18 and is " + testValue. 25 | } 26 | print "success". 27 | -------------------------------------------------------------------------------- /kerboscripts/parser_valid/missions_toukie/Gaia 01.ks: -------------------------------------------------------------------------------- 1 | local DependenciesList is List( 2 | ("0:/lib_toukie/lib_stage"), 3 | ("0:/lib_toukie/lib_atmos_launch") 4 | ). 5 | 6 | T_Boot["CopyAndRunFile"]("lib_space_check", "0:/lib_toukie/"). 7 | T_SpaceCheck["CopyAndRunLib"](DependenciesList). 8 | 9 | // REAL MISSION 10 | 11 | T_AtmosLaunch["MainLaunch"](). 12 | 13 | // REAL MISSION 14 | -------------------------------------------------------------------------------- /kerboscripts/parser_valid/parameters/paramtest1.ks: -------------------------------------------------------------------------------- 1 | print " ". 2 | print "Defaultable prog params.". 3 | print "Try calling with 2, 3, and 4 args.". 4 | 5 | declare parameter p1, p2, p3 is sqrt(4) - 3. // an expression that evals to -1. 6 | declare parameter p4 is -2. // a hardcoded -1, also test case where they aren't all on the same parameter statement. 7 | 8 | print "Parameters as seen inside program are:". 9 | print " " + p1 + ", " + p2 + ", " + p3 + ", " + p4. 10 | -------------------------------------------------------------------------------- /kerboscripts/parser_valid/parameters/paramtest2.ks: -------------------------------------------------------------------------------- 1 | print " ". 2 | print "Default params, one prog calling another.". 3 | print " ". 4 | print "executing RUN paramtest1(100,200).". 5 | RUN paramtest1(100,200). 6 | print "executing RUN paramtest1(100,200,300).". 7 | RUN paramtest1(100,200,300). 8 | print "executing RUN paramtest1(100,200,300,400).". 9 | RUN paramtest1(100,200,300,400). 10 | -------------------------------------------------------------------------------- /kerboscripts/parser_valid/parameters/paramtest3.ks: -------------------------------------------------------------------------------- 1 | print " ". 2 | print "Defaultable params calling functions". 3 | print "from same program they're declared in.". 4 | print " ". 5 | 6 | function needsZeroOfOne { 7 | parameter funcParam1 is "def1". 8 | 9 | print "inside function, the function is seeing param:". 10 | print " " + funcParam1. 11 | } 12 | 13 | function needsTwoOfFour { 14 | parameter funcParam1, funcParam2, funcParam3 is "def3", funcParam4 is "def4". 15 | 16 | print "inside function, the function is seeing params:". 17 | print " " + funcParam1 + ", " + funcParam2 + ", " + funcParam3 + ", " + funcParam4. 18 | } 19 | 20 | print "Calling needsZeroOfOne('a')". // can't embed quotes yet. 21 | needsZeroOfOne("a"). 22 | print "Calling needsZeroOfOne()". 23 | needsZeroOfOne(). 24 | 25 | print "Calling needsTwoOfFour('a','b','c','d')". 26 | needsTwoOfFour("a","b","c","d"). 27 | print "Calling needsTwoOfFour('a','b','c')". 28 | needsTwoOfFour("a","b","c"). 29 | print "Calling needsTwoOfFour('a','b')". 30 | needsTwoOfFour("a","b"). 31 | 32 | -------------------------------------------------------------------------------- /kerboscripts/parser_valid/parameters/paramtest4.ks: -------------------------------------------------------------------------------- 1 | print " ". 2 | print "Defaultable params calling functions". 3 | print "from library program.". 4 | print " ". 5 | 6 | run paramtest4_lib. 7 | 8 | print "Calling needsZeroOfOne('a')". // can't embed quotes yet. 9 | needsZeroOfOne("a"). 10 | print "Calling needsZeroOfOne()". 11 | needsZeroOfOne(). 12 | 13 | print "Calling needsTwoOfFour('a','b','c','d')". 14 | needsTwoOfFour("a","b","c","d"). 15 | print "Calling needsTwoOfFour('a','b','c')". 16 | needsTwoOfFour("a","b","c"). 17 | print "Calling needsTwoOfFour('a','b')". 18 | needsTwoOfFour("a","b"). 19 | 20 | -------------------------------------------------------------------------------- /kerboscripts/parser_valid/parameters/paramtest4_lib.ks: -------------------------------------------------------------------------------- 1 | print " ". 2 | print "Running Library paramtest4_lib". 3 | print " ". 4 | 5 | function needsZeroOfOne { 6 | parameter funcParam1 is "def1". 7 | 8 | print "inside function, the function is seeing param:". 9 | print " " + funcParam1. 10 | } 11 | 12 | function needsTwoOfFour { 13 | parameter funcParam1, funcParam2, funcParam3 is "def3", funcParam4 is "def4". 14 | 15 | print "inside function, the function is seeing params:". 16 | print " " + funcParam1 + ", " + funcParam2 + ", " + funcParam3 + ", " + funcParam4. 17 | } 18 | 19 | -------------------------------------------------------------------------------- /kerboscripts/parser_valid/parameters/paramtest5.ks: -------------------------------------------------------------------------------- 1 | print " ". 2 | print "Defaultable params calling nested functions". 3 | print " ". 4 | 5 | function needsTwoOfFour { 6 | parameter funcParam1, funcParam2, funcParam3 is "def3". 7 | 8 | // Tricky and ugly example - inner function is nested BEFORE the end of 9 | // the parameters - to test the nested tracking of params: 10 | 11 | function needsZeroOfOne { 12 | parameter funcParam1 is "inner def1". 13 | 14 | print " inside needsZeroOfOne". 15 | print " the function is seeing param:". 16 | print " " + funcParam1. 17 | } 18 | 19 | parameter funcParam4 is "def4". 20 | 21 | print " inside needsTwoOfFour.". 22 | print " the function is seeing these params:". 23 | print " " + funcParam1 + ", " + funcParam2 + ", " + funcParam3 + ", " + funcParam4. 24 | needsZeroOfOne("a"). 25 | needsZeroOfOne(). 26 | 27 | } 28 | 29 | print "Calling needsTwoOfFour('a','b','c','d')". 30 | needsTwoOfFour("a","b","c","d"). 31 | print "Calling needsTwoOfFour('a','b','c')". 32 | needsTwoOfFour("a","b","c"). 33 | print "Calling needsTwoOfFour('a','b')". 34 | needsTwoOfFour("a","b"). 35 | 36 | -------------------------------------------------------------------------------- /kerboscripts/parser_valid/parameters/paramtest6.ks: -------------------------------------------------------------------------------- 1 | print " ". 2 | print "Default params - deliberate syntax error.". 3 | print " ". 4 | print "You should see an error as we try to". 5 | print "compile a program that has default". 6 | print "parameters that aren't at the end". 7 | 8 | run paramtest6_error.ks. 9 | -------------------------------------------------------------------------------- /kerboscripts/parser_valid/parameters/paramtest7.ks: -------------------------------------------------------------------------------- 1 | print " ". 2 | print "Default params - deliberate syntax error.". 3 | print " ". 4 | print "You should see an error as we try to". 5 | print "compile a program that has default". 6 | print "parameters that aren't at the end". 7 | 8 | run paramtest7_error.ks. 9 | -------------------------------------------------------------------------------- /kerboscripts/parser_valid/serialization/misc.ks: -------------------------------------------------------------------------------- 1 | // Tests miscellaneous structures2 2 | 3 | print "These should all be 'True':". 4 | 5 | // Body 6 | writejson(kerbin, "body.json"). 7 | set read to readjson("body.json"). 8 | print read:name = "Kerbin". 9 | 10 | // GeoCoordinates 11 | writejson(latlng(10,20), "geo.json"). 12 | set read to readjson("geo.json"). 13 | print read:lat = 10. 14 | print read:lng = 20. 15 | print read:heading <> 0. 16 | 17 | // Timespan 18 | set t to time. 19 | set s to t:seconds. 20 | writejson(t, "timespan.json"). 21 | set read to readjson("timespan.json"). 22 | print read:seconds = s. 23 | 24 | // Vector 25 | set vec to v(1,2,3). 26 | writejson(vec, "vector.json"). 27 | set read to readjson("vector.json"). 28 | print read:x = 1. 29 | print read:y = 2. 30 | print read:z = 3. 31 | 32 | // Vessel 33 | writejson(ship, "vessel.json"). 34 | set read to readjson("vessel.json"). 35 | print read:name = ship:name. 36 | 37 | // Message 38 | ship:connection:sendmessage(lex("key1", 123)). 39 | set m to ship:messages:pop. 40 | writejson(m, "message.json"). 41 | set read to readjson("message.json"). 42 | print read:content["key1"] = 123. 43 | print read:sender:tostring:contains(ship:name). 44 | -------------------------------------------------------------------------------- /kerboscripts/parser_valid/serialization/range.ks: -------------------------------------------------------------------------------- 1 | set r to range(1, 13, 2). 2 | 3 | writejson(r, "range.json"). 4 | set read to readjson("range.json"). 5 | 6 | print "These should all be 'True':". 7 | 8 | print read:length = r:length. 9 | print read:from = 1. 10 | print read:to = 13. 11 | print read:step = 2. 12 | -------------------------------------------------------------------------------- /kerboscripts/parser_valid/serialization/uniqueset.ks: -------------------------------------------------------------------------------- 1 | // Serializes a set with nested structures in it 2 | 3 | set l to uniqueset(). 4 | 5 | l:add("stringvalue"). 6 | l:add(1). 7 | l:add(true). 8 | l:add(1.5). 9 | l:add("3.5"). 10 | l:add(body:atm). // put in a non-serializable type, this should use object's ToString() method 11 | 12 | set nested to lexicon(). 13 | nested:add("nestedkey1", "value"). 14 | l:add(nested). 15 | 16 | set nested_set to uniqueset(). 17 | nested_set:add("element1"). 18 | nested_set:add(1.2). 19 | l:add(nested_set). 20 | 21 | set nested_stack to stack(). 22 | nested_stack:push("test_stack"). 23 | nested_stack:push(2). 24 | l:add(nested_stack). 25 | 26 | set nested_queue to queue(). 27 | nested_queue:push(1). 28 | nested_queue:push("test_queue"). 29 | l:add(nested_queue). 30 | 31 | writejson(l, "set.json"). 32 | 33 | // Reading & verification 34 | 35 | set read to readjson("set.json"). 36 | 37 | print "These should all be 'True':". 38 | 39 | print read:length = 10. 40 | 41 | print read:contains("stringvalue"). 42 | print read:contains(1). 43 | print not read:contains("1"). 44 | print read:contains(true). 45 | print not read:contains("true"). 46 | print read:contains(1.5). 47 | print not read:contains("1.5"). 48 | print read:contains(body:atm:tostring). 49 | -------------------------------------------------------------------------------- /kerboscripts/parser_valid/test_error.ks: -------------------------------------------------------------------------------- 1 | local Options is list(). 2 | local i is 0. 3 | local page is 0. 4 | 5 | print (i - (1 * page)) + ") - " + Options[i]. 6 | print "" + (i - (1 * page)) + ") - " + Options[i]. 7 | -------------------------------------------------------------------------------- /kerboscripts/parser_valid/triggers/testtrigger1.ks: -------------------------------------------------------------------------------- 1 | print "Testing that an `on` trigger works with a complex expression.". 2 | 3 | print "Trigger should fire only when x changes from even to odd or visa versa". 4 | 5 | local x is 1. 6 | on mod(x,2) { 7 | if mod(x,2)=0 { 8 | print " TRIGGERED: x just became even.". 9 | } else { 10 | print " TRIGGERED: x just became odd.". 11 | } 12 | 13 | preserve. 14 | } 15 | 16 | for num in LIST(1, 3, 5, 7, 11, 9, 10, 8, 2, 6, 19, 13, 15, 18, 20) { 17 | print "Changing x.". 18 | print " x was " + x. 19 | set x to num. 20 | print " x is now " + x. 21 | wait 0.2. 22 | } 23 | 24 | 25 | -------------------------------------------------------------------------------- /kerboscripts/parser_valid/triggers/testtrigger3.ks: -------------------------------------------------------------------------------- 1 | // Program to test that triggers can contain wait's in them now: 2 | // 3 | 4 | on ag1 { 5 | print "(You pressed AG1.. thinking....)". 6 | wait 1. 7 | print "(Still thinking about how you pressed AG1...)". 8 | wait 1. 9 | print "(Okay, done thinking about AG1 now.)". 10 | print "(You may press AG1 again if you like.)". 11 | preserve. 12 | } 13 | 14 | print "Test trigger wait using AG1.". 15 | print "AG1 will last a long time with WAIT.". 16 | print "use CTRL-C to quit.". 17 | wait until false. 18 | 19 | -------------------------------------------------------------------------------- /kerboscripts/parser_valid/triggers/testtrigger5.ks: -------------------------------------------------------------------------------- 1 | print "YOU SHOULD SEE THE MESSAGES". 2 | print "IN THE RIGHT ORDER AND TIMING:". 3 | print "These are a complex set of triggers with waits.". 4 | print "that should print the messages in order despite". 5 | print "them being from different triggers and main code.". 6 | print " ". 7 | 8 | set start_time to time:seconds. 9 | 10 | function timestamp_msg { 11 | parameter msg. 12 | print round(time:seconds - start_time, 2) + ": " + msg. 13 | } 14 | 15 | set rightaway to true. 16 | when rightaway then { 17 | timestamp_msg("msg02: Should be after one 'tick'."). 18 | wait 3. 19 | timestamp_msg("msg03: Should be after 3s+1tick."). 20 | } 21 | set twosecondslater to time:seconds+2. 22 | when time:seconds > twosecondslater then { 23 | timestamp_msg("msg04: Despite trigger call getting put on stack at 2s, it won't start until the other trigger's wait is over, so this should be after 3s."). 24 | wait 2. 25 | timestamp_msg("msg05: Should be after 5s."). 26 | } 27 | 28 | timestamp_msg("msg01: Program starting."). 29 | wait 6. 30 | timestamp_msg("msg06: Program ending after 6s."). 31 | -------------------------------------------------------------------------------- /kerboscripts/parser_valid/triggers/testtrigger6.ks: -------------------------------------------------------------------------------- 1 | // Testing triggers with scopes remembered with closure. 2 | 3 | function outer { 4 | inner(). 5 | 6 | local start_time is time:seconds. 7 | function inner { 8 | local delay_time is 3. 9 | print "will trigger in " + delay_time + " seconds". 10 | // Note the trigger's conditional check can use 11 | // local scope vars too: 12 | when time:seconds > start_time + delay_time then { 13 | print "trigger happened after " + delay_time + " seconds.". 14 | return 0. // fire once only. 15 | } 16 | } 17 | local b is 2. // despite being after function 'inner', this should still 18 | // be in the same scope as variable 'a'. 19 | } 20 | 21 | outer(). 22 | wait 5. 23 | print "done". 24 | -------------------------------------------------------------------------------- /kerboscripts/parser_valid/triggers/testtrigger7.ks: -------------------------------------------------------------------------------- 1 | // Testing triggers with scopes remembered with closure. 2 | 3 | function outerA { 4 | 5 | local start_time is time:seconds. 6 | local myname is "A". 7 | function inner { 8 | local delay_time is 3. 9 | print "Trigger " + myname + " will happen in " + delay_time + " seconds". 10 | // Note the trigger's conditional check can use 11 | // local scope vars too: 12 | when time:seconds > start_time + delay_time then { 13 | print "trigger A happened after " + delay_time + " seconds.". 14 | return 0. // fire once only. 15 | } 16 | } 17 | inner(). 18 | } 19 | 20 | // This will use the same variable names but becasue of scope they 21 | // should be different instances with different values: 22 | function outerB { 23 | 24 | local start_time is time:seconds. 25 | local myname is "B". 26 | function inner { 27 | local sustain_time is 1. 28 | print "Trigger " + myname + " will now continue for " + sustain_time + " seconds". 29 | when true then { 30 | print "trigger B now happening.". 31 | return time:seconds < start_time + sustain_time. 32 | } 33 | } 34 | inner(). 35 | } 36 | 37 | 38 | outerA(). 39 | wait 1.5. 40 | outerB(). 41 | wait 5. 42 | print "done". 43 | -------------------------------------------------------------------------------- /kerboscripts/parser_valid/unitTests/analysis/test.ks: -------------------------------------------------------------------------------- 1 | local s is 10. -------------------------------------------------------------------------------- /kerboscripts/parser_valid/unitTests/breaktest.ks: -------------------------------------------------------------------------------- 1 | set x to 10. 2 | until x < 0 { 3 | set x to x - 1. 4 | 5 | if x = 3 { 6 | break. 7 | } 8 | } 9 | 10 | break. 11 | 12 | function example { 13 | parameter a. 14 | 15 | for i in a { 16 | if i = "item" { 17 | break. 18 | } 19 | } 20 | } 21 | 22 | break. 23 | 24 | from { local y to 0. } until y > 10 step { set y to y + 1. } do { 25 | print(y). 26 | 27 | if y > 20 { 28 | break. 29 | } 30 | } -------------------------------------------------------------------------------- /kerboscripts/parser_valid/unitTests/deferredtest.ks: -------------------------------------------------------------------------------- 1 | // because variables used in functions and triggers can be defined 2 | // after the trigger is defined we defer they're processing until afterwards 3 | 4 | when 10 < c then { 5 | print c. 6 | } 7 | 8 | on c { 9 | print c. 10 | } 11 | 12 | local c is 10. 13 | 14 | local function test { 15 | parameter a. 16 | 17 | print a + b. 18 | } 19 | 20 | local b is 10. 21 | test(). -------------------------------------------------------------------------------- /kerboscripts/parser_valid/unitTests/dualTable.ks: -------------------------------------------------------------------------------- 1 | 2 | local a is 10. 3 | { 4 | local lock a to "10". 5 | local a is 10. 6 | print(a). 7 | } 8 | print(a). 9 | 10 | parameter b is 10. 11 | { 12 | local function b { return "10". }. 13 | local b is 10. 14 | print(b). 15 | } 16 | print(b). -------------------------------------------------------------------------------- /kerboscripts/parser_valid/unitTests/loadFiles/empty/empty.ks: -------------------------------------------------------------------------------- 1 | print("hi"). -------------------------------------------------------------------------------- /kerboscripts/parser_valid/unitTests/loadFiles/example.ks: -------------------------------------------------------------------------------- 1 | print("hi"). -------------------------------------------------------------------------------- /kerboscripts/parser_valid/unitTests/loadFiles/ksconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "archive": "..", 3 | "bodies": ["earth", "moon", "mars"], 4 | "linting": { 5 | "control-flow-break": "off" 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /kerboscripts/parser_valid/unitTests/loadFiles/other.js: -------------------------------------------------------------------------------- 1 | console.log('hello world'); 2 | -------------------------------------------------------------------------------- /kerboscripts/parser_valid/unitTests/preservetest.ks: -------------------------------------------------------------------------------- 1 | 2 | function correct { 3 | preserve. 4 | } 5 | 6 | local a is { 7 | print(a). 8 | preserve. 9 | }. 10 | 11 | when 5 > 10 then { 12 | preserve. 13 | } 14 | 15 | for i in range(10) { 16 | print(i). 17 | preserve. 18 | } 19 | 20 | on true { 21 | preserve. 22 | } 23 | 24 | preserve. -------------------------------------------------------------------------------- /kerboscripts/parser_valid/unitTests/returntest.ks: -------------------------------------------------------------------------------- 1 | 2 | function correct { 3 | local function nested { 4 | return 20. 5 | } 6 | 7 | return nested(). 8 | } 9 | 10 | local a is { 11 | return. 12 | }. 13 | 14 | local x is 10. 15 | 16 | when x > 10 then { 17 | return true. 18 | } 19 | 20 | on true { 21 | return true. 22 | } 23 | 24 | if a { 25 | return. 26 | } 27 | 28 | return "exit". -------------------------------------------------------------------------------- /kerboscripts/parser_valid/unitTests/scannertest.ks: -------------------------------------------------------------------------------- 1 | // if file is used to check the scanner produces the correct 2 | // set of tokens upon scanning the file 3 | @lazyglobal on. 4 | global function test { 5 | parameter a, b is 10. 6 | print(b). 7 | 8 | for i in a { 9 | print(i). 10 | } 11 | 12 | from { local x is 0. } until x > 10 step { set x to x + 1.5. } do { 13 | wait until x. // inline comment 14 | } 15 | } 16 | 17 | // comment 18 | lock t to "example". 19 | 20 | on t { 21 | stage. 22 | clearscreen. 23 | log body:target to "example.txt". 24 | } 25 | unlock t. 26 | 27 | test(list(), 10). 28 | 29 | print(choose "hello" if true else "bye"). 30 | 31 | sas off. 32 | runpath("definedtest.ks"). 33 | 34 | reboot. 35 | -------------------------------------------------------------------------------- /kerboscripts/parser_valid/unitTests/shadow/shadowLib.ks: -------------------------------------------------------------------------------- 1 | 2 | function func {} 3 | global lock lock to 10. 4 | global var is "example". 5 | global param is "example". -------------------------------------------------------------------------------- /kerboscripts/parser_valid/unitTests/shadow/shadowSrc.ks: -------------------------------------------------------------------------------- 1 | runOncePath("shadowLib.ks"). 2 | 3 | local function func { 4 | parameter param. 5 | print(param). 6 | } 7 | local lock lock to 10. 8 | local var is "example". 9 | 10 | print(lock). 11 | print(var). 12 | print(func(10)). -------------------------------------------------------------------------------- /kerboscripts/parser_valid/unitTests/shadow/shadowtest.ks: -------------------------------------------------------------------------------- 1 | // This file check that vscode correctly finds the shadowed variable 2 | local a is 0. 3 | 4 | if true { 5 | local a is 0. 6 | print(a). 7 | } 8 | 9 | print(a). -------------------------------------------------------------------------------- /kerboscripts/parser_valid/unitTests/usedtest.ks: -------------------------------------------------------------------------------- 1 | // check that vscode finds the unused variables 2 | local a is 10. 3 | local b is 10. 4 | local c is "example". 5 | 6 | set a to "example". 7 | print c. 8 | 9 | -------------------------------------------------------------------------------- /kerboscripts/parser_valid/user_functions/functest1.ks: -------------------------------------------------------------------------------- 1 | // Basic simple function define function test: 2 | 3 | set glob_one to 10. 4 | set x to 0. 5 | 6 | lock bar to 5. 7 | declare function foo { 8 | declare x to 1. 9 | print "Inside function foo: x is " + x. 10 | 11 | return "FooValue". 12 | }. 13 | 14 | print "Before calling foo(), outside of foo, x is " + x. 15 | 16 | print "return value from foo() is: " + foo(). 17 | 18 | print "After calling foo(), outside of foo, x is " + x. 19 | 20 | print "using a lock, bar = " + bar. 21 | 22 | print "Deliberate error to force a program dump:". 23 | set x to 1/0. 24 | -------------------------------------------------------------------------------- /kerboscripts/parser_valid/user_functions/functest10.ks: -------------------------------------------------------------------------------- 1 | // Testing a script calling a script with arguments. 2 | 3 | declare parameter arg1,arg2,arg3. 4 | 5 | print "Outer script (functest10) called with arguments:". 6 | print " arg1=" + arg1. 7 | print " arg2=" + arg2. 8 | print " arg3=" + arg3. 9 | 10 | print "Now functest10 is going to call functest10_inner,". 11 | print "Giving it the same args in the same order:". 12 | run functest10_inner(arg1,arg2,arg3). 13 | -------------------------------------------------------------------------------- /kerboscripts/parser_valid/user_functions/functest10_inner.ks: -------------------------------------------------------------------------------- 1 | declare parameter inner1, inner2, inner3. 2 | 3 | print "This is functest10_inner talking.". 4 | print "I think my args are:". 5 | 6 | print " arg1="+inner1. 7 | print " arg2="+inner2. 8 | print " arg3="+inner3. 9 | -------------------------------------------------------------------------------- /kerboscripts/parser_valid/user_functions/functest11.ks: -------------------------------------------------------------------------------- 1 | // Testing the case of a function that calls a RUN 2 | // command from inside of itself: 3 | 4 | declare function foo { 5 | print "Inside function: about to run functest10". 6 | run functest10(10,20,30). 7 | print "Inside function: done running functest10". 8 | }. 9 | 10 | print "Outside function: about to call function". 11 | foo(). 12 | print "Outside function: done calling function". 13 | -------------------------------------------------------------------------------- /kerboscripts/parser_valid/user_functions/functest12.ks: -------------------------------------------------------------------------------- 1 | // Testing the case of a function that contains a WHEN trigger 2 | // inside of itself: 3 | 4 | set x to 0. 5 | 6 | // Try this twice to ensure it gets re-enabled in the second 7 | // function call too. 8 | reinit_triggers(). 9 | print "pass 1: triggers initialized... ". 10 | wait 1. 11 | set x to 1. 12 | wait 1. 13 | set x to 2. 14 | 15 | wait 1. 16 | 17 | reinit_triggers(). 18 | print "pass 2: triggers initialized... ". 19 | wait 1. 20 | set x to 1. 21 | wait 1. 22 | set x to 2. 23 | wait 1. 24 | 25 | print "done with test". 26 | 27 | declare function reinit_triggers { 28 | set x to 0. 29 | 30 | when x = 1 then { 31 | print "When x = 1 trigger has been invoked.". 32 | }. 33 | 34 | when x = 2 then { 35 | print "When x = 2 trigger has been invoked.". 36 | }. 37 | }. 38 | 39 | 40 | -------------------------------------------------------------------------------- /kerboscripts/parser_valid/user_functions/functest13.ks: -------------------------------------------------------------------------------- 1 | // Testing the nesting of function calls and locks inside triggers. 2 | 3 | declare function do_print { 4 | declare parameter str. 5 | print("doprint: printing: " + str). 6 | }. 7 | 8 | when x = 1 then { 9 | do_print("trigger body, when x = 1, y = " + y). 10 | }. 11 | 12 | when x = 2 then { 13 | do_print("trigger body, when x = 2, y = " + y). 14 | }. 15 | 16 | set x to 0. 17 | // Also need to ensure that locks compile correctly here: 18 | lock y to -x. 19 | 20 | wait 1. 21 | set x to 1. 22 | wait 1. 23 | set x to 2. 24 | wait 1. 25 | -------------------------------------------------------------------------------- /kerboscripts/parser_valid/user_functions/functest14.ks: -------------------------------------------------------------------------------- 1 | // An example testing nesting a function inside a function 2 | // when both of them end up having the same name: 3 | // Proper nesting rules should mask the outer function 4 | // with the inner function. 5 | 6 | declare function samename { 7 | declare x to 1. 8 | print "outer function samename() has x = " + x. 9 | 10 | declare function samename { 11 | declare x to 2. 12 | print "inner function samename() has x = " + x. 13 | }. 14 | 15 | samename(). 16 | 17 | }. 18 | 19 | samename(). 20 | -------------------------------------------------------------------------------- /kerboscripts/parser_valid/user_functions/functest16.ks: -------------------------------------------------------------------------------- 1 | // Testing the illegal use of modifiers. 2 | 3 | print "This should complain that you can't use global with function:". 4 | declare global function foo { 5 | print "hello". 6 | }. 7 | 8 | foo(). 9 | -------------------------------------------------------------------------------- /kerboscripts/parser_valid/user_functions/functest17.ks: -------------------------------------------------------------------------------- 1 | // Testing the illegal use of modifiers. 2 | 3 | print "This should complain that you can't use global with parameter:". 4 | declare global parameter foo. 5 | print "I was passed " + foo. 6 | -------------------------------------------------------------------------------- /kerboscripts/parser_valid/user_functions/functest18.ks: -------------------------------------------------------------------------------- 1 | // Testing the illegal use of modifiers. 2 | 3 | @lazyglobal off. 4 | 5 | print "This should complain that you can't leave local or global implicit with @lazyglobal off". 6 | declare foo is 1. // This should require local or global and be an error. 7 | print "foo is " + foo. 8 | -------------------------------------------------------------------------------- /kerboscripts/parser_valid/user_functions/functest19.ks: -------------------------------------------------------------------------------- 1 | // Testing local locks. 2 | 3 | 4 | lock xx to "global lock x". 5 | 6 | { 7 | global lock yy to "global lock y". 8 | local lock zz to "local lock z". 9 | 10 | print "inside scope: xx = " + xx. 11 | print "inside scope: yy = " + yy. 12 | print "inside scope: zz = " + zz. 13 | } 14 | 15 | print "outside scope: xx = " + xx. 16 | print "outside scope: yy = " + yy. 17 | print "next line should barf - zz undefined.". 18 | print "outside scope: zz = " + zz. 19 | -------------------------------------------------------------------------------- /kerboscripts/parser_valid/user_functions/functest2.ks: -------------------------------------------------------------------------------- 1 | // Testing basic functions with args 2 | 3 | // Test that the declare parameter statement still 4 | // does its job at the global level to be used with 5 | // the RUN command like before: 6 | declare parameter global_start_param. 7 | declare parameter global_stop_param. 8 | 9 | // example of use: 10 | // RUN FUNCTEST1(1,5). - counts from 1 to 5, and from 1^2 to 5^2. 11 | 12 | declare function foo { 13 | // Test a mixture of both comma args style and separate arg 14 | // statements style: 15 | declare parameter a. 16 | declare parameter b, c. 17 | declare str to "inside foo(), ". 18 | set str to str + " a=" + a. 19 | set str to str + " b=" + b. 20 | set str to str + " c=" + c. 21 | return str. 22 | }. 23 | 24 | 25 | declare num to global_start_param. 26 | print "num = " + num. 27 | print "global_stop_param = " + global_stop_param. 28 | until num > global_stop_param { 29 | print "calling FOO: " + foo(num, num^2, sqrt(num)). 30 | set num to num + 1. 31 | }. 32 | 33 | print "deliberate errror to force a dump in the log.". 34 | set x to 1/0. 35 | -------------------------------------------------------------------------------- /kerboscripts/parser_valid/user_functions/functest20.ks: -------------------------------------------------------------------------------- 1 | // Testing local locks with repetition. 2 | 3 | 4 | lock xx to "global lock x". 5 | 6 | { 7 | global lock yy to "global lock y". 8 | local lock zz to "local lock z". 9 | 10 | print "inside scope part 1: xx = " + xx. 11 | print "inside scope part 1: yy = " + yy. 12 | print "inside scope part 1: zz = " + zz. 13 | 14 | // Now relocking the values to something new 15 | global lock yy to "global lock y-part2". 16 | local lock zz to "local lock z-part2". 17 | 18 | print "inside scope part 2: xx = " + xx. 19 | print "inside scope part 2: yy = " + yy. 20 | print "inside scope part 2: zz = " + zz. 21 | 22 | } 23 | 24 | lock xx to "global lock part 2". 25 | 26 | print "outside scope: xx = " + xx. 27 | print "outside scope: yy = " + yy. 28 | print "next line should barf - zz undefined.". 29 | print "outside scope: zz = " + zz. 30 | -------------------------------------------------------------------------------- /kerboscripts/parser_valid/user_functions/functest21-inner.ks: -------------------------------------------------------------------------------- 1 | // this is supposed to be called by functest21. 2 | 3 | 4 | // Nothing more than a program designed to ensure that 5 | // an update tick must occur while it is running because 6 | // it executes a lot of instructions: 7 | set counter to 0. 8 | until counter >= 5000 { 9 | set counter to counter + 1. 10 | }. 11 | -------------------------------------------------------------------------------- /kerboscripts/parser_valid/user_functions/functest21.ks: -------------------------------------------------------------------------------- 1 | // Test a case where the same variable is used as both a lock 2 | // and a set, but at two different scopes: 3 | 4 | lock x to 1. 5 | lock y to x/3. 6 | print "Testing that locks don't get broken when running ". 7 | print " a long sub-program that outlasts an IPU boundary.". 8 | print "This program runs a long time counting in its head.". 9 | print "Expect it to take a few seconds.". 10 | print "before: x is " + x. 11 | lock steering to up. 12 | lock throttle to y. // indirect levels of locks to get to a value of 0.3333. 13 | 14 | run functest21_inner. 15 | print "If it got this far, then it worked.". 16 | -------------------------------------------------------------------------------- /kerboscripts/parser_valid/user_functions/functest21_inner.ks: -------------------------------------------------------------------------------- 1 | // this is supposed to be called by functest21. 2 | 3 | 4 | // Nothing more than a program designed to ensure that 5 | // an update tick must occur while it is running because 6 | // it executes a lot of instructions: 7 | set counter to 0. 8 | until counter >= 1000 { 9 | set counter to counter + 1. 10 | }. 11 | -------------------------------------------------------------------------------- /kerboscripts/parser_valid/user_functions/functest22.ks: -------------------------------------------------------------------------------- 1 | // Testing the case of a WHEN trigger containing a lock statement. 2 | 3 | print "If this test operates properly, then". 4 | print "you should see the script print '0' over ". 5 | print "and over for 5 seconds, then start ". 6 | print "printing the current time:seconds over ". 7 | print "and over after that for another 5 ". 8 | print "seconds.". 9 | 10 | lock t to 0. 11 | set ut to time:seconds. 12 | when time:seconds > ut + 5 then { 13 | lock t to time:seconds. 14 | } 15 | 16 | until time:seconds > ut + 10 { 17 | print t. 18 | wait 0.5. 19 | } 20 | print "done with test". 21 | -------------------------------------------------------------------------------- /kerboscripts/parser_valid/user_functions/functest23.ks: -------------------------------------------------------------------------------- 1 | // Testing attempt to lock throttle and steering 2 | // without mentioning them at the global 3 | // scope - only in triggers. From github issue #799 4 | // 5 | print "Test by launching a small rocket manually straight up ". 6 | print "and then waiting for the script to take over at 50m up.". 7 | print "If it works right, the craft should start deflecting down". 8 | print "at 50m, and cut the throttle to 80%.". 9 | print "At 500m it should just stay pointed whichever way it's ". 10 | print "currently going at that moment.". 11 | print " ". 12 | print "If it fails, then the rocket will just keep going straight up.". 13 | print "You have 30 seconds to perform the test.". 14 | 15 | when alt:radar > 50 then { 16 | print "Alt:radar now >50.". 17 | lock steering to (up + r(0,-45,0)). 18 | lock throttle to 0.8. //added 19 | when alt:radar > 500 then { 20 | print "Alt:radar now >500.". 21 | lock steering to ship:prograde:vector. 22 | } 23 | } 24 | // lock steering to up. 25 | // lock throttle to 1. 26 | wait 30. 27 | unlock steering. 28 | unlock throttle. 29 | -------------------------------------------------------------------------------- /kerboscripts/parser_valid/user_functions/functest24.ks: -------------------------------------------------------------------------------- 1 | // Testing calling a built-in function from inside a double-nested fucntion. 2 | 3 | function outer_clamp { 4 | function inner_clamp{ 5 | parameter x. 6 | parameter minval. 7 | parameter maxval. 8 | 9 | return max( min( x, maxval), minval). 10 | }. 11 | print "clamp of 10 to rage 4,9 is ". 12 | print inner_clamp(10,4,9). 13 | }. 14 | 15 | outer_clamp(). 16 | -------------------------------------------------------------------------------- /kerboscripts/parser_valid/user_functions/functest25.ks: -------------------------------------------------------------------------------- 1 | // Test weird case with index nested inside suffix and visa versa. 2 | // within SET statements. 3 | 4 | set a to list(1,2,3). 5 | set endIndex to a:length()-1. 6 | 7 | print "This test case should NOT error out.". 8 | print "------------------------------------". 9 | print " ". 10 | print "Testing nesting suffixes inside set list element:". 11 | print "Of the list " + a + " ...". 12 | print "the last element is currently " + a[endIndex]. 13 | print "or also gotten another way, " + a[a:length()-1]. 14 | 15 | print "And now we change to 5 it one way:". 16 | set a[endIndex] to 5. 17 | print "And the list is now: " + a. 18 | 19 | print "And now we change to 10 a different way:". 20 | set a[a:length()-1] to 10. 21 | print "And the list is now: " + a. 22 | 23 | print " ". 24 | print "Testing list element lookups inside setting suffixes:". 25 | 26 | set b to ship. 27 | print "Setting ship's rootpart tagname to a new name: 'aaaa' ". 28 | set b:parts[0]:tag to "aaaa". 29 | print "New name is '" + b:parts[0]:tag + "'". 30 | 31 | -------------------------------------------------------------------------------- /kerboscripts/parser_valid/user_functions/functest26.ks: -------------------------------------------------------------------------------- 1 | // Test for empty return statement: 2 | 3 | @lazyglobal off. 4 | function reproduce_bug{ 5 | return. 6 | } 7 | print "Testing whether or not naked return works.". 8 | print "The next line should print zero.". 9 | print reproduce_bug(). 10 | print "If it got this far, it worked.". 11 | -------------------------------------------------------------------------------- /kerboscripts/parser_valid/user_functions/functest27.ks: -------------------------------------------------------------------------------- 1 | print "running a test to see if you can call". 2 | print "a function from inside a KSM file.". 3 | 4 | print "Ensuring functest27_b.ksm is deleted:". 5 | log "" to "functest27_b.ksm". deletepath("functest27_b.ksm"). 6 | 7 | print "Trying to compile functest27_b.ks to KSM file:". 8 | compile functest27_b. 9 | print "Now running the compiled KSM file:". 10 | run functest27_b.ksm. 11 | print "Now trying to call the function that was in KSM:". 12 | print_check(). 13 | print "If you got here without error, test passed.". 14 | 15 | -------------------------------------------------------------------------------- /kerboscripts/parser_valid/user_functions/functest27_b.ks: -------------------------------------------------------------------------------- 1 | function print_check { 2 | print "++ I am the function inside functest27_b.". 3 | }. 4 | -------------------------------------------------------------------------------- /kerboscripts/parser_valid/user_functions/functest28.ks: -------------------------------------------------------------------------------- 1 | // Testing issue 1801 - functions nested in anon functions. 2 | 3 | // global named function called from anon function: 4 | function foo_works1 { print "Global named func called from anon works.". } 5 | local fn_works1 is { foo_works1(). }. 6 | fn_works1(). 7 | 8 | // anon function nested in anon function: 9 | local fn_works2 is { 10 | local foo_works2 is { 11 | print "Anon func nested in anon func works.". 12 | }. 13 | foo_works2(). 14 | }. 15 | fn_works2(). 16 | 17 | // nanmed function nested in named function: 18 | function fn_works3 { 19 | function foo_works3 { 20 | print "named func nested in named func works.". 21 | } 22 | foo_works3(). 23 | } 24 | fn_works3(). 25 | 26 | // named function inside anything that is not a function 27 | if true { 28 | function func_inside_if { 29 | print "named func nested in generic braces works.". 30 | } 31 | func_inside_if(). 32 | } 33 | 34 | // named function nested in anon function: 35 | local fn_fails is { 36 | function foo_fails { 37 | print "named func nested in anon func works.". 38 | } 39 | foo_fails(). 40 | }. 41 | fn_fails(). 42 | 43 | -------------------------------------------------------------------------------- /kerboscripts/parser_valid/user_functions/functest29.ks: -------------------------------------------------------------------------------- 1 | print "Testing default function scoping rules". 2 | 3 | run once "functest29_lib.ks". 4 | 5 | print "Should say Func1: " + func1(). 6 | if (func1() <> "Func1") print "!!!!!!!!!! ERROR ERROR ERROR !!!!!!!!!!!" + char(7) + char(7). 7 | local f2 is getfunc2(). 8 | print "Should say Func2: " + f2(). 9 | if (f2() <> "Func2") print "!!!!!!!!!! ERROR ERROR ERROR !!!!!!!!!!!" + char(7) + char(7). 10 | 11 | local f3 is getfunc3(). 12 | print "Should say Func3: " + f3(). 13 | if (f3() <> "Func3") print "!!!!!!!!!! ERROR ERROR ERROR !!!!!!!!!!!" + char(7) + char(7). 14 | 15 | -------------------------------------------------------------------------------- /kerboscripts/parser_valid/user_functions/functest29_lib.ks: -------------------------------------------------------------------------------- 1 | function func1 { 2 | return "Func1". 3 | } 4 | 5 | function getfunc2 { 6 | function sameName { // <--------+--- These two innner functions have the same name 7 | return "Func2". // <-----+--|--- But have different effects when called. 8 | } // | | 9 | return sameName@. // <--+--|--|--- These should return the 2 different versions. 10 | } // | | | 11 | // | | | 12 | function getfunc3 { // | | | 13 | function sameName { // <--|--|--' 14 | return "Func3". // <--|--' 15 | } // | 16 | return sameName@. // <--' 17 | } // 18 | -------------------------------------------------------------------------------- /kerboscripts/parser_valid/user_functions/functest30.ks: -------------------------------------------------------------------------------- 1 | print "Testing explicit function scope keywords override.". 2 | 3 | run once "functest30_lib.ks". 4 | local del is outer(). 5 | 6 | print "Should say global1: " + global1(). 7 | if (global1() <> "global1") print "!!!!!!!!!! ERROR ERRROR !!!!!!!!!!" + char(7) + char (7). 8 | print "Should say global2: " + global2(). 9 | if (global2() <> "global2") print "!!!!!!!!!! ERROR ERRROR !!!!!!!!!!" + char(7) + char (7). 10 | print "Should say global3: " + global3(). 11 | if (global3() <> "global3") print "!!!!!!!!!! ERROR ERRROR !!!!!!!!!!" + char(7) + char (7). 12 | print "Should say local2: " + del(). 13 | if (del() <> "local2") print "!!!!!!!!!! ERROR ERRROR !!!!!!!!!!" + char(7) + char (7). 14 | 15 | print " ". 16 | print "PROGRAM SHOULD NOW FAIL WITH 'local1' NOT FOUND.". 17 | print local1(). 18 | -------------------------------------------------------------------------------- /kerboscripts/parser_valid/user_functions/functest30_lib.ks: -------------------------------------------------------------------------------- 1 | global function global1 { return "global1". } 2 | function global2 { return "global2". } 3 | local function local1 { return "local1". } 4 | 5 | function outer { 6 | function local2 { return "local2". } // local by default 7 | global function global3 { return "global3". } // explicit global keyword despite being nested 8 | function local1 { return local2(). } // Note this local1 should mask the outer local1 9 | 10 | return local1@. // via this delegate, it actually will call local2(). 11 | } 12 | -------------------------------------------------------------------------------- /kerboscripts/parser_valid/user_functions/functest32.ks: -------------------------------------------------------------------------------- 1 | print "testing how arg count works with premature return.". 2 | 3 | function foo { 4 | parameter a. 5 | if a < 1 { 6 | print "abort function foo, invalid arg count given". 7 | return. 8 | } 9 | print "reading " + a + " args.". 10 | from {local i is 1.} until i > a step {set i to i + 1.} do { 11 | parameter temp. 12 | print "arg " + i + " is " + temp. 13 | } 14 | 15 | return. 16 | } 17 | 18 | 19 | foo(1,"a"). 20 | foo(3,"a","b","c"). 21 | print "Premature return test, with no extra args passed. Should be okay.". 22 | foo(0). 23 | print "Premature return test, with some extra args passed. Should be okay.". 24 | foo(0,1,1,1). // check that premature return stmt consumes args properly. 25 | print "Trying again after the premature return cases.". 26 | foo(3,"aaa","bbb","ccc"). // what happens after the premature abort case? 27 | print " ". 28 | print "BUT, THE FOLLOWING SHOULD STILL FAIL.". 29 | print "BECAUSE IT HAS WRONG ARGS BUT NOT A PREMATURE RETURN.". 30 | foo(1,"a","b","c"). // will only read it up to the "a". 31 | -------------------------------------------------------------------------------- /kerboscripts/parser_valid/user_functions/functest33.ks: -------------------------------------------------------------------------------- 1 | // Testing that anon functions can have locks in them. 2 | // (Test added in response to issue #1784 and #1801). 3 | 4 | // Tests that the compiler will properly recurse into 5 | // all the weird places an anon function might be, 6 | // which is pretty much *any* expression, and walk 7 | // their contents looking for LOCK statements. 8 | 9 | function named_func { lock foo to 1. } 10 | 11 | function func_that_invokes_delegate { parameter del. del(). } 12 | function func_that_returns_delegate { return {lock foo to 1.}. } 13 | 14 | global declare_global_anon_func is { lock foo to 1. }. 15 | 16 | set set_stmt_anon_func to { lock foo to 1. }. 17 | 18 | print "Should see no output, no errors. Just program end". 19 | print "==================================================". 20 | named_func(). 21 | declare_global_anon_func(). 22 | set_stmt_anon_func(). 23 | { // do-nothing nested braces for local scoping. 24 | local declare_local_anon_func is { lock foo to 1. }. 25 | declare_local_anon_func(). 26 | } 27 | func_that_invokes_delegate( { lock foo to 1. } ). 28 | func_that_invokes_delegate( func_that_returns_delegate() ). 29 | -------------------------------------------------------------------------------- /kerboscripts/parser_valid/user_functions/functest4.ks: -------------------------------------------------------------------------------- 1 | // functest4. 2 | // An example of a complex function scoping situation with 3 | // nested functions. 4 | 5 | declare a to 1. 6 | 7 | declare function foo { 8 | declare parameter parm. 9 | declare b to 2. 10 | 11 | declare function foo_bar { 12 | declare c to 3. 13 | 14 | return "a is " + a + ", b is " + b + ", c is " + c + " parm is " + parm. 15 | }. 16 | 17 | return foo_bar(). 18 | }. 19 | 20 | print "calling foo() from global scope: " + foo(100). 21 | 22 | // pointless nesting 23 | { 24 | 25 | declare function more_pointless_nesting { 26 | declare a to 5. 27 | print "calling foo() from local scope depth 2: " + foo(100). 28 | }. 29 | declare a to 4. 30 | print "calling foo() from local scope depth 1: " + foo(100). 31 | 32 | more_pointless_nesting(). 33 | }. 34 | 35 | // Should print this every time no matter where it's called from: 36 | // a is 1, b is 2, c is 3, parm is 100. 37 | // not this: 38 | // a is 4, b is 2, c is 3, parm is 100. 39 | // nor this: 40 | // a is 5, b is 2, c is 3, parm is 100. 41 | -------------------------------------------------------------------------------- /kerboscripts/parser_valid/user_functions/functest5.ks: -------------------------------------------------------------------------------- 1 | // One test of the nolazyglobal keyword. 2 | // This should work correctly. 3 | 4 | set x to 1. // this should make a global x for us. 5 | 6 | print "next line should bomb out because lazyglobal isn't at the top.". 7 | @lazyglobal off. 8 | 9 | declare function foo { 10 | set z to 1. 11 | }. 12 | foo(). 13 | -------------------------------------------------------------------------------- /kerboscripts/parser_valid/user_functions/functest6.ks: -------------------------------------------------------------------------------- 1 | // One test of the nolazyglobal keyword. 2 | // This should error out because nolazyglobal isn't at global scope. 3 | 4 | set x to 1. // this should make a global x for us. 5 | 6 | 7 | declare function foo { 8 | print "next line should bomb out because lazyglobal is nested inside braces". 9 | @lazyglobal off. 10 | set z to 1. 11 | }. 12 | foo(). 13 | -------------------------------------------------------------------------------- /kerboscripts/parser_valid/user_functions/functest7.ks: -------------------------------------------------------------------------------- 1 | // One test of the nolazyglobal keyword. 2 | 3 | @lazyglobal off. // at the top - should be okay. 4 | 5 | local x is 1. // this should be fine. 6 | set x to 2. // this should be fine because x exists now. 7 | print "Should bomb out with error because there was no 'declare y' statement and lazyglobals disabled.". 8 | set y to 1. 9 | 10 | declare function foo { 11 | set z to 1. 12 | print "this should not get this far: z = " + z. 13 | }. 14 | foo(). 15 | -------------------------------------------------------------------------------- /kerboscripts/parser_valid/user_functions/functest8.ks: -------------------------------------------------------------------------------- 1 | // Prove that one file can call functions defined in another file. 2 | 3 | run functest3. // library of functions to be used from here. 4 | 5 | print "------------------------------------". 6 | print "Now printing the tree starting from all parts you named 'printme'.". 7 | print "------------------------------------". 8 | 9 | set printMeParts to ship:partstagged("printme"). 10 | if printMeParts:length = 0 { 11 | print "You need to give at least one part the nametag of 'printme' to run this program.". 12 | } else { 13 | for p in printMeParts { 14 | print "----- Branch starting with part " + p + " -----". 15 | printBranch(p, ""). // this function is actually defined in functest3.ks 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /kerboscripts/parser_valid/user_functions/functest9.ks: -------------------------------------------------------------------------------- 1 | print "THIS IS A DELIBERATE TEST OF INFINITE RECURSION.". 2 | print "Let's see how long this goes before KSP barfs.". 3 | print "And let's make sure KSP barfs in a 'clean' way.". 4 | 5 | // Give some time to hit ctrl-C before the big spew of scrolling starts: 6 | print "Starting recurse in....". 7 | print "5 seconds". 8 | wait 1. 9 | print "4 seconds". 10 | wait 1. 11 | print "3 seconds". 12 | wait 1. 13 | print "2 seconds". 14 | wait 1. 15 | print "1 seconds". 16 | wait 1. 17 | print "now". 18 | 19 | recurse(0). 20 | 21 | declare function recurse { 22 | declare parameter depth. 23 | 24 | print " Recurse depth="+depth. 25 | 26 | return recurse(depth+1). 27 | }. 28 | -------------------------------------------------------------------------------- /kerboscripts/parser_valid/user_functions/test1.ks: -------------------------------------------------------------------------------- 1 | global function test { 2 | print("sup"). 3 | } -------------------------------------------------------------------------------- /kerboscripts/parser_valid/user_functions/test2.ks: -------------------------------------------------------------------------------- 1 | runpath("test1.ks"). 2 | -------------------------------------------------------------------------------- /kerboscripts/parser_valid/user_functions/testanonymousfunc1.ks: -------------------------------------------------------------------------------- 1 | print " ==== Anonymous functions. Test 1 ====". 2 | 3 | // Just a dumb test that prints everything 4 | // in the collection that matches the boolean 5 | // test function: 6 | function print_hits { 7 | parameter things, func. 8 | 9 | for thing in things { 10 | if func(thing) 11 | print thing. 12 | } 13 | } 14 | 15 | function is_even { 16 | parameter num. 17 | return (mod(num,2)=0). 18 | } 19 | 20 | local test_list is list(1,2,3,4,5, 50,51,52,53, 6, 7, 8). 21 | 22 | print "Calling print_hits with named function.". 23 | print_hits(test_list, is_even@). 24 | print "Calling print_hits with anonymous function.". 25 | print "Should give the same results as above.". 26 | print_hits(test_list, { parameter num. return mod(num,2)=0. } ). 27 | 28 | -------------------------------------------------------------------------------- /kerboscripts/parser_valid/user_functions/testclosure1.ks: -------------------------------------------------------------------------------- 1 | // Simple test of lock closures 2 | // Test 1: one scope level, not in a function: 3 | 4 | set x to 1. 5 | lock testlock to x. 6 | 7 | print "testlock before scope = " + testlock. 8 | if true { // pointless 'if' to have an excuse for a set of braces 9 | declare local_x to 4. 10 | 11 | lock testlock to x + local_x. // a mix of both local and global things in the expression. 12 | 13 | print "testlock inside scope = " + testlock. 14 | }. 15 | print "testlock after scope = " + testlock. 16 | -------------------------------------------------------------------------------- /kerboscripts/parser_valid/user_functions/testclosure2.ks: -------------------------------------------------------------------------------- 1 | // Simple test of lock closures 2 | // Test 2: nested scope levels, not in a function: 3 | 4 | set x to 1. 5 | set indent to " ". 6 | lock testlock to x. 7 | 8 | declare function printindent{ 9 | declare parameter indent. 10 | print indent + "testlock = " + testlock. 11 | } 12 | 13 | printindent(indent + " before, "). 14 | 15 | // The 'if true' commands are just here to allow valid braces to exist: 16 | if true { 17 | declare local_x to 2. 18 | declare indent to indent + " ". // indent with a longer indent string 19 | 20 | lock testlock to x + local_x. 21 | printindent(indent + " before, "). 22 | 23 | if true { 24 | declare localer_x to 3. 25 | declare indent to indent + " ". 26 | 27 | lock testlock to x + local_x + localer_x. 28 | printindent(indent + " before, "). 29 | 30 | if true { 31 | declare localest_x to 4. 32 | declare indent to indent + " ". 33 | 34 | lock testlock to x + local_x + localer_x + localest_x. 35 | printindent(indent + " innermost, "). 36 | }. 37 | printindent(indent + " after, "). 38 | }. 39 | printindent(indent + " after, "). 40 | }. 41 | printindent(indent + " after, "). 42 | -------------------------------------------------------------------------------- /kerboscripts/parser_valid/user_functions/testclosure3.ks: -------------------------------------------------------------------------------- 1 | // Test of lock closures in which the thing being locked 2 | // is cooked control values 'steering' and 'throttle': 3 | 4 | 5 | // silly example to set the throttle to a 6 | // random value within a clamped range: 7 | declare function set_throt_to_clamped_random { 8 | declare parameter minVal, maxVal. 9 | 10 | declare variance to random(). 11 | 12 | lock throttle to minVal + (maxVal-minVal)*variance. 13 | }. 14 | 15 | // silly example to set the steering to a 16 | // random rotation: 17 | declare function set_steering_random 18 | { 19 | declare xrot to random()*360. 20 | declare yrot to random()*360. 21 | declare zrot to random()*360. 22 | 23 | lock steering to R(xrot,yrot,zrot). 24 | } 25 | 26 | print "Fiddling with the controls randomly for a few seconds:". 27 | set iteration to 0. 28 | until iteration >= 3 { 29 | set_throt_to_clamped_random(0,0.5). 30 | set_steering_random. 31 | print "Keeping these new values for 5 seconds:". 32 | print " trottle = " + round(throttle, 3) + " (clamped from 0 to 0.5).". 33 | print " steering = " + steering. 34 | wait 5. 35 | set iteration to iteration + 1. 36 | }. 37 | 38 | print "Now leaving controls alone at whatever they were.". 39 | print "For 10 seconds before quitting program.". 40 | wait 10. 41 | -------------------------------------------------------------------------------- /kerboscripts/parser_valid/user_functions/testreturn2.ks: -------------------------------------------------------------------------------- 1 | // Testing returns without arguments. 2 | 3 | print "testing return statements without an argument". 4 | 5 | declare function outer1 { 6 | print "function outer1: before for loop". 7 | set foo to list(). 8 | foo:add(1). 9 | foo:add(2). 10 | foo:add(3). 11 | for thing in foo { 12 | print "thing is " + thing. 13 | if thing = 3 { 14 | return. 15 | }. 16 | }. 17 | print "function outer1: after for loop". 18 | return. 19 | }. 20 | 21 | print "before calling function outer1.". 22 | outer1(). 23 | 24 | -------------------------------------------------------------------------------- /kos.configuration.json: -------------------------------------------------------------------------------- 1 | { 2 | "comments": { 3 | "lineComment": "//" 4 | }, 5 | "brackets": [["{", "}"], ["[", "]"], ["(", ")"]], 6 | "autoClosingPairs": [ 7 | { "open": "[", "close": "]" }, 8 | { "open": "{", "close": "}" }, 9 | { "open": "(", "close": ")" }, 10 | { "open": "\"", "close": "\"", "notIn": ["string", "comment"] } 11 | ], 12 | "surroundingPairs": [["{", "}"], ["[", "]"], ["(", ")"]] 13 | } 14 | -------------------------------------------------------------------------------- /server/.npmignore: -------------------------------------------------------------------------------- 1 | kerboscripts -------------------------------------------------------------------------------- /server/.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "typescript.tsdk": "node_modules/typescript/lib" 3 | } -------------------------------------------------------------------------------- /server/benchmark/old/array.benchmark2.ts: -------------------------------------------------------------------------------- 1 | import { benchmark } from '@dynatrace/zakzak'; 2 | import { performance } from 'perf_hooks'; 3 | 4 | benchmark('temp', () => { 5 | const a: number[] = [1, 2, 3]; 6 | let c: number[] = []; 7 | 8 | const catStart = performance.now(); 9 | 10 | for (let i = 0; i < 10000; i++) { 11 | c = c.concat(a, a, a); 12 | } 13 | const catEnd = performance.now(); 14 | 15 | const pushStart = performance.now(); 16 | 17 | for (let i = 0; i < 10000; i++) { 18 | c.push(...a, ...a, ...a); 19 | } 20 | const pushEnd = performance.now(); 21 | 22 | console.log(`concat: ${catEnd - catStart}`); 23 | console.log(`push: ${pushEnd - pushStart}`); 24 | }); 25 | -------------------------------------------------------------------------------- /server/benchmark/scanner.benchmark.ts: -------------------------------------------------------------------------------- 1 | import { suite, benchmark, setup } from '@dynatrace/zakzak'; 2 | import { Scanner } from '../src/scanner/scanner'; 3 | import { join } from 'path'; 4 | import { readFileSync } from 'fs'; 5 | 6 | const testDir = join(__dirname, '../../../kerboscripts/parser_valid/'); 7 | const fakeUri = 'file:///fake/base'; 8 | 9 | suite('scanner', () => { 10 | let ap: string; 11 | let boostback: string; 12 | let allLanguage: string; 13 | 14 | setup(() => { 15 | ap = readFileSync(join(testDir, 'ap.ks'), 'utf8'); 16 | boostback = readFileSync(join(testDir, 'boostback.ks'), 'utf8'); 17 | allLanguage = readFileSync( 18 | join(testDir, 'unitTests', 'allLanguage.ks'), 19 | 'utf8', 20 | ); 21 | }); 22 | 23 | benchmark('construct', () => { 24 | new Scanner('', ''); 25 | return true; 26 | }); 27 | 28 | benchmark('ap.ks', () => { 29 | new Scanner(ap, fakeUri).scanTokens(); 30 | return true; 31 | }); 32 | 33 | benchmark('boostback.ks', () => { 34 | new Scanner(boostback, fakeUri).scanTokens(); 35 | return true; 36 | }); 37 | 38 | benchmark('allLanguage.ks', () => { 39 | new Scanner(allLanguage, fakeUri).scanTokens(); 40 | return true; 41 | }); 42 | }); 43 | -------------------------------------------------------------------------------- /server/bin/kos: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | require('../dist/server.js'); 3 | -------------------------------------------------------------------------------- /server/jest.config.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | const path = require('path'); 3 | const { cpus } = require('os'); 4 | 5 | const config = { 6 | testEnvironment: 'node', 7 | reporters: ['default', 'jest-junit'], 8 | coverageReporters: ['html', 'cobertura'], 9 | maxWorkers: cpus().length, 10 | roots: ['src', 'test'], 11 | coverageDirectory: 'coverage', 12 | collectCoverage: true, 13 | transform: { 14 | '^.+.tsx?$': [ 15 | 'ts-jest', 16 | { 17 | tsconfig: './tsconfig.json', 18 | suiteName: 'jest tests', 19 | classNameTemplate: '{classname} - {title}', 20 | titleTemplate: '{classname} - {title}', 21 | ancestorSeparator: ' > ', 22 | usePathForSuiteName: true, 23 | output: './TEST.xml', 24 | }, 25 | ], 26 | }, 27 | }; 28 | 29 | module.exports = config; 30 | -------------------------------------------------------------------------------- /server/src/@types/jstats.d.ts: -------------------------------------------------------------------------------- 1 | declare module 'jstat'; 2 | -------------------------------------------------------------------------------- /server/src/analysis/models/scopePosition.ts: -------------------------------------------------------------------------------- 1 | import { RealEnvironmentRange } from '../types'; 2 | import { Position } from 'vscode-languageserver'; 3 | import { ScopeKind } from '../../parser/types'; 4 | 5 | export class ScopePosition implements RealEnvironmentRange { 6 | constructor( 7 | public start: Position, 8 | public end: Position) { 9 | } 10 | 11 | get kind(): ScopeKind.local { 12 | return ScopeKind.local; 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /server/src/analysis/models/setResult.ts: -------------------------------------------------------------------------------- 1 | import { ISetResolverResult } from '../types'; 2 | import { flatten } from '../../utilities/arrayUtils'; 3 | import { Token } from '../../models/token'; 4 | 5 | export const setResult = ( 6 | set: Maybe = undefined, 7 | ...used: Token[][] 8 | ): ISetResolverResult => { 9 | return { 10 | set, 11 | used: flatten(used), 12 | }; 13 | }; 14 | -------------------------------------------------------------------------------- /server/src/analysis/models/typeTracker.ts: -------------------------------------------------------------------------------- 1 | import { SymbolTrackerBase, IKsDeclared, TrackerKind, KsSymbol } from '../types'; 2 | import { Location, Range, Position } from 'vscode-languageserver'; 3 | import { builtIn } from '../../utilities/constants'; 4 | import { IType } from '../../typeChecker/types'; 5 | 6 | export class TypeTracker 7 | implements SymbolTrackerBase { 8 | public declared: IKsDeclared; 9 | 10 | constructor(symbol: T, public type: IType) { 11 | this.declared = { 12 | symbol, 13 | type, 14 | uri: builtIn, 15 | range: Range.create(Position.create(0, 0), Position.create(0, 0)), 16 | }; 17 | } 18 | 19 | /** 20 | * Get the the type of the suffix type 21 | * @param _ location is irrelevant since suffix types cannot be changed 22 | */ 23 | public getType(_: Location): IType { 24 | return this.declared.type; 25 | } 26 | 27 | /** 28 | * What kind of tracker is this type 29 | */ 30 | public get kind(): TrackerKind.type { 31 | return TrackerKind.type; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /server/src/controlFlow/models/narrowing.ts: -------------------------------------------------------------------------------- 1 | import { KsSymbol } from '../../analysis/types'; 2 | import { IType } from '../../typeChecker/types'; 3 | 4 | /** 5 | * A class representing a type narrowing. Typically this would be accomplished with 6 | * something of this form `a:istype("string")` 7 | */ 8 | export class Narrowing { 9 | /** 10 | * The symbol to be narrowed 11 | */ 12 | public readonly symbols: KsSymbol; 13 | 14 | /** 15 | * The types that were "included" in this narrowing 16 | */ 17 | public readonly includes: IType[]; 18 | 19 | /** 20 | * The types that were "excluded" in this narrowing 21 | */ 22 | public readonly excludes: IType[]; 23 | 24 | public constructor(symbols: KsSymbol, includes: IType[], excludes: IType[]) { 25 | this.symbols = symbols; 26 | this.includes = includes; 27 | this.excludes = excludes; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /server/src/directives/basicDirectives.ts: -------------------------------------------------------------------------------- 1 | import { Token } from '../models/token'; 2 | import { TokenType } from '../models/tokentypes'; 3 | import { DirectiveTokens } from './types'; 4 | 5 | /** 6 | * Generate new basic directives that follow the form #directive 7 | */ 8 | export class BasicDirective { 9 | /** 10 | * 11 | */ 12 | directive: Token; 13 | 14 | /** 15 | * Construct a new 16 | * @param directive 17 | */ 18 | constructor(directive: Token) { 19 | this.directive = directive; 20 | } 21 | 22 | /** 23 | * Attempt to parse a include directive 24 | * @param directive include directive 25 | */ 26 | static parse( 27 | directive: DirectiveTokens, 28 | ): BasicDirective { 29 | return new BasicDirective(directive.directive); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /server/src/directives/directiveContainer.ts: -------------------------------------------------------------------------------- 1 | import { Include } from './include'; 2 | import { BasicDirective } from './basicDirectives'; 3 | import { TokenType } from '../models/tokentypes'; 4 | 5 | /** 6 | * Available directives is kos-language-server 7 | */ 8 | export interface DirectiveContainer { 9 | /** 10 | * Include directives for have kls act like a file has been run 11 | */ 12 | include: Include[]; 13 | 14 | /** 15 | * Region directives for indicating the beginning of a foldable region 16 | */ 17 | region: BasicDirective[]; 18 | 19 | /** 20 | * End region directives for indicating the end of a foldable region 21 | */ 22 | endRegion: BasicDirective[]; 23 | } 24 | -------------------------------------------------------------------------------- /server/src/directives/types.ts: -------------------------------------------------------------------------------- 1 | import { TokenType } from "../models/tokentypes"; 2 | import { Token } from "../models/token"; 3 | 4 | export interface DirectiveTokens { 5 | directive: Token; 6 | tokens: Token[]; 7 | } -------------------------------------------------------------------------------- /server/src/directives/utils.ts: -------------------------------------------------------------------------------- 1 | import { DirectiveTokens } from './types'; 2 | import { TokenType } from '../models/tokentypes'; 3 | 4 | /** 5 | * Determine if this directive is of a certain type 6 | * @param type expected directive type 7 | * @param directive directive 8 | */ 9 | export const isDirective = ( 10 | type: T, 11 | directive: DirectiveTokens, 12 | ): directive is DirectiveTokens => { 13 | return directive.directive.type === type; 14 | }; 15 | 16 | /** 17 | * Create a type guard for a given type 18 | * @param type type to guard 19 | */ 20 | const makeDirectiveGuard = (type: T) => ( 21 | directive: DirectiveTokens, 22 | ): directive is DirectiveTokens => isDirective(type, directive); 23 | 24 | /** 25 | * Determine if this directive is an include directive 26 | * @param directive directive to check 27 | */ 28 | export const isInclude = makeDirectiveGuard(TokenType.include); 29 | 30 | /** 31 | * Determine if this directive is an region directive 32 | * @param directive directive to check 33 | */ 34 | export const isRegion = makeDirectiveGuard(TokenType.region); 35 | 36 | /** 37 | * Determine if this directive is an endRegion directive 38 | * @param directive directive to check 39 | */ 40 | export const isEndRegion = makeDirectiveGuard(TokenType.endRegion); 41 | -------------------------------------------------------------------------------- /server/src/generator/types.ts: -------------------------------------------------------------------------------- 1 | interface IMutation { 2 | active: boolean; 3 | rate: number; 4 | } 5 | -------------------------------------------------------------------------------- /server/src/models/function.ts: -------------------------------------------------------------------------------- 1 | import { ScopeKind } from '../parser/types'; 2 | import { KsSymbolKind } from '../analysis/types'; 3 | import { Token } from './token'; 4 | import { Range } from 'vscode-languageserver'; 5 | 6 | /** 7 | * A class containing the information of a function 8 | */ 9 | export class KsFunction { 10 | /** 11 | * A kerboscript function constructor 12 | * @param scope the scope of this variable 13 | * @param name the name of this variable 14 | * @param range the range of the function 15 | * @param requiredParameters the number of required parameters 16 | * @param optionalParameters the number of optional parameters 17 | * @param returnValue does the function return a value 18 | */ 19 | constructor( 20 | public readonly scope: ScopeKind, 21 | public readonly name: Token, 22 | public readonly range: Range, 23 | public readonly requiredParameters: number, 24 | public readonly optionalParameters: number, 25 | public readonly returnValue: boolean, 26 | ) { 27 | } 28 | 29 | /** 30 | * What kind of symbol is represented in this case a parameter 31 | */ 32 | get tag(): KsSymbolKind.function { 33 | return KsSymbolKind.function; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /server/src/models/grouping.ts: -------------------------------------------------------------------------------- 1 | import { KsSymbolKind } from '../analysis/types'; 2 | 3 | /** 4 | * A class containing the information of a suffix 5 | */ 6 | export class KsGrouping { 7 | /** 8 | * A kerboscript suffix constructor 9 | * @param name the name of this suffix 10 | */ 11 | constructor(public readonly name: string) {} 12 | 13 | /** 14 | * What kind of symbol is represented in this case a grouping 15 | */ 16 | get tag(): KsSymbolKind.grouping { 17 | return KsSymbolKind.grouping; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /server/src/models/lock.ts: -------------------------------------------------------------------------------- 1 | import { ScopeKind } from '../parser/types'; 2 | import { KsSymbolKind } from '../analysis/types'; 3 | import { Token } from './token'; 4 | import { Range } from 'vscode-languageserver'; 5 | 6 | /** 7 | * A class containing the information of a lock 8 | */ 9 | export class KsLock { 10 | /** 11 | * A kerboscript lock constructor 12 | * @param scope the scope of this lock 13 | * @param name the name of this lock 14 | * @param range the range of this lock 15 | */ 16 | constructor( 17 | public readonly scope: ScopeKind, 18 | public readonly name: Token, 19 | public readonly range: Range, 20 | ) 21 | { } 22 | 23 | /** 24 | * Is this lock "cooked" 25 | */ 26 | get cooked(): boolean { 27 | switch (this.name.lookup) { 28 | case 'throttle': 29 | case 'steering': 30 | case 'wheelthrottle': 31 | case 'wheelsteering': 32 | return true; 33 | default: 34 | return false; 35 | } 36 | } 37 | 38 | /** 39 | * What kind of symbol is represented in this case a lock 40 | */ 41 | get tag(): KsSymbolKind.lock { 42 | return KsSymbolKind.lock; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /server/src/models/parameter.ts: -------------------------------------------------------------------------------- 1 | import { KsSymbolKind } from '../analysis/types'; 2 | import { Token } from './token'; 3 | import { Range } from 'vscode-languageserver'; 4 | 5 | /** 6 | * A class containing the information of a parameter 7 | */ 8 | export class KsParameter { 9 | /** 10 | * A kerboscript parameter constructor 11 | * @param name the name of this parameter 12 | * @param range the range of this parameter 13 | */ 14 | constructor( 15 | public readonly name: Token, 16 | public readonly range: Range, 17 | ) 18 | { } 19 | 20 | /** 21 | * What kind of symbol is represented in this case a parameter 22 | */ 23 | get tag(): KsSymbolKind.parameter { 24 | return KsSymbolKind.parameter; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /server/src/models/suffix.ts: -------------------------------------------------------------------------------- 1 | import { KsSymbolKind } from '../analysis/types'; 2 | 3 | /** 4 | * A class containing the information of a suffix 5 | */ 6 | export class KsSuffix { 7 | /** 8 | * A kerboscript suffix constructor 9 | * @param name the name of this suffix 10 | */ 11 | constructor( 12 | public readonly name: string, 13 | ) 14 | { } 15 | 16 | /** 17 | * What kind of symbol is represented in this case a suffix 18 | */ 19 | get tag(): KsSymbolKind.suffix { 20 | return KsSymbolKind.suffix; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /server/src/models/variable.ts: -------------------------------------------------------------------------------- 1 | import { ScopeKind } from '../parser/types'; 2 | import { KsSymbolKind } from '../analysis/types'; 3 | import { Token } from './token'; 4 | import { Range } from 'vscode-languageserver'; 5 | 6 | /** 7 | * A class containing the information of a variable 8 | */ 9 | export class KsVariable { 10 | /** 11 | * A kerboscript variable constructor 12 | * @param scope the scope of this variable 13 | * @param name the name of this variable 14 | * @param range the range of this variable 15 | */ 16 | constructor( 17 | public readonly scope: ScopeKind, 18 | public readonly name: Token, 19 | public readonly range: Range, 20 | ) 21 | { } 22 | 23 | /** 24 | * What kind of symbol is represented in this case a variable 25 | */ 26 | get tag(): KsSymbolKind.variable { 27 | return KsSymbolKind.variable; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /server/src/parser/models/base.ts: -------------------------------------------------------------------------------- 1 | import { RangeSequence } from '../types'; 2 | import { Location, Position, Range } from 'vscode-languageserver'; 3 | import { EOL } from 'os'; 4 | 5 | export abstract class NodeBase implements RangeSequence { 6 | /** 7 | * Array of all valid ranges in the syntax node 8 | */ 9 | public abstract get ranges(): Range[]; 10 | 11 | /** 12 | * String representation of the syntax node 13 | */ 14 | public toString(): string { 15 | return this.toLines().join(EOL); 16 | } 17 | 18 | /** 19 | * String representation of the syntax node where each element is a line 20 | */ 21 | public abstract toLines(): string[]; 22 | 23 | /** 24 | * Position of start of syntax node 25 | */ 26 | public abstract get start(): Position; 27 | 28 | /** 29 | * Position of end of syntax node 30 | */ 31 | public abstract get end(): Position; 32 | 33 | /** 34 | * Create a uri location for this node element 35 | * @param uri uri to set location to 36 | */ 37 | public toLocation(uri: string): Location { 38 | return { uri, range: { start: this.start, end: this.end } }; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /server/src/parser/utils/parseResult.ts: -------------------------------------------------------------------------------- 1 | import { INodeResult } from '../types'; 2 | import { ParseError } from '../models/parserError'; 3 | 4 | export const nodeResult = ( 5 | stmt: T, 6 | errors: ParseError[], 7 | ): INodeResult => { 8 | return { 9 | errors, 10 | value: stmt, 11 | }; 12 | }; 13 | -------------------------------------------------------------------------------- /server/src/parser/utils/toStringUtils.ts: -------------------------------------------------------------------------------- 1 | 2 | export const joinLines = (separator: string, ...lines: string[][]): string[] => { 3 | if (lines.length === 1) { 4 | return lines[0]; 5 | } 6 | 7 | if (lines.every(t => t.length === 1)) { 8 | return [lines.map(l => l[0]).join(separator)]; 9 | } 10 | 11 | const [first, ...rest] = lines; 12 | const result = first; 13 | for (const restLines of rest) { 14 | result[result.length - 1] = `${result[result.length - 1]}${separator}${restLines[0]}`; 15 | 16 | for (let i = 1; i < restLines.length; i += 1) { 17 | result.push(restLines[i]); 18 | } 19 | } 20 | 21 | return result; 22 | }; 23 | -------------------------------------------------------------------------------- /server/src/scanner/models/marker.ts: -------------------------------------------------------------------------------- 1 | import { Position } from 'vscode-languageserver'; 2 | 3 | /** 4 | * Implementation of vscode position interface 5 | */ 6 | export class Marker implements Position { 7 | public readonly line: number; 8 | public readonly character: number; 9 | 10 | constructor(line: number, character: number) { 11 | this.line = line; 12 | this.character = character; 13 | } 14 | } 15 | 16 | /** 17 | * A mutable implementation of vscode's position interface 18 | */ 19 | export class MutableMarker implements Position { 20 | public line: number; 21 | public character: number; 22 | 23 | constructor(line: number, character: number) { 24 | this.line = line; 25 | this.character = character; 26 | } 27 | 28 | /** 29 | * Create an immutable marker from this mutable marker 30 | */ 31 | public toImmutable(): Marker { 32 | return new Marker(this.line, this.character); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /server/src/typeChecker/initialize.ts: -------------------------------------------------------------------------------- 1 | import { partInitializer } from './ksTypes/parts/initialize'; 2 | import { orbitalInitializer } from './ksTypes/orbital/initialize'; 3 | import { primitiveInitializer } from './ksTypes/primitives/initialize'; 4 | import { collectionInitializer } from './ksTypes/collections/initialize'; 5 | import { guiInitializer } from './ksTypes/gui/initialize'; 6 | import { timeInitializer } from './ksTypes/time/initalize'; 7 | 8 | export const typeInitializer = () => { 9 | primitiveInitializer(); 10 | orbitalInitializer(); 11 | partInitializer(); 12 | collectionInitializer(); 13 | guiInitializer(); 14 | timeInitializer(); 15 | }; 16 | -------------------------------------------------------------------------------- /server/src/typeChecker/ksTypes/addon/addon.ts: -------------------------------------------------------------------------------- 1 | import { createType, createSuffixType, noMap } from '../../utilities/typeCreators'; 2 | import { structureType } from '../primitives/structure'; 3 | import { booleanType } from '../primitives/boolean'; 4 | 5 | export const addonType = createType('addon'); 6 | addonType.addSuper(noMap(structureType)); 7 | 8 | addonType.addSuffixes(noMap(createSuffixType('available', booleanType))); 9 | -------------------------------------------------------------------------------- /server/src/typeChecker/ksTypes/addon/addonList.ts: -------------------------------------------------------------------------------- 1 | import { createType, createArgSuffixType, noMap } from '../../utilities/typeCreators'; 2 | import { structureType } from '../primitives/structure'; 3 | import { booleanType } from '../primitives/boolean'; 4 | import { stringType } from '../primitives/string'; 5 | 6 | export const addonListType = createType('addonList'); 7 | addonListType.addSuper(noMap(structureType)); 8 | 9 | addonListType.addSuffixes( 10 | /* TODO this type can have runtime addons with string -> addon maps */ 11 | noMap(createArgSuffixType('available', booleanType, stringType)), 12 | noMap(createArgSuffixType('hasAddon', booleanType, stringType)), 13 | ); 14 | -------------------------------------------------------------------------------- /server/src/typeChecker/ksTypes/bodyatmosphere.ts: -------------------------------------------------------------------------------- 1 | import { 2 | createType, 3 | createArgSuffixType, 4 | createSuffixType, 5 | noMap, 6 | } from '../utilities/typeCreators'; 7 | import { structureType } from './primitives/structure'; 8 | import { stringType } from './primitives/string'; 9 | import { booleanType } from './primitives/boolean'; 10 | import { scalarType } from './primitives/scalar'; 11 | 12 | export const bodyAtmosphereType = createType('bodyAtmosphere'); 13 | bodyAtmosphereType.addSuper(noMap(structureType)); 14 | 15 | bodyAtmosphereType.addSuffixes( 16 | noMap(createSuffixType('body', stringType)), 17 | noMap(createSuffixType('exists', booleanType)), 18 | noMap(createSuffixType('oxygen', booleanType)), 19 | noMap(createSuffixType('seaLevelPressure', scalarType)), 20 | noMap(createSuffixType('height', scalarType)), 21 | noMap(createArgSuffixType('altitudePressure', scalarType, scalarType)), 22 | noMap(createSuffixType('molarMass', scalarType)), 23 | noMap(createSuffixType('adiabaticIndex', scalarType)), 24 | noMap(createSuffixType('adbIdx', scalarType)), 25 | noMap(createArgSuffixType('altitudeTemperature', scalarType, scalarType)), 26 | noMap(createArgSuffixType('altTemp', scalarType, scalarType)), 27 | ); 28 | -------------------------------------------------------------------------------- /server/src/typeChecker/ksTypes/career.ts: -------------------------------------------------------------------------------- 1 | import { createType, createSuffixType, noMap } from '../utilities/typeCreators'; 2 | import { structureType } from './primitives/structure'; 3 | import { booleanType } from './primitives/boolean'; 4 | import { scalarType } from './primitives/scalar'; 5 | 6 | export const careerType = createType('career'); 7 | careerType.addSuper(noMap(structureType)); 8 | 9 | careerType.addSuffixes( 10 | noMap(createSuffixType('canTrackObjects', booleanType)), 11 | noMap(createSuffixType('patchLimit', scalarType)), 12 | noMap(createSuffixType('canMakeNodes', booleanType)), 13 | noMap(createSuffixType('canDoActions', booleanType)), 14 | ); 15 | -------------------------------------------------------------------------------- /server/src/typeChecker/ksTypes/collections/direction.ts: -------------------------------------------------------------------------------- 1 | import { createType } from '../../utilities/typeCreators'; 2 | 3 | export const directionType = createType('direction'); 4 | -------------------------------------------------------------------------------- /server/src/typeChecker/ksTypes/collections/enumerator.ts: -------------------------------------------------------------------------------- 1 | import { 2 | createArgSuffixType, 3 | createParametricType, 4 | noMap, 5 | mapTypes, 6 | createParametricArgSuffixType, 7 | } from '../../utilities/typeCreators'; 8 | import { structureType } from '../primitives/structure'; 9 | import { booleanType } from '../primitives/boolean'; 10 | import { scalarType } from '../primitives/scalar'; 11 | 12 | export const enumeratorType = createParametricType('enumerator', ['T']); 13 | enumeratorType.addSuper(noMap(structureType)); 14 | 15 | const valueSuffix = createParametricArgSuffixType('value', ['T'], 'T'); 16 | 17 | enumeratorType.addSuffixes( 18 | noMap(createArgSuffixType('next', booleanType)), 19 | noMap(createArgSuffixType('atEnd', booleanType)), 20 | noMap(createArgSuffixType('index', scalarType)), 21 | mapTypes(enumeratorType, valueSuffix), 22 | ); 23 | -------------------------------------------------------------------------------- /server/src/typeChecker/ksTypes/collections/queue.ts: -------------------------------------------------------------------------------- 1 | import { 2 | createParametricType, 3 | createParametricArgSuffixType, 4 | mapTypes, 5 | createArgSuffixType, 6 | noMap, 7 | } from '../../utilities/typeCreators'; 8 | import { enumerableType } from './enumerable'; 9 | import { noneType } from '../primitives/none'; 10 | 11 | export const queueType = createParametricType('queue', ['T']); 12 | queueType.addSuper(mapTypes(queueType, enumerableType)); 13 | 14 | const copySuffix = createParametricArgSuffixType('copy', ['T'], queueType); 15 | const pushSuffix = createParametricArgSuffixType('push', ['T'], noneType, 'T'); 16 | const popSuffix = createParametricArgSuffixType('pop', ['T'], 'T'); 17 | const peekSuffix = createParametricArgSuffixType('peek', ['T'], 'T'); 18 | 19 | queueType.addSuffixes( 20 | mapTypes(queueType, copySuffix), 21 | mapTypes(queueType, pushSuffix), 22 | mapTypes(queueType, popSuffix), 23 | mapTypes(queueType, peekSuffix), 24 | noMap(createArgSuffixType('clear', noneType)), 25 | ); 26 | -------------------------------------------------------------------------------- /server/src/typeChecker/ksTypes/collections/range.ts: -------------------------------------------------------------------------------- 1 | import { 2 | createArgSuffixType, 3 | createType, 4 | noMap, 5 | } from '../../utilities/typeCreators'; 6 | import { enumerableType } from './enumerable'; 7 | import { scalarType } from '../primitives/scalar'; 8 | 9 | export const rangeType = createType('range'); 10 | rangeType.addSuper(noMap(enumerableType.apply(scalarType))); 11 | 12 | rangeType.addSuffixes( 13 | noMap(createArgSuffixType('start', scalarType)), 14 | noMap(createArgSuffixType('stop', scalarType)), 15 | noMap(createArgSuffixType('step', scalarType)), 16 | ); 17 | -------------------------------------------------------------------------------- /server/src/typeChecker/ksTypes/collections/stack.ts: -------------------------------------------------------------------------------- 1 | import { 2 | createParametricType, 3 | createParametricArgSuffixType, 4 | mapTypes, 5 | noMap, 6 | createArgSuffixType, 7 | } from '../../utilities/typeCreators'; 8 | import { enumerableType } from './enumerable'; 9 | import { noneType } from '../primitives/none'; 10 | 11 | export const stackType = createParametricType('stack', ['T']); 12 | stackType.addSuper(mapTypes(stackType, enumerableType)); 13 | 14 | const copySuffix = createParametricArgSuffixType('copy', ['T'], stackType); 15 | const pushSuffix = createParametricArgSuffixType('push', ['T'], noneType, 'T'); 16 | const popSuffix = createParametricArgSuffixType('pop', ['T'], 'T'); 17 | const peekSuffix = createParametricArgSuffixType('peek', ['T'], 'T'); 18 | 19 | stackType.addSuffixes( 20 | mapTypes(stackType, copySuffix), 21 | mapTypes(stackType, pushSuffix), 22 | mapTypes(stackType, popSuffix), 23 | mapTypes(stackType, peekSuffix), 24 | noMap(createArgSuffixType('clear', noneType)), 25 | ); 26 | -------------------------------------------------------------------------------- /server/src/typeChecker/ksTypes/collections/uniqueset.ts: -------------------------------------------------------------------------------- 1 | import { 2 | createParametricType, 3 | createParametricArgSuffixType, 4 | mapTypes, 5 | } from '../../utilities/typeCreators'; 6 | import { noneType } from '../primitives/none'; 7 | import { collectionType } from './enumerable'; 8 | import { booleanType } from '../primitives/boolean'; 9 | 10 | export const uniqueSetType = createParametricType('uniqueSet', ['T']); 11 | uniqueSetType.addSuper(mapTypes(uniqueSetType, collectionType)); 12 | 13 | const copySuffix = createParametricArgSuffixType('copy', ['T'], uniqueSetType); 14 | const addSuffix = createParametricArgSuffixType('add', ['T'], noneType, 'T'); 15 | const removeSuffix = createParametricArgSuffixType( 16 | 'remove', 17 | ['T'], 18 | booleanType, 19 | 'T', 20 | ); 21 | 22 | uniqueSetType.addSuffixes( 23 | mapTypes(uniqueSetType, copySuffix), 24 | mapTypes(uniqueSetType, addSuffix), 25 | mapTypes(uniqueSetType, removeSuffix), 26 | ); 27 | -------------------------------------------------------------------------------- /server/src/typeChecker/ksTypes/collections/userList.ts: -------------------------------------------------------------------------------- 1 | import { listType } from './list'; 2 | import { structureType } from '../primitives/structure'; 3 | 4 | export const userListType = listType.apply(structureType); 5 | -------------------------------------------------------------------------------- /server/src/typeChecker/ksTypes/collections/vector.ts: -------------------------------------------------------------------------------- 1 | import { createType } from '../../utilities/typeCreators'; 2 | 3 | export const vectorType = createType('vector'); 4 | -------------------------------------------------------------------------------- /server/src/typeChecker/ksTypes/communication/connection.ts: -------------------------------------------------------------------------------- 1 | import { 2 | createType, 3 | createArgSuffixType, 4 | createSuffixType, 5 | noMap, 6 | } from '../../utilities/typeCreators'; 7 | import { structureType } from '../primitives/structure'; 8 | import { booleanType } from '../primitives/boolean'; 9 | import { scalarType } from '../primitives/scalar'; 10 | 11 | export const connectionType = createType('connection'); 12 | connectionType.addSuper(noMap(structureType)); 13 | 14 | connectionType.addSuffixes( 15 | noMap(createSuffixType('isConnected', booleanType)), 16 | noMap(createSuffixType('delay', scalarType)), 17 | noMap(createArgSuffixType('sendMessage', booleanType, structureType)), 18 | noMap(createArgSuffixType('destination', structureType)), 19 | ); 20 | -------------------------------------------------------------------------------- /server/src/typeChecker/ksTypes/communication/controlConnection.ts: -------------------------------------------------------------------------------- 1 | import { createType, noMap } from '../../utilities/typeCreators'; 2 | import { connectionType } from './connection'; 3 | 4 | export const controlConnectionType = createType('controlConnection'); 5 | controlConnectionType.addSuper(noMap(connectionType)); 6 | -------------------------------------------------------------------------------- /server/src/typeChecker/ksTypes/communication/homeConnection.ts: -------------------------------------------------------------------------------- 1 | import { createType, noMap } from '../../utilities/typeCreators'; 2 | import { connectionType } from './connection'; 3 | 4 | export const homeConnectionType = createType('homeConnection'); 5 | homeConnectionType.addSuper(noMap(connectionType)); 6 | -------------------------------------------------------------------------------- /server/src/typeChecker/ksTypes/communication/message.ts: -------------------------------------------------------------------------------- 1 | import { createType, createSuffixType, noMap } from '../../utilities/typeCreators'; 2 | import { structureType } from '../primitives/structure'; 3 | import { serializableType } from '../primitives/serializeableStructure'; 4 | import { timeSpanType } from '../time/timespan'; 5 | 6 | export const messageType = createType('message'); 7 | messageType.addSuper(noMap(serializableType)); 8 | 9 | messageType.addSuffixes( 10 | noMap(createSuffixType('sentAt', timeSpanType)), 11 | noMap(createSuffixType('receivedAt', timeSpanType)), 12 | noMap(createSuffixType('sender', structureType)), 13 | noMap(createSuffixType('hasSender', structureType)), 14 | noMap(createSuffixType('content', structureType)), 15 | ); 16 | -------------------------------------------------------------------------------- /server/src/typeChecker/ksTypes/communication/messageQueue.ts: -------------------------------------------------------------------------------- 1 | import { createType, createArgSuffixType, noMap } from '../../utilities/typeCreators'; 2 | import { structureType } from '../primitives/structure'; 3 | 4 | import { messageType } from './message'; 5 | import { noneType } from '../primitives/none'; 6 | import { booleanType } from '../primitives/boolean'; 7 | import { scalarType } from '../primitives/scalar'; 8 | 9 | export const messageQueueType = createType('messageQueue'); 10 | messageQueueType.addSuper(noMap(structureType)); 11 | 12 | messageQueueType.addSuffixes( 13 | noMap(createArgSuffixType('empty', booleanType)), 14 | noMap(createArgSuffixType('length', scalarType)), 15 | noMap(createArgSuffixType('pop', messageType)), 16 | noMap(createArgSuffixType('peek', messageType)), 17 | noMap(createArgSuffixType('clear', noneType)), 18 | noMap(createArgSuffixType('push', noneType, structureType)), 19 | ); 20 | -------------------------------------------------------------------------------- /server/src/typeChecker/ksTypes/communication/processorConnection.ts: -------------------------------------------------------------------------------- 1 | import { createType, noMap } from '../../utilities/typeCreators'; 2 | import { connectionType } from './connection'; 3 | 4 | export const processorConnectionType = createType( 5 | 'processorConnection', 6 | ); 7 | processorConnectionType.addSuper(noMap(connectionType)); 8 | -------------------------------------------------------------------------------- /server/src/typeChecker/ksTypes/communication/vesselConnection.ts: -------------------------------------------------------------------------------- 1 | import { createType, noMap } from '../../utilities/typeCreators'; 2 | import { connectionType } from './connection'; 3 | 4 | export const vesselConnectionType = createType('vesselConnection'); 5 | vesselConnectionType.addSuper(noMap(connectionType)); 6 | -------------------------------------------------------------------------------- /server/src/typeChecker/ksTypes/config.ts: -------------------------------------------------------------------------------- 1 | import { createType, createSetSuffixType, noMap } from '../utilities/typeCreators'; 2 | import { structureType } from './primitives/structure'; 3 | import { scalarType } from './primitives/scalar'; 4 | import { booleanType } from './primitives/boolean'; 5 | 6 | export const configType = createType('config'); 7 | configType.addSuper(noMap(structureType)); 8 | 9 | configType.addSuffixes( 10 | noMap(createSetSuffixType('ipu', scalarType)), 11 | noMap(createSetSuffixType('ucp', booleanType)), 12 | noMap(createSetSuffixType('stat', booleanType)), 13 | noMap(createSetSuffixType('arch', booleanType)), 14 | noMap(createSetSuffixType('obeyHideUi', booleanType)), 15 | noMap(createSetSuffixType('safe', booleanType)), 16 | noMap(createSetSuffixType('audioErr', booleanType)), 17 | noMap(createSetSuffixType('verbose', booleanType)), 18 | noMap(createSetSuffixType('debugEachOpCode', booleanType)), 19 | noMap(createSetSuffixType('blizzy', booleanType)), 20 | noMap(createSetSuffixType('brightness', scalarType)), 21 | noMap(createSetSuffixType('defaultFontSize', scalarType)), 22 | noMap(createSetSuffixType('suppressAutopilot', booleanType)), 23 | ); 24 | -------------------------------------------------------------------------------- /server/src/typeChecker/ksTypes/core.ts: -------------------------------------------------------------------------------- 1 | import { 2 | createType, 3 | createArgSuffixType, 4 | createSuffixType, 5 | noMap, 6 | } from '../utilities/typeCreators'; 7 | import { kosProcessorFieldsType } from './kosProcessorFields'; 8 | import { volumeType } from './io/volume'; 9 | import { versionInfoType } from './versionInfo'; 10 | import { vesselTargetType } from './orbital/vesselTarget'; 11 | import { elementType } from './parts/element'; 12 | import { messageQueueType } from './communication/messageQueue'; 13 | 14 | export const coreType = createType('core'); 15 | coreType.addSuper(noMap(kosProcessorFieldsType)); 16 | 17 | coreType.addSuffixes( 18 | noMap(createSuffixType('version', versionInfoType)), 19 | noMap(createSuffixType('vessel', vesselTargetType)), 20 | noMap(createSuffixType('element', elementType)), 21 | noMap(createSuffixType('currentVolume', volumeType)), 22 | noMap(createArgSuffixType('messages', messageQueueType)), 23 | ); 24 | -------------------------------------------------------------------------------- /server/src/typeChecker/ksTypes/craftTemplate.ts: -------------------------------------------------------------------------------- 1 | import { createType, createSuffixType, noMap } from '../utilities/typeCreators'; 2 | import { structureType } from './primitives/structure'; 3 | import { stringType } from './primitives/string'; 4 | import { scalarType } from './primitives/scalar'; 5 | 6 | export const craftTemplateType = createType('craftTemplate'); 7 | craftTemplateType.addSuper(noMap(structureType)); 8 | 9 | craftTemplateType.addSuffixes( 10 | noMap(createSuffixType('name', stringType)), 11 | noMap(createSuffixType('description', stringType)), 12 | noMap(createSuffixType('editor', stringType)), 13 | noMap(createSuffixType('launchSite', stringType)), 14 | noMap(createSuffixType('mass', stringType)), 15 | noMap(createSuffixType('cost', stringType)), 16 | noMap(createSuffixType('partCount', scalarType)), 17 | ); 18 | -------------------------------------------------------------------------------- /server/src/typeChecker/ksTypes/crew.ts: -------------------------------------------------------------------------------- 1 | import { createType, createSuffixType, noMap } from '../utilities/typeCreators'; 2 | import { scalarType } from './primitives/scalar'; 3 | import { structureType } from './primitives/structure'; 4 | import { stringType } from './primitives/string'; 5 | import { booleanType } from './primitives/boolean'; 6 | import { partType } from './parts/part'; 7 | 8 | export const crewType = createType('crewMember'); 9 | crewType.addSuper(noMap(structureType)); 10 | 11 | crewType.addSuffixes( 12 | noMap(createSuffixType('name', stringType)), 13 | noMap(createSuffixType('tourist', booleanType)), 14 | noMap(createSuffixType('gender', stringType)), 15 | noMap(createSuffixType('trait', stringType)), 16 | noMap(createSuffixType('experience', scalarType)), 17 | noMap(createSuffixType('part', partType)), 18 | noMap(createSuffixType('status', stringType)), 19 | noMap(createSuffixType('experienceValue', scalarType)), 20 | noMap(createSuffixType('kerbalType', stringType)), 21 | ); -------------------------------------------------------------------------------- /server/src/typeChecker/ksTypes/deltaV.ts: -------------------------------------------------------------------------------- 1 | import { 2 | createType, 3 | createSuffixType, 4 | noMap, 5 | createArgSuffixType, 6 | } from '../utilities/typeCreators'; 7 | import { doubleType } from './primitives/scalar'; 8 | import { structureType } from './primitives/structure'; 9 | import { noneType } from './primitives/none'; 10 | 11 | export const deltaVType = createType('deltaV'); 12 | deltaVType.addSuper(noMap(structureType)); 13 | 14 | deltaVType.addSuffixes( 15 | noMap(createSuffixType('current', doubleType)), 16 | noMap(createSuffixType('asl', doubleType)), 17 | noMap(createSuffixType('vacuum', doubleType)), 18 | noMap(createSuffixType('duration', doubleType)), 19 | noMap(createArgSuffixType('forceCalc', noneType)), 20 | ); 21 | -------------------------------------------------------------------------------- /server/src/typeChecker/ksTypes/geoCoordinates.ts: -------------------------------------------------------------------------------- 1 | import { 2 | createType, 3 | createSuffixType, 4 | createArgSuffixType, 5 | noMap, 6 | } from '../utilities/typeCreators'; 7 | import { vectorType } from './collections/vector'; 8 | import { orbitableVelocityType } from './orbitalVelocity'; 9 | import { scalarType } from './primitives/scalar'; 10 | import { serializableType } from './primitives/serializeableStructure'; 11 | import { bodyTargetType } from './orbital/bodyTarget'; 12 | 13 | export const geoCoordinatesType = createType('geoCoordinates'); 14 | geoCoordinatesType.addSuper(noMap(serializableType)); 15 | 16 | geoCoordinatesType.addSuffixes( 17 | noMap(createSuffixType('lat', scalarType)), 18 | noMap(createSuffixType('lng', scalarType)), 19 | noMap(createSuffixType('body', bodyTargetType)), 20 | noMap(createSuffixType('terrainHeight', scalarType)), 21 | noMap(createSuffixType('distance', scalarType)), 22 | noMap(createSuffixType('heading', scalarType)), 23 | noMap(createSuffixType('bearing', scalarType)), 24 | noMap(createSuffixType('position', vectorType)), 25 | noMap(createSuffixType('velocity', orbitableVelocityType)), 26 | noMap(createArgSuffixType('altitudePosition', vectorType, scalarType)), 27 | noMap( 28 | createArgSuffixType('altitudeVelocity', orbitableVelocityType, scalarType), 29 | ), 30 | ); 31 | -------------------------------------------------------------------------------- /server/src/typeChecker/ksTypes/gui/box.ts: -------------------------------------------------------------------------------- 1 | import { createType } from '../../utilities/typeCreators'; 2 | 3 | export const boxType = createType('box'); 4 | -------------------------------------------------------------------------------- /server/src/typeChecker/ksTypes/gui/elements/button.ts: -------------------------------------------------------------------------------- 1 | import { 2 | createType, 3 | createSetSuffixType, 4 | noMap, 5 | } from '../../../utilities/typeCreators'; 6 | import { userDelegateType } from '../../userDelegate'; 7 | import { labelType } from './label'; 8 | import { booleanType } from '../../primitives/boolean'; 9 | 10 | export const buttonType = createType('button'); 11 | buttonType.addSuper(noMap(labelType)); 12 | 13 | buttonType.addSuffixes( 14 | noMap(createSetSuffixType('pressed', booleanType)), 15 | noMap(createSetSuffixType('takePress', booleanType)), 16 | noMap(createSetSuffixType('toggle', booleanType)), 17 | noMap(createSetSuffixType('exclusive', booleanType)), 18 | noMap(createSetSuffixType('onToggle', userDelegateType)), 19 | noMap(createSetSuffixType('onClick', userDelegateType)), 20 | ); 21 | -------------------------------------------------------------------------------- /server/src/typeChecker/ksTypes/gui/elements/label.ts: -------------------------------------------------------------------------------- 1 | import { 2 | createType, 3 | createSetSuffixType, 4 | noMap, 5 | } from '../../../utilities/typeCreators'; 6 | import { widgetType } from '../widget'; 7 | 8 | import { userDelegateType } from '../../userDelegate'; 9 | import { stringType } from '../../primitives/string'; 10 | 11 | export const labelType = createType('label'); 12 | labelType.addSuper(noMap(widgetType)); 13 | 14 | labelType.addSuffixes( 15 | noMap(createSetSuffixType('text', stringType)), 16 | noMap(createSetSuffixType('image', stringType)), 17 | noMap(createSetSuffixType('textUpdater', userDelegateType)), 18 | noMap(createSetSuffixType('tooltip', stringType)), 19 | ); 20 | -------------------------------------------------------------------------------- /server/src/typeChecker/ksTypes/gui/elements/slider.ts: -------------------------------------------------------------------------------- 1 | import { 2 | createType, 3 | createSetSuffixType, 4 | noMap, 5 | } from '../../../utilities/typeCreators'; 6 | import { userDelegateType } from '../../userDelegate'; 7 | import { widgetType } from '../widget'; 8 | import { scalarType } from '../../primitives/scalar'; 9 | 10 | export const sliderType = createType('slider'); 11 | sliderType.addSuper(noMap(widgetType)); 12 | 13 | sliderType.addSuffixes( 14 | noMap(createSetSuffixType('value', scalarType)), 15 | noMap(createSetSuffixType('min', scalarType)), 16 | noMap(createSetSuffixType('max', scalarType)), 17 | noMap(createSetSuffixType('onChange', userDelegateType)), 18 | ); 19 | -------------------------------------------------------------------------------- /server/src/typeChecker/ksTypes/gui/elements/textField.ts: -------------------------------------------------------------------------------- 1 | import { 2 | createType, 3 | createSetSuffixType, 4 | noMap, 5 | } from '../../../utilities/typeCreators'; 6 | import { userDelegateType } from '../../userDelegate'; 7 | import { labelType } from './label'; 8 | import { booleanType } from '../../primitives/boolean'; 9 | 10 | export const textFieldType = createType('textField'); 11 | textFieldType.addSuper(noMap(labelType)); 12 | 13 | textFieldType.addSuffixes( 14 | noMap(createSetSuffixType('changed', booleanType)), 15 | noMap(createSetSuffixType('confirmed', booleanType)), 16 | noMap(createSetSuffixType('onChange', userDelegateType)), 17 | noMap(createSetSuffixType('onConfirm', userDelegateType)), 18 | ); 19 | -------------------------------------------------------------------------------- /server/src/typeChecker/ksTypes/gui/guiWidget.ts: -------------------------------------------------------------------------------- 1 | import { createType } from '../../utilities/typeCreators'; 2 | 3 | export const guiWidgetType = createType('gui'); 4 | -------------------------------------------------------------------------------- /server/src/typeChecker/ksTypes/gui/scrollBox.ts: -------------------------------------------------------------------------------- 1 | import { 2 | createSetSuffixType, 3 | createType, 4 | noMap, 5 | } from '../../utilities/typeCreators'; 6 | import { boxType } from './box'; 7 | import { vectorType } from '../collections/vector'; 8 | import { booleanType } from '../primitives/boolean'; 9 | 10 | export const scrollBoxType = createType('scrollBox'); 11 | scrollBoxType.addSuper(noMap(boxType)); 12 | 13 | scrollBoxType.addSuffixes( 14 | noMap(createSetSuffixType('hAlways', booleanType)), 15 | noMap(createSetSuffixType('vAlways', booleanType)), 16 | noMap(createSetSuffixType('position', vectorType)), 17 | ); 18 | -------------------------------------------------------------------------------- /server/src/typeChecker/ksTypes/gui/spacing.ts: -------------------------------------------------------------------------------- 1 | import { 2 | createSetSuffixType, 3 | createType, 4 | noMap, 5 | } from '../../utilities/typeCreators'; 6 | import { widgetType } from './widget'; 7 | import { scalarType } from '../primitives/scalar'; 8 | 9 | export const spacingType = createType('spacing'); 10 | spacingType.addSuper(noMap(widgetType)); 11 | 12 | spacingType.addSuffixes(noMap(createSetSuffixType('amount', scalarType))); 13 | -------------------------------------------------------------------------------- /server/src/typeChecker/ksTypes/gui/widget.ts: -------------------------------------------------------------------------------- 1 | import { createType } from '../../utilities/typeCreators'; 2 | 3 | export const widgetType = createType('widget'); 4 | -------------------------------------------------------------------------------- /server/src/typeChecker/ksTypes/gui/widgetStyleRectOffset.ts: -------------------------------------------------------------------------------- 1 | import { structureType } from '../primitives/structure'; 2 | import { createSetSuffixType, createType, noMap } from '../../utilities/typeCreators'; 3 | import { integerType } from '../primitives/scalar'; 4 | 5 | export const widgetStyleRectOffsetType = createType('styleRectOffset'); 6 | widgetStyleRectOffsetType.addSuper(noMap(structureType)); 7 | 8 | widgetStyleRectOffsetType.addSuffixes( 9 | noMap(createSetSuffixType('h', integerType)), 10 | noMap(createSetSuffixType('v', integerType)), 11 | noMap(createSetSuffixType('left', integerType)), 12 | noMap(createSetSuffixType('right', integerType)), 13 | noMap(createSetSuffixType('top', integerType)), 14 | noMap(createSetSuffixType('bottom', integerType)), 15 | ); 16 | -------------------------------------------------------------------------------- /server/src/typeChecker/ksTypes/gui/widgetStyleState.ts: -------------------------------------------------------------------------------- 1 | import { structureType } from '../primitives/structure'; 2 | import { createSetSuffixType, createType, noMap } from '../../utilities/typeCreators'; 3 | import { rgbaType } from '../rgba'; 4 | import { stringType } from '../primitives/string'; 5 | 6 | export const widgetStyleStateType = createType('styleState'); 7 | widgetStyleStateType.addSuper(noMap(structureType)); 8 | 9 | widgetStyleStateType.addSuffixes( 10 | noMap(createSetSuffixType('bg', stringType)), 11 | noMap(createSetSuffixType('textColor', rgbaType)), 12 | ); 13 | -------------------------------------------------------------------------------- /server/src/typeChecker/ksTypes/highlight.ts: -------------------------------------------------------------------------------- 1 | import { createType, createSetSuffixType, noMap } from '../utilities/typeCreators'; 2 | import { structureType } from './primitives/structure'; 3 | import { rgbaType } from './rgba'; 4 | import { booleanType } from './primitives/boolean'; 5 | 6 | export const highlightType = createType('highlight'); 7 | highlightType.addSuper(noMap(structureType)); 8 | 9 | highlightType.addSuffixes( 10 | noMap(createSetSuffixType('color', rgbaType)), 11 | noMap(createSetSuffixType('enabled', booleanType)), 12 | ); 13 | -------------------------------------------------------------------------------- /server/src/typeChecker/ksTypes/hsva.ts: -------------------------------------------------------------------------------- 1 | import { 2 | createType, 3 | createSetSuffixType, 4 | noMap, 5 | } from '../utilities/typeCreators'; 6 | import { rgbaType } from './rgba'; 7 | import { scalarType } from './primitives/scalar'; 8 | 9 | export const hsvaType = createType('hsva'); 10 | hsvaType.addSuper(noMap(rgbaType)); 11 | 12 | hsvaType.addSuffixes( 13 | noMap(createSetSuffixType('h', scalarType)), 14 | noMap(createSetSuffixType('hue', scalarType)), 15 | noMap(createSetSuffixType('s', scalarType)), 16 | noMap(createSetSuffixType('saturation', scalarType)), 17 | noMap(createSetSuffixType('v', scalarType)), 18 | noMap(createSetSuffixType('value', scalarType)), 19 | ); 20 | -------------------------------------------------------------------------------- /server/src/typeChecker/ksTypes/io/fileContent.ts: -------------------------------------------------------------------------------- 1 | import { 2 | createType, 3 | createSuffixType, 4 | noMap, 5 | } from '../../utilities/typeCreators'; 6 | import { enumeratorType } from '../collections/enumerator'; 7 | import { integerType, scalarType } from '../primitives/scalar'; 8 | import { booleanType } from '../primitives/boolean'; 9 | import { stringType } from '../primitives/string'; 10 | import { serializableType } from '../primitives/serializeableStructure'; 11 | import { listType } from '../collections/list'; 12 | 13 | export const fileContentType = createType('fileContent'); 14 | fileContentType.addSuper(noMap(serializableType)); 15 | 16 | fileContentType.addSuffixes( 17 | noMap(createSuffixType('length', scalarType)), 18 | noMap(createSuffixType('empty', booleanType)), 19 | noMap(createSuffixType('type', stringType)), 20 | noMap(createSuffixType('string', stringType)), 21 | noMap(createSuffixType('binary', listType.apply(integerType))), 22 | noMap(createSuffixType('iterator', enumeratorType.apply(stringType))), 23 | ); 24 | -------------------------------------------------------------------------------- /server/src/typeChecker/ksTypes/io/volumeDirectory.ts: -------------------------------------------------------------------------------- 1 | import { 2 | createType, 3 | createArgSuffixType, 4 | createSuffixType, 5 | noMap, 6 | } from '../../utilities/typeCreators'; 7 | import { volumeItemType } from './volumeItem'; 8 | import { lexiconType } from '../collections/lexicon'; 9 | import { enumeratorType } from '../collections/enumerator'; 10 | import { iterator } from '../../../utilities/constants'; 11 | 12 | export const volumeDirectoryType = createType('volumeDirectory'); 13 | volumeDirectoryType.addSuper(noMap(volumeItemType)); 14 | 15 | volumeDirectoryType.addSuffixes( 16 | noMap(createArgSuffixType(iterator, enumeratorType.apply(volumeItemType))), 17 | noMap(createSuffixType('list', lexiconType)), 18 | noMap(createSuffixType('lex', lexiconType)), 19 | noMap(createSuffixType('lexicon', lexiconType)), 20 | ); 21 | -------------------------------------------------------------------------------- /server/src/typeChecker/ksTypes/io/volumeItem.ts: -------------------------------------------------------------------------------- 1 | import { createType, createSuffixType, noMap } from '../../utilities/typeCreators'; 2 | import { structureType } from '../primitives/structure'; 3 | import { stringType } from '../primitives/string'; 4 | import { integerType } from '../primitives/scalar'; 5 | import { booleanType } from '../primitives/boolean'; 6 | 7 | export const volumeItemType = createType('volumeitem'); 8 | volumeItemType.addSuper(noMap(structureType)); 9 | 10 | volumeItemType.addSuffixes( 11 | noMap(createSuffixType('name', stringType)), 12 | noMap(createSuffixType('size', integerType)), 13 | noMap(createSuffixType('extension', stringType)), 14 | noMap(createSuffixType('isfile', booleanType)), 15 | ); 16 | -------------------------------------------------------------------------------- /server/src/typeChecker/ksTypes/io/volumneFile.ts: -------------------------------------------------------------------------------- 1 | import { 2 | createType, 3 | createArgSuffixType, 4 | createSuffixType, 5 | noMap, 6 | } from '../../utilities/typeCreators'; 7 | import { structureType } from '../primitives/structure'; 8 | import { volumeItemType } from './volumeItem'; 9 | import { fileContentType } from './fileContent'; 10 | import { noneType } from '../primitives/none'; 11 | import { booleanType } from '../primitives/boolean'; 12 | import { stringType } from '../primitives/string'; 13 | 14 | export const volumeFileType = createType('volumefile'); 15 | volumeFileType.addSuper(noMap(volumeItemType)); 16 | 17 | volumeFileType.addSuffixes( 18 | noMap(createSuffixType('readAll', fileContentType)), 19 | noMap(createArgSuffixType('write', booleanType, structureType)), 20 | noMap(createArgSuffixType('writeln', booleanType, stringType)), 21 | noMap(createArgSuffixType('clear', noneType)), 22 | ); 23 | -------------------------------------------------------------------------------- /server/src/typeChecker/ksTypes/kacAlarmWrapper.ts: -------------------------------------------------------------------------------- 1 | import { 2 | createType, 3 | createSuffixType, 4 | createSetSuffixType, 5 | noMap, 6 | } from '../utilities/typeCreators'; 7 | import { structureType } from './primitives/structure'; 8 | import { stringType } from './primitives/string'; 9 | import { scalarType } from './primitives/scalar'; 10 | import { booleanType } from './primitives/boolean'; 11 | 12 | export const kacAlarmType = createType('kacAlarm'); 13 | kacAlarmType.addSuper(noMap(structureType)); 14 | 15 | kacAlarmType.addSuffixes( 16 | noMap(createSuffixType('id', stringType)), 17 | noMap(createSetSuffixType('name', stringType)), 18 | noMap(createSetSuffixType('notes', stringType)), 19 | noMap(createSetSuffixType('actions', stringType)), 20 | noMap(createSuffixType('type', stringType)), 21 | noMap(createSuffixType('remaining', scalarType)), 22 | noMap(createSetSuffixType('time', scalarType)), 23 | noMap(createSetSuffixType('margin', scalarType)), 24 | noMap(createSetSuffixType('repeat', booleanType)), 25 | noMap(createSetSuffixType('repeatPeriod', scalarType)), 26 | noMap(createSetSuffixType('originBody', stringType)), 27 | noMap(createSetSuffixType('targetBody', stringType)), 28 | ); 29 | -------------------------------------------------------------------------------- /server/src/typeChecker/ksTypes/kosProcessorFields.ts: -------------------------------------------------------------------------------- 1 | import { createType, createArgSuffixType, noMap } from '../utilities/typeCreators'; 2 | import { partModuleType } from './parts/partModule'; 3 | import { volumeType } from './io/volume'; 4 | import { processorConnectionType } from './communication/processorConnection'; 5 | import { noneType } from './primitives/none'; 6 | import { stringType } from './primitives/string'; 7 | 8 | export const kosProcessorFieldsType = createType('kosProcessorFields'); 9 | kosProcessorFieldsType.addSuper(noMap(partModuleType)); 10 | 11 | kosProcessorFieldsType.addSuffixes( 12 | noMap(createArgSuffixType('mode', stringType)), 13 | noMap(createArgSuffixType('activate', noneType)), 14 | noMap(createArgSuffixType('deactivate', noneType)), 15 | noMap(createArgSuffixType('volume', volumeType)), 16 | noMap(createArgSuffixType('tag', stringType)), 17 | noMap(createArgSuffixType('bootFilename', stringType)), 18 | noMap(createArgSuffixType('connection', processorConnectionType)), 19 | ); 20 | -------------------------------------------------------------------------------- /server/src/typeChecker/ksTypes/loadDistance.ts: -------------------------------------------------------------------------------- 1 | import { createType, createSuffixType, noMap } from '../utilities/typeCreators'; 2 | import { structureType } from './primitives/structure'; 3 | import { situationLoadDistanceType } from './situtationLoadDistance'; 4 | 5 | export const loadDistanceType = createType('loadDistance'); 6 | loadDistanceType.addSuper(noMap(structureType)); 7 | 8 | loadDistanceType.addSuffixes( 9 | noMap(createSuffixType('escaping', situationLoadDistanceType)), 10 | noMap(createSuffixType('flying', situationLoadDistanceType)), 11 | noMap(createSuffixType('landed', situationLoadDistanceType)), 12 | noMap(createSuffixType('orbit', situationLoadDistanceType)), 13 | noMap(createSuffixType('prelaunch', situationLoadDistanceType)), 14 | noMap(createSuffixType('splashed', situationLoadDistanceType)), 15 | noMap(createSuffixType('suborbital', situationLoadDistanceType)), 16 | ); 17 | -------------------------------------------------------------------------------- /server/src/typeChecker/ksTypes/node.ts: -------------------------------------------------------------------------------- 1 | import { 2 | createType, 3 | createSuffixType, 4 | createSetSuffixType, 5 | noMap, 6 | } from '../utilities/typeCreators'; 7 | import { structureType } from './primitives/structure'; 8 | import { vectorType } from './collections/vector'; 9 | import { orbitInfoType } from './orbitInfo'; 10 | import { scalarType } from './primitives/scalar'; 11 | 12 | export const nodeType = createType('node'); 13 | nodeType.addSuper(noMap(structureType)); 14 | 15 | nodeType.addSuffixes( 16 | noMap(createSuffixType('deltaV', vectorType)), 17 | noMap(createSuffixType('burnVector', vectorType)), 18 | noMap(createSetSuffixType('eta', scalarType)), 19 | noMap(createSetSuffixType('prograde', scalarType)), 20 | noMap(createSetSuffixType('radialOut', scalarType)), 21 | noMap(createSetSuffixType('normal', scalarType)), 22 | noMap(createSuffixType('obt', orbitInfoType)), 23 | noMap(createSuffixType('orbit', orbitInfoType)), 24 | ); 25 | -------------------------------------------------------------------------------- /server/src/typeChecker/ksTypes/note.ts: -------------------------------------------------------------------------------- 1 | import { createType, createSuffixType, noMap } from '../utilities/typeCreators'; 2 | import { doubleType } from './primitives/scalar'; 3 | import { serializableType } from './primitives/serializeableStructure'; 4 | 5 | export const noteType = createType('note'); 6 | noteType.addSuper(noMap(serializableType)); 7 | 8 | noteType.addSuffixes( 9 | noMap(createSuffixType('frequency', doubleType)), 10 | noMap(createSuffixType('endFrequency', doubleType)), 11 | noMap(createSuffixType('volume', doubleType)), 12 | noMap(createSuffixType('keyDownLength', doubleType)), 13 | noMap(createSuffixType('duration', doubleType)), 14 | ); 15 | -------------------------------------------------------------------------------- /server/src/typeChecker/ksTypes/orbitEta.ts: -------------------------------------------------------------------------------- 1 | import { 2 | createArgSuffixType, 3 | createType, 4 | noMap, 5 | } from '../utilities/typeCreators'; 6 | import { scalarType } from './primitives/scalar'; 7 | import { structureType } from './primitives/structure'; 8 | 9 | export const orbitEtaType = createType('orbitEta'); 10 | orbitEtaType.addSuper(noMap(structureType)); 11 | 12 | orbitEtaType.addSuffixes( 13 | noMap(createArgSuffixType('apoapsis', scalarType)), 14 | noMap(createArgSuffixType('periapsis', scalarType)), 15 | noMap(createArgSuffixType('transition', scalarType)), 16 | noMap(createArgSuffixType('nextNode', scalarType)), 17 | ); 18 | -------------------------------------------------------------------------------- /server/src/typeChecker/ksTypes/orbital/bodyTarget.ts: -------------------------------------------------------------------------------- 1 | import { createType } from '../../utilities/typeCreators'; 2 | 3 | export const bodyTargetType = createType('bodyTarget'); 4 | -------------------------------------------------------------------------------- /server/src/typeChecker/ksTypes/orbital/orbitable.ts: -------------------------------------------------------------------------------- 1 | import { createType } from '../../utilities/typeCreators'; 2 | 3 | export const orbitableType = createType('orbitable'); 4 | -------------------------------------------------------------------------------- /server/src/typeChecker/ksTypes/orbital/vesselTarget.ts: -------------------------------------------------------------------------------- 1 | import { createType } from '../../utilities/typeCreators'; 2 | 3 | export const vesselTargetType = createType('vesselTarget'); 4 | -------------------------------------------------------------------------------- /server/src/typeChecker/ksTypes/orbitalVelocity.ts: -------------------------------------------------------------------------------- 1 | import { createType, createSuffixType, noMap } from '../utilities/typeCreators'; 2 | import { structureType } from './primitives/structure'; 3 | import { vectorType } from './collections/vector'; 4 | 5 | export const orbitableVelocityType = createType('orbitableVelocity'); 6 | orbitableVelocityType.addSuper(noMap(structureType)); 7 | 8 | orbitableVelocityType.addSuffixes( 9 | noMap(createSuffixType('obt', vectorType)), 10 | noMap(createSuffixType('orbit', vectorType)), 11 | noMap(createSuffixType('surface', vectorType)), 12 | ); 13 | -------------------------------------------------------------------------------- /server/src/typeChecker/ksTypes/parts/activeResource.ts: -------------------------------------------------------------------------------- 1 | import { createType, noMap } from '../../utilities/typeCreators'; 2 | import { aggregateResourceType } from './aggregateResource'; 3 | 4 | export const activeResourceType = createType('activeResource'); 5 | activeResourceType.addSuper(noMap(aggregateResourceType)); 6 | -------------------------------------------------------------------------------- /server/src/typeChecker/ksTypes/parts/aggregateResource.ts: -------------------------------------------------------------------------------- 1 | import { createType, createSuffixType, noMap } from '../../utilities/typeCreators'; 2 | import { structureType } from '../primitives/structure'; 3 | import { stringType } from '../primitives/string'; 4 | import { scalarType } from '../primitives/scalar'; 5 | import { listType } from '../collections/list'; 6 | import { partType } from './part'; 7 | 8 | export const aggregateResourceType = createType('aggregateResource'); 9 | aggregateResourceType.addSuper(noMap(structureType)); 10 | 11 | aggregateResourceType.addSuffixes( 12 | noMap(createSuffixType('name', stringType)), 13 | noMap(createSuffixType('density', scalarType)), 14 | noMap(createSuffixType('amount', scalarType)), 15 | noMap(createSuffixType('capacity', scalarType)), 16 | noMap(createSuffixType('parts', listType.apply(partType))), 17 | ); 18 | -------------------------------------------------------------------------------- /server/src/typeChecker/ksTypes/parts/bounds.ts: -------------------------------------------------------------------------------- 1 | import { 2 | createType, 3 | createSetSuffixType, 4 | createArgSuffixType, 5 | noMap, 6 | } from '../../utilities/typeCreators'; 7 | import { structureType } from '../primitives/structure'; 8 | import { scalarType } from '../primitives/scalar'; 9 | import { vectorType } from '../collections/vector'; 10 | import { directionType } from '../collections/direction'; 11 | 12 | export const boundsType = createType('bounds'); 13 | boundsType.addSuper(noMap(structureType)); 14 | 15 | boundsType.addSuffixes( 16 | noMap(createSetSuffixType('absOrigin', vectorType)), 17 | noMap(createSetSuffixType('facing', directionType)), 18 | noMap(createSetSuffixType('relMin', vectorType)), 19 | noMap(createSetSuffixType('relMax', vectorType)), 20 | noMap(createArgSuffixType('absMin', vectorType)), 21 | noMap(createArgSuffixType('absMax', vectorType)), 22 | noMap(createArgSuffixType('relCenter', vectorType)), 23 | noMap(createArgSuffixType('absCenter', vectorType)), 24 | noMap(createSetSuffixType('extents', vectorType)), 25 | noMap(createSetSuffixType('size', vectorType)), 26 | noMap(createArgSuffixType('furthestCorner', vectorType, vectorType)), 27 | noMap(createArgSuffixType('bottomAlt', scalarType)), 28 | noMap(createArgSuffixType('bottomAltRadar', scalarType)), 29 | ); 30 | -------------------------------------------------------------------------------- /server/src/typeChecker/ksTypes/parts/consumedResource.ts: -------------------------------------------------------------------------------- 1 | import { 2 | createType, 3 | createSuffixType, 4 | noMap, 5 | } from '../../utilities/typeCreators'; 6 | import { structureType } from '../primitives/structure'; 7 | import { stringType } from '../primitives/string'; 8 | import { scalarType } from '../primitives/scalar'; 9 | 10 | export const aggregateResourceType = createType('consumedResource'); 11 | aggregateResourceType.addSuper(noMap(structureType)); 12 | 13 | aggregateResourceType.addSuffixes( 14 | noMap(createSuffixType('name', stringType)), 15 | noMap(createSuffixType('density', scalarType)), 16 | noMap(createSuffixType('fuelFlow', scalarType)), 17 | noMap(createSuffixType('maxFuelFlow', scalarType)), 18 | noMap(createSuffixType('requiredFlow', scalarType)), 19 | noMap(createSuffixType('massFlow', scalarType)), 20 | noMap(createSuffixType('maxMassFlow', scalarType)), 21 | noMap(createSuffixType('ratio', scalarType)), 22 | noMap(createSuffixType('amount', scalarType)), 23 | noMap(createSuffixType('capacity', scalarType)), 24 | ); 25 | -------------------------------------------------------------------------------- /server/src/typeChecker/ksTypes/parts/consumedResourceRcs.ts: -------------------------------------------------------------------------------- 1 | import { 2 | createType, 3 | createSuffixType, 4 | noMap, 5 | } from '../../utilities/typeCreators'; 6 | import { structureType } from '../primitives/structure'; 7 | import { stringType } from '../primitives/string'; 8 | import { scalarType } from '../primitives/scalar'; 9 | 10 | export const aggregateResourceType = createType('consumedResourceRcs'); 11 | aggregateResourceType.addSuper(noMap(structureType)); 12 | 13 | aggregateResourceType.addSuffixes( 14 | noMap(createSuffixType('name', stringType)), 15 | noMap(createSuffixType('density', scalarType)), 16 | noMap(createSuffixType('ratio', scalarType)), 17 | noMap(createSuffixType('amount', scalarType)), 18 | noMap(createSuffixType('capacity', scalarType)), 19 | ); 20 | -------------------------------------------------------------------------------- /server/src/typeChecker/ksTypes/parts/decoupler.ts: -------------------------------------------------------------------------------- 1 | import { createType, noMap } from '../../utilities/typeCreators'; 2 | import { partType } from './part'; 3 | 4 | export const decouplerType = createType('decoupler'); 5 | decouplerType.addSuper(noMap(partType)); 6 | -------------------------------------------------------------------------------- /server/src/typeChecker/ksTypes/parts/element.ts: -------------------------------------------------------------------------------- 1 | import { createType, createSuffixType, noMap } from '../../utilities/typeCreators'; 2 | import { structureType } from '../primitives/structure'; 3 | import { listType } from '../collections/list'; 4 | import { stringType } from '../primitives/string'; 5 | import { vesselTargetType } from '../orbital/vesselTarget'; 6 | import { partType } from './part'; 7 | import { dockingPortType } from './dockingPort'; 8 | import { aggregateResourceType } from './aggregateResource'; 9 | import { decouplerType } from './decoupler'; 10 | 11 | export const elementType = createType('element'); 12 | elementType.addSuper(noMap(structureType)); 13 | 14 | elementType.addSuffixes( 15 | noMap(createSuffixType('name', stringType)), 16 | noMap(createSuffixType('uid', stringType)), 17 | noMap(createSuffixType('vessel', vesselTargetType)), 18 | noMap(createSuffixType('parts', listType.apply(partType))), 19 | noMap(createSuffixType('dockingPorts', listType.apply(dockingPortType))), 20 | noMap(createSuffixType('decouplers', listType.apply(decouplerType))), 21 | noMap(createSuffixType('separators', listType.apply(decouplerType))), 22 | noMap(createSuffixType('resources', listType.apply(aggregateResourceType))), 23 | ); 24 | -------------------------------------------------------------------------------- /server/src/typeChecker/ksTypes/parts/gimbal.ts: -------------------------------------------------------------------------------- 1 | import { 2 | createType, 3 | createSuffixType, 4 | createSetSuffixType, 5 | noMap, 6 | } from '../../utilities/typeCreators'; 7 | import { booleanType } from '../primitives/boolean'; 8 | import { partModuleType } from './partModule'; 9 | import { scalarType } from '../primitives/scalar'; 10 | 11 | export const gimbalType = createType('gimbal'); 12 | gimbalType.addSuper(noMap(partModuleType)); 13 | 14 | gimbalType.addSuffixes( 15 | noMap(createSetSuffixType('lock', booleanType)), 16 | noMap(createSetSuffixType('pitch', booleanType)), 17 | noMap(createSetSuffixType('yaw', booleanType)), 18 | noMap(createSetSuffixType('roll', booleanType)), 19 | noMap(createSetSuffixType('limit', scalarType)), 20 | noMap(createSuffixType('range', scalarType)), 21 | noMap(createSuffixType('responseSpeed', scalarType)), 22 | noMap(createSuffixType('pitchAngle', scalarType)), 23 | noMap(createSuffixType('yawAngle', scalarType)), 24 | noMap(createSuffixType('rollAngle', scalarType)), 25 | ); 26 | -------------------------------------------------------------------------------- /server/src/typeChecker/ksTypes/parts/part.ts: -------------------------------------------------------------------------------- 1 | import { createType } from '../../utilities/typeCreators'; 2 | 3 | export const partType = createType('part'); 4 | -------------------------------------------------------------------------------- /server/src/typeChecker/ksTypes/parts/partModule.ts: -------------------------------------------------------------------------------- 1 | import { createType } from '../../utilities/typeCreators'; 2 | 3 | export const partModuleType = createType('partModule'); 4 | -------------------------------------------------------------------------------- /server/src/typeChecker/ksTypes/parts/resource.ts: -------------------------------------------------------------------------------- 1 | import { 2 | createType, 3 | createSuffixType, 4 | createSetSuffixType, 5 | noMap, 6 | } from '../../utilities/typeCreators'; 7 | import { structureType } from '../primitives/structure'; 8 | import { stringType } from '../primitives/string'; 9 | import { scalarType } from '../primitives/scalar'; 10 | import { booleanType } from '../primitives/boolean'; 11 | 12 | export const resourceType = createType('resource'); 13 | resourceType.addSuper(noMap(structureType)); 14 | 15 | resourceType.addSuffixes( 16 | noMap(createSuffixType('name', stringType)), 17 | noMap(createSuffixType('amount', scalarType)), 18 | noMap(createSuffixType('density', scalarType)), 19 | noMap(createSuffixType('capacity', scalarType)), 20 | noMap(createSuffixType('toggleable', booleanType)), 21 | noMap(createSetSuffixType('enabled', booleanType)), 22 | ); 23 | -------------------------------------------------------------------------------- /server/src/typeChecker/ksTypes/parts/scienceContainerModule.ts: -------------------------------------------------------------------------------- 1 | import { 2 | createArgSuffixType, 3 | createSuffixType, 4 | createType, 5 | noMap, 6 | } from '../../utilities/typeCreators'; 7 | import { userListType } from '../collections/userList'; 8 | import { booleanType } from '../primitives/boolean'; 9 | import { noneType } from '../primitives/none'; 10 | import { integerType } from '../primitives/scalar'; 11 | import { partModuleType } from './partModule'; 12 | 13 | export const scienceContainerModuleType = createType('scienceContainerModule'); 14 | scienceContainerModuleType.addSuper(noMap(partModuleType)); 15 | 16 | scienceContainerModuleType.addSuffixes( 17 | noMap(createSuffixType('hasData', booleanType)), 18 | noMap(createSuffixType('data', userListType)), 19 | noMap(createArgSuffixType('dumpData', noneType, integerType)), 20 | noMap(createArgSuffixType('collectAll', noneType)), 21 | ); 22 | -------------------------------------------------------------------------------- /server/src/typeChecker/ksTypes/parts/scienceExperimentModule.ts: -------------------------------------------------------------------------------- 1 | import { createType } from '../../utilities/typeCreators'; 2 | 3 | export const scienceExperimentType = createType('scienceExperimentModule'); 4 | -------------------------------------------------------------------------------- /server/src/typeChecker/ksTypes/parts/separator.ts: -------------------------------------------------------------------------------- 1 | import { createSuffixType, createType, noMap } from '../../utilities/typeCreators'; 2 | import { booleanType } from '../primitives/boolean'; 3 | import { scalarType } from '../primitives/scalar'; 4 | import { decouplerType } from './decoupler'; 5 | 6 | export const separatorType = createType('separator'); 7 | separatorType.addSuper(noMap(decouplerType)); 8 | 9 | separatorType.addSuffixes( 10 | noMap(createSuffixType('ejectionForce', scalarType)), 11 | noMap(createSuffixType('isDecoupled', booleanType)), 12 | noMap(createSuffixType('staged', booleanType)), 13 | ); 14 | -------------------------------------------------------------------------------- /server/src/typeChecker/ksTypes/primitives/boolean.ts: -------------------------------------------------------------------------------- 1 | import { createType } from '../../utilities/typeCreators'; 2 | 3 | // ---------- base of boolean types -------------------- 4 | export const booleanType = createType('boolean'); 5 | -------------------------------------------------------------------------------- /server/src/typeChecker/ksTypes/primitives/builtInDelegate.ts: -------------------------------------------------------------------------------- 1 | import { createType, noMap } from '../../utilities/typeCreators'; 2 | import { delegateType } from './delegate'; 3 | 4 | export const builtInDelegateType = createType('builtInDelegate'); 5 | builtInDelegateType.addSuper(noMap(delegateType)); 6 | -------------------------------------------------------------------------------- /server/src/typeChecker/ksTypes/primitives/delegate.ts: -------------------------------------------------------------------------------- 1 | import { createVarType } from '../../utilities/typeCreators'; 2 | import { Type } from '../../models/types/type'; 3 | import { TypeKind } from '../../types'; 4 | import { CallSignature } from '../../models/types/callSignature'; 5 | import { structureType } from './structure'; 6 | 7 | export const delegateType = new Type( 8 | 'delegate', 9 | { get: true, set: true }, 10 | new Map(), 11 | TypeKind.basic, 12 | new CallSignature([createVarType(structureType)], structureType), 13 | ); 14 | -------------------------------------------------------------------------------- /server/src/typeChecker/ksTypes/primitives/none.ts: -------------------------------------------------------------------------------- 1 | import { TypeKind } from '../../types'; 2 | import { Type } from '../../models/types/type'; 3 | 4 | export const noneType = new Type( 5 | 'none', 6 | { get: false, set: false }, 7 | new Map(), 8 | TypeKind.basic, 9 | undefined, 10 | undefined, 11 | false, 12 | true, 13 | ); 14 | -------------------------------------------------------------------------------- /server/src/typeChecker/ksTypes/primitives/primitives.ts: -------------------------------------------------------------------------------- 1 | import { createType } from '../../utilities/typeCreators'; 2 | 3 | export const primitiveType = createType('primitive'); 4 | -------------------------------------------------------------------------------- /server/src/typeChecker/ksTypes/primitives/scalar.ts: -------------------------------------------------------------------------------- 1 | import { createType } from '../../utilities/typeCreators'; 2 | 3 | export const scalarType = createType('scalar'); 4 | export const integerType = createType('int'); 5 | export const doubleType = createType('double'); 6 | -------------------------------------------------------------------------------- /server/src/typeChecker/ksTypes/primitives/serializeableStructure.ts: -------------------------------------------------------------------------------- 1 | import { createType } from '../../utilities/typeCreators'; 2 | 3 | export const serializableType = createType('serializableStructure'); 4 | -------------------------------------------------------------------------------- /server/src/typeChecker/ksTypes/primitives/string.ts: -------------------------------------------------------------------------------- 1 | import { createType } from '../../utilities/typeCreators'; 2 | 3 | export const stringType = createType('string'); 4 | -------------------------------------------------------------------------------- /server/src/typeChecker/ksTypes/primitives/structure.ts: -------------------------------------------------------------------------------- 1 | import { TypeKind } from '../../types'; 2 | import { Type } from '../../models/types/type'; 3 | 4 | export const structureType = new Type( 5 | 'structure', 6 | { get: true, set: true }, 7 | new Map(), 8 | TypeKind.basic, 9 | undefined, 10 | undefined, 11 | true, 12 | ); 13 | -------------------------------------------------------------------------------- /server/src/typeChecker/ksTypes/resourceTransfer.ts: -------------------------------------------------------------------------------- 1 | import { 2 | createType, 3 | createSuffixType, 4 | createSetSuffixType, 5 | noMap, 6 | } from '../utilities/typeCreators'; 7 | import { structureType } from './primitives/structure'; 8 | import { scalarType } from './primitives/scalar'; 9 | import { stringType } from './primitives/string'; 10 | import { booleanType } from './primitives/boolean'; 11 | 12 | export const resourceTransferType = createType('transfer'); 13 | resourceTransferType.addSuper(noMap(structureType)); 14 | 15 | resourceTransferType.addSuffixes( 16 | noMap(createSuffixType('goal', scalarType)), 17 | noMap(createSuffixType('transferred', scalarType)), 18 | noMap(createSuffixType('status', stringType)), 19 | noMap(createSuffixType('message', stringType)), 20 | noMap(createSuffixType('resource', stringType)), 21 | noMap(createSetSuffixType('active', booleanType)), 22 | ); 23 | -------------------------------------------------------------------------------- /server/src/typeChecker/ksTypes/rgba.ts: -------------------------------------------------------------------------------- 1 | import { 2 | createType, 3 | createArgSuffixType, 4 | createSetSuffixType, 5 | noMap, 6 | } from '../utilities/typeCreators'; 7 | import { scalarType } from './primitives/scalar'; 8 | import { serializableType } from './primitives/serializeableStructure'; 9 | 10 | export const rgbaType = createType('rgba'); 11 | rgbaType.addSuper(noMap(serializableType)); 12 | 13 | rgbaType.addSuffixes( 14 | noMap(createSetSuffixType('r', scalarType)), 15 | noMap(createSetSuffixType('red', scalarType)), 16 | noMap(createSetSuffixType('g', scalarType)), 17 | noMap(createSetSuffixType('green', scalarType)), 18 | noMap(createSetSuffixType('b', scalarType)), 19 | noMap(createSetSuffixType('blue', scalarType)), 20 | noMap(createSetSuffixType('a', scalarType)), 21 | noMap(createSetSuffixType('alpha', scalarType)), 22 | noMap(createArgSuffixType('html', scalarType)), 23 | noMap(createArgSuffixType('hex', scalarType)), 24 | ); 25 | -------------------------------------------------------------------------------- /server/src/typeChecker/ksTypes/scienceData.ts: -------------------------------------------------------------------------------- 1 | import { createType, createArgSuffixType, noMap } from '../utilities/typeCreators'; 2 | import { scalarType } from './primitives/scalar'; 3 | import { structureType } from './primitives/structure'; 4 | import { stringType } from './primitives/string'; 5 | 6 | export const scienceDataType = createType('scienceData'); 7 | scienceDataType.addSuper(noMap(structureType)); 8 | 9 | scienceDataType.addSuffixes( 10 | noMap(createArgSuffixType('dataAmount', scalarType)), 11 | noMap(createArgSuffixType('scienceValue', scalarType)), 12 | noMap(createArgSuffixType('transmitValue', scalarType)), 13 | noMap(createArgSuffixType('title', stringType)), 14 | ); 15 | -------------------------------------------------------------------------------- /server/src/typeChecker/ksTypes/situtationLoadDistance.ts: -------------------------------------------------------------------------------- 1 | import { createType, createSetSuffixType, noMap } from '../utilities/typeCreators'; 2 | import { structureType } from './primitives/structure'; 3 | import { scalarType } from './primitives/scalar'; 4 | 5 | export const situationLoadDistanceType = createType( 6 | 'situationLoadDistance', 7 | ); 8 | situationLoadDistanceType.addSuper(noMap(structureType)); 9 | 10 | situationLoadDistanceType.addSuffixes( 11 | noMap(createSetSuffixType('load', scalarType)), 12 | noMap(createSetSuffixType('unload', scalarType)), 13 | noMap(createSetSuffixType('pack', scalarType)), 14 | noMap(createSetSuffixType('unpack', scalarType)), 15 | ); 16 | -------------------------------------------------------------------------------- /server/src/typeChecker/ksTypes/terminalStruct.ts: -------------------------------------------------------------------------------- 1 | import { 2 | createType, 3 | createArgSuffixType, 4 | createSuffixType, 5 | createSetSuffixType, 6 | noMap, 7 | } from '../utilities/typeCreators'; 8 | import { structureType } from './primitives/structure'; 9 | import { uniqueSetType } from './collections/uniqueset'; 10 | import { terminalInputType } from './terminalInput'; 11 | import { scalarType } from './primitives/scalar'; 12 | import { booleanType } from './primitives/boolean'; 13 | import { userDelegateType } from './userDelegate'; 14 | 15 | export const terminalStructType = createType('terminalStruct'); 16 | terminalStructType.addSuper(noMap(structureType)); 17 | 18 | terminalStructType.addSuffixes( 19 | noMap(createSetSuffixType('height', scalarType)), 20 | noMap(createSetSuffixType('width', scalarType)), 21 | noMap(createSetSuffixType('reverse', booleanType)), 22 | noMap(createSetSuffixType('visualBeep', booleanType)), 23 | noMap(createSetSuffixType('brightness', scalarType)), 24 | noMap(createSetSuffixType('charWidth', scalarType)), 25 | noMap(createSetSuffixType('charHeight', scalarType)), 26 | noMap(createArgSuffixType( 27 | 'resizeWatchers', 28 | uniqueSetType.apply(userDelegateType), 29 | )), 30 | noMap(createSuffixType('input', terminalInputType)), 31 | ); 32 | -------------------------------------------------------------------------------- /server/src/typeChecker/ksTypes/time/timebase.ts.ts: -------------------------------------------------------------------------------- 1 | import { createType, noMap } from "../../utilities/typeCreators"; 2 | import { serializableType } from "../primitives/serializeableStructure"; 3 | 4 | export const timeBaseType = createType('timeBase'); 5 | timeBaseType.addSuper(noMap(serializableType)); 6 | 7 | -------------------------------------------------------------------------------- /server/src/typeChecker/ksTypes/time/timespan.ts: -------------------------------------------------------------------------------- 1 | import { createType } from "../../utilities/typeCreators"; 2 | 3 | export const timeSpanType = createType('timeSpan'); 4 | 5 | -------------------------------------------------------------------------------- /server/src/typeChecker/ksTypes/time/timestamp.ts: -------------------------------------------------------------------------------- 1 | import { createType } from "../../utilities/typeCreators"; 2 | 3 | export const timeStampType = createType('timeStamp'); 4 | -------------------------------------------------------------------------------- /server/src/typeChecker/ksTypes/timewarp.ts: -------------------------------------------------------------------------------- 1 | import { 2 | createType, 3 | createSuffixType, 4 | createArgSuffixType, 5 | noMap, 6 | createSetSuffixType, 7 | } from '../utilities/typeCreators'; 8 | import { listType } from './collections/list'; 9 | import { noneType } from './primitives/none'; 10 | import { scalarType, integerType } from './primitives/scalar'; 11 | import { stringType } from './primitives/string'; 12 | import { booleanType } from './primitives/boolean'; 13 | import { serializableType } from './primitives/serializeableStructure'; 14 | 15 | export const timeWarpType = createType('timeWarp'); 16 | timeWarpType.addSuper(noMap(serializableType)); 17 | 18 | timeWarpType.addSuffixes( 19 | noMap(createSetSuffixType('rate', scalarType)), 20 | noMap(createSuffixType('rateList', listType.apply(scalarType))), 21 | noMap(createSuffixType('railRateList', listType.apply(scalarType))), 22 | noMap(createSuffixType('physicsRateList', listType.apply(scalarType))), 23 | noMap(createSetSuffixType('mode', stringType)), 24 | noMap(createSetSuffixType('warp', integerType)), 25 | noMap(createArgSuffixType('warpTo', scalarType)), 26 | noMap(createArgSuffixType('cancelWarp', noneType)), 27 | noMap(createArgSuffixType('physicsDeltaT', scalarType)), 28 | noMap(createArgSuffixType('isSettled', booleanType)), 29 | ); 30 | -------------------------------------------------------------------------------- /server/src/typeChecker/ksTypes/userDelegate.ts: -------------------------------------------------------------------------------- 1 | import { createType, noMap } from '../utilities/typeCreators'; 2 | import { delegateType } from './primitives/delegate'; 3 | 4 | export const userDelegateType = createType('userDelegate'); 5 | userDelegateType.addSuper(noMap(delegateType)); 6 | -------------------------------------------------------------------------------- /server/src/typeChecker/ksTypes/versionInfo.ts: -------------------------------------------------------------------------------- 1 | import { createType, createSuffixType, noMap } from '../utilities/typeCreators'; 2 | import { structureType } from './primitives/structure'; 3 | import { scalarType } from './primitives/scalar'; 4 | 5 | export const versionInfoType = createType('versioninfo'); 6 | versionInfoType.addSuper(noMap(structureType)); 7 | 8 | versionInfoType.addSuffixes( 9 | noMap(createSuffixType('major', scalarType)), 10 | noMap(createSuffixType('minor', scalarType)), 11 | noMap(createSuffixType('patch', scalarType)), 12 | noMap(createSuffixType('build', scalarType)), 13 | ); 14 | -------------------------------------------------------------------------------- /server/src/typeChecker/ksTypes/vessel/stage.ts: -------------------------------------------------------------------------------- 1 | import { createType, createSuffixType, noMap } from '../../utilities/typeCreators'; 2 | import { structureType } from '../primitives/structure'; 3 | import { listType } from '../collections/list'; 4 | import { lexiconType } from '../collections/lexicon'; 5 | import { activeResourceType } from '../parts/activeResource'; 6 | import { scalarType } from '../primitives/scalar'; 7 | import { booleanType } from '../primitives/boolean'; 8 | 9 | export const stageType = createType('stage'); 10 | stageType.addSuper(noMap(structureType)); 11 | 12 | stageType.addSuffixes( 13 | noMap(createSuffixType('number', scalarType)), 14 | noMap(createSuffixType('ready', booleanType)), 15 | noMap(createSuffixType('resources', listType.apply(activeResourceType))), 16 | noMap(createSuffixType('resourcesLex', lexiconType)), 17 | noMap(createSuffixType('nextDecoupler', structureType)), 18 | noMap(createSuffixType('nextSeparator', structureType)), 19 | ); 20 | -------------------------------------------------------------------------------- /server/src/typeChecker/ksTypes/vessel/vesselAlt.ts: -------------------------------------------------------------------------------- 1 | import { createType, createArgSuffixType, noMap } from '../../utilities/typeCreators'; 2 | import { structureType } from '../primitives/structure'; 3 | import { scalarType } from '../primitives/scalar'; 4 | 5 | export const vesselAltType = createType('vesselAlt'); 6 | vesselAltType.addSuper(noMap(structureType)); 7 | 8 | vesselAltType.addSuffixes( 9 | noMap(createArgSuffixType('apoapsis', scalarType)), 10 | noMap(createArgSuffixType('periapsis', scalarType)), 11 | noMap(createArgSuffixType('radar', scalarType)), 12 | ); 13 | -------------------------------------------------------------------------------- /server/src/typeChecker/ksTypes/vessel/vesselEta.ts: -------------------------------------------------------------------------------- 1 | import { createType, createArgSuffixType, noMap } from '../../utilities/typeCreators'; 2 | import { structureType } from '../primitives/structure'; 3 | import { scalarType } from '../primitives/scalar'; 4 | 5 | export const vesselEtaType = createType('vesselEta'); 6 | vesselEtaType.addSuper(noMap(structureType)); 7 | 8 | vesselEtaType.addSuffixes( 9 | noMap(createArgSuffixType('apoapsis', scalarType)), 10 | noMap(createArgSuffixType('periapsis', scalarType)), 11 | noMap(createArgSuffixType('transition', scalarType)), 12 | ); 13 | -------------------------------------------------------------------------------- /server/src/typeChecker/ksTypes/vessel/vesselSensors.ts: -------------------------------------------------------------------------------- 1 | import { createType, createSuffixType, noMap } from '../../utilities/typeCreators'; 2 | import { structureType } from '../primitives/structure'; 3 | import { vectorType } from '../collections/vector'; 4 | import { scalarType } from '../primitives/scalar'; 5 | 6 | export const vesselSensorsType = createType('vesselSensors'); 7 | vesselSensorsType.addSuper(noMap(structureType)); 8 | 9 | vesselSensorsType.addSuffixes( 10 | noMap(createSuffixType('acc', vectorType)), 11 | noMap(createSuffixType('pres', scalarType)), 12 | noMap(createSuffixType('temp', scalarType)), 13 | noMap(createSuffixType('grav', vectorType)), 14 | noMap(createSuffixType('light', scalarType)), 15 | ); 16 | -------------------------------------------------------------------------------- /server/src/typeChecker/ksTypes/voice.ts: -------------------------------------------------------------------------------- 1 | import { 2 | createType, 3 | createArgSuffixType, 4 | createSetSuffixType, 5 | noMap, 6 | } from '../utilities/typeCreators'; 7 | import { structureType } from './primitives/structure'; 8 | import { noneType } from './primitives/none'; 9 | import { scalarType } from './primitives/scalar'; 10 | import { stringType } from './primitives/string'; 11 | import { booleanType } from './primitives/boolean'; 12 | 13 | export const voiceType = createType('voice'); 14 | voiceType.addSuper(noMap(structureType)); 15 | 16 | voiceType.addSuffixes( 17 | noMap(createSetSuffixType('attack', scalarType)), 18 | noMap(createSetSuffixType('decay', scalarType)), 19 | noMap(createSetSuffixType('sustain', scalarType)), 20 | noMap(createSetSuffixType('release', scalarType)), 21 | noMap(createSetSuffixType('volume', scalarType)), 22 | noMap(createSetSuffixType('wave', stringType)), 23 | noMap(createArgSuffixType('play', noneType, structureType)), 24 | noMap(createArgSuffixType('stop', noneType)), 25 | noMap(createSetSuffixType('loop', booleanType)), 26 | noMap(createSetSuffixType('isPlaying', booleanType)), 27 | noMap(createSetSuffixType('tempo', scalarType)), 28 | ); 29 | -------------------------------------------------------------------------------- /server/src/typeChecker/models/suffixTypeNode.ts: -------------------------------------------------------------------------------- 1 | import { IType } from '../types'; 2 | 3 | export class SuffixTypeBuilder { 4 | public nodes: IType[]; 5 | 6 | constructor() { 7 | this.nodes = []; 8 | } 9 | 10 | public isTrailer(): boolean { 11 | return this.nodes.length > 0; 12 | } 13 | 14 | public current(): IType { 15 | if (this.nodes.length > 0) { 16 | return this.nodes[this.nodes.length - 1]; 17 | } 18 | 19 | throw new Error('Must have at least one node before current can be called'); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /server/src/typeChecker/models/typeNode.ts: -------------------------------------------------------------------------------- 1 | import { SuffixTermBase } from '../../parser/models/suffixTerm'; 2 | import { Position, Range } from 'vscode-languageserver'; 3 | import { IType } from '../types'; 4 | 5 | /** 6 | * Storage type for suffix terms in the type checker 7 | */ 8 | export class TypeNode implements Range { 9 | /** 10 | * TypeNode constructor 11 | * @param type type at a suffix term node 12 | * @param node suffix term node 13 | */ 14 | constructor(public readonly type: T, public readonly node: SuffixTermBase) {} 15 | 16 | /** 17 | * start position of the node 18 | */ 19 | public get start(): Position { 20 | return this.node.start; 21 | } 22 | 23 | /** 24 | * end position of the node 25 | */ 26 | public get end(): Position { 27 | return this.node.end; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /server/src/typeChecker/models/types/constantType.ts: -------------------------------------------------------------------------------- 1 | import { 2 | Access, 3 | IType, 4 | TypeKind, 5 | ICallSignature, 6 | IParametricType, 7 | } from '../../types'; 8 | import { Type } from './type'; 9 | 10 | /** 11 | * Represents a constant type, or a type with a fixed value 12 | */ 13 | export class ConstantType extends Type { 14 | public readonly value: T; 15 | 16 | /** 17 | * Construct a constant type 18 | * @param name name of this constant type 19 | * @param value value of this constant type 20 | */ 21 | constructor( 22 | name: string, 23 | value: T, 24 | access: Access, 25 | typeArguments: Map, 26 | kind: TypeKind, 27 | callSignature?: ICallSignature, 28 | typeTemplate?: IParametricType, 29 | ) { 30 | super(name, access, typeArguments, kind, callSignature, typeTemplate); 31 | this.value = value; 32 | } 33 | 34 | /** 35 | * Create a type string from this type 36 | */ 37 | public toString(): string { 38 | return `${super.toString()} = ${this.value}`; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /server/src/typeChecker/models/types/indexer.ts: -------------------------------------------------------------------------------- 1 | import { 2 | IParametricType, 3 | IType, 4 | TypeKind, 5 | ICallSignature, 6 | IIndexer, 7 | } from '../../types'; 8 | import { Type } from './type'; 9 | import { empty } from '../../../utilities/typeGuards'; 10 | 11 | export class Indexer extends Type implements IIndexer { 12 | public readonly kind: TypeKind.indexer; 13 | 14 | constructor( 15 | callSignature: ICallSignature, 16 | typeArgument: Map, 17 | ) { 18 | super( 19 | 'Indexer', 20 | { get: true, set: true }, 21 | typeArgument, 22 | TypeKind.indexer, 23 | callSignature, 24 | undefined, 25 | false, 26 | ); 27 | 28 | this.kind = TypeKind.indexer; 29 | } 30 | 31 | public toString(): string { 32 | const callSignature = this.callSignature(); 33 | if (empty(callSignature)) { 34 | throw new Error('Indexer somehow has empty call signature'); 35 | } 36 | 37 | const [index] = callSignature.params(); 38 | const returns = callSignature.returns(); 39 | 40 | return `[${index.toString()}] => ${returns.toString()}`; 41 | } 42 | 43 | public apply(_: Map | IType): IIndexer { 44 | return this; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /server/src/utilities/debounce.ts: -------------------------------------------------------------------------------- 1 | import { empty } from './typeGuards'; 2 | 3 | /** 4 | * Debounce a function to execute after a call hasn't been made for timeout milliseconds 5 | * @param timeout timeout before the function is called 6 | * @param func function to call 7 | */ 8 | export function debounce void>( 9 | timeout: number, 10 | func: T, 11 | ): (...args: Parameters) => void { 12 | let timeoutId: Maybe = undefined; 13 | let lastCall: number = 0; 14 | 15 | return (...args: Parameters) => { 16 | const now = Date.now(); 17 | if (!empty(timeoutId) && now - lastCall < timeout) { 18 | clearTimeout(timeoutId); 19 | } 20 | 21 | lastCall = now; 22 | timeoutId = setTimeout(func, timeout, ...args); 23 | }; 24 | } 25 | -------------------------------------------------------------------------------- /server/src/utilities/fsUtils.ts: -------------------------------------------------------------------------------- 1 | import { readdirSync, statSync } from 'fs'; 2 | import { readFile } from 'fs/promises'; 3 | import { join } from 'path'; 4 | 5 | /** 6 | * Wrap the node read file in a promise 7 | * @param path path of the file to read 8 | * @param encoding the file encoding 9 | */ 10 | export const readFileAsync = ( 11 | path: string, 12 | encoding: BufferEncoding, 13 | ): Promise => { 14 | return readFile(path, encoding); 15 | }; 16 | 17 | /** 18 | * Walk a directory of files 19 | * @param dir directory to walk 20 | * @param callback callback for each file in the directory 21 | */ 22 | export const walkDir = ( 23 | dir: string, 24 | callback: (fileName: string) => void, 25 | ): void => { 26 | readdirSync(dir).forEach(f => { 27 | const dirPath = join(dir, f); 28 | const isDirectory = statSync(dirPath).isDirectory(); 29 | isDirectory ? walkDir(dirPath, callback) : callback(join(dir, f)); 30 | }); 31 | }; 32 | -------------------------------------------------------------------------------- /server/src/utilities/levenshtein.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Levenshtein Distance between a string a and b 3 | * @param a first string 4 | * @param b second string 5 | */ 6 | export function levenshteinDistance(a: string, b: string) { 7 | const distanceMatrix: number[][] = Array(b.length + 1) 8 | .fill(0) 9 | .map(() => Array(a.length + 1).fill(0)); 10 | 11 | for (let i = 0; i <= a.length; i += 1) { 12 | distanceMatrix[0][i] = i; 13 | } 14 | 15 | for (let j = 0; j <= b.length; j += 1) { 16 | distanceMatrix[j][0] = j; 17 | } 18 | 19 | const aLower = a.toLowerCase(); 20 | const bLower = b.toLowerCase(); 21 | 22 | for (let j = 1; j <= b.length; j += 1) { 23 | for (let i = 1; i <= a.length; i += 1) { 24 | const indicator = aLower[i - 1] === bLower[j - 1] ? 0 : 1; 25 | distanceMatrix[j][i] = Math.min( 26 | distanceMatrix[j][i - 1] + 1, // deletion 27 | distanceMatrix[j - 1][i] + 1, // insertion 28 | distanceMatrix[j - 1][i - 1] + indicator, // substitution 29 | ); 30 | } 31 | } 32 | 33 | return distanceMatrix[b.length][a.length]; 34 | } 35 | -------------------------------------------------------------------------------- /server/src/utilities/mapper.ts: -------------------------------------------------------------------------------- 1 | import { empty } from './typeGuards'; 2 | 3 | /** 4 | * Generate a mapping function using a provided map object 5 | * @param map the map to generate the function from 6 | * @param name the name of the mapping function 7 | */ 8 | export const mapper = (map: Map, name: string) => 9 | (key: TKey): TValue => { 10 | const value = map.get(key); 11 | if (empty(value)) { 12 | throw new Error(`No mapping for ${key} in ${name}`); 13 | } 14 | 15 | return value; 16 | }; 17 | -------------------------------------------------------------------------------- /server/src/utilities/memoize.ts: -------------------------------------------------------------------------------- 1 | import { empty } from './typeGuards'; 2 | 3 | /** 4 | * memoize single parameter function 5 | * @param func function to memoize 6 | */ 7 | export const memoize = ( 8 | func: (arg1: T1) => TReturn, 9 | ): ((arg1: T1) => TReturn) => { 10 | const memory: Map = new Map(); 11 | 12 | return (arg1: T1): TReturn => { 13 | const result = memory.get(arg1); 14 | if (!empty(result)) return result; 15 | 16 | const newResult = func(arg1); 17 | memory.set(arg1, newResult); 18 | return newResult; 19 | }; 20 | }; 21 | -------------------------------------------------------------------------------- /server/src/utilities/randomUtils.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Get a random integer 3 | * @param max max integer value 4 | */ 5 | export const getRandomInt = (max: number): number => 6 | Math.floor(Math.random() * Math.floor(max)); 7 | -------------------------------------------------------------------------------- /server/src/utilities/stringUtils.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Convert a set of string segments to the requested case 3 | * @param caseKind requested case 4 | * @param segments string segments 5 | */ 6 | export const toCase = (caseKind: CaseKind, ...segments: string[]): string => { 7 | switch (caseKind) { 8 | case CaseKind.lowerCase: 9 | return segments.map(s => s.toLowerCase()).join(''); 10 | case CaseKind.upperCase: 11 | return segments.map(s => s.toUpperCase()).join(''); 12 | case CaseKind.camelCase: 13 | return toCamelCase(...segments); 14 | case CaseKind.pascalCase: 15 | return toPascalCase(...segments); 16 | } 17 | }; 18 | 19 | /** 20 | * Convert a set of string segments to pascal case 21 | * @param segments string segments 22 | */ 23 | const toPascalCase = (...segments: string[]): string => { 24 | return segments 25 | .map(s => s.charAt(0).toUpperCase() + s.slice(1).toLowerCase()) 26 | .join(''); 27 | }; 28 | 29 | /** 30 | * Convert a set of string segments to camel case 31 | * @param segments string segments 32 | */ 33 | const toCamelCase = (...segments: string[]): string => { 34 | if (segments.length === 1) { 35 | return segments[0].toLowerCase(); 36 | } 37 | 38 | const [first, ...rest] = segments; 39 | return [first.toLowerCase(), toPascalCase(...rest)].join(''); 40 | }; 41 | -------------------------------------------------------------------------------- /server/src/utilities/typeGuards.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Is this value undefined 3 | * @param value maybe T 4 | */ 5 | export const empty = (value: Maybe): value is undefined => { 6 | return value === undefined; 7 | }; 8 | 9 | /** 10 | * Is this value not undefined 11 | * @param value maybe T 12 | */ 13 | export const notEmpty = (value: Maybe): value is T => { 14 | return value !== undefined; 15 | }; 16 | 17 | /** 18 | * Unwrap the a maybe throws an exception if undefined 19 | * @param value maybe T 20 | */ 21 | export const unWrap = (value: Maybe): T => { 22 | if (!empty(value)) { 23 | return value; 24 | } 25 | 26 | throw new Error('value was undefined'); 27 | }; 28 | 29 | /** 30 | * Unwrap an array of maybe values 31 | * @param values array of maybe T 32 | */ 33 | export const unWrapMany = (...values: Maybe[]): T[] => { 34 | return values.map(x => unWrap(x)); 35 | }; 36 | -------------------------------------------------------------------------------- /server/test/utilities/factories.ts: -------------------------------------------------------------------------------- 1 | import { Token } from '../../src/models/token'; 2 | import { TokenType } from '../../src/models/tokentypes'; 3 | 4 | export const createToken = ( 5 | type: T, 6 | lexeme: string, 7 | literal?: any, 8 | ): Token => { 9 | return new Token( 10 | type, 11 | lexeme, 12 | literal, 13 | { 14 | line: 0, 15 | character: 0, 16 | }, 17 | { 18 | line: 0, 19 | character: 1, 20 | }, 21 | 'file:///fake.ks', 22 | ); 23 | }; 24 | -------------------------------------------------------------------------------- /server/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tsconfig.base.json", 3 | "compilerOptions": { 4 | "module": "commonjs", 5 | "target": "es6", 6 | "moduleResolution": "node", 7 | "outDir": "out", 8 | "lib": ["es2015", "esnext.asynciterable"], 9 | "sourceMap": true, 10 | "strict": true, 11 | "allowSyntheticDefaultImports": true, 12 | "esModuleInterop": true, 13 | "noEmit": false, 14 | "resolveJsonModule": true, 15 | "incremental": false 16 | // "tsBuildInfoFile": "./build/buildcache.json", 17 | }, 18 | "include": [ 19 | "src", "test", "benchmark" 20 | ], 21 | "exclude": [ 22 | "node_modules", 23 | "out", 24 | "dist" 25 | ] 26 | } 27 | -------------------------------------------------------------------------------- /server/zakzak.config.json: -------------------------------------------------------------------------------- 1 | { 2 | "benchmark": { 3 | "minTime": 50000000, 4 | "maxTime": 5000000000, 5 | "minSamples": 5, 6 | "maxSamples": 5000, 7 | "minIterations": 0, 8 | "maxIterations": 0, 9 | "memoryBenchmark": true, 10 | "minMemorySamples": 10, 11 | "maxMemorySamples": 100, 12 | "cpuProfiling": true, 13 | "minCpuProfilingIterations": 100, 14 | "maxCpuProfilingIterations": 10000, 15 | "samplingInterval": 5000 16 | }, 17 | "manager": { 18 | "runParallel": 2, 19 | "pattern": "./**/*.benchmark.js", 20 | "path": "./out/", 21 | "exporter": ["hierarchy", "console"] 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /tsconfig.base.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "declaration": true, 4 | "strict": true /* Enable all strict type-checking options. */, 5 | "diagnostics": true, 6 | 7 | /* Additional Checks */ 8 | "noUnusedLocals": true /* Report errors on unused locals. */, 9 | "noUnusedParameters": true /* Report errors on unused parameters. */, 10 | "noImplicitReturns": true /* Report error when not all code paths in function return a value. */, 11 | "noFallthroughCasesInSwitch": true /* Report errors for fallthrough cases in switch statement. */, 12 | 13 | /* Debugging Options */ 14 | "traceResolution": false /* Report module resolution log messages. */, 15 | "listEmittedFiles": false /* Print names of generated files part of the compilation. */, 16 | "listFiles": false /* Print names of files part of the compilation. */, 17 | "pretty": true /* Stylize errors and messages using color and context. */, 18 | }, 19 | "compileOnSave": false, 20 | } 21 | --------------------------------------------------------------------------------