├── .github ├── ISSUE_TEMPLATE │ ├── bug_report.md │ └── feature_request.md └── workflows │ └── maven.yml ├── .gitignore ├── CITATION.cff ├── CONTRIBUTING.md ├── LICENSE ├── README.md ├── SECURITY.md ├── TODO.md ├── docs ├── CNAME ├── index.html └── org │ ├── byteskript │ ├── index.html │ └── skript │ │ ├── api │ │ ├── Deletable.html │ │ ├── Document.html │ │ ├── Event.html │ │ ├── Flag.html │ │ ├── HandlerType.html │ │ ├── LanguageElement.html │ │ ├── Library.html │ │ ├── ModifiableLibrary.html │ │ ├── PropertyHandler.html │ │ ├── Referent.html │ │ ├── SyntaxElement.html │ │ ├── automatic │ │ │ ├── GeneratedEffect.html │ │ │ ├── GeneratedEntryNode.html │ │ │ ├── GeneratedEntrySection.html │ │ │ ├── GeneratedEventHolder.html │ │ │ ├── GeneratedExpression.html │ │ │ └── index.html │ │ ├── index.html │ │ ├── note │ │ │ ├── Documentation.html │ │ │ ├── Effect.html │ │ │ ├── EntryNode.html │ │ │ ├── EntrySection.html │ │ │ ├── Event.html │ │ │ ├── EventValue.html │ │ │ ├── Expression.html │ │ │ ├── ForceBridge.html │ │ │ ├── ForceExtract.html │ │ │ ├── ForceInline.html │ │ │ ├── Property.html │ │ │ ├── SkriptType.html │ │ │ └── index.html │ │ └── syntax │ │ │ ├── ComplexExpression.html │ │ │ ├── Condition.html │ │ │ ├── ControlEffect.html │ │ │ ├── Effect.html │ │ │ ├── Element.html │ │ │ ├── EventHolder.html │ │ │ ├── EventValueExpression.html │ │ │ ├── ExtractedSection.html │ │ │ ├── InnerModifyExpression.html │ │ │ ├── Literal.html │ │ │ ├── Member.html │ │ │ ├── RelationalExpression.html │ │ │ ├── Section.html │ │ │ ├── SectionEntry.html │ │ │ ├── SimpleEntry.html │ │ │ ├── SimpleExpression.html │ │ │ ├── TriggerHolder.html │ │ │ └── index.html │ │ ├── index.html │ │ └── runtime │ │ ├── Script.html │ │ ├── Skript$RuntimeClassLoader.html │ │ ├── Skript$SkriptMirror.html │ │ ├── Skript.html │ │ ├── config │ │ ├── ConfigEntry.html │ │ ├── ConfigMap.html │ │ └── index.html │ │ ├── index.html │ │ ├── internal │ │ ├── Bootstrapper.html │ │ ├── CompiledScript.html │ │ ├── CompilerDependent.html │ │ ├── GlobalVariableMap.html │ │ ├── LibraryClassLoader.html │ │ ├── Member.html │ │ ├── Metafactory.html │ │ ├── ModifiableCompiler.html │ │ ├── Promise.html │ │ ├── ThreadSpecific.html │ │ └── index.html │ │ ├── threading │ │ ├── AirlockQueue.html │ │ ├── OperationController.html │ │ ├── ScriptExceptionHandler.html │ │ ├── ScriptFinishFuture.html │ │ ├── ScriptRunner.html │ │ ├── ScriptThread.html │ │ ├── ScriptThreadPoolExecutor.html │ │ ├── SkriptThreadProvider.html │ │ └── index.html │ │ └── type │ │ ├── AtomicVariable.html │ │ ├── Converter$Data.html │ │ ├── Converter.html │ │ ├── DataList.html │ │ ├── DataMap.html │ │ ├── OperatorFunction$Data.html │ │ ├── OperatorFunction$Type.html │ │ ├── OperatorFunction.html │ │ └── index.html │ └── index.html ├── pom.xml ├── scripts └── install-byteskript.sh └── src ├── main └── java │ ├── org │ └── byteskript │ │ └── skript │ │ ├── api │ │ ├── AsyncEvent.java │ │ ├── DebugTypeMeta.java │ │ ├── Deletable.java │ │ ├── Document.java │ │ ├── Event.java │ │ ├── Flag.java │ │ ├── FunctionalEntrySection.java │ │ ├── HandlerType.java │ │ ├── LanguageElement.java │ │ ├── Library.java │ │ ├── ModifiableLibrary.java │ │ ├── PropertyHandler.java │ │ ├── Referent.java │ │ ├── SyntaxAnnotationUnwrapper.java │ │ ├── SyntaxElement.java │ │ ├── automatic │ │ │ ├── GeneratedEffect.java │ │ │ ├── GeneratedEntryNode.java │ │ │ ├── GeneratedEntrySection.java │ │ │ ├── GeneratedEventHolder.java │ │ │ └── GeneratedExpression.java │ │ ├── note │ │ │ ├── Documentation.java │ │ │ ├── Effect.java │ │ │ ├── EntryNode.java │ │ │ ├── EntrySection.java │ │ │ ├── Event.java │ │ │ ├── EventValue.java │ │ │ ├── Expression.java │ │ │ ├── ForceBridge.java │ │ │ ├── ForceExtract.java │ │ │ ├── ForceInline.java │ │ │ ├── Property.java │ │ │ └── SkriptType.java │ │ └── syntax │ │ │ ├── ComplexExpression.java │ │ │ ├── Condition.java │ │ │ ├── ControlEffect.java │ │ │ ├── Effect.java │ │ │ ├── Element.java │ │ │ ├── EventHolder.java │ │ │ ├── EventValueExpression.java │ │ │ ├── ExtractedSection.java │ │ │ ├── InnerModifyExpression.java │ │ │ ├── Literal.java │ │ │ ├── Member.java │ │ │ ├── RelationalExpression.java │ │ │ ├── Section.java │ │ │ ├── SectionEntry.java │ │ │ ├── SimpleEntry.java │ │ │ ├── SimpleExpression.java │ │ │ └── TriggerHolder.java │ │ ├── app │ │ ├── ByteSkriptApp.java │ │ ├── ScriptCompiler.java │ │ ├── ScriptDebugger.java │ │ ├── ScriptJarBuilder.java │ │ ├── ScriptLoader.java │ │ ├── ScriptRunner.java │ │ ├── SimpleThrottleController.java │ │ └── SkriptApp.java │ │ ├── compiler │ │ ├── AreaFlag.java │ │ ├── BasicInlineController.java │ │ ├── BridgeCompiler.java │ │ ├── CommonTypes.java │ │ ├── CompileState.java │ │ ├── Context.java │ │ ├── DebugSkriptCompiler.java │ │ ├── ElementTree.java │ │ ├── FileContext.java │ │ ├── InlineController.java │ │ ├── Pattern.java │ │ ├── SimpleSkriptCompiler.java │ │ ├── SkriptCompiler.java │ │ ├── SkriptLangSpec.java │ │ ├── SkriptParser.java │ │ ├── Unit.java │ │ └── structure │ │ │ ├── BasicTree.java │ │ │ ├── ErrorDetails.java │ │ │ ├── ExtractionTree.java │ │ │ ├── Frame.java │ │ │ ├── Function.java │ │ │ ├── IfElseTree.java │ │ │ ├── LoopTree.java │ │ │ ├── MonitorTree.java │ │ │ ├── MultiLabel.java │ │ │ ├── PreVariable.java │ │ │ ├── ProgrammaticSplitTree.java │ │ │ ├── PropertyAccessGenerator.java │ │ │ ├── SectionMeta.java │ │ │ ├── SyntaxTree.java │ │ │ ├── TestTree.java │ │ │ ├── TriggerTree.java │ │ │ ├── TryCatchTree.java │ │ │ ├── VerifyTree.java │ │ │ └── WhileTree.java │ │ ├── error │ │ ├── ScriptAssertionError.java │ │ ├── ScriptBootstrapError.java │ │ ├── ScriptCompileError.java │ │ ├── ScriptError.java │ │ ├── ScriptLibraryError.java │ │ ├── ScriptLoadError.java │ │ ├── ScriptParseError.java │ │ ├── ScriptReassemblyError.java │ │ └── ScriptRuntimeError.java │ │ ├── lang │ │ ├── element │ │ │ └── StandardElements.java │ │ ├── handler │ │ │ └── StandardHandlers.java │ │ └── syntax │ │ │ ├── comparison │ │ │ ├── ExprContains.java │ │ │ ├── ExprExists.java │ │ │ ├── ExprGT.java │ │ │ ├── ExprGTEQ.java │ │ │ ├── ExprIsArray.java │ │ │ ├── ExprIsEqual.java │ │ │ ├── ExprIsOfType.java │ │ │ ├── ExprLT.java │ │ │ ├── ExprLTEQ.java │ │ │ ├── ExprMatches.java │ │ │ └── ExprNotEqual.java │ │ │ ├── config │ │ │ ├── EffectSaveConfig.java │ │ │ ├── ExprConfigFileSection.java │ │ │ ├── ExprKeyInConfig.java │ │ │ └── ExprNewConfig.java │ │ │ ├── control │ │ │ ├── EffectAdd.java │ │ │ ├── EffectDelete.java │ │ │ ├── EffectRemove.java │ │ │ └── EffectSet.java │ │ │ ├── dictionary │ │ │ ├── EffectImportFunction.java │ │ │ ├── EffectImportType.java │ │ │ ├── EffectUseLibrary.java │ │ │ └── MemberDictionary.java │ │ │ ├── entry │ │ │ ├── EntryExtends.java │ │ │ ├── EntryParameters.java │ │ │ ├── EntryReturn.java │ │ │ ├── EntryTemplate.java │ │ │ ├── EntryTriggerSection.java │ │ │ ├── EntryVerifySection.java │ │ │ └── syntax │ │ │ │ ├── EntrySyntax.java │ │ │ │ ├── EntrySyntaxEffect.java │ │ │ │ ├── EntrySyntaxExpression.java │ │ │ │ ├── EntrySyntaxMode.java │ │ │ │ ├── EntrySyntaxProperty.java │ │ │ │ └── ICreateSyntax.java │ │ │ ├── event │ │ │ ├── EventAnyLoad.java │ │ │ ├── EventLoad.java │ │ │ ├── EventUnload.java │ │ │ └── ExprCurrentEvent.java │ │ │ ├── flow │ │ │ ├── EffectAssert.java │ │ │ ├── EffectAssertWithError.java │ │ │ ├── EffectBreak.java │ │ │ ├── EffectBreakIf.java │ │ │ ├── EffectBreakLoop.java │ │ │ ├── EffectContinue.java │ │ │ ├── EffectExit.java │ │ │ ├── EffectExitThread.java │ │ │ ├── EffectReturn.java │ │ │ ├── EffectStop.java │ │ │ ├── conditional │ │ │ │ ├── ElseIfSection.java │ │ │ │ ├── ElseSection.java │ │ │ │ └── IfSection.java │ │ │ ├── error │ │ │ │ ├── CatchSection.java │ │ │ │ ├── EffectTry.java │ │ │ │ └── TrySection.java │ │ │ ├── execute │ │ │ │ ├── EffectMonitorSection.java │ │ │ │ ├── EffectRun.java │ │ │ │ ├── EffectRunAsync.java │ │ │ │ ├── EffectRunWith.java │ │ │ │ ├── EffectRunWithAsync.java │ │ │ │ ├── EffectWaitFor.java │ │ │ │ └── ExprResult.java │ │ │ ├── lambda │ │ │ │ ├── ExprLemmaSection.java │ │ │ │ ├── ExprRunnableSection.java │ │ │ │ └── ExprSupplierSection.java │ │ │ └── loop │ │ │ │ ├── EffectLoopInSection.java │ │ │ │ ├── EffectLoopTimesSection.java │ │ │ │ └── EffectWhileSection.java │ │ │ ├── function │ │ │ ├── ExprFunction.java │ │ │ ├── ExprFunctionDynamic.java │ │ │ ├── ExprFunctionExternal.java │ │ │ ├── ExprFunctionNoArgs.java │ │ │ ├── ExprFunctionProperty.java │ │ │ ├── MemberFunction.java │ │ │ └── MemberFunctionNoArgs.java │ │ │ ├── generic │ │ │ ├── EffectPrint.java │ │ │ ├── ExprBinaryOtherwise.java │ │ │ ├── ExprBracket.java │ │ │ ├── ExprConverter.java │ │ │ ├── ExprJavaVersion.java │ │ │ ├── ExprNewLine.java │ │ │ ├── ExprProperty.java │ │ │ ├── ExprSystemInput.java │ │ │ ├── ExprSystemProperty.java │ │ │ └── ExprTernaryOtherwise.java │ │ │ ├── list │ │ │ ├── EffectClearList.java │ │ │ ├── ExprIndexOfList.java │ │ │ ├── ExprNewArray.java │ │ │ ├── ExprNewList.java │ │ │ └── ExprSizeOfList.java │ │ │ ├── literal │ │ │ ├── BooleanLiteral.java │ │ │ ├── DoubleLiteral.java │ │ │ ├── FloatLiteral.java │ │ │ ├── IntegerLiteral.java │ │ │ ├── LongLiteral.java │ │ │ ├── NoneLiteral.java │ │ │ ├── RegexLiteral.java │ │ │ └── StringLiteral.java │ │ │ ├── map │ │ │ ├── ExprKeyInMap.java │ │ │ └── ExprNewMap.java │ │ │ ├── maths │ │ │ ├── ExprAdd.java │ │ │ ├── ExprDivide.java │ │ │ ├── ExprMultiply.java │ │ │ ├── ExprSquareRoot.java │ │ │ ├── ExprSubtract.java │ │ │ └── SymbolJoiner.java │ │ │ ├── script │ │ │ ├── EffectLoadScript.java │ │ │ ├── EffectUnloadScript.java │ │ │ ├── ExprCompiler.java │ │ │ ├── ExprCurrentScript.java │ │ │ └── ExprLoadedScripts.java │ │ │ ├── test │ │ │ └── EffectTest.java │ │ │ ├── timing │ │ │ ├── EffectSleep.java │ │ │ ├── EffectWait.java │ │ │ ├── EffectWake.java │ │ │ ├── ExprDays.java │ │ │ ├── ExprHours.java │ │ │ ├── ExprMilliseconds.java │ │ │ ├── ExprMinutes.java │ │ │ ├── ExprMonths.java │ │ │ ├── ExprSeconds.java │ │ │ ├── ExprThread.java │ │ │ ├── ExprWeeks.java │ │ │ ├── ExprYears.java │ │ │ └── MemberEvery.java │ │ │ ├── type │ │ │ ├── ExprNewType.java │ │ │ ├── ExprThisThing.java │ │ │ ├── ExprType.java │ │ │ ├── MemberTemplateType.java │ │ │ ├── MemberType.java │ │ │ └── property │ │ │ │ ├── EntryFinal.java │ │ │ │ ├── EntryLocal.java │ │ │ │ ├── EntryProperty.java │ │ │ │ └── EntryType.java │ │ │ └── variable │ │ │ ├── ExprVariable.java │ │ │ ├── ExprVariableAtomic.java │ │ │ ├── ExprVariableGlobal.java │ │ │ └── ExprVariableThread.java │ │ └── runtime │ │ ├── Script.java │ │ ├── Skript.java │ │ ├── UnsafeAccessor.java │ │ ├── config │ │ ├── ConfigEntry.java │ │ └── ConfigMap.java │ │ ├── data │ │ ├── EventData.java │ │ ├── Function.java │ │ ├── HandlerData.java │ │ ├── PeriodicalData.java │ │ ├── ScriptData.java │ │ ├── SourceData.java │ │ ├── Structure.java │ │ └── TypeData.java │ │ ├── event │ │ ├── Empty.java │ │ ├── Load.java │ │ └── Unload.java │ │ ├── internal │ │ ├── Bootstrapper.java │ │ ├── CompiledScript.java │ │ ├── CompilerDependent.java │ │ ├── ConsoleColour.java │ │ ├── EventHandler.java │ │ ├── ExtractedSyntaxCalls.java │ │ ├── GlobalVariableMap.java │ │ ├── IOHandlers.java │ │ ├── Instruction.java │ │ ├── InvokingScriptRunner.java │ │ ├── LibraryClassLoader.java │ │ ├── Member.java │ │ ├── Metafactory.java │ │ ├── ModifiableCompiler.java │ │ ├── OperatorHandler.java │ │ ├── Promise.java │ │ ├── ScriptClassLoader.java │ │ ├── ThreadSpecific.java │ │ ├── ThreadVariableMap.java │ │ ├── VariableMap.java │ │ ├── WeakList.java │ │ └── package-info.java │ │ ├── threading │ │ ├── AirlockQueue.java │ │ ├── OperationController.java │ │ ├── ScriptExceptionHandler.java │ │ ├── ScriptFinishFuture.java │ │ ├── ScriptRunner.java │ │ ├── ScriptThread.java │ │ ├── ScriptThreadPoolExecutor.java │ │ └── SkriptThreadProvider.java │ │ └── type │ │ ├── AtomicVariable.java │ │ ├── Converter.java │ │ ├── DataList.java │ │ ├── DataMap.java │ │ ├── EventData.java │ │ ├── Executable.java │ │ ├── OperatorFunction.java │ │ └── Query.java │ ├── skript.java │ └── unsafe.java └── test ├── java └── org │ └── byteskript │ └── skript │ └── test │ ├── AsyncCompileTest.java │ ├── ConfigTest.java │ ├── CreatePages.java │ ├── ExampleController.java │ ├── MainTest.java │ ├── RecompileTest.java │ ├── SkriptTest.java │ ├── SyntaxTest.java │ ├── SyntaxTreeTest.java │ ├── TestingLibrary.java │ └── ThreadingTest.java └── resources ├── main.bsk └── tests ├── addeffect.bsk ├── anyloadevent.bsk ├── asserteffect.bsk ├── atomicvariable.bsk ├── binaryotherwise.bsk ├── bracket.bsk ├── breakeffect.bsk ├── breakifeffect.bsk ├── breakloopeffect.bsk ├── clearlist.bsk ├── compiler.bsk ├── configcreator.bsk ├── configfile.bsk ├── contains.bsk ├── continueeffect.bsk ├── conversion.bsk ├── currentevent.bsk ├── currentscript.bsk ├── customsyntax.bsk ├── deleteeffect.bsk ├── dictionary.bsk ├── dynamicfunction.bsk ├── every.bsk ├── exists.bsk ├── extends.bsk ├── externalfunction.bsk ├── finalmember.bsk ├── functionexpression.bsk ├── functionmember.bsk ├── globalvariable.bsk ├── greaterthan.bsk ├── greaterthanequalto.bsk ├── if.bsk ├── implicitarray.bsk ├── importfunction.bsk ├── importtype.bsk ├── indexinlist.bsk ├── io.bsk ├── isarray.bsk ├── isequal.bsk ├── isoftype.bsk ├── javaversion.bsk ├── keyinconfig.bsk ├── keyinmap.bsk ├── lemma.bsk ├── lessthan.bsk ├── lessthanequalto.bsk ├── literals.bsk ├── loadedscripts.bsk ├── loadevent.bsk ├── loadscript.bsk ├── localmember.bsk ├── localvariable.bsk ├── loopin.bsk ├── looptimes.bsk ├── matches.bsk ├── maths.bsk ├── monitor.bsk ├── namespaceskript.bsk ├── newline.bsk ├── notequal.bsk ├── parameters.bsk ├── print.bsk ├── properties.bsk ├── propertyfunction.bsk ├── propertymember.bsk ├── removeeffect.bsk ├── resultof.bsk ├── returneffect.bsk ├── returntype.bsk ├── run.bsk ├── runasync.bsk ├── runnable.bsk ├── runwith.bsk ├── runwithasync.bsk ├── saveconfig.bsk ├── seteffect.bsk ├── sizeoflist.bsk ├── sleep.bsk ├── supplier.bsk ├── systemproperty.bsk ├── template.bsk ├── templatetype.bsk ├── ternaryotherwise.bsk ├── testeffect.bsk ├── threadexpression.bsk ├── threadvariable.bsk ├── timespans.bsk ├── trigger.bsk ├── trycatch.bsk ├── tryeffect.bsk ├── typecreator.bsk ├── typemember.bsk ├── unloadscript.bsk ├── verify.bsk ├── waitfor.bsk ├── wake.bsk └── while.bsk /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve 4 | title: '' 5 | labels: '' 6 | assignees: '' 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 | **Desktop (please complete the following information):** 27 | - OS: [e.g. iOS] 28 | - Browser [e.g. chrome, safari] 29 | - Version [e.g. 22] 30 | 31 | **Smartphone (please complete the following information):** 32 | - Device: [e.g. iPhone6] 33 | - OS: [e.g. iOS8.1] 34 | - Browser [e.g. stock browser, safari] 35 | - Version [e.g. 22] 36 | 37 | **Additional context** 38 | Add any other context about the problem here. 39 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for this project 4 | title: '' 5 | labels: '' 6 | assignees: '' 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/workflows/maven.yml: -------------------------------------------------------------------------------- 1 | name: Run Tests 2 | on: 3 | push: 4 | paths-ignore: 5 | - '**.md' 6 | - '**.yml' 7 | jobs: 8 | run_tests: 9 | runs-on: ubuntu-latest 10 | steps: 11 | - name: Checkout the repository 12 | uses: actions/checkout@v2 13 | - name: Set up JDK 17 14 | uses: actions/setup-java@v1 15 | with: 16 | java-version: 17 17 | - name: Cache Maven packages 18 | uses: actions/cache@v2 19 | with: 20 | path: ~/.m2 21 | key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }} 22 | restore-keys: ${{ runner.os }}-m2 23 | - name: Run tests with Maven 24 | run: mvn -B test --file pom.xml 25 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Project exclude paths 2 | /target/ 3 | .DS_Store 4 | *.class 5 | .idea/ 6 | -------------------------------------------------------------------------------- /CITATION.cff: -------------------------------------------------------------------------------- 1 | cff-version: 1.2.0 2 | message: "If you use this software, please cite it as below." 3 | authors: 4 | - family-names: "Scott" 5 | given-names: "Mackenzie" 6 | - family-names: "Suhonen" 7 | given-names: "Ilari" 8 | title: "ByteSkript" 9 | version: 1.0.0 10 | date-released: 2021-12-25 11 | url: "https://github.com/Moderocky/ByteSkript" 12 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | 3 | Please see the contributing guidelines and 4 | guide [here](https://docs.byteskript.org/tutorials/contributing-to-byteskript). 5 | 6 | Please also refer to the contributors 7 | licensing [instructions](https://docs.byteskript.org/readme/licence-information#contributing-to-byteskript). 8 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2021 Moderocky 2 | 3 | Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 4 | 5 | 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 6 | 7 | 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 8 | 9 | 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. 10 | 11 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 12 | 13 | You acknowledge that this software is not designed, licensed or intended for use in the design, construction, operation or maintenance of any nuclear facility. 14 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ByteSkript 2 | 3 | ### Opus #11 4 | 5 | An experimental language based on Skript (with no pre-eminent DSL dependencies) compiled to JVM bytecode. 6 | 7 | ## Visit the documentation and wiki [here](https://docs.byteskript.org). 8 | 9 | ## Get the latest compiler release [here](https://github.com/Moderocky/ByteSkript/releases). 10 | 11 | ByteSkript draws heavily from the original [Skript](https://github.com/SkriptLang/Skript/) language design, with some 12 | minor structural adaptations to strengthen the language grammar, to remove some unnecessary jargon and make the language 13 | more reliable. ByteSkript also increases interoperability with existing JVM languages. 14 | 15 | **ByteSkript is not affiliated with [SkriptLang](https://github.com/SkriptLang/Skript/).** 16 | 17 | ByteSkript is a completely **new** implementation of the general guide and style of the 'Skript' language, with its own 18 | language specification, goals and licence. 19 | 20 | ## Libraries Used 21 | 22 | * [ObjectWeb ASM](https://asm.ow2.io) \ 23 | A bytecode-assembling library used internally by the Java JDK.\ 24 | Used for compiling complex syntax. 25 | * [Mirror](https://github.com/Moderocky/Mirror) \ 26 | An on-the-fly member access compiler, alternative to Java reflection.\ 27 | Used for compiling dynamic method handles at runtime. 28 | * [Foundation](https://github.com/Moderocky/Foundation) \ 29 | A class-building framework to simplify method creation.\ 30 | Used for compiling simple syntax. 31 | * [Jupiter](https://github.com/Moderocky/Jupiter) \ 32 | An I/O-based library for buffers and memory management.\ 33 | Used for lazy-iteration and efficient data disposal. 34 | * [AutoDocs](https://github.com/Moderocky/AutoDocs) \ 35 | A web-documentation generator.\ 36 | Used for generating the [API docs](https://apidocs.byteskript.org/org/byteskript/skript/). 37 | -------------------------------------------------------------------------------- /SECURITY.md: -------------------------------------------------------------------------------- 1 | # Security Policy 2 | 3 | ## Supported Versions 4 | 5 | Security vulnerabilities will be retroactively patched on the last **three** medium versions (1.**X**.0). 6 | This will require users to redownload (or rebuild) the affected version. 7 | 8 | ## Reporting a Vulnerability 9 | 10 | For minor vulnerabilities, issues can be made on the GitHub. 11 | For more serious vulnerabilites, please make direct private contact with any organisation member. 12 | -------------------------------------------------------------------------------- /TODO.md: -------------------------------------------------------------------------------- 1 | # Tasks to Complete 2 | 3 | This file contains a list of tasks that need completing, ordered by various factors. 4 | 5 | Contributors can consider this a 'bounty' list of things to do. If you are looking to contribute, consider picking a 6 | task from this list. 7 | 8 | Tasks are categorised by importance and marked by difficulty. 9 | 10 | ### Most Important 11 | 12 | - Finish documentation for built-in syntax. \ 13 | Some syntax is missing proper [documentation](https://moderocky.gitbook.io/byteskript/). \ 14 | Difficulty: trivial 15 | - Write more comprehensive tests. \ 16 | It is important to test all expected behaviour - some syntax are missing full tests. \ 17 | It is also important to test forbidden behaviour does *not* work, and proper negative tests are not implemented yet. \ 18 | It would also be nice to stress-test complex and difficult-to-parse syntax structures. \ 19 | Difficulty: easy 20 | 21 | ### Medium Importance 22 | 23 | - Create a library for Java GUIs. \ 24 | This will probably need to interact with JavaFX. \ 25 | This should be handled by somebody with experience using Java front-end. \ 26 | Difficulty: medium 27 | - Write a better default parser. \ 28 | The current parser uses RegEx for assembling patterns. \ 29 | Since the matching is trivial, I think these can be converted to string-matches. \ 30 | Difficulty: easy 31 | 32 | ### Least Important 33 | 34 | - Create a library for web-servers. \ 35 | Support opening a web-server and receiving requests. \ 36 | Support sending HTTP requests to a web-server. \ 37 | Difficulty: medium 38 | - Create a library for Discord bots. \ 39 | Difficulty: easy 40 | -------------------------------------------------------------------------------- /docs/CNAME: -------------------------------------------------------------------------------- 1 | apidocs.byteskript.org -------------------------------------------------------------------------------- /scripts/install-byteskript.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | current_dir=$(pwd) 4 | script_dir=$(dirname "$0") 5 | 6 | cd $script_dir 7 | if [[ ! -e bin ]]; then 8 | mkdir "bin" 9 | cd "bin" 10 | 11 | echo $'#!/bin/bash\njava -jar '$script_dir'/ByteSkript.jar $@' > "bsk" 12 | fi 13 | 14 | if [[ ! -e /usr/local/bin/bsk ]]; then 15 | rm /usr/local/bin/bsk 16 | fi 17 | 18 | ln -s $script_dir"/bin/bsk" "/usr/local/bin/bsk" 19 | 20 | chmod a+x $script_dir"/bin/bsk" 21 | chmod a+x /usr/local/bin/bsk 22 | -------------------------------------------------------------------------------- /src/main/java/org/byteskript/skript/api/AsyncEvent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 ByteSkript org (Moderocky) 3 | * View the full licence information and permissions: 4 | * https://github.com/Moderocky/ByteSkript/blob/master/LICENSE 5 | */ 6 | 7 | package org.byteskript.skript.api; 8 | 9 | import mx.kenzie.autodoc.api.note.Ignore; 10 | 11 | @Ignore 12 | public abstract class AsyncEvent extends Event { 13 | 14 | @Override 15 | public final boolean isAsync() { 16 | return true; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/org/byteskript/skript/api/DebugTypeMeta.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2022 ByteSkript org (Moderocky) 3 | * View the full licence information and permissions: 4 | * https://github.com/Moderocky/ByteSkript/blob/master/LICENSE 5 | */ 6 | 7 | package org.byteskript.skript.api; 8 | 9 | import mx.kenzie.foundation.Type; 10 | 11 | import java.util.Objects; 12 | 13 | public interface DebugTypeMeta { 14 | 15 | default String debug(Object meta) { 16 | if (meta instanceof Type type) return type.getSimpleName(); 17 | return Objects.toString(meta); 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/org/byteskript/skript/api/Deletable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2022 ByteSkript org (Moderocky) 3 | * View the full licence information and permissions: 4 | * https://github.com/Moderocky/ByteSkript/blob/master/LICENSE 5 | */ 6 | 7 | package org.byteskript.skript.api; 8 | 9 | /** 10 | * Something that can be deleted, and should be compiled as normal to handle the effect. 11 | */ 12 | public interface Deletable { 13 | } 14 | -------------------------------------------------------------------------------- /src/main/java/org/byteskript/skript/api/Document.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2022 ByteSkript org (Moderocky) 3 | * View the full licence information and permissions: 4 | * https://github.com/Moderocky/ByteSkript/blob/master/LICENSE 5 | */ 6 | 7 | package org.byteskript.skript.api; 8 | 9 | import mx.kenzie.autodoc.api.note.Description; 10 | 11 | @Description("A miniature record for holding documentation for a syntax element.") 12 | public record Document(String name, String type, String[] patterns, String description, String... examples) { 13 | } 14 | -------------------------------------------------------------------------------- /src/main/java/org/byteskript/skript/api/Flag.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 ByteSkript org (Moderocky) 3 | * View the full licence information and permissions: 4 | * https://github.com/Moderocky/ByteSkript/blob/master/LICENSE 5 | */ 6 | 7 | package org.byteskript.skript.api; 8 | 9 | import mx.kenzie.autodoc.api.note.Description; 10 | 11 | @Description(""" 12 | Compiler flags to provide trivial information to the matcher. 13 | This should be implemented by an enum. 14 | """) 15 | public interface Flag { 16 | 17 | String name(); 18 | 19 | } 20 | -------------------------------------------------------------------------------- /src/main/java/org/byteskript/skript/api/FunctionalEntrySection.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 ByteSkript org (Moderocky) 3 | * View the full licence information and permissions: 4 | * https://github.com/Moderocky/ByteSkript/blob/master/LICENSE 5 | */ 6 | 7 | package org.byteskript.skript.api; 8 | 9 | import mx.kenzie.autodoc.api.note.Ignore; 10 | import org.byteskript.skript.compiler.Context; 11 | 12 | @Ignore 13 | public interface FunctionalEntrySection { 14 | 15 | void compile(Context context) throws Throwable; 16 | 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/org/byteskript/skript/api/HandlerType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 ByteSkript org (Moderocky) 3 | * View the full licence information and permissions: 4 | * https://github.com/Moderocky/ByteSkript/blob/master/LICENSE 5 | */ 6 | 7 | package org.byteskript.skript.api; 8 | 9 | import mx.kenzie.autodoc.api.note.Description; 10 | 11 | @Description(""" 12 | A handler mode for interacting with expressions. 13 | The defaults (get/set/add/delete/...) are detailed in StandardHandlers. 14 | 15 | Special implementations could add behaviour like COMPARE_AND_SWAP or GET_ATOMIC. 16 | """) 17 | public interface HandlerType { 18 | 19 | String name(); 20 | 21 | boolean expectInputs(); 22 | 23 | boolean expectReturn(); 24 | 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/org/byteskript/skript/api/LanguageElement.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 ByteSkript org (Moderocky) 3 | * View the full licence information and permissions: 4 | * https://github.com/Moderocky/ByteSkript/blob/master/LICENSE 5 | */ 6 | 7 | package org.byteskript.skript.api; 8 | 9 | import mx.kenzie.autodoc.api.note.Description; 10 | import org.byteskript.skript.lang.element.StandardElements; 11 | 12 | /** 13 | * Language elements. For advanced use only. 14 | * See {@link StandardElements} for the built-in ones. 15 | */ 16 | @Description(""" 17 | Language elements. For advanced use only. 18 | This is designed for adding entirely new pieces of grammar to the language. 19 | 20 | See StandardElements for the built-in ones that most syntax must use. 21 | """) 22 | public interface LanguageElement { 23 | 24 | String name(); 25 | 26 | Library getProvider(); 27 | 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/org/byteskript/skript/api/PropertyHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 ByteSkript org (Moderocky) 3 | * View the full licence information and permissions: 4 | * https://github.com/Moderocky/ByteSkript/blob/master/LICENSE 5 | */ 6 | 7 | package org.byteskript.skript.api; 8 | 9 | import mx.kenzie.autodoc.api.note.Description; 10 | import mx.kenzie.autodoc.api.note.Example; 11 | import mx.kenzie.foundation.Type; 12 | 13 | import java.lang.reflect.Method; 14 | import java.lang.reflect.Modifier; 15 | 16 | @Description(""" 17 | A property handler. 18 | """) 19 | public record PropertyHandler(String name, HandlerType type, Type holder, Type value, Method method) { 20 | 21 | @Example(""" 22 | new PropertyHandler(StandardHandlers.GET, method, "name"); 23 | """) 24 | public PropertyHandler(HandlerType type, Method method, String name) { 25 | this(name, type, createHolder(method), createValue(type, method), method); 26 | } 27 | 28 | private static Type createHolder(Method method) { 29 | if (Modifier.isStatic(method.getModifiers())) { 30 | final Class[] classes = method.getParameterTypes(); 31 | assert classes.length > 0; 32 | return new Type(classes[0]); 33 | } else { 34 | return new Type(method.getDeclaringClass()); 35 | } 36 | } 37 | 38 | private static Type createValue(HandlerType type, Method method) { 39 | if (type.expectInputs()) { 40 | final Class[] classes = method.getParameterTypes(); 41 | assert classes.length > 0; 42 | return new Type(classes[classes.length - 1]); 43 | } else if (type.expectReturn()) { 44 | return new Type(method.getReturnType()); 45 | } else { 46 | return new Type(void.class); 47 | } 48 | } 49 | 50 | 51 | } 52 | -------------------------------------------------------------------------------- /src/main/java/org/byteskript/skript/api/Referent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 ByteSkript org (Moderocky) 3 | * View the full licence information and permissions: 4 | * https://github.com/Moderocky/ByteSkript/blob/master/LICENSE 5 | */ 6 | 7 | package org.byteskript.skript.api; 8 | 9 | import mx.kenzie.autodoc.api.note.Description; 10 | import mx.kenzie.foundation.MethodBuilder; 11 | import mx.kenzie.foundation.Type; 12 | import mx.kenzie.foundation.compiler.State; 13 | import org.byteskript.skript.compiler.CompileState; 14 | import org.byteskript.skript.compiler.Context; 15 | import org.byteskript.skript.compiler.Pattern; 16 | import org.byteskript.skript.error.ScriptCompileError; 17 | import org.byteskript.skript.lang.handler.StandardHandlers; 18 | 19 | import java.lang.reflect.Method; 20 | 21 | @Description("This syntax is designed to be set or altered in some way.") 22 | public interface Referent extends SyntaxElement { 23 | 24 | Type getHolderType(); 25 | 26 | @Override 27 | default void compile(Context context, Pattern.Match match) throws Throwable { 28 | final MethodBuilder method = context.getMethod(); 29 | assert method != null; 30 | final Method target = getHandler(StandardHandlers.GET); 31 | if (target == null) throw new ScriptCompileError(context.lineNumber(), "Referent has no get handler."); 32 | if (target.getReturnType() == void.class) 33 | throw new ScriptCompileError(context.lineNumber(), "Referent get handler must not have a void return."); 34 | this.writeCall(context.getMethod(), target, context); 35 | context.setState(CompileState.STATEMENT); 36 | } 37 | 38 | @Override 39 | default boolean allowedIn(State state, Context context) { 40 | return state == CompileState.STATEMENT && context.hasCurrentUnit(); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/org/byteskript/skript/api/automatic/GeneratedEffect.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 ByteSkript org (Moderocky) 3 | * View the full licence information and permissions: 4 | * https://github.com/Moderocky/ByteSkript/blob/master/LICENSE 5 | */ 6 | 7 | package org.byteskript.skript.api.automatic; 8 | 9 | import mx.kenzie.foundation.MethodBuilder; 10 | import mx.kenzie.foundation.WriteInstruction; 11 | import org.byteskript.skript.api.Library; 12 | import org.byteskript.skript.api.syntax.Effect; 13 | import org.byteskript.skript.compiler.CompileState; 14 | import org.byteskript.skript.compiler.Context; 15 | import org.byteskript.skript.compiler.Pattern; 16 | import org.byteskript.skript.lang.element.StandardElements; 17 | 18 | import java.lang.reflect.Method; 19 | 20 | public final class GeneratedEffect extends Effect { 21 | 22 | private final Method target; 23 | 24 | public GeneratedEffect(Library provider, final Method target, String... patterns) { 25 | super(provider, StandardElements.EFFECT, patterns); 26 | this.target = target; 27 | } 28 | 29 | @Override 30 | public void compile(Context context, Pattern.Match match) throws Throwable { 31 | final MethodBuilder method = context.getMethod(); 32 | this.writeCall(method, target, context); 33 | if (target.getReturnType() != void.class) method.writeCode(WriteInstruction.pop()); 34 | context.setState(CompileState.CODE_BODY); 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/org/byteskript/skript/api/automatic/GeneratedEventHolder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 ByteSkript org (Moderocky) 3 | * View the full licence information and permissions: 4 | * https://github.com/Moderocky/ByteSkript/blob/master/LICENSE 5 | */ 6 | 7 | package org.byteskript.skript.api.automatic; 8 | 9 | import org.byteskript.skript.api.Event; 10 | import org.byteskript.skript.api.Library; 11 | import org.byteskript.skript.api.syntax.EventHolder; 12 | 13 | public final class GeneratedEventHolder extends EventHolder { 14 | 15 | private final Class owner; 16 | 17 | public GeneratedEventHolder(Library provider, Class owner, String... patterns) { 18 | super(provider, patterns); 19 | this.owner = owner; 20 | } 21 | 22 | @Override 23 | public Class eventClass() { 24 | return owner; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/org/byteskript/skript/api/automatic/GeneratedExpression.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 ByteSkript org (Moderocky) 3 | * View the full licence information and permissions: 4 | * https://github.com/Moderocky/ByteSkript/blob/master/LICENSE 5 | */ 6 | 7 | package org.byteskript.skript.api.automatic; 8 | 9 | import mx.kenzie.foundation.MethodBuilder; 10 | import mx.kenzie.foundation.Type; 11 | import org.byteskript.skript.api.Library; 12 | import org.byteskript.skript.api.syntax.SimpleExpression; 13 | import org.byteskript.skript.compiler.CompileState; 14 | import org.byteskript.skript.compiler.Context; 15 | import org.byteskript.skript.compiler.Pattern; 16 | import org.byteskript.skript.lang.element.StandardElements; 17 | 18 | import java.lang.reflect.Method; 19 | 20 | public final class GeneratedExpression extends SimpleExpression { 21 | 22 | private final Method target; 23 | private final Type value; 24 | 25 | public GeneratedExpression(Library provider, final Method target, String... patterns) { 26 | super(provider, StandardElements.EXPRESSION, patterns); 27 | this.target = target; 28 | this.value = new Type(target.getReturnType()); 29 | } 30 | 31 | @Override 32 | public Type getReturnType() { 33 | return value; 34 | } 35 | 36 | @Override 37 | public void compile(Context context, Pattern.Match match) throws Throwable { 38 | final MethodBuilder method = context.getMethod(); 39 | assert target.getReturnType() != void.class; 40 | this.writeCall(method, target, context); 41 | context.setState(CompileState.STATEMENT); 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/org/byteskript/skript/api/note/Documentation.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2022 ByteSkript org (Moderocky) 3 | * View the full licence information and permissions: 4 | * https://github.com/Moderocky/ByteSkript/blob/master/LICENSE 5 | */ 6 | 7 | package org.byteskript.skript.api.note; 8 | 9 | import java.lang.annotation.Retention; 10 | import java.lang.annotation.RetentionPolicy; 11 | 12 | @Retention(RetentionPolicy.RUNTIME) 13 | public @interface Documentation { 14 | 15 | String name() default ""; 16 | 17 | String description() default ""; 18 | 19 | String[] examples() default {}; 20 | 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/org/byteskript/skript/api/note/Effect.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 ByteSkript org (Moderocky) 3 | * View the full licence information and permissions: 4 | * https://github.com/Moderocky/ByteSkript/blob/master/LICENSE 5 | */ 6 | 7 | package org.byteskript.skript.api.note; 8 | 9 | import java.lang.annotation.ElementType; 10 | import java.lang.annotation.Retention; 11 | import java.lang.annotation.RetentionPolicy; 12 | import java.lang.annotation.Target; 13 | 14 | @Target(ElementType.METHOD) 15 | @Retention(RetentionPolicy.RUNTIME) 16 | public @interface Effect { 17 | 18 | String[] value(); 19 | 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/org/byteskript/skript/api/note/EntryNode.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 ByteSkript org (Moderocky) 3 | * View the full licence information and permissions: 4 | * https://github.com/Moderocky/ByteSkript/blob/master/LICENSE 5 | */ 6 | 7 | package org.byteskript.skript.api.note; 8 | 9 | import java.lang.annotation.ElementType; 10 | import java.lang.annotation.Retention; 11 | import java.lang.annotation.RetentionPolicy; 12 | import java.lang.annotation.Target; 13 | 14 | @Target({ElementType.RECORD_COMPONENT, ElementType.METHOD}) 15 | @Retention(RetentionPolicy.RUNTIME) 16 | public @interface EntryNode { 17 | 18 | String[] value(); 19 | 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/org/byteskript/skript/api/note/EntrySection.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 ByteSkript org (Moderocky) 3 | * View the full licence information and permissions: 4 | * https://github.com/Moderocky/ByteSkript/blob/master/LICENSE 5 | */ 6 | 7 | package org.byteskript.skript.api.note; 8 | 9 | import java.lang.annotation.ElementType; 10 | import java.lang.annotation.Retention; 11 | import java.lang.annotation.RetentionPolicy; 12 | import java.lang.annotation.Target; 13 | 14 | @Target({ElementType.TYPE}) 15 | @Retention(RetentionPolicy.RUNTIME) 16 | public @interface EntrySection { 17 | 18 | String[] value(); 19 | 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/org/byteskript/skript/api/note/Event.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 ByteSkript org (Moderocky) 3 | * View the full licence information and permissions: 4 | * https://github.com/Moderocky/ByteSkript/blob/master/LICENSE 5 | */ 6 | 7 | package org.byteskript.skript.api.note; 8 | 9 | import java.lang.annotation.ElementType; 10 | import java.lang.annotation.Retention; 11 | import java.lang.annotation.RetentionPolicy; 12 | import java.lang.annotation.Target; 13 | 14 | @Target(ElementType.TYPE) 15 | @Retention(RetentionPolicy.RUNTIME) 16 | public @interface Event { 17 | 18 | String[] value(); 19 | 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/org/byteskript/skript/api/note/EventValue.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 ByteSkript org (Moderocky) 3 | * View the full licence information and permissions: 4 | * https://github.com/Moderocky/ByteSkript/blob/master/LICENSE 5 | */ 6 | 7 | package org.byteskript.skript.api.note; 8 | 9 | import java.lang.annotation.ElementType; 10 | import java.lang.annotation.Retention; 11 | import java.lang.annotation.RetentionPolicy; 12 | import java.lang.annotation.Target; 13 | 14 | @Target(ElementType.METHOD) 15 | @Retention(RetentionPolicy.RUNTIME) 16 | public @interface EventValue { 17 | 18 | String value(); 19 | 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/org/byteskript/skript/api/note/Expression.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 ByteSkript org (Moderocky) 3 | * View the full licence information and permissions: 4 | * https://github.com/Moderocky/ByteSkript/blob/master/LICENSE 5 | */ 6 | 7 | package org.byteskript.skript.api.note; 8 | 9 | import java.lang.annotation.ElementType; 10 | import java.lang.annotation.Retention; 11 | import java.lang.annotation.RetentionPolicy; 12 | import java.lang.annotation.Target; 13 | 14 | @Target(ElementType.METHOD) 15 | @Retention(RetentionPolicy.RUNTIME) 16 | public @interface Expression { 17 | 18 | String[] value(); 19 | 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/org/byteskript/skript/api/note/ForceBridge.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 ByteSkript org (Moderocky) 3 | * View the full licence information and permissions: 4 | * https://github.com/Moderocky/ByteSkript/blob/master/LICENSE 5 | */ 6 | 7 | package org.byteskript.skript.api.note; 8 | 9 | import java.lang.annotation.ElementType; 10 | import java.lang.annotation.Retention; 11 | import java.lang.annotation.RetentionPolicy; 12 | import java.lang.annotation.Target; 13 | 14 | /** 15 | * Forces a method's raw bytecode to be extracted into the compiled class. 16 | * This should be used sparingly. It is natively unsafe. 17 | */ 18 | @Target({ElementType.METHOD, ElementType.CONSTRUCTOR}) 19 | @Retention(RetentionPolicy.RUNTIME) 20 | public @interface ForceBridge { 21 | } 22 | 23 | -------------------------------------------------------------------------------- /src/main/java/org/byteskript/skript/api/note/ForceExtract.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 ByteSkript org (Moderocky) 3 | * View the full licence information and permissions: 4 | * https://github.com/Moderocky/ByteSkript/blob/master/LICENSE 5 | */ 6 | 7 | package org.byteskript.skript.api.note; 8 | 9 | import java.lang.annotation.ElementType; 10 | import java.lang.annotation.Retention; 11 | import java.lang.annotation.RetentionPolicy; 12 | import java.lang.annotation.Target; 13 | 14 | /** 15 | * Forces a method's raw bytecode to be extracted into the compiled class. 16 | * This should be used sparingly. It is natively unsafe. 17 | */ 18 | @Target({ElementType.METHOD, ElementType.CONSTRUCTOR}) 19 | @Retention(RetentionPolicy.RUNTIME) 20 | public @interface ForceExtract { 21 | } 22 | 23 | -------------------------------------------------------------------------------- /src/main/java/org/byteskript/skript/api/note/ForceInline.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 ByteSkript org (Moderocky) 3 | * View the full licence information and permissions: 4 | * https://github.com/Moderocky/ByteSkript/blob/master/LICENSE 5 | */ 6 | 7 | package org.byteskript.skript.api.note; 8 | 9 | import java.lang.annotation.ElementType; 10 | import java.lang.annotation.Retention; 11 | import java.lang.annotation.RetentionPolicy; 12 | import java.lang.annotation.Target; 13 | 14 | /** 15 | * Forces a method's raw bytecode to be written into all compilation targets. 16 | * This should be used sparingly. It is natively unsafe. 17 | */ 18 | @Target({ElementType.METHOD, ElementType.CONSTRUCTOR}) 19 | @Retention(RetentionPolicy.RUNTIME) 20 | public @interface ForceInline { 21 | } 22 | 23 | -------------------------------------------------------------------------------- /src/main/java/org/byteskript/skript/api/note/Property.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 ByteSkript org (Moderocky) 3 | * View the full licence information and permissions: 4 | * https://github.com/Moderocky/ByteSkript/blob/master/LICENSE 5 | */ 6 | 7 | package org.byteskript.skript.api.note; 8 | 9 | import org.byteskript.skript.lang.handler.StandardHandlers; 10 | 11 | import java.lang.annotation.ElementType; 12 | import java.lang.annotation.Retention; 13 | import java.lang.annotation.RetentionPolicy; 14 | import java.lang.annotation.Target; 15 | 16 | @Target(ElementType.METHOD) 17 | @Retention(RetentionPolicy.RUNTIME) 18 | public @interface Property { 19 | 20 | String value(); 21 | 22 | StandardHandlers type() default StandardHandlers.GET; 23 | 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/org/byteskript/skript/api/note/SkriptType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 ByteSkript org (Moderocky) 3 | * View the full licence information and permissions: 4 | * https://github.com/Moderocky/ByteSkript/blob/master/LICENSE 5 | */ 6 | 7 | package org.byteskript.skript.api.note; 8 | 9 | import java.lang.annotation.ElementType; 10 | import java.lang.annotation.Retention; 11 | import java.lang.annotation.RetentionPolicy; 12 | import java.lang.annotation.Target; 13 | 14 | @Target(ElementType.TYPE) 15 | @Retention(RetentionPolicy.RUNTIME) 16 | public @interface SkriptType { 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/org/byteskript/skript/api/syntax/ComplexExpression.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 ByteSkript org (Moderocky) 3 | * View the full licence information and permissions: 4 | * https://github.com/Moderocky/ByteSkript/blob/master/LICENSE 5 | */ 6 | 7 | package org.byteskript.skript.api.syntax; 8 | 9 | import mx.kenzie.foundation.compiler.State; 10 | import org.byteskript.skript.api.LanguageElement; 11 | import org.byteskript.skript.api.Library; 12 | import org.byteskript.skript.api.SyntaxElement; 13 | import org.byteskript.skript.compiler.CompileState; 14 | import org.byteskript.skript.compiler.Context; 15 | import org.byteskript.skript.compiler.Pattern; 16 | 17 | import java.lang.reflect.Method; 18 | 19 | public abstract class ComplexExpression extends Element implements SyntaxElement { 20 | 21 | public ComplexExpression(final Library provider, final LanguageElement type, final String... patterns) { 22 | super(provider, type, patterns); 23 | } 24 | 25 | @Override 26 | public void preCompile(Context context, Pattern.Match match) throws Throwable { 27 | super.preCompile(context, match); 28 | final Method target = handlers.get(context.getHandlerMode()); 29 | if (target == null) return; 30 | this.prepareExpectedTypes(context, target); 31 | } 32 | 33 | @Override 34 | public boolean allowedIn(State state, Context context) { 35 | return state == CompileState.STATEMENT && context.hasCurrentUnit(); 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/org/byteskript/skript/api/syntax/Condition.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 ByteSkript org (Moderocky) 3 | * View the full licence information and permissions: 4 | * https://github.com/Moderocky/ByteSkript/blob/master/LICENSE 5 | */ 6 | 7 | package org.byteskript.skript.api.syntax; 8 | 9 | import org.byteskript.skript.api.LanguageElement; 10 | import org.byteskript.skript.api.Library; 11 | import org.byteskript.skript.api.SyntaxElement; 12 | import org.byteskript.skript.lang.handler.StandardHandlers; 13 | 14 | public abstract class Condition extends Element implements SyntaxElement { 15 | 16 | public Condition(final Library provider, final LanguageElement type, final String... patterns) { 17 | super(provider, type, patterns); 18 | try { 19 | handlers.put(StandardHandlers.FIND, this.getClass().getMethod("find", Object[].class)); 20 | } catch (NoSuchMethodException e) { 21 | e.printStackTrace(); 22 | } 23 | } 24 | 25 | public abstract Object find(Object... delta); 26 | 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/org/byteskript/skript/api/syntax/ControlEffect.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 ByteSkript org (Moderocky) 3 | * View the full licence information and permissions: 4 | * https://github.com/Moderocky/ByteSkript/blob/master/LICENSE 5 | */ 6 | 7 | package org.byteskript.skript.api.syntax; 8 | 9 | import org.byteskript.skript.api.HandlerType; 10 | import org.byteskript.skript.api.LanguageElement; 11 | import org.byteskript.skript.api.Library; 12 | import org.byteskript.skript.compiler.Context; 13 | import org.byteskript.skript.compiler.Pattern; 14 | 15 | public abstract class ControlEffect extends Effect { 16 | public ControlEffect(Library provider, LanguageElement type, String... patterns) { 17 | super(provider, type, patterns); 18 | } 19 | 20 | public abstract HandlerType getType(Context context, Pattern.Match match); 21 | 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/org/byteskript/skript/api/syntax/InnerModifyExpression.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 ByteSkript org (Moderocky) 3 | * View the full licence information and permissions: 4 | * https://github.com/Moderocky/ByteSkript/blob/master/LICENSE 5 | */ 6 | 7 | package org.byteskript.skript.api.syntax; 8 | 9 | import mx.kenzie.foundation.compiler.State; 10 | import org.byteskript.skript.api.LanguageElement; 11 | import org.byteskript.skript.api.Library; 12 | import org.byteskript.skript.api.SyntaxElement; 13 | import org.byteskript.skript.compiler.CompileState; 14 | import org.byteskript.skript.compiler.Context; 15 | import org.byteskript.skript.compiler.Pattern; 16 | 17 | /** 18 | * A special variety of expression designed as a placeholder to modify or contain an inner expression 19 | * and not to be present in the output tree. 20 | *

21 | * Designed for brackets, etc. 22 | */ 23 | public abstract class InnerModifyExpression extends Element implements SyntaxElement { 24 | 25 | public InnerModifyExpression(final Library provider, final LanguageElement type, final String... patterns) { 26 | super(provider, type, patterns); 27 | } 28 | 29 | @Override 30 | public final void compile(Context context, Pattern.Match match) { 31 | } 32 | 33 | @Override 34 | public boolean allowedIn(State state, Context context) { 35 | return state == CompileState.STATEMENT && context.hasCurrentUnit(); 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/org/byteskript/skript/api/syntax/Literal.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 ByteSkript org (Moderocky) 3 | * View the full licence information and permissions: 4 | * https://github.com/Moderocky/ByteSkript/blob/master/LICENSE 5 | */ 6 | 7 | package org.byteskript.skript.api.syntax; 8 | 9 | import mx.kenzie.foundation.MethodBuilder; 10 | import mx.kenzie.foundation.WriteInstruction; 11 | import mx.kenzie.foundation.compiler.State; 12 | import org.byteskript.skript.api.LanguageElement; 13 | import org.byteskript.skript.api.Library; 14 | import org.byteskript.skript.api.SyntaxElement; 15 | import org.byteskript.skript.compiler.CompileState; 16 | import org.byteskript.skript.compiler.Context; 17 | import org.byteskript.skript.compiler.Pattern; 18 | import org.byteskript.skript.lang.handler.StandardHandlers; 19 | 20 | import java.lang.reflect.Method; 21 | 22 | public abstract class Literal extends Element implements SyntaxElement { 23 | 24 | public Literal(final Library provider, final LanguageElement type, final String... patterns) { 25 | super(provider, type, patterns); 26 | } 27 | 28 | @Override 29 | public void compile(Context context, Pattern.Match match) throws Throwable { 30 | final MethodBuilder method = context.getMethod(); 31 | assert method != null; 32 | final Method target = handlers.get(StandardHandlers.GET); 33 | assert target != null; 34 | assert target.getReturnType() != void.class; 35 | this.writeCall(method, target, context); 36 | final mx.kenzie.foundation.Type type = context.getCompileCurrent().wanted; 37 | if (type != null) method.writeCode(WriteInstruction.cast(type)); 38 | } 39 | 40 | @Override 41 | public boolean allowedIn(State state, Context context) { 42 | return 43 | (state == CompileState.STATEMENT || state == CompileState.ENTRY_VALUE); // remove unit check 44 | } 45 | 46 | public abstract Type parse(String input); 47 | 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/org/byteskript/skript/api/syntax/Member.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 ByteSkript org (Moderocky) 3 | * View the full licence information and permissions: 4 | * https://github.com/Moderocky/ByteSkript/blob/master/LICENSE 5 | */ 6 | 7 | package org.byteskript.skript.api.syntax; 8 | 9 | import mx.kenzie.foundation.Type; 10 | import org.byteskript.skript.api.LanguageElement; 11 | import org.byteskript.skript.api.Library; 12 | import org.byteskript.skript.compiler.CommonTypes; 13 | import org.byteskript.skript.compiler.CompileState; 14 | import org.byteskript.skript.compiler.Context; 15 | import org.byteskript.skript.compiler.structure.SectionMeta; 16 | 17 | public abstract class Member extends Section { 18 | public Member(Library provider, LanguageElement type, String... patterns) { 19 | super(provider, type, patterns); 20 | } 21 | 22 | @Override 23 | public LanguageElement getType() { 24 | return super.getType(); 25 | } 26 | 27 | @Override 28 | public void onSectionExit(Context context, SectionMeta meta) { 29 | context.emptyVariables(); 30 | context.setMethod(null, true); 31 | context.setField(null); 32 | context.setState(CompileState.ROOT); 33 | } 34 | 35 | @Override 36 | public boolean allowAsInputFor(Type type) { 37 | return false; 38 | } 39 | 40 | @Override 41 | public Type getReturnType() { 42 | return CommonTypes.VOID; 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/org/byteskript/skript/api/syntax/Section.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 ByteSkript org (Moderocky) 3 | * View the full licence information and permissions: 4 | * https://github.com/Moderocky/ByteSkript/blob/master/LICENSE 5 | */ 6 | 7 | package org.byteskript.skript.api.syntax; 8 | 9 | import mx.kenzie.foundation.Type; 10 | import org.byteskript.skript.api.LanguageElement; 11 | import org.byteskript.skript.api.Library; 12 | import org.byteskript.skript.compiler.Context; 13 | import org.byteskript.skript.compiler.Pattern; 14 | import org.byteskript.skript.compiler.structure.SectionMeta; 15 | import org.byteskript.skript.error.ScriptCompileError; 16 | 17 | public abstract class Section extends Element { 18 | public Section(Library provider, LanguageElement type, String... patterns) { 19 | super(provider, type, patterns); 20 | } 21 | 22 | 23 | public abstract void onSectionExit(Context context, SectionMeta meta); 24 | 25 | public void compileInline(Context context, Pattern.Match match) throws Throwable { 26 | throw new ScriptCompileError(context.lineNumber(), "'" + name() + "' must be used as a section-header."); 27 | } 28 | 29 | public void preCompileInline(Context context, Pattern.Match match) throws Throwable { 30 | // Rarely used 31 | } 32 | 33 | @Override 34 | public boolean allowAsInputFor(Type type) { 35 | return false; 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/org/byteskript/skript/api/syntax/SectionEntry.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 ByteSkript org (Moderocky) 3 | * View the full licence information and permissions: 4 | * https://github.com/Moderocky/ByteSkript/blob/master/LICENSE 5 | */ 6 | 7 | package org.byteskript.skript.api.syntax; 8 | 9 | import mx.kenzie.foundation.Type; 10 | import mx.kenzie.foundation.compiler.State; 11 | import org.byteskript.skript.api.LanguageElement; 12 | import org.byteskript.skript.api.Library; 13 | import org.byteskript.skript.compiler.CommonTypes; 14 | import org.byteskript.skript.compiler.CompileState; 15 | import org.byteskript.skript.compiler.Context; 16 | 17 | public abstract class SectionEntry extends Section { 18 | public SectionEntry(Library provider, LanguageElement type, String... patterns) { 19 | super(provider, type, patterns); 20 | } 21 | 22 | @Override 23 | public CompileState getSubState() { 24 | return CompileState.MEMBER_BODY; 25 | } 26 | 27 | @Override 28 | public Type getReturnType() { 29 | return CommonTypes.VOID; 30 | } 31 | 32 | @Override 33 | public boolean allowedIn(State state, Context context) { 34 | return state == CompileState.MEMBER_BODY; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/org/byteskript/skript/api/syntax/SimpleEntry.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 ByteSkript org (Moderocky) 3 | * View the full licence information and permissions: 4 | * https://github.com/Moderocky/ByteSkript/blob/master/LICENSE 5 | */ 6 | 7 | package org.byteskript.skript.api.syntax; 8 | 9 | import mx.kenzie.foundation.Type; 10 | import mx.kenzie.foundation.compiler.State; 11 | import org.byteskript.skript.api.DebugTypeMeta; 12 | import org.byteskript.skript.api.LanguageElement; 13 | import org.byteskript.skript.api.Library; 14 | import org.byteskript.skript.compiler.CommonTypes; 15 | import org.byteskript.skript.compiler.CompileState; 16 | import org.byteskript.skript.compiler.Context; 17 | import org.byteskript.skript.compiler.Pattern; 18 | 19 | public abstract class SimpleEntry extends Element implements DebugTypeMeta { 20 | public SimpleEntry(Library provider, LanguageElement type, String... patterns) { 21 | super(provider, type, patterns); 22 | } 23 | 24 | @Override 25 | public Pattern.Match match(String thing, Context context) { 26 | return super.match(thing, context); 27 | } 28 | 29 | @Override 30 | public CompileState getSubState() { 31 | return CompileState.MEMBER_BODY; 32 | } 33 | 34 | @Override 35 | public boolean allowAsInputFor(Type type) { 36 | return false; 37 | } 38 | 39 | @Override 40 | public Type getReturnType() { 41 | return CommonTypes.VOID; 42 | } 43 | 44 | @Override 45 | public boolean allowedIn(State state, Context context) { 46 | return state == CompileState.MEMBER_BODY; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/org/byteskript/skript/api/syntax/TriggerHolder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 ByteSkript org (Moderocky) 3 | * View the full licence information and permissions: 4 | * https://github.com/Moderocky/ByteSkript/blob/master/LICENSE 5 | */ 6 | 7 | package org.byteskript.skript.api.syntax; 8 | 9 | import mx.kenzie.foundation.MethodBuilder; 10 | import mx.kenzie.foundation.Type; 11 | import org.byteskript.skript.api.LanguageElement; 12 | import org.byteskript.skript.api.Library; 13 | import org.byteskript.skript.compiler.CompileState; 14 | import org.byteskript.skript.compiler.Context; 15 | import org.byteskript.skript.compiler.Pattern; 16 | 17 | import java.lang.reflect.Modifier; 18 | import java.util.regex.Matcher; 19 | 20 | public abstract class TriggerHolder extends Member { 21 | public TriggerHolder(Library provider, LanguageElement type, String... patterns) { 22 | super(provider, type, patterns); 23 | } 24 | 25 | @Override 26 | public void compile(Context context, Pattern.Match match) { 27 | final MethodBuilder method = context.getBuilder() 28 | .addMethod(callSiteName(context, match)) 29 | .addModifiers(Modifier.STATIC) 30 | .setReturnType(returnType(context, match)) 31 | .addParameter(parameters(context, match.matcher())); 32 | context.setMethod(method, true); 33 | context.setState(CompileState.MEMBER_BODY); 34 | } 35 | 36 | public abstract String callSiteName(Context context, Pattern.Match match); 37 | 38 | public abstract Type returnType(Context context, Pattern.Match match); 39 | 40 | public Type[] parameters(Context context, Matcher match) { 41 | return new Type[0]; 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/org/byteskript/skript/app/ScriptCompiler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 ByteSkript org (Moderocky) 3 | * View the full licence information and permissions: 4 | * https://github.com/Moderocky/ByteSkript/blob/master/LICENSE 5 | */ 6 | 7 | package org.byteskript.skript.app; 8 | 9 | import org.byteskript.skript.runtime.Skript; 10 | 11 | import java.io.IOException; 12 | 13 | public final class ScriptCompiler extends SkriptApp { 14 | private static final Skript SKRIPT = new Skript(); 15 | 16 | public static void main(String... args) throws IOException { 17 | registerLibraries(SKRIPT); 18 | SKRIPT.compileScripts(SOURCE, OUTPUT); 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/org/byteskript/skript/app/ScriptDebugger.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2022 ByteSkript org (Moderocky) 3 | * View the full licence information and permissions: 4 | * https://github.com/Moderocky/ByteSkript/blob/master/LICENSE 5 | */ 6 | 7 | package org.byteskript.skript.app; 8 | 9 | import mx.kenzie.jupiter.stream.Stream; 10 | import org.byteskript.skript.compiler.DebugSkriptCompiler; 11 | import org.byteskript.skript.runtime.Skript; 12 | 13 | import java.io.File; 14 | import java.io.FileInputStream; 15 | import java.io.FileOutputStream; 16 | import java.io.IOException; 17 | 18 | public class ScriptDebugger extends SkriptApp { 19 | 20 | public static void main(String... args) throws IOException { 21 | final File file = new File(ROOT, "debug.txt"); 22 | try (final FileOutputStream stream = new FileOutputStream(file)) { 23 | final Skript skript = new Skript(new DebugSkriptCompiler(Stream.controller(stream))); 24 | registerLibraries(skript); 25 | skript.compileScripts(SOURCE); 26 | } 27 | } 28 | 29 | public static void debug(File file) throws IOException { 30 | final File debug = new File(ROOT, "debug.txt"); 31 | try (final FileOutputStream stream = new FileOutputStream(debug)) { 32 | try (final FileInputStream input = new FileInputStream(file)) { 33 | final Skript skript = new Skript(new DebugSkriptCompiler(Stream.controller(stream))); 34 | registerLibraries(skript); 35 | skript.compileScript(input, "skript/" + file.getName()); 36 | } 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/org/byteskript/skript/app/ScriptLoader.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 ByteSkript org (Moderocky) 3 | * View the full licence information and permissions: 4 | * https://github.com/Moderocky/ByteSkript/blob/master/LICENSE 5 | */ 6 | 7 | package org.byteskript.skript.app; 8 | 9 | import org.byteskript.skript.runtime.Skript; 10 | 11 | import java.io.IOException; 12 | 13 | public final class ScriptLoader extends SkriptApp { 14 | private static final Skript SKRIPT = new Skript(); 15 | 16 | public static void main(String... args) throws IOException { 17 | registerLibraries(SKRIPT); 18 | SKRIPT.compileLoadScripts(SOURCE); 19 | new SimpleThrottleController(SKRIPT).run(); 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/org/byteskript/skript/app/SimpleThrottleController.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 ByteSkript org (Moderocky) 3 | * View the full licence information and permissions: 4 | * https://github.com/Moderocky/ByteSkript/blob/master/LICENSE 5 | */ 6 | 7 | package org.byteskript.skript.app; 8 | 9 | import org.byteskript.skript.runtime.Skript; 10 | import org.byteskript.skript.runtime.internal.Instruction; 11 | import org.byteskript.skript.runtime.threading.AirlockQueue; 12 | import org.byteskript.skript.runtime.threading.OperationController; 13 | 14 | public record SimpleThrottleController(Skript skript) implements Runnable { 15 | 16 | @Override 17 | public void run() { 18 | while (true) { 19 | for (final OperationController process : skript.getProcesses()) { 20 | final AirlockQueue queue; 21 | synchronized (queue = process.getQueue()) { 22 | if (queue.isEmpty()) continue; 23 | for (Instruction runnable : queue) { 24 | try { 25 | runnable.run(); 26 | } catch (Throwable e) { 27 | e.printStackTrace(); 28 | } 29 | } 30 | queue.clear(); 31 | } 32 | synchronized (process) { 33 | process.notifyAll(); 34 | } 35 | } 36 | try { 37 | Thread.sleep(10); 38 | } catch (InterruptedException e) { 39 | e.printStackTrace(); 40 | break; 41 | } 42 | } 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/org/byteskript/skript/compiler/AreaFlag.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 ByteSkript org (Moderocky) 3 | * View the full licence information and permissions: 4 | * https://github.com/Moderocky/ByteSkript/blob/master/LICENSE 5 | */ 6 | 7 | package org.byteskript.skript.compiler; 8 | 9 | import org.byteskript.skript.api.Flag; 10 | 11 | public enum AreaFlag implements Flag { 12 | IN_SYNTAX, 13 | IN_FUNCTION, 14 | IN_VERIFIER, 15 | IN_TRIGGER, 16 | IN_PROPERTY, 17 | IN_TYPE, 18 | IN_ABSTRACT_TYPE, 19 | IN_EVENT, 20 | IN_DICTIONARY 21 | 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/org/byteskript/skript/compiler/CompileState.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 ByteSkript org (Moderocky) 3 | * View the full licence information and permissions: 4 | * https://github.com/Moderocky/ByteSkript/blob/master/LICENSE 5 | */ 6 | 7 | package org.byteskript.skript.compiler; 8 | 9 | import mx.kenzie.foundation.compiler.State; 10 | 11 | public enum CompileState implements State { 12 | ROOT, 13 | MEMBER_BODY, 14 | CODE_BODY, 15 | STATEMENT, 16 | ENTRY_VALUE, 17 | IMPORT_BODY, 18 | AREA_BODY, 19 | HEADER 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/org/byteskript/skript/compiler/SkriptParser.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 ByteSkript org (Moderocky) 3 | * View the full licence information and permissions: 4 | * https://github.com/Moderocky/ByteSkript/blob/master/LICENSE 5 | */ 6 | 7 | package org.byteskript.skript.compiler; 8 | 9 | import mx.kenzie.foundation.Type; 10 | import org.byteskript.skript.compiler.structure.ErrorDetails; 11 | 12 | public interface SkriptParser { 13 | 14 | ElementTree parseLine(final String line, final FileContext context); 15 | 16 | ElementTree assembleStatement(final String statement, final FileContext context, final ErrorDetails details); 17 | 18 | ElementTree assembleExpression(String expression, final Type expected, final FileContext context, final ErrorDetails details); 19 | 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/org/byteskript/skript/compiler/Unit.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 ByteSkript org (Moderocky) 3 | * View the full licence information and permissions: 4 | * https://github.com/Moderocky/ByteSkript/blob/master/LICENSE 5 | */ 6 | 7 | package org.byteskript.skript.compiler; 8 | 9 | import org.byteskript.skript.api.LanguageElement; 10 | 11 | public record Unit(LanguageElement type) { 12 | 13 | } 14 | -------------------------------------------------------------------------------- /src/main/java/org/byteskript/skript/compiler/structure/BasicTree.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2022 ByteSkript org (Moderocky) 3 | * View the full licence information and permissions: 4 | * https://github.com/Moderocky/ByteSkript/blob/master/LICENSE 5 | */ 6 | 7 | package org.byteskript.skript.compiler.structure; 8 | 9 | import org.byteskript.skript.api.SyntaxElement; 10 | import org.byteskript.skript.compiler.Context; 11 | 12 | public abstract class BasicTree extends ProgrammaticSplitTree { 13 | 14 | private final SectionMeta owner; 15 | private final MultiLabel end; 16 | 17 | public BasicTree(SectionMeta owner) { 18 | this.owner = owner; 19 | this.end = new MultiLabel(); 20 | } 21 | 22 | @Override 23 | public SectionMeta owner() { 24 | return owner; 25 | } 26 | 27 | @Override 28 | public MultiLabel getEnd() { 29 | return end; 30 | } 31 | 32 | @Override 33 | public void start(Context context) { 34 | 35 | } 36 | 37 | @Override 38 | public void branch(Context context) { 39 | 40 | } 41 | 42 | @Override 43 | public void close(Context context) { 44 | if (end.uses.size() > 0) 45 | context.getMethod().writeCode(end.instruction()); 46 | context.removeTree(this); 47 | } 48 | 49 | @Override 50 | public boolean permit(SyntaxElement element) { 51 | return false; 52 | } 53 | 54 | @Override 55 | public boolean isOpen() { 56 | return false; 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/main/java/org/byteskript/skript/compiler/structure/ErrorDetails.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 ByteSkript org (Moderocky) 3 | * View the full licence information and permissions: 4 | * https://github.com/Moderocky/ByteSkript/blob/master/LICENSE 5 | */ 6 | 7 | package org.byteskript.skript.compiler.structure; 8 | 9 | import org.byteskript.skript.api.SyntaxElement; 10 | 11 | import java.util.HashMap; 12 | import java.util.Map; 13 | 14 | public class ErrorDetails { 15 | 16 | public final Map hints = new HashMap<>(); 17 | public String file; 18 | public String line; 19 | public SyntaxElement lineMatched; 20 | public String expression; 21 | public SyntaxElement expressionMatched; 22 | 23 | public void addHint(SyntaxElement source, String hint) { 24 | hints.put(source, hint); 25 | } 26 | 27 | @Override 28 | public ErrorDetails clone() { 29 | final ErrorDetails details = new ErrorDetails(); 30 | details.file = file; 31 | details.line = line; 32 | details.lineMatched = lineMatched; 33 | details.expression = expression; 34 | details.expressionMatched = expressionMatched; 35 | details.hints.putAll(hints); 36 | return details; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/org/byteskript/skript/compiler/structure/Frame.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2022 ByteSkript org (Moderocky) 3 | * View the full licence information and permissions: 4 | * https://github.com/Moderocky/ByteSkript/blob/master/LICENSE 5 | */ 6 | 7 | package org.byteskript.skript.compiler.structure; 8 | 9 | import mx.kenzie.foundation.Type; 10 | 11 | public interface Frame { 12 | 13 | int size(); 14 | 15 | void add(Type... types); 16 | 17 | void remove(Type... types); 18 | 19 | } 20 | -------------------------------------------------------------------------------- /src/main/java/org/byteskript/skript/compiler/structure/MultiLabel.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 ByteSkript org (Moderocky) 3 | * View the full licence information and permissions: 4 | * https://github.com/Moderocky/ByteSkript/blob/master/LICENSE 5 | */ 6 | 7 | package org.byteskript.skript.compiler.structure; 8 | 9 | import mx.kenzie.foundation.WriteInstruction; 10 | import org.objectweb.asm.Label; 11 | 12 | import java.util.ArrayList; 13 | import java.util.List; 14 | 15 | public class MultiLabel { 16 | 17 | protected final List

handlers; 16 | private final List data; 17 | 18 | public SectionMeta(Section handler) { 19 | this.handlers = new ArrayList<>(); 20 | this.handlers.add(handler); 21 | this.data = new ArrayList<>(); 22 | } 23 | 24 | public List
getHandlers() { 25 | return handlers; 26 | } 27 | 28 | public List getData() { 29 | return data; 30 | } 31 | 32 | @Override 33 | public String toString() { 34 | return "SectionMeta[" + 35 | "handler=" + handler().name() + ']'; 36 | } 37 | 38 | public Section handler() { 39 | return handlers.get(0); 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/org/byteskript/skript/compiler/structure/TestTree.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 ByteSkript org (Moderocky) 3 | * View the full licence information and permissions: 4 | * https://github.com/Moderocky/ByteSkript/blob/master/LICENSE 5 | */ 6 | 7 | package org.byteskript.skript.compiler.structure; 8 | 9 | import mx.kenzie.foundation.MethodBuilder; 10 | import org.byteskript.skript.api.SyntaxElement; 11 | import org.byteskript.skript.compiler.Context; 12 | import org.byteskript.skript.error.ScriptCompileError; 13 | import org.objectweb.asm.Label; 14 | 15 | public class TestTree extends ProgrammaticSplitTree { 16 | 17 | private final SectionMeta owner; 18 | private final MultiLabel end = new MultiLabel(); 19 | private final Label next = new Label(); 20 | private boolean open; 21 | 22 | public TestTree(SectionMeta owner) { 23 | this.owner = owner; 24 | this.open = true; 25 | } 26 | 27 | @Override 28 | public SectionMeta owner() { 29 | return owner; 30 | } 31 | 32 | public Label getNext() { 33 | return next; 34 | } 35 | 36 | public MultiLabel getEnd() { 37 | return end; 38 | } 39 | 40 | @Override 41 | public void start(Context context) { 42 | 43 | } 44 | 45 | @Override 46 | public void branch(Context context) { 47 | 48 | } 49 | 50 | @Override 51 | public void close(Context context) { 52 | this.open = false; 53 | final MethodBuilder method = context.getMethod(); 54 | if (method == null) throw new ScriptCompileError(context.lineNumber(), "Extraction tree left unclosed."); 55 | method.writeCode(end.instruction()); 56 | context.removeTree(this); 57 | } 58 | 59 | @Override 60 | public boolean permit(SyntaxElement element) { 61 | return false; 62 | } 63 | 64 | @Override 65 | public boolean isOpen() { 66 | return open; 67 | } 68 | 69 | } 70 | -------------------------------------------------------------------------------- /src/main/java/org/byteskript/skript/compiler/structure/TriggerTree.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 ByteSkript org (Moderocky) 3 | * View the full licence information and permissions: 4 | * https://github.com/Moderocky/ByteSkript/blob/master/LICENSE 5 | */ 6 | 7 | package org.byteskript.skript.compiler.structure; 8 | 9 | import org.byteskript.skript.api.SyntaxElement; 10 | import org.byteskript.skript.compiler.Context; 11 | 12 | import java.util.Collection; 13 | 14 | public class TriggerTree extends ProgrammaticSplitTree { 15 | 16 | private final SectionMeta owner; 17 | private final MultiLabel end; 18 | private final Collection variables; 19 | 20 | public TriggerTree(SectionMeta owner, Collection variables) { 21 | this.owner = owner; 22 | this.end = new MultiLabel(); 23 | this.variables = variables; 24 | } 25 | 26 | public Collection getVariables() { 27 | return variables; 28 | } 29 | 30 | @Override 31 | public SectionMeta owner() { 32 | return owner; 33 | } 34 | 35 | @Override 36 | public MultiLabel getEnd() { 37 | return end; 38 | } 39 | 40 | @Override 41 | public void start(Context context) { 42 | 43 | } 44 | 45 | @Override 46 | public void branch(Context context) { 47 | 48 | } 49 | 50 | @Override 51 | public void close(Context context) { 52 | if (end.uses.size() > 0) 53 | context.getMethod().writeCode(end.instruction()); 54 | } 55 | 56 | @Override 57 | public boolean permit(SyntaxElement element) { 58 | return false; 59 | } 60 | 61 | @Override 62 | public boolean isOpen() { 63 | return false; 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/main/java/org/byteskript/skript/compiler/structure/WhileTree.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 ByteSkript org (Moderocky) 3 | * View the full licence information and permissions: 4 | * https://github.com/Moderocky/ByteSkript/blob/master/LICENSE 5 | */ 6 | 7 | package org.byteskript.skript.compiler.structure; 8 | 9 | import mx.kenzie.foundation.MethodBuilder; 10 | import org.byteskript.skript.compiler.Context; 11 | import org.byteskript.skript.error.ScriptCompileError; 12 | import org.objectweb.asm.Label; 13 | 14 | public class WhileTree extends LoopTree { 15 | 16 | public WhileTree(SectionMeta owner) { 17 | super(owner); 18 | } 19 | 20 | @Override 21 | public void close(Context context) { 22 | final MethodBuilder method = context.getMethod(); 23 | if (method == null) throw new ScriptCompileError(context.lineNumber(), "While block left unclosed."); 24 | final Label top = this.getTop(); 25 | method.writeCode((writer, visitor) -> visitor.visitJumpInsn(167, top)); 26 | super.close(context); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/org/byteskript/skript/error/ScriptBootstrapError.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 ByteSkript org (Moderocky) 3 | * View the full licence information and permissions: 4 | * https://github.com/Moderocky/ByteSkript/blob/master/LICENSE 5 | */ 6 | 7 | package org.byteskript.skript.error; 8 | 9 | public class ScriptBootstrapError extends Error implements ScriptError { 10 | 11 | public ScriptBootstrapError() { 12 | super(); 13 | } 14 | 15 | public ScriptBootstrapError(String message) { 16 | super(message); 17 | } 18 | 19 | public ScriptBootstrapError(String message, Throwable cause) { 20 | super(message, cause); 21 | } 22 | 23 | public ScriptBootstrapError(Throwable cause) { 24 | super(cause); 25 | } 26 | 27 | protected ScriptBootstrapError(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) { 28 | super(message, cause, enableSuppression, writableStackTrace); 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/org/byteskript/skript/error/ScriptCompileError.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 ByteSkript org (Moderocky) 3 | * View the full licence information and permissions: 4 | * https://github.com/Moderocky/ByteSkript/blob/master/LICENSE 5 | */ 6 | 7 | package org.byteskript.skript.error; 8 | 9 | public class ScriptCompileError extends Error implements ScriptError { 10 | 11 | private final boolean fill = true; 12 | private final int line; 13 | 14 | public ScriptCompileError(int line) { 15 | super(); 16 | this.line = line; 17 | } 18 | 19 | public ScriptCompileError(int line, String message) { 20 | super(message); 21 | this.line = line; 22 | } 23 | 24 | public ScriptCompileError(int line, String message, Throwable cause) { 25 | super(message, cause); 26 | this.line = line; 27 | } 28 | 29 | public ScriptCompileError(int line, Throwable cause) { 30 | super(cause); 31 | this.line = line; 32 | } 33 | 34 | protected ScriptCompileError(int line, String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) { 35 | super(message, cause, enableSuppression, writableStackTrace); 36 | this.line = line; 37 | } 38 | 39 | public int getLine() { 40 | return line; 41 | } 42 | 43 | @Override 44 | public String toString() { 45 | String s = getClass().getSimpleName(); 46 | String message = getLocalizedMessage(); 47 | return ((message != null) ? (s + ": " + message) : s) + " (Line " + line + ")"; 48 | } 49 | 50 | @Override 51 | public synchronized Throwable fillInStackTrace() { 52 | if (fill && System.getProperty("debug_mode") != null) 53 | return super.fillInStackTrace(); 54 | return this; 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/main/java/org/byteskript/skript/error/ScriptError.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 ByteSkript org (Moderocky) 3 | * View the full licence information and permissions: 4 | * https://github.com/Moderocky/ByteSkript/blob/master/LICENSE 5 | */ 6 | 7 | package org.byteskript.skript.error; 8 | 9 | import java.io.PrintStream; 10 | import java.io.PrintWriter; 11 | 12 | public interface ScriptError { 13 | 14 | interface Output { 15 | void println(String string); 16 | } 17 | 18 | record OutputWriter(PrintStream stream, PrintWriter writer) implements Output { 19 | 20 | @Override 21 | public void println(String string) { 22 | if (stream != null) stream.println(string); 23 | else writer.println(string); 24 | } 25 | 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/org/byteskript/skript/error/ScriptLibraryError.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 ByteSkript org (Moderocky) 3 | * View the full licence information and permissions: 4 | * https://github.com/Moderocky/ByteSkript/blob/master/LICENSE 5 | */ 6 | 7 | package org.byteskript.skript.error; 8 | 9 | public class ScriptLibraryError extends Error implements ScriptError { 10 | 11 | public ScriptLibraryError() { 12 | super(); 13 | } 14 | 15 | public ScriptLibraryError(String message) { 16 | super(message); 17 | } 18 | 19 | public ScriptLibraryError(String message, Throwable cause) { 20 | super(message, cause); 21 | } 22 | 23 | public ScriptLibraryError(Throwable cause) { 24 | super(cause); 25 | } 26 | 27 | protected ScriptLibraryError(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) { 28 | super(message, cause, enableSuppression, writableStackTrace); 29 | } 30 | 31 | @Override 32 | public synchronized Throwable fillInStackTrace() { 33 | return this; 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/org/byteskript/skript/error/ScriptLoadError.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 ByteSkript org (Moderocky) 3 | * View the full licence information and permissions: 4 | * https://github.com/Moderocky/ByteSkript/blob/master/LICENSE 5 | */ 6 | 7 | package org.byteskript.skript.error; 8 | 9 | public class ScriptLoadError extends Error implements ScriptError { 10 | 11 | public ScriptLoadError() { 12 | super(); 13 | } 14 | 15 | public ScriptLoadError(String message) { 16 | super(message); 17 | } 18 | 19 | public ScriptLoadError(String message, Throwable cause) { 20 | super(message, cause); 21 | } 22 | 23 | public ScriptLoadError(Throwable cause) { 24 | super(cause); 25 | } 26 | 27 | protected ScriptLoadError(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) { 28 | super(message, cause, enableSuppression, writableStackTrace); 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/org/byteskript/skript/error/ScriptReassemblyError.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 ByteSkript org (Moderocky) 3 | * View the full licence information and permissions: 4 | * https://github.com/Moderocky/ByteSkript/blob/master/LICENSE 5 | */ 6 | 7 | package org.byteskript.skript.error; 8 | 9 | public class ScriptReassemblyError extends Error implements ScriptError { 10 | 11 | private final boolean fill = true; 12 | private final int line; 13 | 14 | public ScriptReassemblyError(int line) { 15 | super(); 16 | this.line = line; 17 | } 18 | 19 | public ScriptReassemblyError(int line, String message) { 20 | super(message); 21 | this.line = line; 22 | } 23 | 24 | public ScriptReassemblyError(int line, String message, Throwable cause) { 25 | super(message, cause); 26 | this.line = line; 27 | } 28 | 29 | public ScriptReassemblyError(int line, Throwable cause) { 30 | super(cause); 31 | this.line = line; 32 | } 33 | 34 | protected ScriptReassemblyError(int line, String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) { 35 | super(message, cause, enableSuppression, writableStackTrace); 36 | this.line = line; 37 | } 38 | 39 | public int getLine() { 40 | return line; 41 | } 42 | 43 | @Override 44 | public String toString() { 45 | String s = getClass().getSimpleName(); 46 | String message = getLocalizedMessage(); 47 | return ((message != null) ? (s + ": " + message) : s) + " (Line " + line + ")"; 48 | } 49 | 50 | @Override 51 | public synchronized Throwable fillInStackTrace() { 52 | if (fill && System.getProperty("debug_mode") != null) 53 | return super.fillInStackTrace(); 54 | return this; 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/main/java/org/byteskript/skript/error/ScriptRuntimeError.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 ByteSkript org (Moderocky) 3 | * View the full licence information and permissions: 4 | * https://github.com/Moderocky/ByteSkript/blob/master/LICENSE 5 | */ 6 | 7 | package org.byteskript.skript.error; 8 | 9 | public class ScriptRuntimeError extends Error implements ScriptError { 10 | 11 | public ScriptRuntimeError() { 12 | super(); 13 | } 14 | 15 | public ScriptRuntimeError(String message) { 16 | super(message); 17 | } 18 | 19 | public ScriptRuntimeError(String message, Throwable cause) { 20 | super(message, cause); 21 | } 22 | 23 | public ScriptRuntimeError(Throwable cause) { 24 | super(cause); 25 | } 26 | 27 | protected ScriptRuntimeError(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) { 28 | super(message, cause, enableSuppression, writableStackTrace); 29 | } 30 | 31 | @Override 32 | public synchronized Throwable fillInStackTrace() { 33 | return super.fillInStackTrace(); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/org/byteskript/skript/lang/element/StandardElements.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 ByteSkript org (Moderocky) 3 | * View the full licence information and permissions: 4 | * https://github.com/Moderocky/ByteSkript/blob/master/LICENSE 5 | */ 6 | 7 | package org.byteskript.skript.lang.element; 8 | 9 | import org.byteskript.skript.api.LanguageElement; 10 | import org.byteskript.skript.api.Library; 11 | import org.byteskript.skript.compiler.SkriptLangSpec; 12 | 13 | public enum StandardElements implements LanguageElement { 14 | METADATA, 15 | NODE, 16 | SECTION, 17 | MEMBER, 18 | EFFECT, 19 | CONDITION, 20 | EXPRESSION, 21 | 22 | ; 23 | 24 | @Override 25 | public Library getProvider() { 26 | return SkriptLangSpec.LIBRARY; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/org/byteskript/skript/lang/handler/StandardHandlers.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 ByteSkript org (Moderocky) 3 | * View the full licence information and permissions: 4 | * https://github.com/Moderocky/ByteSkript/blob/master/LICENSE 5 | */ 6 | 7 | package org.byteskript.skript.lang.handler; 8 | 9 | import org.byteskript.skript.api.HandlerType; 10 | 11 | public enum StandardHandlers implements HandlerType { 12 | 13 | RUN(true, false), 14 | SET(true, false), 15 | ADD(true, false), 16 | REMOVE(true, false), 17 | GET(false, true), 18 | DELETE(false, false), 19 | FIND(true, true); 20 | final boolean expectInputs; 21 | final boolean expectReturn; 22 | 23 | StandardHandlers(boolean expectInputs, boolean expectReturn) { 24 | this.expectInputs = expectInputs; 25 | this.expectReturn = expectReturn; 26 | } 27 | 28 | @Override 29 | public boolean expectInputs() { 30 | return expectInputs; 31 | } 32 | 33 | @Override 34 | public boolean expectReturn() { 35 | return expectReturn; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/org/byteskript/skript/lang/syntax/comparison/ExprGT.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 ByteSkript org (Moderocky) 3 | * View the full licence information and permissions: 4 | * https://github.com/Moderocky/ByteSkript/blob/master/LICENSE 5 | */ 6 | 7 | package org.byteskript.skript.lang.syntax.comparison; 8 | 9 | import mx.kenzie.foundation.Type; 10 | import org.byteskript.skript.api.note.Documentation; 11 | import org.byteskript.skript.api.syntax.RelationalExpression; 12 | import org.byteskript.skript.compiler.CommonTypes; 13 | import org.byteskript.skript.compiler.SkriptLangSpec; 14 | import org.byteskript.skript.lang.element.StandardElements; 15 | import org.byteskript.skript.lang.handler.StandardHandlers; 16 | import org.byteskript.skript.runtime.internal.OperatorHandler; 17 | 18 | @Documentation( 19 | name = "Greater Than", 20 | description = "Check whether the first number is greater than the second.", 21 | examples = { 22 | "assert 4 is greater than 3", 23 | """ 24 | if {var} > 6: 25 | print "hello" 26 | """ 27 | } 28 | ) 29 | public class ExprGT extends RelationalExpression { 30 | 31 | public ExprGT() { 32 | super(SkriptLangSpec.LIBRARY, StandardElements.EXPRESSION, "%Object%( is greater than | ?> ?)%Object%"); 33 | try { 34 | handlers.put(StandardHandlers.FIND, OperatorHandler.class.getMethod("gt", Object.class, Object.class)); 35 | handlers.put(StandardHandlers.GET, OperatorHandler.class.getMethod("gt", Object.class, Object.class)); 36 | } catch (NoSuchMethodException e) { 37 | e.printStackTrace(); 38 | } 39 | } 40 | 41 | @Override 42 | public Type getReturnType() { 43 | return CommonTypes.BOOLEAN; 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /src/main/java/org/byteskript/skript/lang/syntax/comparison/ExprGTEQ.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 ByteSkript org (Moderocky) 3 | * View the full licence information and permissions: 4 | * https://github.com/Moderocky/ByteSkript/blob/master/LICENSE 5 | */ 6 | 7 | package org.byteskript.skript.lang.syntax.comparison; 8 | 9 | import mx.kenzie.foundation.Type; 10 | import org.byteskript.skript.api.note.Documentation; 11 | import org.byteskript.skript.api.syntax.RelationalExpression; 12 | import org.byteskript.skript.compiler.CommonTypes; 13 | import org.byteskript.skript.compiler.SkriptLangSpec; 14 | import org.byteskript.skript.lang.element.StandardElements; 15 | import org.byteskript.skript.lang.handler.StandardHandlers; 16 | import org.byteskript.skript.runtime.internal.OperatorHandler; 17 | 18 | @Documentation( 19 | name = "Greater or Equal", 20 | description = "Check whether the first number is greater than or equal to the second.", 21 | examples = { 22 | "assert 4 is greater than or equal to 3", 23 | """ 24 | if {var} >= 6: 25 | print "hello" 26 | """ 27 | } 28 | ) 29 | public class ExprGTEQ extends RelationalExpression { 30 | 31 | public ExprGTEQ() { 32 | super(SkriptLangSpec.LIBRARY, StandardElements.EXPRESSION, "%Object%( is greater than or equal to | ?>= ?)%Object%"); 33 | try { 34 | handlers.put(StandardHandlers.FIND, OperatorHandler.class.getMethod("gteq", Object.class, Object.class)); 35 | handlers.put(StandardHandlers.GET, OperatorHandler.class.getMethod("gteq", Object.class, Object.class)); 36 | } catch (NoSuchMethodException e) { 37 | e.printStackTrace(); 38 | } 39 | } 40 | 41 | @Override 42 | public Type getReturnType() { 43 | return CommonTypes.BOOLEAN; 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /src/main/java/org/byteskript/skript/lang/syntax/comparison/ExprLT.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 ByteSkript org (Moderocky) 3 | * View the full licence information and permissions: 4 | * https://github.com/Moderocky/ByteSkript/blob/master/LICENSE 5 | */ 6 | 7 | package org.byteskript.skript.lang.syntax.comparison; 8 | 9 | import mx.kenzie.foundation.Type; 10 | import org.byteskript.skript.api.note.Documentation; 11 | import org.byteskript.skript.api.syntax.RelationalExpression; 12 | import org.byteskript.skript.compiler.CommonTypes; 13 | import org.byteskript.skript.compiler.SkriptLangSpec; 14 | import org.byteskript.skript.lang.element.StandardElements; 15 | import org.byteskript.skript.lang.handler.StandardHandlers; 16 | import org.byteskript.skript.runtime.internal.OperatorHandler; 17 | 18 | @Documentation( 19 | name = "Less Than", 20 | description = "Check whether the first number is less than the second.", 21 | examples = { 22 | "assert 4 is less than 5", 23 | """ 24 | if {var} < 6: 25 | print "hello" 26 | """ 27 | } 28 | ) 29 | public class ExprLT extends RelationalExpression { 30 | 31 | public ExprLT() { 32 | super(SkriptLangSpec.LIBRARY, StandardElements.EXPRESSION, "%Object%( is less than | ?< ?)%Object%"); 33 | try { 34 | handlers.put(StandardHandlers.FIND, OperatorHandler.class.getMethod("lt", Object.class, Object.class)); 35 | handlers.put(StandardHandlers.GET, OperatorHandler.class.getMethod("lt", Object.class, Object.class)); 36 | } catch (NoSuchMethodException e) { 37 | e.printStackTrace(); 38 | } 39 | } 40 | 41 | @Override 42 | public Type getReturnType() { 43 | return CommonTypes.BOOLEAN; 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /src/main/java/org/byteskript/skript/lang/syntax/comparison/ExprLTEQ.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 ByteSkript org (Moderocky) 3 | * View the full licence information and permissions: 4 | * https://github.com/Moderocky/ByteSkript/blob/master/LICENSE 5 | */ 6 | 7 | package org.byteskript.skript.lang.syntax.comparison; 8 | 9 | import mx.kenzie.foundation.Type; 10 | import org.byteskript.skript.api.note.Documentation; 11 | import org.byteskript.skript.api.syntax.RelationalExpression; 12 | import org.byteskript.skript.compiler.CommonTypes; 13 | import org.byteskript.skript.compiler.SkriptLangSpec; 14 | import org.byteskript.skript.lang.element.StandardElements; 15 | import org.byteskript.skript.lang.handler.StandardHandlers; 16 | import org.byteskript.skript.runtime.internal.OperatorHandler; 17 | 18 | @Documentation( 19 | name = "Less or Equal", 20 | description = "Check whether the first number is less than or equal to the second.", 21 | examples = { 22 | "assert 4 is less than or equal to 4", 23 | """ 24 | if {var} <= 6: 25 | print "hello" 26 | """ 27 | } 28 | ) 29 | public class ExprLTEQ extends RelationalExpression { 30 | 31 | public ExprLTEQ() { 32 | super(SkriptLangSpec.LIBRARY, StandardElements.EXPRESSION, "%Object%( is less than or equal to | ?<= ?)%Object%"); 33 | try { 34 | handlers.put(StandardHandlers.FIND, OperatorHandler.class.getMethod("lteq", Object.class, Object.class)); 35 | handlers.put(StandardHandlers.GET, OperatorHandler.class.getMethod("lteq", Object.class, Object.class)); 36 | } catch (NoSuchMethodException e) { 37 | e.printStackTrace(); 38 | } 39 | } 40 | 41 | @Override 42 | public Type getReturnType() { 43 | return CommonTypes.BOOLEAN; 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /src/main/java/org/byteskript/skript/lang/syntax/config/ExprNewConfig.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 ByteSkript org (Moderocky) 3 | * View the full licence information and permissions: 4 | * https://github.com/Moderocky/ByteSkript/blob/master/LICENSE 5 | */ 6 | 7 | package org.byteskript.skript.lang.syntax.config; 8 | 9 | import mx.kenzie.foundation.Type; 10 | import org.byteskript.skript.api.note.Documentation; 11 | import org.byteskript.skript.api.note.ForceInline; 12 | import org.byteskript.skript.api.syntax.SimpleExpression; 13 | import org.byteskript.skript.compiler.CommonTypes; 14 | import org.byteskript.skript.compiler.SkriptLangSpec; 15 | import org.byteskript.skript.lang.element.StandardElements; 16 | import org.byteskript.skript.lang.handler.StandardHandlers; 17 | import org.byteskript.skript.runtime.config.ConfigMap; 18 | 19 | @Documentation( 20 | name = "New Config", 21 | description = """ 22 | A new key/value config. 23 | This functions like a map and can be written to a file. 24 | """, 25 | examples = { 26 | """ 27 | set {config} to a new config 28 | set "blob" in {map} to 55.3 29 | """ 30 | } 31 | ) 32 | public class ExprNewConfig extends SimpleExpression { 33 | 34 | public ExprNewConfig() { 35 | super(SkriptLangSpec.LIBRARY, StandardElements.EXPRESSION, "[a] new config[uration]"); 36 | handlers.put(StandardHandlers.GET, findMethod(this.getClass(), "create")); 37 | } 38 | 39 | @ForceInline 40 | public static ConfigMap create() { 41 | return new ConfigMap(); 42 | } 43 | 44 | @Override 45 | public Type getReturnType() { 46 | return CommonTypes.CONFIG; 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /src/main/java/org/byteskript/skript/lang/syntax/entry/syntax/ICreateSyntax.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 ByteSkript org (Moderocky) 3 | * View the full licence information and permissions: 4 | * https://github.com/Moderocky/ByteSkript/blob/master/LICENSE 5 | */ 6 | 7 | package org.byteskript.skript.lang.syntax.entry.syntax; 8 | 9 | /** 10 | * Used to spot syntax creators. 11 | */ 12 | public interface ICreateSyntax { 13 | } 14 | -------------------------------------------------------------------------------- /src/main/java/org/byteskript/skript/lang/syntax/event/EventAnyLoad.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 ByteSkript org (Moderocky) 3 | * View the full licence information and permissions: 4 | * https://github.com/Moderocky/ByteSkript/blob/master/LICENSE 5 | */ 6 | 7 | package org.byteskript.skript.lang.syntax.event; 8 | 9 | import org.byteskript.skript.api.Event; 10 | import org.byteskript.skript.api.note.Documentation; 11 | import org.byteskript.skript.api.syntax.EventHolder; 12 | import org.byteskript.skript.compiler.SkriptLangSpec; 13 | import org.byteskript.skript.runtime.event.Load; 14 | 15 | @Documentation( 16 | name = "Any Load", 17 | description = """ 18 | Run when any script loads. 19 | Scripts will not see load events for scripts loaded before them.""", 20 | examples = { 21 | """ 22 | on any script load: 23 | trigger: 24 | print "a script loaded" 25 | """ 26 | } 27 | ) 28 | public class EventAnyLoad extends EventHolder { 29 | 30 | public EventAnyLoad() { 31 | super(SkriptLangSpec.LIBRARY, "on any [script] load"); 32 | } 33 | 34 | @Override 35 | public Class eventClass() { 36 | return Load.class; 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/org/byteskript/skript/lang/syntax/event/EventLoad.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 ByteSkript org (Moderocky) 3 | * View the full licence information and permissions: 4 | * https://github.com/Moderocky/ByteSkript/blob/master/LICENSE 5 | */ 6 | 7 | package org.byteskript.skript.lang.syntax.event; 8 | 9 | import org.byteskript.skript.api.Event; 10 | import org.byteskript.skript.api.note.Documentation; 11 | import org.byteskript.skript.api.syntax.EventHolder; 12 | import org.byteskript.skript.compiler.SkriptLangSpec; 13 | import org.byteskript.skript.runtime.event.Load; 14 | 15 | @Documentation( 16 | name = "Load", 17 | description = """ 18 | Run when this script loads.""", 19 | examples = { 20 | """ 21 | on script load: 22 | trigger: 23 | print "this script loaded" 24 | """ 25 | } 26 | ) 27 | public class EventLoad extends EventHolder { 28 | 29 | public EventLoad() { 30 | super(SkriptLangSpec.LIBRARY, "on [script] load"); 31 | } 32 | 33 | @Override 34 | public Class eventClass() { 35 | return Load.LoadThis.class; 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/org/byteskript/skript/lang/syntax/event/EventUnload.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 ByteSkript org (Moderocky) 3 | * View the full licence information and permissions: 4 | * https://github.com/Moderocky/ByteSkript/blob/master/LICENSE 5 | */ 6 | 7 | package org.byteskript.skript.lang.syntax.event; 8 | 9 | import org.byteskript.skript.api.Event; 10 | import org.byteskript.skript.api.note.Documentation; 11 | import org.byteskript.skript.api.syntax.EventHolder; 12 | import org.byteskript.skript.compiler.SkriptLangSpec; 13 | import org.byteskript.skript.runtime.event.Unload; 14 | 15 | @Documentation( 16 | name = "Unload", 17 | description = """ 18 | Run when another script is unloaded.""", 19 | examples = { 20 | """ 21 | on script unload: 22 | trigger: 23 | print "a script was unloaded" 24 | """ 25 | } 26 | ) 27 | public class EventUnload extends EventHolder { 28 | 29 | public EventUnload() { 30 | super(SkriptLangSpec.LIBRARY, "on [any] [script] unload"); 31 | } 32 | 33 | @Override 34 | public Class eventClass() { 35 | return Unload.class; 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/org/byteskript/skript/lang/syntax/flow/EffectExitThread.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 ByteSkript org (Moderocky) 3 | * View the full licence information and permissions: 4 | * https://github.com/Moderocky/ByteSkript/blob/master/LICENSE 5 | */ 6 | 7 | package org.byteskript.skript.lang.syntax.flow; 8 | 9 | import mx.kenzie.foundation.MethodBuilder; 10 | import mx.kenzie.foundation.WriteInstruction; 11 | import org.byteskript.skript.api.note.Documentation; 12 | import org.byteskript.skript.api.syntax.Effect; 13 | import org.byteskript.skript.compiler.CompileState; 14 | import org.byteskript.skript.compiler.Context; 15 | import org.byteskript.skript.compiler.Pattern; 16 | import org.byteskript.skript.compiler.SkriptLangSpec; 17 | import org.byteskript.skript.lang.element.StandardElements; 18 | 19 | @Documentation( 20 | name = "Exit Thread", 21 | description = """ 22 | Exits the current process (thread). 23 | This kills the process immediately, so no future instructions will be run. 24 | Other processes are not affected. 25 | """, 26 | examples = { 27 | """ 28 | exit the current thread 29 | """ 30 | } 31 | ) 32 | public class EffectExitThread extends Effect { 33 | 34 | public EffectExitThread() { 35 | super(SkriptLangSpec.LIBRARY, StandardElements.EFFECT, "(exit|stop) %Thread%"); 36 | } 37 | 38 | @Override 39 | public Pattern.Match match(String thing, Context context) { 40 | if (!thing.startsWith("exit ") && !thing.startsWith("stop ")) return null; 41 | return super.match(thing, context); 42 | } 43 | 44 | @Override 45 | public void compile(Context context, Pattern.Match match) throws Throwable { 46 | final MethodBuilder method = context.getMethod(); 47 | assert method != null; 48 | method.writeCode(WriteInstruction.invokeVirtual(Thread.class.getMethod("stop"))); 49 | context.setState(CompileState.CODE_BODY); 50 | } 51 | 52 | } 53 | -------------------------------------------------------------------------------- /src/main/java/org/byteskript/skript/lang/syntax/flow/EffectReturn.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 ByteSkript org (Moderocky) 3 | * View the full licence information and permissions: 4 | * https://github.com/Moderocky/ByteSkript/blob/master/LICENSE 5 | */ 6 | 7 | package org.byteskript.skript.lang.syntax.flow; 8 | 9 | import mx.kenzie.foundation.MethodBuilder; 10 | import mx.kenzie.foundation.Type; 11 | import mx.kenzie.foundation.WriteInstruction; 12 | import org.byteskript.skript.api.note.Documentation; 13 | import org.byteskript.skript.api.syntax.Effect; 14 | import org.byteskript.skript.compiler.*; 15 | import org.byteskript.skript.lang.element.StandardElements; 16 | 17 | @Documentation( 18 | name = "Return", 19 | description = """ 20 | Stops the current trigger, giving back this value to whatever started. 21 | This is designed for use in functions and suppliers. 22 | Some triggers cannot return a value, such as events. 23 | """, 24 | examples = { 25 | """ 26 | return "hello" 27 | return 63 28 | """ 29 | } 30 | ) 31 | public class EffectReturn extends Effect { 32 | 33 | public EffectReturn() { 34 | super(SkriptLangSpec.LIBRARY, StandardElements.EFFECT, "return %Object%"); 35 | } 36 | 37 | @Override 38 | public Pattern.Match match(String thing, Context context) { 39 | if (!thing.startsWith("return ")) return null; 40 | return super.match(thing, context); 41 | } 42 | 43 | @Override 44 | public void compile(Context context, Pattern.Match match) { 45 | final MethodBuilder method = context.getMethod(); 46 | assert method != null; 47 | final Type type = method.getErasure().returnType(); 48 | if (!type.equals(CommonTypes.OBJECT)) method.writeCode(WriteInstruction.cast(type)); 49 | method.writeCode(WriteInstruction.returnObject()); 50 | context.setState(CompileState.CODE_BODY); 51 | } 52 | 53 | } 54 | -------------------------------------------------------------------------------- /src/main/java/org/byteskript/skript/lang/syntax/flow/lambda/ExprLemmaSection.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 ByteSkript org (Moderocky) 3 | * View the full licence information and permissions: 4 | * https://github.com/Moderocky/ByteSkript/blob/master/LICENSE 5 | */ 6 | 7 | package org.byteskript.skript.lang.syntax.flow.lambda; 8 | 9 | import mx.kenzie.foundation.Type; 10 | import org.byteskript.skript.api.note.Documentation; 11 | import org.byteskript.skript.api.syntax.ExtractedSection; 12 | import org.byteskript.skript.compiler.CommonTypes; 13 | import org.byteskript.skript.compiler.Context; 14 | import org.byteskript.skript.compiler.Pattern; 15 | import org.byteskript.skript.compiler.SkriptLangSpec; 16 | import org.byteskript.skript.lang.element.StandardElements; 17 | 18 | /** 19 | * A dangerous instruction form. 20 | * To be used internally by the new bake-phase to inline calls. 21 | */ 22 | @Documentation( 23 | name = "Lemma", 24 | description = """ 25 | Creates a section of re-usable code. 26 | """, 27 | examples = {} 28 | ) 29 | public class ExprLemmaSection extends ExtractedSection { 30 | 31 | public ExprLemmaSection() { 32 | super(SkriptLangSpec.LIBRARY, StandardElements.EXPRESSION, "[a] new lemma"); 33 | } 34 | 35 | 36 | @Override 37 | public Pattern.Match match(String thing, Context context) { 38 | if (true) return null; // todo: not implemented yet. 39 | if (!thing.contains(" new lemma")) return null; 40 | return super.match(thing, context); 41 | } 42 | 43 | @Override 44 | public Type getReturnType() { 45 | return CommonTypes.EXECUTABLE; 46 | } 47 | 48 | @Override 49 | public boolean allowAsInputFor(Type type) { 50 | return CommonTypes.OBJECT.equals(type) || CommonTypes.EXECUTABLE.equals(type); 51 | } 52 | 53 | 54 | } 55 | -------------------------------------------------------------------------------- /src/main/java/org/byteskript/skript/lang/syntax/generic/EffectPrint.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 ByteSkript org (Moderocky) 3 | * View the full licence information and permissions: 4 | * https://github.com/Moderocky/ByteSkript/blob/master/LICENSE 5 | */ 6 | 7 | package org.byteskript.skript.lang.syntax.generic; 8 | 9 | import mx.kenzie.foundation.MethodBuilder; 10 | import mx.kenzie.foundation.WriteInstruction; 11 | import org.byteskript.skript.api.note.Documentation; 12 | import org.byteskript.skript.api.syntax.Effect; 13 | import org.byteskript.skript.compiler.CompileState; 14 | import org.byteskript.skript.compiler.Context; 15 | import org.byteskript.skript.compiler.Pattern; 16 | import org.byteskript.skript.compiler.SkriptLangSpec; 17 | import org.byteskript.skript.lang.element.StandardElements; 18 | import org.byteskript.skript.runtime.internal.ExtractedSyntaxCalls; 19 | 20 | @Documentation( 21 | name = "Print", 22 | description = """ 23 | Prints the given object to the system console as a string. 24 | Some programs may hijack this to print to a different console/output. 25 | """, 26 | examples = { 27 | """ 28 | print "hello!" 29 | print "my name is " + {name} 30 | """ 31 | } 32 | ) 33 | public class EffectPrint extends Effect { 34 | 35 | public EffectPrint() { 36 | super(SkriptLangSpec.LIBRARY, StandardElements.EFFECT, "print %Object%"); 37 | } 38 | 39 | @Override 40 | public void compile(Context context, Pattern.Match match) throws Throwable { 41 | final MethodBuilder method = context.getMethod(); 42 | method.writeCode(WriteInstruction.invokeStatic(ExtractedSyntaxCalls.class.getMethod("print", Object.class))); 43 | context.setState(CompileState.CODE_BODY); 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /src/main/java/org/byteskript/skript/lang/syntax/generic/ExprNewLine.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 ByteSkript org (Moderocky) 3 | * View the full licence information and permissions: 4 | * https://github.com/Moderocky/ByteSkript/blob/master/LICENSE 5 | */ 6 | 7 | package org.byteskript.skript.lang.syntax.generic; 8 | 9 | import mx.kenzie.foundation.Type; 10 | import org.byteskript.skript.api.note.Documentation; 11 | import org.byteskript.skript.api.syntax.SimpleExpression; 12 | import org.byteskript.skript.compiler.CommonTypes; 13 | import org.byteskript.skript.compiler.SkriptLangSpec; 14 | import org.byteskript.skript.lang.element.StandardElements; 15 | import org.byteskript.skript.lang.handler.StandardHandlers; 16 | 17 | @Documentation( 18 | name = "New Line", 19 | description = """ 20 | Returns the system-local line separator character(s). 21 | This may be different from the typical `\\n`. 22 | """, 23 | examples = { 24 | """ 25 | print "hello" + newline + "there" 26 | """ 27 | } 28 | ) 29 | public class ExprNewLine extends SimpleExpression { 30 | 31 | public ExprNewLine() { 32 | super(SkriptLangSpec.LIBRARY, StandardElements.EXPRESSION, "(new[ ]line|nl)"); 33 | handlers.put(StandardHandlers.GET, findMethod(System.class, "lineSeparator")); 34 | } 35 | 36 | @Override 37 | public Type getReturnType() { 38 | return CommonTypes.STRING; 39 | } 40 | 41 | @Override 42 | public boolean allowAsInputFor(Type type) { 43 | return CommonTypes.STRING.equals(type) || CommonTypes.OBJECT.equals(type); 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /src/main/java/org/byteskript/skript/lang/syntax/list/EffectClearList.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 ByteSkript org (Moderocky) 3 | * View the full licence information and permissions: 4 | * https://github.com/Moderocky/ByteSkript/blob/master/LICENSE 5 | */ 6 | 7 | package org.byteskript.skript.lang.syntax.list; 8 | 9 | import org.byteskript.skript.api.note.Documentation; 10 | import org.byteskript.skript.api.note.ForceInline; 11 | import org.byteskript.skript.api.syntax.Effect; 12 | import org.byteskript.skript.compiler.Context; 13 | import org.byteskript.skript.compiler.Pattern; 14 | import org.byteskript.skript.compiler.SkriptLangSpec; 15 | import org.byteskript.skript.lang.element.StandardElements; 16 | import org.byteskript.skript.lang.handler.StandardHandlers; 17 | 18 | import java.util.Arrays; 19 | import java.util.Collection; 20 | import java.util.Map; 21 | 22 | @Documentation( 23 | name = "Clear Collection", 24 | description = """ 25 | Empties the given collection. 26 | """, 27 | examples = { 28 | """ 29 | clear {list} 30 | clear {array} 31 | clear {map} 32 | """ 33 | } 34 | ) 35 | public class EffectClearList extends Effect { 36 | 37 | public EffectClearList() { 38 | super(SkriptLangSpec.LIBRARY, StandardElements.EFFECT, "clear %Object%"); 39 | handlers.put(StandardHandlers.RUN, findMethod(this.getClass(), "run", Object.class)); 40 | } 41 | 42 | @ForceInline 43 | public static void run(Object object) { 44 | if (object instanceof Collection list) list.clear(); 45 | if (object instanceof Map map) map.clear(); // in case this is loaded in preference. 46 | else if (object instanceof Object[] array) Arrays.fill(array, null); 47 | } 48 | 49 | @Override 50 | public Pattern.Match match(String thing, Context context) { 51 | if (!thing.startsWith("clear ")) return null; 52 | return super.match(thing, context); 53 | } 54 | 55 | 56 | } 57 | -------------------------------------------------------------------------------- /src/main/java/org/byteskript/skript/lang/syntax/list/ExprNewList.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 ByteSkript org (Moderocky) 3 | * View the full licence information and permissions: 4 | * https://github.com/Moderocky/ByteSkript/blob/master/LICENSE 5 | */ 6 | 7 | package org.byteskript.skript.lang.syntax.list; 8 | 9 | import mx.kenzie.foundation.Type; 10 | import org.byteskript.skript.api.note.Documentation; 11 | import org.byteskript.skript.api.note.ForceInline; 12 | import org.byteskript.skript.api.syntax.SimpleExpression; 13 | import org.byteskript.skript.compiler.CommonTypes; 14 | import org.byteskript.skript.compiler.SkriptLangSpec; 15 | import org.byteskript.skript.lang.element.StandardElements; 16 | import org.byteskript.skript.lang.handler.StandardHandlers; 17 | import org.byteskript.skript.runtime.type.DataList; 18 | 19 | @Documentation( 20 | name = "New List", 21 | description = """ 22 | Creates a new modifiable list. 23 | Values can be added to this. 24 | """, 25 | examples = { 26 | """ 27 | set {list} to a new list 28 | add "hello" to {list} 29 | loop {word} in {list}: 30 | print {word} 31 | """ 32 | } 33 | ) 34 | public class ExprNewList extends SimpleExpression { 35 | 36 | public ExprNewList() { 37 | super(SkriptLangSpec.LIBRARY, StandardElements.EXPRESSION, "[a] new list"); 38 | try { 39 | handlers.put(StandardHandlers.GET, this.getClass().getMethod("create")); 40 | } catch (NoSuchMethodException e) { 41 | e.printStackTrace(); 42 | } 43 | } 44 | 45 | @ForceInline 46 | public static DataList create() { 47 | return new DataList(); 48 | } 49 | 50 | @Override 51 | public Type getReturnType() { 52 | return CommonTypes.LIST; 53 | } 54 | 55 | } 56 | -------------------------------------------------------------------------------- /src/main/java/org/byteskript/skript/lang/syntax/map/ExprNewMap.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 ByteSkript org (Moderocky) 3 | * View the full licence information and permissions: 4 | * https://github.com/Moderocky/ByteSkript/blob/master/LICENSE 5 | */ 6 | 7 | package org.byteskript.skript.lang.syntax.map; 8 | 9 | import mx.kenzie.foundation.Type; 10 | import org.byteskript.skript.api.note.Documentation; 11 | import org.byteskript.skript.api.note.ForceInline; 12 | import org.byteskript.skript.api.syntax.SimpleExpression; 13 | import org.byteskript.skript.compiler.CommonTypes; 14 | import org.byteskript.skript.compiler.SkriptLangSpec; 15 | import org.byteskript.skript.lang.element.StandardElements; 16 | import org.byteskript.skript.lang.handler.StandardHandlers; 17 | import org.byteskript.skript.runtime.type.DataMap; 18 | 19 | @Documentation( 20 | name = "New Map", 21 | description = """ 22 | A new key/value map. 23 | """, 24 | examples = { 25 | """ 26 | set {map} to a new map 27 | set "blob" in {map} to 55.3 28 | """ 29 | } 30 | ) 31 | public class ExprNewMap extends SimpleExpression { 32 | 33 | public ExprNewMap() { 34 | super(SkriptLangSpec.LIBRARY, StandardElements.EXPRESSION, "[a] new map"); 35 | handlers.put(StandardHandlers.GET, findMethod(this.getClass(), "create")); 36 | } 37 | 38 | @ForceInline 39 | public static DataMap create() { 40 | return new DataMap(); 41 | } 42 | 43 | @Override 44 | public Type getReturnType() { 45 | return CommonTypes.MAP; 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/org/byteskript/skript/lang/syntax/maths/ExprSquareRoot.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 ByteSkript org (Moderocky) 3 | * View the full licence information and permissions: 4 | * https://github.com/Moderocky/ByteSkript/blob/master/LICENSE 5 | */ 6 | 7 | package org.byteskript.skript.lang.syntax.maths; 8 | 9 | import mx.kenzie.foundation.Type; 10 | import org.byteskript.skript.api.note.Documentation; 11 | import org.byteskript.skript.api.syntax.RelationalExpression; 12 | import org.byteskript.skript.compiler.CommonTypes; 13 | import org.byteskript.skript.compiler.SkriptLangSpec; 14 | import org.byteskript.skript.lang.element.StandardElements; 15 | import org.byteskript.skript.lang.handler.StandardHandlers; 16 | import org.byteskript.skript.runtime.internal.OperatorHandler; 17 | 18 | @Documentation( 19 | name = "Square Root", 20 | description = """ 21 | Find the square root of a number. 22 | This is quite a slow calculation. 23 | """, 24 | examples = { 25 | """ 26 | set {var} to sqrt of 25 27 | """ 28 | } 29 | ) 30 | public class ExprSquareRoot extends RelationalExpression { 31 | 32 | public ExprSquareRoot() { 33 | super(SkriptLangSpec.LIBRARY, StandardElements.EXPRESSION, "[the ]sq[uare ]r[oo]t of %Number%"); 34 | try { 35 | handlers.put(StandardHandlers.GET, OperatorHandler.class.getMethod("root", Object.class)); 36 | handlers.put(StandardHandlers.FIND, OperatorHandler.class.getMethod("root", Object.class)); 37 | } catch (NoSuchMethodException e) { 38 | e.printStackTrace(); 39 | } 40 | } 41 | 42 | @Override 43 | public Type getReturnType() { 44 | return CommonTypes.NUMBER; 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/org/byteskript/skript/lang/syntax/script/EffectUnloadScript.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 ByteSkript org (Moderocky) 3 | * View the full licence information and permissions: 4 | * https://github.com/Moderocky/ByteSkript/blob/master/LICENSE 5 | */ 6 | 7 | package org.byteskript.skript.lang.syntax.script; 8 | 9 | import org.byteskript.skript.api.note.Documentation; 10 | import org.byteskript.skript.api.note.ForceExtract; 11 | import org.byteskript.skript.api.syntax.Effect; 12 | import org.byteskript.skript.compiler.SkriptLangSpec; 13 | import org.byteskript.skript.lang.element.StandardElements; 14 | import org.byteskript.skript.lang.handler.StandardHandlers; 15 | import org.byteskript.skript.runtime.Script; 16 | import org.byteskript.skript.runtime.Skript; 17 | 18 | @Documentation( 19 | name = "Unload Script", 20 | description = """ 21 | Unloads a script by its class name. 22 | If you store the script or any of its functions it will not unload. 23 | This is a **very** destructive operation - misusing it can cause serious errors. 24 | """, 25 | examples = { 26 | """ 27 | unload script skript/myscript 28 | """ 29 | } 30 | ) 31 | public class EffectUnloadScript extends Effect { 32 | 33 | public EffectUnloadScript() { 34 | super(SkriptLangSpec.LIBRARY, StandardElements.EFFECT, "unload script %Object%"); 35 | handlers.put(StandardHandlers.RUN, findMethod(this.getClass(), "unloadScript", Object.class)); 36 | } 37 | 38 | @ForceExtract 39 | public static void unloadScript(Object object) { 40 | if (object instanceof Class main) 41 | Skript.localInstance().unloadScript(main); 42 | else if (object instanceof Script script) 43 | Skript.localInstance().unloadScript(script); 44 | else if (object instanceof String name) 45 | Skript.localInstance().unloadScript(Skript.localLoader().findClass(name.replace('/', '.'))); 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/org/byteskript/skript/lang/syntax/script/ExprCompiler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 ByteSkript org (Moderocky) 3 | * View the full licence information and permissions: 4 | * https://github.com/Moderocky/ByteSkript/blob/master/LICENSE 5 | */ 6 | 7 | package org.byteskript.skript.lang.syntax.script; 8 | 9 | import mx.kenzie.foundation.Type; 10 | import org.byteskript.skript.api.note.Documentation; 11 | import org.byteskript.skript.api.syntax.SimpleExpression; 12 | import org.byteskript.skript.compiler.CommonTypes; 13 | import org.byteskript.skript.compiler.SkriptLangSpec; 14 | import org.byteskript.skript.lang.element.StandardElements; 15 | import org.byteskript.skript.lang.handler.StandardHandlers; 16 | import org.byteskript.skript.runtime.internal.ExtractedSyntaxCalls; 17 | import org.byteskript.skript.runtime.internal.ModifiableCompiler; 18 | 19 | @Documentation( 20 | name = "Compiler", 21 | description = """ 22 | Obtains the current compiler. This may not exist. 23 | This can be used to check whether this installation is able to load scripts. 24 | If the compiler is `null`, the load effect will be unavailable. 25 | """, 26 | examples = { 27 | """ 28 | set {var} to the compiler 29 | if the compiler exists: 30 | print "can load scripts :)" 31 | """ 32 | } 33 | ) 34 | public class ExprCompiler extends SimpleExpression { 35 | 36 | public ExprCompiler() { 37 | super(SkriptLangSpec.LIBRARY, StandardElements.EXPRESSION, "[the] compiler"); 38 | handlers.put(StandardHandlers.GET, findMethod(ExtractedSyntaxCalls.class, "getCompiler")); 39 | } 40 | 41 | @Override 42 | public Type getReturnType() { 43 | return new Type(ModifiableCompiler.class); 44 | } 45 | 46 | @Override 47 | public boolean allowAsInputFor(Type type) { 48 | return CommonTypes.OBJECT.equals(type) || super.allowAsInputFor(type); 49 | } 50 | 51 | } 52 | -------------------------------------------------------------------------------- /src/main/java/org/byteskript/skript/lang/syntax/script/ExprCurrentScript.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021-2022 ByteSkript org (Moderocky) 3 | * View the full licence information and permissions: 4 | * https://github.com/Moderocky/ByteSkript/blob/master/LICENSE 5 | */ 6 | 7 | package org.byteskript.skript.lang.syntax.script; 8 | 9 | import mx.kenzie.foundation.MethodBuilder; 10 | import mx.kenzie.foundation.Type; 11 | import mx.kenzie.foundation.WriteInstruction; 12 | import org.byteskript.skript.api.note.Documentation; 13 | import org.byteskript.skript.api.syntax.SimpleExpression; 14 | import org.byteskript.skript.compiler.Context; 15 | import org.byteskript.skript.compiler.Pattern; 16 | import org.byteskript.skript.compiler.SkriptLangSpec; 17 | import org.byteskript.skript.lang.element.StandardElements; 18 | import org.byteskript.skript.runtime.Script; 19 | 20 | @Documentation( 21 | name = "Current Script", 22 | description = """ 23 | Returns the class object for the current script. 24 | This can be used in the `name of...` expression or for finding a function. 25 | """, 26 | examples = { 27 | """ 28 | set {var} to name of the current script 29 | """ 30 | } 31 | ) 32 | public class ExprCurrentScript extends SimpleExpression { 33 | 34 | public ExprCurrentScript() { 35 | super(SkriptLangSpec.LIBRARY, StandardElements.EXPRESSION, "[the] [current] script"); 36 | } 37 | 38 | @Override 39 | public Type getReturnType() { 40 | return new Type(Script.class); 41 | } 42 | 43 | @Override 44 | public void compile(Context context, Pattern.Match match) throws Throwable { 45 | final MethodBuilder method = context.getMethod(); 46 | assert method != null; 47 | method.writeCode(WriteInstruction.loadClassConstant(context.getType())); 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /src/main/java/org/byteskript/skript/lang/syntax/script/ExprLoadedScripts.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 ByteSkript org (Moderocky) 3 | * View the full licence information and permissions: 4 | * https://github.com/Moderocky/ByteSkript/blob/master/LICENSE 5 | */ 6 | 7 | package org.byteskript.skript.lang.syntax.script; 8 | 9 | import mx.kenzie.foundation.Type; 10 | import org.byteskript.skript.api.note.Documentation; 11 | import org.byteskript.skript.api.syntax.SimpleExpression; 12 | import org.byteskript.skript.compiler.CommonTypes; 13 | import org.byteskript.skript.compiler.SkriptLangSpec; 14 | import org.byteskript.skript.lang.element.StandardElements; 15 | import org.byteskript.skript.lang.handler.StandardHandlers; 16 | import org.byteskript.skript.runtime.internal.ExtractedSyntaxCalls; 17 | 18 | @Documentation( 19 | name = "Loaded Scripts", 20 | description = """ 21 | A list of the main classes for all loaded scripts. 22 | Storing these will prevent them being unloaded safely. 23 | """, 24 | examples = { 25 | """ 26 | set {list} to the loaded scripts 27 | loop {script} in {list}: 28 | print name of {script} 29 | """ 30 | } 31 | ) 32 | public class ExprLoadedScripts extends SimpleExpression { 33 | 34 | public ExprLoadedScripts() { 35 | super(SkriptLangSpec.LIBRARY, StandardElements.EXPRESSION, "[(the|all)] loaded scripts"); 36 | handlers.put(StandardHandlers.GET, findMethod(ExtractedSyntaxCalls.class, "getLoadedScripts")); 37 | } 38 | 39 | @Override 40 | public Type getReturnType() { 41 | return CommonTypes.LIST; 42 | } 43 | 44 | @Override 45 | public boolean allowAsInputFor(Type type) { 46 | return CommonTypes.LIST.equals(type) || super.allowAsInputFor(type); 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /src/main/java/org/byteskript/skript/lang/syntax/type/ExprThisThing.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 ByteSkript org (Moderocky) 3 | * View the full licence information and permissions: 4 | * https://github.com/Moderocky/ByteSkript/blob/master/LICENSE 5 | */ 6 | 7 | package org.byteskript.skript.lang.syntax.type; 8 | 9 | import mx.kenzie.foundation.MethodBuilder; 10 | import mx.kenzie.foundation.Type; 11 | import mx.kenzie.foundation.WriteInstruction; 12 | import org.byteskript.skript.api.note.Documentation; 13 | import org.byteskript.skript.api.syntax.SimpleExpression; 14 | import org.byteskript.skript.compiler.*; 15 | import org.byteskript.skript.lang.element.StandardElements; 16 | 17 | @Documentation( 18 | name = "This Object", 19 | description = """ 20 | Returns the current object, while in a function from a type. 21 | Outside a custom type this will not be usable. 22 | """, 23 | examples = """ 24 | type Square: 25 | function my_func: 26 | trigger: 27 | return this object 28 | """ 29 | ) 30 | public class ExprThisThing extends SimpleExpression { 31 | 32 | public ExprThisThing() { 33 | super(SkriptLangSpec.LIBRARY, StandardElements.EXPRESSION, "this (thing|object)"); 34 | } 35 | 36 | @Override 37 | public Type getReturnType() { 38 | return CommonTypes.OBJECT; 39 | } 40 | 41 | @Override 42 | public void compile(Context context, Pattern.Match match) throws Throwable { 43 | final MethodBuilder method = context.getMethod(); 44 | assert method != null; 45 | method.writeCode(WriteInstruction.loadThis()); 46 | } 47 | 48 | @Override 49 | public Pattern.Match match(String thing, Context context) { 50 | if (!thing.startsWith("this ")) return null; 51 | if (!context.hasFlag(AreaFlag.IN_TYPE)) return null; 52 | return super.match(thing, context); 53 | } 54 | 55 | } 56 | -------------------------------------------------------------------------------- /src/main/java/org/byteskript/skript/runtime/data/EventData.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 ByteSkript org (Moderocky) 3 | * View the full licence information and permissions: 4 | * https://github.com/Moderocky/ByteSkript/blob/master/LICENSE 5 | */ 6 | 7 | package org.byteskript.skript.runtime.data; 8 | 9 | import mx.kenzie.autodoc.api.note.Ignore; 10 | 11 | import java.lang.annotation.ElementType; 12 | import java.lang.annotation.Retention; 13 | import java.lang.annotation.RetentionPolicy; 14 | import java.lang.annotation.Target; 15 | 16 | @Ignore 17 | @Target(ElementType.METHOD) 18 | @Retention(RetentionPolicy.RUNTIME) 19 | public @interface EventData { 20 | 21 | String name(); 22 | 23 | String event(); 24 | 25 | boolean async(); 26 | 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/org/byteskript/skript/runtime/data/Function.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 ByteSkript org (Moderocky) 3 | * View the full licence information and permissions: 4 | * https://github.com/Moderocky/ByteSkript/blob/master/LICENSE 5 | */ 6 | 7 | package org.byteskript.skript.runtime.data; 8 | 9 | import mx.kenzie.autodoc.api.note.Ignore; 10 | 11 | import java.lang.annotation.ElementType; 12 | import java.lang.annotation.Retention; 13 | import java.lang.annotation.RetentionPolicy; 14 | import java.lang.annotation.Target; 15 | 16 | @Ignore 17 | @Target(ElementType.METHOD) 18 | @Retention(RetentionPolicy.RUNTIME) 19 | public @interface Function { 20 | 21 | String name(); 22 | 23 | int arguments(); 24 | 25 | boolean async(); 26 | 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/org/byteskript/skript/runtime/data/HandlerData.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 ByteSkript org (Moderocky) 3 | * View the full licence information and permissions: 4 | * https://github.com/Moderocky/ByteSkript/blob/master/LICENSE 5 | */ 6 | 7 | package org.byteskript.skript.runtime.data; 8 | 9 | import mx.kenzie.autodoc.api.note.Ignore; 10 | 11 | @Ignore 12 | public @interface HandlerData { 13 | 14 | String type(); 15 | 16 | String name(); 17 | 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/org/byteskript/skript/runtime/data/PeriodicalData.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 ByteSkript org (Moderocky) 3 | * View the full licence information and permissions: 4 | * https://github.com/Moderocky/ByteSkript/blob/master/LICENSE 5 | */ 6 | 7 | package org.byteskript.skript.runtime.data; 8 | 9 | import mx.kenzie.autodoc.api.note.Ignore; 10 | 11 | import java.lang.annotation.ElementType; 12 | import java.lang.annotation.Retention; 13 | import java.lang.annotation.RetentionPolicy; 14 | import java.lang.annotation.Target; 15 | 16 | @Ignore 17 | @Target(ElementType.METHOD) 18 | @Retention(RetentionPolicy.RUNTIME) 19 | public @interface PeriodicalData { 20 | 21 | String control(); 22 | 23 | boolean fixed(); 24 | 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/org/byteskript/skript/runtime/data/ScriptData.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 ByteSkript org (Moderocky) 3 | * View the full licence information and permissions: 4 | * https://github.com/Moderocky/ByteSkript/blob/master/LICENSE 5 | */ 6 | 7 | package org.byteskript.skript.runtime.data; 8 | 9 | import mx.kenzie.autodoc.api.note.Ignore; 10 | 11 | import java.lang.annotation.ElementType; 12 | import java.lang.annotation.Retention; 13 | import java.lang.annotation.RetentionPolicy; 14 | import java.lang.annotation.Target; 15 | 16 | @Ignore 17 | @Target(ElementType.TYPE) 18 | @Retention(RetentionPolicy.RUNTIME) 19 | public @interface ScriptData { 20 | 21 | String sourceFile(); 22 | 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/org/byteskript/skript/runtime/data/SourceData.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 ByteSkript org (Moderocky) 3 | * View the full licence information and permissions: 4 | * https://github.com/Moderocky/ByteSkript/blob/master/LICENSE 5 | */ 6 | 7 | package org.byteskript.skript.runtime.data; 8 | 9 | import mx.kenzie.autodoc.api.note.Ignore; 10 | 11 | import java.lang.annotation.Retention; 12 | import java.lang.annotation.RetentionPolicy; 13 | 14 | @Ignore 15 | @Retention(RetentionPolicy.RUNTIME) 16 | public @interface SourceData { 17 | 18 | int line(); 19 | 20 | String type() default "unknown"; 21 | 22 | String name() default "unknown"; 23 | 24 | String file() default "Unknown"; 25 | 26 | long compiled(); 27 | 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/org/byteskript/skript/runtime/data/Structure.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 ByteSkript org (Moderocky) 3 | * View the full licence information and permissions: 4 | * https://github.com/Moderocky/ByteSkript/blob/master/LICENSE 5 | */ 6 | 7 | package org.byteskript.skript.runtime.data; 8 | 9 | import mx.kenzie.autodoc.api.note.Ignore; 10 | 11 | import java.lang.reflect.AnnotatedElement; 12 | 13 | @Ignore 14 | public record Structure(String type, String name, AnnotatedElement element) { 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/org/byteskript/skript/runtime/data/TypeData.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 ByteSkript org (Moderocky) 3 | * View the full licence information and permissions: 4 | * https://github.com/Moderocky/ByteSkript/blob/master/LICENSE 5 | */ 6 | 7 | package org.byteskript.skript.runtime.data; 8 | 9 | import mx.kenzie.autodoc.api.note.Ignore; 10 | 11 | import java.lang.annotation.ElementType; 12 | import java.lang.annotation.Retention; 13 | import java.lang.annotation.RetentionPolicy; 14 | import java.lang.annotation.Target; 15 | 16 | @Ignore 17 | @Target(ElementType.METHOD) 18 | @Retention(RetentionPolicy.RUNTIME) 19 | public @interface TypeData { 20 | 21 | String name(); 22 | 23 | boolean template(); 24 | 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/org/byteskript/skript/runtime/event/Empty.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2022 ByteSkript org (Moderocky) 3 | * View the full licence information and permissions: 4 | * https://github.com/Moderocky/ByteSkript/blob/master/LICENSE 5 | */ 6 | 7 | package org.byteskript.skript.runtime.event; 8 | 9 | import mx.kenzie.autodoc.api.note.Ignore; 10 | import org.byteskript.skript.api.Event; 11 | 12 | @Ignore 13 | public class Empty extends Event {} 14 | -------------------------------------------------------------------------------- /src/main/java/org/byteskript/skript/runtime/event/Load.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 ByteSkript org (Moderocky) 3 | * View the full licence information and permissions: 4 | * https://github.com/Moderocky/ByteSkript/blob/master/LICENSE 5 | */ 6 | 7 | package org.byteskript.skript.runtime.event; 8 | 9 | import mx.kenzie.autodoc.api.note.Ignore; 10 | import org.byteskript.skript.api.Event; 11 | import org.byteskript.skript.api.note.EventValue; 12 | import org.byteskript.skript.runtime.Script; 13 | 14 | @Ignore 15 | public class Load extends Event { 16 | 17 | protected final Script script; 18 | 19 | public Load(Script script) { 20 | this.script = script; 21 | } 22 | 23 | @EventValue("name") 24 | public String getName() { 25 | return script.getSimpleName(); 26 | } 27 | 28 | @EventValue("script") 29 | public String getPath() { 30 | return script.getPath(); 31 | } 32 | 33 | @Ignore 34 | public static class LoadThis extends Event { 35 | 36 | protected final Script script; 37 | 38 | public LoadThis(Script script) { 39 | this.script = script; 40 | } 41 | 42 | @EventValue("name") 43 | public String getName() { 44 | return script.getSimpleName(); 45 | } 46 | 47 | @EventValue("script") 48 | public String getPath() { 49 | return script.getPath(); 50 | } 51 | 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /src/main/java/org/byteskript/skript/runtime/event/Unload.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 ByteSkript org (Moderocky) 3 | * View the full licence information and permissions: 4 | * https://github.com/Moderocky/ByteSkript/blob/master/LICENSE 5 | */ 6 | 7 | package org.byteskript.skript.runtime.event; 8 | 9 | import mx.kenzie.autodoc.api.note.Ignore; 10 | import org.byteskript.skript.api.Event; 11 | import org.byteskript.skript.api.note.EventValue; 12 | import org.byteskript.skript.runtime.Script; 13 | 14 | @Ignore 15 | public class Unload extends Event { 16 | 17 | protected final String name, path; 18 | 19 | public Unload(Script script) { 20 | this.name = script.getSimpleName(); 21 | this.path = script.getPath(); 22 | } 23 | 24 | @EventValue("name") 25 | public String getName() { 26 | return name; 27 | } 28 | 29 | @EventValue("script") 30 | public String getPath() { 31 | return path; 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/org/byteskript/skript/runtime/internal/CompiledScript.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 ByteSkript org (Moderocky) 3 | * View the full licence information and permissions: 4 | * https://github.com/Moderocky/ByteSkript/blob/master/LICENSE 5 | */ 6 | 7 | package org.byteskript.skript.runtime.internal; 8 | 9 | import mx.kenzie.autodoc.api.note.Description; 10 | 11 | @Description(""" 12 | Script main classes should extend this class. 13 | As it is internal, this is not assured. 14 | """) 15 | public abstract class CompiledScript { 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/org/byteskript/skript/runtime/internal/CompilerDependent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2022 ByteSkript org (Moderocky) 3 | * View the full licence information and permissions: 4 | * https://github.com/Moderocky/ByteSkript/blob/master/LICENSE 5 | */ 6 | 7 | package org.byteskript.skript.runtime.internal; 8 | 9 | import mx.kenzie.autodoc.api.note.Description; 10 | 11 | import java.lang.annotation.Retention; 12 | import java.lang.annotation.RetentionPolicy; 13 | 14 | @Description(""" 15 | Denotes behaviour that is dependent on a specific compiler being available. 16 | """) 17 | @Retention(RetentionPolicy.CLASS) 18 | public @interface CompilerDependent { 19 | } 20 | -------------------------------------------------------------------------------- /src/main/java/org/byteskript/skript/runtime/internal/ConsoleColour.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2022 ByteSkript org (Moderocky) 3 | * View the full licence information and permissions: 4 | * https://github.com/Moderocky/ByteSkript/blob/master/LICENSE 5 | */ 6 | 7 | package org.byteskript.skript.runtime.internal; 8 | 9 | import mx.kenzie.autodoc.api.note.Ignore; 10 | 11 | @Ignore 12 | public enum ConsoleColour { 13 | RESET("\033[0m"), 14 | BLACK("\033[0;30m"), 15 | RED("\033[0;31m"), 16 | GREEN("\033[0;32m"), 17 | YELLOW("\033[0;33m"), 18 | BLUE("\033[0;34m"), 19 | PURPLE("\033[0;35m"), 20 | CYAN("\033[0;36m"), 21 | CYAN_UNDERLINED("\033[4;36m"), 22 | BRIGHT_PURPLE("\033[0;95m"), 23 | BLACK_BACKGROUND("\033[40m"); 24 | 25 | private final String code; 26 | 27 | ConsoleColour(String code) { 28 | this.code = code; 29 | } 30 | 31 | @Override 32 | public String toString() { 33 | if ("true".equals(System.getProperty("byteskript.no_colours"))) return ""; 34 | if (System.console() == null || System.getenv().get("TERM") != null) { 35 | return code; 36 | } else { 37 | return ""; 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/org/byteskript/skript/runtime/internal/Instruction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 ByteSkript org (Moderocky) 3 | * View the full licence information and permissions: 4 | * https://github.com/Moderocky/ByteSkript/blob/master/LICENSE 5 | */ 6 | 7 | package org.byteskript.skript.runtime.internal; 8 | 9 | import mx.kenzie.autodoc.api.note.Ignore; 10 | 11 | @Ignore 12 | public interface Instruction { 13 | 14 | default Type get() { 15 | return null; 16 | } 17 | 18 | default void runSafely() { 19 | try { 20 | this.run(); 21 | } catch (Throwable ex) { 22 | ex.printStackTrace(); 23 | } 24 | } 25 | 26 | void run() throws Throwable; 27 | 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/org/byteskript/skript/runtime/internal/InvokingScriptRunner.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 ByteSkript org (Moderocky) 3 | * View the full licence information and permissions: 4 | * https://github.com/Moderocky/ByteSkript/blob/master/LICENSE 5 | */ 6 | 7 | package org.byteskript.skript.runtime.internal; 8 | 9 | import mx.kenzie.autodoc.api.note.Ignore; 10 | import org.byteskript.skript.runtime.threading.ScriptRunner; 11 | 12 | @Ignore 13 | public record InvokingScriptRunner(Class owner, Member method, 14 | Object... parameters) implements ScriptRunner { 15 | 16 | @Override 17 | public void start() { 18 | method.invoke(parameters); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/org/byteskript/skript/runtime/internal/LibraryClassLoader.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 ByteSkript org (Moderocky) 3 | * View the full licence information and permissions: 4 | * https://github.com/Moderocky/ByteSkript/blob/master/LICENSE 5 | */ 6 | 7 | package org.byteskript.skript.runtime.internal; 8 | 9 | import mx.kenzie.autodoc.api.note.Description; 10 | import mx.kenzie.autodoc.api.note.Ignore; 11 | 12 | import java.io.File; 13 | import java.io.IOException; 14 | import java.net.URL; 15 | import java.net.URLClassLoader; 16 | 17 | @Description(""" 18 | The class-loader used by libraries. 19 | This can be searched by script class-loaders. 20 | """) 21 | public class LibraryClassLoader extends URLClassLoader { 22 | 23 | @Ignore 24 | public LibraryClassLoader(File file, ClassLoader parent) throws IOException { 25 | super(new URL[] {file.toURI().toURL()}, parent); 26 | } 27 | 28 | @Ignore 29 | @Override 30 | public Class findClass(String name) throws ClassNotFoundException { 31 | return super.findClass(name); 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/org/byteskript/skript/runtime/internal/ThreadSpecific.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2022 ByteSkript org (Moderocky) 3 | * View the full licence information and permissions: 4 | * https://github.com/Moderocky/ByteSkript/blob/master/LICENSE 5 | */ 6 | 7 | package org.byteskript.skript.runtime.internal; 8 | 9 | import mx.kenzie.autodoc.api.note.Description; 10 | 11 | import java.lang.annotation.Retention; 12 | import java.lang.annotation.RetentionPolicy; 13 | 14 | @Description("Denotes behaviour that is thread-specific.") 15 | @Retention(RetentionPolicy.CLASS) 16 | public @interface ThreadSpecific { 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/org/byteskript/skript/runtime/internal/VariableMap.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2022 ByteSkript org (Moderocky) 3 | * View the full licence information and permissions: 4 | * https://github.com/Moderocky/ByteSkript/blob/master/LICENSE 5 | */ 6 | 7 | package org.byteskript.skript.runtime.internal; 8 | 9 | import java.util.LinkedHashMap; 10 | 11 | public class VariableMap extends LinkedHashMap { 12 | } 13 | -------------------------------------------------------------------------------- /src/main/java/org/byteskript/skript/runtime/internal/WeakList.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2022 ByteSkript org (Moderocky) 3 | * View the full licence information and permissions: 4 | * https://github.com/Moderocky/ByteSkript/blob/master/LICENSE 5 | */ 6 | 7 | package org.byteskript.skript.runtime.internal; 8 | 9 | import mx.kenzie.autodoc.api.note.Ignore; 10 | import org.jetbrains.annotations.NotNull; 11 | 12 | import java.lang.ref.WeakReference; 13 | import java.util.ArrayList; 14 | import java.util.Collection; 15 | import java.util.Iterator; 16 | import java.util.List; 17 | 18 | @Ignore 19 | public class WeakList extends ArrayList> { 20 | 21 | public Type getActual(int index) { 22 | return super.get(index).get(); 23 | } 24 | 25 | public boolean addActual(Type thing) { 26 | return super.add(new WeakReference<>(thing)); 27 | } 28 | 29 | public Collection collectRemaining() { 30 | final List list = new ArrayList<>(); 31 | for (WeakReference reference : this) { 32 | final Type type = reference.get(); 33 | if (type == null) continue; 34 | list.add(type); 35 | } 36 | return list; 37 | } 38 | 39 | @NotNull 40 | @Override 41 | public Iterator> iterator() { 42 | this.collect(); 43 | return super.iterator(); 44 | } 45 | 46 | public void collect() { 47 | this.removeIf(typeWeakReference -> typeWeakReference.get() == null); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/main/java/org/byteskript/skript/runtime/internal/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2022 ByteSkript org (Moderocky) 3 | * View the full licence information and permissions: 4 | * https://github.com/Moderocky/ByteSkript/blob/master/LICENSE 5 | */ 6 | 7 | /** 8 | * This file contains handlers for the Skript runtime. 9 | * Nothing in this package is designed to be used directly by third-party libraries. 10 | * Most of the classes will be either encapsulated or simply inaccessible. 11 | *

12 | * No class in this file is guaranteed to be present when the program is run. 13 | * Distributions may implement the runtime differently and not include these internals. 14 | */ 15 | package org.byteskript.skript.runtime.internal; 16 | -------------------------------------------------------------------------------- /src/main/java/org/byteskript/skript/runtime/threading/AirlockQueue.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 ByteSkript org (Moderocky) 3 | * View the full licence information and permissions: 4 | * https://github.com/Moderocky/ByteSkript/blob/master/LICENSE 5 | */ 6 | 7 | package org.byteskript.skript.runtime.threading; 8 | 9 | import org.byteskript.skript.runtime.internal.Instruction; 10 | 11 | import java.util.ArrayList; 12 | 13 | public class AirlockQueue extends ArrayList> { 14 | 15 | public AirlockQueue() { 16 | super(); 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /src/main/java/org/byteskript/skript/runtime/threading/OperationController.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 ByteSkript org (Moderocky) 3 | * View the full licence information and permissions: 4 | * https://github.com/Moderocky/ByteSkript/blob/master/LICENSE 5 | */ 6 | 7 | package org.byteskript.skript.runtime.threading; 8 | 9 | import org.byteskript.skript.runtime.Skript; 10 | import org.byteskript.skript.runtime.internal.Instruction; 11 | 12 | /** 13 | * This is the runtime half of the airlock system. 14 | * A distribution needs to provide the other half, which is the throttle controller. 15 | *

16 | * Together, these two halves bind multiple threads to the 'main' thread. 17 | * This allows for the behaviour defined in the language specification. 18 | */ 19 | public class OperationController { 20 | 21 | protected final AirlockQueue queue; 22 | protected final SkriptThreadProvider provider; 23 | protected final Skript skript; 24 | protected boolean state; 25 | 26 | public OperationController(final Skript skript, final SkriptThreadProvider provider) { 27 | this.queue = new AirlockQueue(); 28 | this.provider = provider; 29 | this.skript = skript; 30 | this.skript.getProcesses().add(this); 31 | } 32 | 33 | public Skript getSkript() { 34 | return skript; 35 | } 36 | 37 | public synchronized void addInstruction(final Instruction runnable) { 38 | synchronized (this.queue) { 39 | this.queue.add(runnable); 40 | } 41 | } 42 | 43 | public synchronized AirlockQueue getQueue() { 44 | return queue; 45 | } 46 | 47 | public synchronized void kill() { 48 | this.skript.getProcesses().remove(this); 49 | } 50 | 51 | } 52 | -------------------------------------------------------------------------------- /src/main/java/org/byteskript/skript/runtime/threading/ScriptRunner.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 ByteSkript org (Moderocky) 3 | * View the full licence information and permissions: 4 | * https://github.com/Moderocky/ByteSkript/blob/master/LICENSE 5 | */ 6 | 7 | package org.byteskript.skript.runtime.threading; 8 | 9 | import org.byteskript.skript.runtime.internal.CompiledScript; 10 | 11 | /** 12 | * A task designed to start the script-running process. 13 | */ 14 | public interface ScriptRunner extends Runnable { 15 | 16 | @Override 17 | default void run() { 18 | this.start(); 19 | final ScriptThread thread = (ScriptThread) Thread.currentThread(); 20 | thread.controller.kill(); 21 | thread.variables.clear(); 22 | } 23 | 24 | void start(); 25 | 26 | default Object result() { 27 | return null; 28 | } 29 | 30 | Class owner(); 31 | 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/org/byteskript/skript/runtime/threading/ScriptThreadPoolExecutor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2022 ByteSkript org (Moderocky) 3 | * View the full licence information and permissions: 4 | * https://github.com/Moderocky/ByteSkript/blob/master/LICENSE 5 | */ 6 | 7 | package org.byteskript.skript.runtime.threading; 8 | 9 | import org.jetbrains.annotations.NotNull; 10 | 11 | import java.util.concurrent.BlockingQueue; 12 | import java.util.concurrent.ThreadFactory; 13 | import java.util.concurrent.ThreadPoolExecutor; 14 | import java.util.concurrent.TimeUnit; 15 | 16 | public class ScriptThreadPoolExecutor extends ThreadPoolExecutor { 17 | 18 | public ScriptThreadPoolExecutor(int corePoolSize, int maximumPoolSize, long keepAliveTime, @NotNull TimeUnit unit, @NotNull BlockingQueue workQueue, @NotNull ThreadFactory threadFactory) { 19 | super(corePoolSize, maximumPoolSize, keepAliveTime, unit, workQueue, threadFactory); 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/org/byteskript/skript/runtime/threading/SkriptThreadProvider.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 ByteSkript org (Moderocky) 3 | * View the full licence information and permissions: 4 | * https://github.com/Moderocky/ByteSkript/blob/master/LICENSE 5 | */ 6 | 7 | package org.byteskript.skript.runtime.threading; 8 | 9 | import org.byteskript.skript.runtime.Skript; 10 | 11 | import java.util.concurrent.ThreadFactory; 12 | 13 | /** 14 | * Provides {@link ScriptThread}s for the runtime to use. 15 | */ 16 | public class SkriptThreadProvider implements ThreadFactory { 17 | 18 | private final ScriptExceptionHandler handler = new ScriptExceptionHandler(); 19 | volatile int counter; 20 | private Skript skript; 21 | 22 | public SkriptThreadProvider() { 23 | } 24 | 25 | public void setSkriptInstance(Skript skript) { 26 | this.skript = skript; 27 | } 28 | 29 | @Override 30 | public Thread newThread(Runnable r) { 31 | return this.newThread(new OperationController(this.skript, this), r, false); 32 | } 33 | 34 | public synchronized ScriptThread newThread(final OperationController controller, Runnable runnable, boolean inheritLocals) { 35 | final ScriptThread thread = new ScriptThread(skript, controller, Skript.THREAD_GROUP, runnable, Skript.THREAD_GROUP.getName() + "-" + counter++, 0, inheritLocals); 36 | thread.setUncaughtExceptionHandler(handler); 37 | if (inheritLocals && Thread.currentThread() instanceof ScriptThread current) 38 | thread.variables.putAll(current.variables); // inherits locals :) 39 | return thread; 40 | } 41 | 42 | public Thread.UncaughtExceptionHandler getHandler() { 43 | return handler; 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /src/main/java/org/byteskript/skript/runtime/type/Converter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2022 ByteSkript org (Moderocky) 3 | * View the full licence information and permissions: 4 | * https://github.com/Moderocky/ByteSkript/blob/master/LICENSE 5 | */ 6 | 7 | package org.byteskript.skript.runtime.type; 8 | 9 | @FunctionalInterface 10 | public interface Converter { 11 | 12 | To convert(From from) throws Throwable; 13 | 14 | record Data(Class from, Class to) {} 15 | 16 | } 17 | 18 | -------------------------------------------------------------------------------- /src/main/java/org/byteskript/skript/runtime/type/DataList.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 ByteSkript org (Moderocky) 3 | * View the full licence information and permissions: 4 | * https://github.com/Moderocky/ByteSkript/blob/master/LICENSE 5 | */ 6 | 7 | package org.byteskript.skript.runtime.type; 8 | 9 | import mx.kenzie.autodoc.api.note.Description; 10 | import org.jetbrains.annotations.NotNull; 11 | 12 | import java.io.Serializable; 13 | import java.util.ArrayList; 14 | import java.util.Arrays; 15 | import java.util.Collection; 16 | 17 | @Description(""" 18 | The list implementation used by Skript lists. 19 | This is an extension of Java's ArrayList. 20 | 21 | Currently, this has no special behaviour. 22 | """) 23 | public class DataList extends ArrayList implements Serializable { 24 | 25 | public DataList() { 26 | super(); 27 | } 28 | 29 | public DataList(@NotNull Collection c) { 30 | super(c); 31 | } 32 | 33 | public static Integer getSize(Collection target) { 34 | return target.size(); 35 | } 36 | 37 | public static DataList of(Object... objects) { 38 | return new DataList(Arrays.asList(objects)); 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/org/byteskript/skript/runtime/type/DataMap.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 ByteSkript org (Moderocky) 3 | * View the full licence information and permissions: 4 | * https://github.com/Moderocky/ByteSkript/blob/master/LICENSE 5 | */ 6 | 7 | package org.byteskript.skript.runtime.type; 8 | 9 | import mx.kenzie.autodoc.api.note.Description; 10 | 11 | import java.io.Serializable; 12 | import java.util.HashMap; 13 | import java.util.Map; 14 | 15 | @Description(""" 16 | The map implementation used by Skript maps. 17 | This is an extension of Java's HashMap. 18 | 19 | Currently, this has no special behaviour. 20 | """) 21 | public class DataMap extends HashMap implements Serializable { 22 | 23 | public static DataList getKeys(Map target) { 24 | return new DataList(target.keySet()); 25 | } 26 | 27 | public static DataList getValues(Map target) { 28 | return new DataList(target.values()); 29 | } 30 | 31 | public static Integer getSize(Map target) { 32 | return target.size(); 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/org/byteskript/skript/runtime/type/Executable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 ByteSkript org (Moderocky) 3 | * View the full licence information and permissions: 4 | * https://github.com/Moderocky/ByteSkript/blob/master/LICENSE 5 | */ 6 | 7 | package org.byteskript.skript.runtime.type; 8 | 9 | import mx.kenzie.autodoc.api.note.Ignore; 10 | import mx.kenzie.foundation.MethodErasure; 11 | import mx.kenzie.foundation.Type; 12 | 13 | import java.lang.reflect.Method; 14 | 15 | @Ignore 16 | public record Executable(Type owner, MethodErasure erasure) { 17 | 18 | public Executable(Method method) { 19 | this(new Type(method.getDeclaringClass()), new MethodErasure(method)); 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/org/byteskript/skript/runtime/type/OperatorFunction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2022 ByteSkript org (Moderocky) 3 | * View the full licence information and permissions: 4 | * https://github.com/Moderocky/ByteSkript/blob/master/LICENSE 5 | */ 6 | 7 | package org.byteskript.skript.runtime.type; 8 | 9 | @FunctionalInterface 10 | public interface OperatorFunction { 11 | 12 | default OperatorFunction opposite() { 13 | final OperatorFunction function = this; 14 | return new OperatorFunction<>() { 15 | @Override 16 | public Object union(B first, A second) throws Throwable { 17 | return function.union2(first, second); 18 | } 19 | 20 | @Override 21 | public Object union2(A first, B second) throws Throwable { 22 | return function.union(first, second); 23 | } 24 | 25 | @Override 26 | public boolean reversible() { 27 | return function.reversible(); 28 | } 29 | }; 30 | } 31 | 32 | default Object union2(B first, A second) throws Throwable { 33 | return this.union(second, first); 34 | } 35 | 36 | Object union(A first, B second) throws Throwable; 37 | 38 | default boolean reversible() { 39 | return true; 40 | } 41 | 42 | enum Type { 43 | ADD, SUB, MUL, DIV 44 | } 45 | 46 | record Data(Type type, Class first, Class second) {} 47 | 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/org/byteskript/skript/runtime/type/Query.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 ByteSkript org (Moderocky) 3 | * View the full licence information and permissions: 4 | * https://github.com/Moderocky/ByteSkript/blob/master/LICENSE 5 | */ 6 | 7 | package org.byteskript.skript.runtime.type; 8 | 9 | import mx.kenzie.autodoc.api.note.Ignore; 10 | 11 | @Ignore 12 | @FunctionalInterface 13 | public interface Query { 14 | 15 | boolean check(Object value); 16 | 17 | } 18 | -------------------------------------------------------------------------------- /src/test/java/org/byteskript/skript/test/CreatePages.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2022 ByteSkript org (Moderocky) 3 | * View the full licence information and permissions: 4 | * https://github.com/Moderocky/ByteSkript/blob/master/LICENSE 5 | */ 6 | 7 | package org.byteskript.skript.test; 8 | 9 | import mx.kenzie.autodoc.DocBuilder; 10 | 11 | import java.io.File; 12 | import java.io.IOException; 13 | 14 | /** 15 | * This is not technically a test - but AutoDocs is available for testing. 16 | */ 17 | public class CreatePages { 18 | 19 | public static void main(String[] args) throws IOException { 20 | try (final DocBuilder builder = new DocBuilder("ByteSkript", new File("docs/"))) { 21 | builder.setJar(new File("target/ByteSkript.jar")); 22 | builder.setSourceRoot(new File("src/main/java")); 23 | builder.addClassesFrom("org.byteskript.skript.api").addClassesFrom("org.byteskript.skript.runtime"); 24 | builder.setDescription("The API documentation for ByteSkript."); 25 | builder.setBody(""" 26 | 27 | ## ByteSkript 28 | 29 | Visit the website [here](https://docs.byteskript.org). 30 | 31 | This website contains documentation for the [API](org/byteskript/skript/api/) and [Runtime](org/byteskript/skript/runtime/). 32 | """); 33 | builder.build(); 34 | } 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /src/test/java/org/byteskript/skript/test/MainTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 ByteSkript org (Moderocky) 3 | * View the full licence information and permissions: 4 | * https://github.com/Moderocky/ByteSkript/blob/master/LICENSE 5 | */ 6 | 7 | package org.byteskript.skript.test; 8 | 9 | import mx.kenzie.foundation.language.PostCompileClass; 10 | import org.byteskript.skript.runtime.Script; 11 | import org.byteskript.skript.runtime.Skript; 12 | 13 | public class MainTest extends SkriptTest { 14 | 15 | private static final Skript skript = new Skript(); 16 | 17 | public static void main(String[] args) { 18 | final PostCompileClass cls = skript.compileScript(MainTest.class.getClassLoader() 19 | .getResourceAsStream("main.bsk"), "skript.main"); 20 | Script script = skript.loadScript(cls); 21 | new ExampleController(skript).run(); 22 | System.out.println("Finished."); 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /src/test/java/org/byteskript/skript/test/RecompileTest.java: -------------------------------------------------------------------------------- 1 | package org.byteskript.skript.test; 2 | 3 | import org.byteskript.skript.runtime.Script; 4 | import org.byteskript.skript.runtime.Skript; 5 | import org.byteskript.skript.runtime.event.Load; 6 | import org.junit.Test; 7 | 8 | import java.io.ByteArrayOutputStream; 9 | import java.io.PrintStream; 10 | 11 | public class RecompileTest extends SkriptTest { 12 | 13 | private static final Skript skript = new Skript(); 14 | 15 | @Test 16 | public void testRecompile() { 17 | final ByteArrayOutputStream output = new ByteArrayOutputStream(); 18 | skript.setOutput(new PrintStream(output)); 19 | final Script first = RecompileTest.loadSync(""" 20 | on script load: 21 | trigger: 22 | print "Foo" 23 | """); 24 | skript.unloadScript(first); 25 | final Script second = RecompileTest.loadSync(""" 26 | on script load: 27 | trigger: 28 | print "Bar" 29 | """); 30 | skript.unloadScript(second); 31 | assert output.toString().equals("Foo\nBar\n") : output.toString(); 32 | } 33 | 34 | private static Script loadSync(final String source) { 35 | final Script script = skript.assembleScript( 36 | skript.compileScript(source, "skript.recompilation.bsk")); 37 | skript.runEvent(new Load.LoadThis(script), script).all().join(); 38 | return script; 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /src/test/java/org/byteskript/skript/test/SkriptTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 ByteSkript org (Moderocky) 3 | * View the full licence information and permissions: 4 | * https://github.com/Moderocky/ByteSkript/blob/master/LICENSE 5 | */ 6 | 7 | package org.byteskript.skript.test; 8 | 9 | import mx.kenzie.foundation.language.PostCompileClass; 10 | 11 | import java.io.FileOutputStream; 12 | import java.io.OutputStream; 13 | 14 | public abstract class SkriptTest { 15 | 16 | protected static void debug(final PostCompileClass source) throws Throwable { 17 | try (final OutputStream stream = 18 | new FileOutputStream(source.name() + ".class")) { 19 | stream.write(source.code()); 20 | } 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /src/test/java/org/byteskript/skript/test/TestingLibrary.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 ByteSkript org (Moderocky) 3 | * View the full licence information and permissions: 4 | * https://github.com/Moderocky/ByteSkript/blob/master/LICENSE 5 | */ 6 | 7 | package org.byteskript.skript.test; 8 | 9 | import org.byteskript.skript.api.Library; 10 | import org.byteskript.skript.api.ModifiableLibrary; 11 | import org.byteskript.skript.api.syntax.Effect; 12 | import org.byteskript.skript.compiler.CompileState; 13 | import org.byteskript.skript.lang.element.StandardElements; 14 | import org.byteskript.skript.lang.handler.StandardHandlers; 15 | 16 | public final class TestingLibrary extends ModifiableLibrary { 17 | public TestingLibrary() { 18 | super("testing"); 19 | this.registerSyntax(CompileState.CODE_BODY, new ThrowException(this)); 20 | } 21 | 22 | public static class ThrowException extends Effect { 23 | 24 | public ThrowException(Library provider) { 25 | super(provider, StandardElements.EFFECT, "throw exception"); 26 | handlers.put(StandardHandlers.RUN, findMethod(ThrowException.class, "error")); 27 | } 28 | 29 | public static void error() { 30 | throw new RuntimeException("Testing error."); 31 | } 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /src/test/resources/tests/addeffect.bsk: -------------------------------------------------------------------------------- 1 | 2 | function test: 3 | trigger: 4 | set {var} to a new list 5 | add 1 to {var} 6 | add 3 to {var} 7 | assert {var} contains 1 8 | assert {var} contains 3 9 | assert ({var} contains 2) is false 10 | set {var} to 1 11 | add 1 to {var} 12 | assert {var} is 2 13 | set {_var} to 1 14 | add 1 to {_var} 15 | assert {_var} is 2 16 | delete {_var} 17 | set {@var} to 1 18 | add 1 to {@var} 19 | assert {@var} is 2 20 | set {!var} to 1 21 | add 1 to {!var} 22 | assert {!var} is 2 23 | delete {!var} 24 | return true 25 | -------------------------------------------------------------------------------- /src/test/resources/tests/anyloadevent.bsk: -------------------------------------------------------------------------------- 1 | 2 | on any load: 3 | trigger: 4 | set {!any} to 5 5 | 6 | function test: 7 | trigger: 8 | while {!any} is not 5: 9 | wait 1 millisecond 10 | assert {!any} is 5 11 | return true 12 | -------------------------------------------------------------------------------- /src/test/resources/tests/asserteffect.bsk: -------------------------------------------------------------------------------- 1 | 2 | function test: 3 | trigger: 4 | assert 1 is 1 5 | assert true is true 6 | assert true is not false 7 | assert 1 is not 2 8 | assert true is true: "Assertion failed." 9 | return true 10 | -------------------------------------------------------------------------------- /src/test/resources/tests/binaryotherwise.bsk: -------------------------------------------------------------------------------- 1 | 2 | function box: 3 | trigger: 4 | assert false 5 | return 5 6 | 7 | function test: 8 | trigger: 9 | set {var} to 10 ? 5 10 | assert {var} is 10 11 | set {var} to null ? 5 12 | assert {var} is 5 13 | assert (10 ? 5) is 10 14 | assert (null ? 5) is 5 15 | set {var} to 10 ? box() 16 | assert {var} is 10 17 | set {var} to {blob} otherwise "hello" 18 | assert {var} is "hello": "Binary otherwise (long form) failed." 19 | set {var} to "goodbye" otherwise "hello" 20 | assert {var} is "goodbye": "Binary otherwise (long form) failed." 21 | set {var} to "bean" ? "hello" 22 | assert {var} is "bean": "Binary otherwise (short form) failed." 23 | set {var} to null ? "hello" 24 | assert {var} is "hello": "Binary otherwise (short form) failed." 25 | assert ("hi" ? "bye") is "hi": "Binary otherwise (short form) failed." 26 | assert (null ? "bye") is "bye": "Binary otherwise (short form) failed." 27 | assert (null ? null) is null: "Binary otherwise (short form) failed." 28 | return true 29 | -------------------------------------------------------------------------------- /src/test/resources/tests/bracket.bsk: -------------------------------------------------------------------------------- 1 | 2 | function test: 3 | trigger: 4 | set {var} to 1 - 2 - 3 5 | assert {var} is 2: ("Var was " + {var}) 6 | set {var} to (1 - (2 - 3)) 7 | assert {var} is 2: ("Var was " + {var}) 8 | set {var} to ((1 - 2) - 3) 9 | assert {var} is -4: ("Var was " + {var}) 10 | return true 11 | -------------------------------------------------------------------------------- /src/test/resources/tests/breakeffect.bsk: -------------------------------------------------------------------------------- 1 | 2 | function test: 3 | trigger: 4 | set {var} to 0 5 | while true is true: 6 | add 1 to {var} 7 | if {var} is 2: 8 | assert false: "Break effect test failed." 9 | stop 10 | break section 11 | if 1 is 1: 12 | break section 13 | assert false: "Break effect test failed." 14 | assert true 15 | return true 16 | -------------------------------------------------------------------------------- /src/test/resources/tests/breakifeffect.bsk: -------------------------------------------------------------------------------- 1 | function test: 2 | trigger: 3 | set {var} to 0 4 | while true is true: 5 | add 1 to {var} 6 | if {var} is 2: 7 | assert false: "Break-if effect test failed." 8 | exit section if {var} is 1 9 | assert false: "Break-if effect test failed." 10 | assert true 11 | return true 12 | -------------------------------------------------------------------------------- /src/test/resources/tests/breakloopeffect.bsk: -------------------------------------------------------------------------------- 1 | function test: 2 | trigger: 3 | set {var} to 0 4 | while true is true: 5 | add 1 to {var} 6 | if {var} is 2: 7 | assert false: "Exit loop test failed." 8 | exit loop 9 | assert false 10 | assert true 11 | loop 10 times: 12 | assert true 13 | exit loop 14 | assert false 15 | set {var} to a new list 16 | add 1 to {var} 17 | loop {thing} in {var}: 18 | assert {thing} exists 19 | exit loop 20 | assert false 21 | assert true 22 | return true 23 | -------------------------------------------------------------------------------- /src/test/resources/tests/clearlist.bsk: -------------------------------------------------------------------------------- 1 | 2 | function test: 3 | trigger: 4 | set {var} to a new list 5 | add 1 to {var} 6 | assert {var} contains 1 7 | clear {var} 8 | assert {var} exists 9 | assert {var} is a list 10 | assert ({var} contains 1) is false 11 | return true 12 | -------------------------------------------------------------------------------- /src/test/resources/tests/compiler.bsk: -------------------------------------------------------------------------------- 1 | 2 | function test: 3 | trigger: 4 | assert the compiler exists 5 | return true 6 | -------------------------------------------------------------------------------- /src/test/resources/tests/configcreator.bsk: -------------------------------------------------------------------------------- 1 | 2 | function test: 3 | trigger: 4 | assert a new config exists 5 | set {var} to a new config 6 | assert {var} exists 7 | assert {var} is an object 8 | delete hello.csk 9 | return true 10 | -------------------------------------------------------------------------------- /src/test/resources/tests/configfile.bsk: -------------------------------------------------------------------------------- 1 | 2 | function old: 3 | trigger: 4 | set {conf} to hello.csk: 5 | add "key: bean" to {conf} 6 | assert "key" from {conf} is "bean" 7 | add "key: value" to {conf} 8 | assert "key" from {conf} is "value" 9 | set "thing" from {conf} to "hello there!" 10 | assert "thing" from {conf} is "hello there!" 11 | delete hello.csk 12 | set {conf2} to a new config 13 | add "key: bean" to {conf2} 14 | assert "key" from {conf2} is "bean" 15 | save config {conf2} to hello.csk 16 | set {conf} to hello.csk 17 | assert "key" from {conf} is "bean" 18 | delete hello.csk 19 | 20 | function test: 21 | trigger: 22 | assert hello.csk exists 23 | set {config} to hello.csk: 24 | add "hello: there" to {config} 25 | assert {config} exists 26 | delete {config} 27 | delete hello.csk 28 | run old() 29 | return true 30 | 31 | -------------------------------------------------------------------------------- /src/test/resources/tests/contains.bsk: -------------------------------------------------------------------------------- 1 | 2 | function test: 3 | trigger: 4 | assert "hello" contains "h": "Contains string part failed." 5 | assert "hello" contains "ello": "Contains string part failed." 6 | assert "hello" contains "hello": "Contains string self failed." 7 | assert "hello" contains "there" is false: "Contains string incorrectly succeeded." 8 | assert "hello" contains "helo" is false: "Contains string incorrectly succeeded." 9 | assert (1, 2, 3) contains 1: "Contains array failed." 10 | assert (1, 2, 3) contains 3: "Contains array failed." 11 | assert (1, 2, 3) contains 4 is false: "Contains array failed." 12 | set {list} to a new list 13 | add 1 to {list} 14 | add 2 to {list} 15 | assert {list} contains 1: "Contains list failed." 16 | assert {list} contains 2: "Contains list failed." 17 | assert {x} contains {x} is false: "Nothing contains nothing." 18 | return true 19 | -------------------------------------------------------------------------------- /src/test/resources/tests/continueeffect.bsk: -------------------------------------------------------------------------------- 1 | 2 | function test: 3 | trigger: 4 | set {var} to 0 5 | loop 2 times: 6 | continue loop 7 | assert false 8 | assert true 9 | set {var} to 0 10 | while {var} < 5: 11 | assert true 12 | add 1 to {var} 13 | continue loop 14 | assert false 15 | assert {var} is 5 16 | return true 17 | -------------------------------------------------------------------------------- /src/test/resources/tests/conversion.bsk: -------------------------------------------------------------------------------- 1 | 2 | function test: 3 | trigger: 4 | set {thing} to "10" 5 | set {number} to {thing} as an integer 6 | assert {number} is a number 7 | set {number} to {thing} as a number 8 | assert {number} is a number 9 | set {thing} to {number} as a string 10 | assert {thing} is a string 11 | set {thing} to "java.lang.Object" as a class 12 | assert {thing} is a class 13 | set {thing} to {thing} as a string 14 | assert {thing} is a string 15 | return true 16 | -------------------------------------------------------------------------------- /src/test/resources/tests/currentevent.bsk: -------------------------------------------------------------------------------- 1 | 2 | on load: 3 | trigger: 4 | set {!event} to the current event 5 | assert event exists 6 | assert event-script is "skript.currentevent" 7 | 8 | function test: 9 | trigger: 10 | while {!event} is null: 11 | wait 1 millisecond 12 | assert {!event} exists 13 | return true 14 | -------------------------------------------------------------------------------- /src/test/resources/tests/currentscript.bsk: -------------------------------------------------------------------------------- 1 | 2 | function test: 3 | trigger: 4 | assert the current script exists 5 | assert name of script exists 6 | assert name of script is "currentscript" 7 | return true 8 | -------------------------------------------------------------------------------- /src/test/resources/tests/customsyntax.bsk: -------------------------------------------------------------------------------- 1 | 2 | function test_effect(string, number): 3 | syntax: 4 | effect: my [cool] %String% and %Number% 5 | trigger: 6 | assert {string} is "hello" 7 | assert {number} is 5 8 | 9 | function test_expression(string): 10 | syntax: 11 | expression: a [cool] %String% 12 | mode: get 13 | trigger: 14 | return "hello" 15 | 16 | function test_set_property(thing, string): 17 | syntax: 18 | property: prop 19 | mode: set 20 | trigger: 21 | print "hello" 22 | 23 | function test_get_property(thing): 24 | syntax: 25 | property: prop 26 | mode: get 27 | return: String 28 | trigger: 29 | return "hello" 30 | 31 | function test: 32 | trigger: 33 | return true 34 | -------------------------------------------------------------------------------- /src/test/resources/tests/deleteeffect.bsk: -------------------------------------------------------------------------------- 1 | 2 | function test: 3 | trigger: 4 | set {var} to "hello" 5 | assert {var} is "hello" 6 | delete {var} 7 | assert {var} is not "hello" 8 | set {_var} to "hello" 9 | assert {_var} is "hello" 10 | delete {_var} 11 | assert {_var} is not "hello" 12 | set {@var} to 10 13 | assert {@var} is 10 14 | delete {@var} 15 | assert {@var} exists is false 16 | return true 17 | -------------------------------------------------------------------------------- /src/test/resources/tests/dictionary.bsk: -------------------------------------------------------------------------------- 1 | dictionary: 2 | import type java/util/Objects 3 | import type java/lang/System 4 | import function "equals" from java/util/Objects 5 | use unsafe 6 | 7 | function test: 8 | trigger: 9 | set {var} to nanoTime() from System 10 | assert {var} > 0 11 | set {var} to equals("hello", "there") from Objects 12 | assert {var} is false 13 | set {var} to equals("hello", "hello") from Objects 14 | assert {var} is true 15 | assert get_runtime() exists 16 | return true 17 | -------------------------------------------------------------------------------- /src/test/resources/tests/dynamicfunction.bsk: -------------------------------------------------------------------------------- 1 | 2 | function box(a, b): 3 | trigger: 4 | set {!var} to {a} + {b} 5 | 6 | function box: 7 | trigger: 8 | set {!var} to 10 9 | 10 | function test: 11 | trigger: 12 | set {!var} to 1 13 | assert {!var} is 1 14 | run function "box()" 15 | assert {!var} is 10 16 | set {!var} to 1 17 | assert {!var} is 1 18 | run function "box() from skript/dynamicfunction" 19 | assert {!var} is 10 20 | run function "box(a, b) from skript/dynamicfunction" with (2, 3) 21 | assert {!var} is 5 22 | run function "box(a, b)" with (3, 3) 23 | assert {!var} is 6 24 | delete {!var} 25 | return true 26 | -------------------------------------------------------------------------------- /src/test/resources/tests/every.bsk: -------------------------------------------------------------------------------- 1 | 2 | every 5 minutes: // parse test only 3 | trigger: 4 | assert true 5 | 6 | function test: 7 | trigger: 8 | return true 9 | -------------------------------------------------------------------------------- /src/test/resources/tests/exists.bsk: -------------------------------------------------------------------------------- 1 | 2 | function test: 3 | trigger: 4 | assert "hello" exists: "Exists check failed." 5 | assert "" exists: "Exists check failed." 6 | assert {x} exists is false: "Exists check failed." 7 | assert true exists: "Exists check failed." 8 | assert false exists: "Exists check failed." 9 | set {var} to true 10 | assert {var} exists: "Exists check failed." 11 | assert 1 exists: "Exists check failed." 12 | assert (1, 2, 3) exists: "Exists check failed." 13 | return true 14 | -------------------------------------------------------------------------------- /src/test/resources/tests/extends.bsk: -------------------------------------------------------------------------------- 1 | 2 | type Square: 3 | function something: 4 | return: String 5 | trigger: 6 | return "hello" 7 | 8 | type Box: 9 | extend: Square 10 | 11 | function test: 12 | trigger: 13 | set {var} to a new Box 14 | assert {var} is a Box 15 | assert {var} is a Square 16 | set {var} to a new Square 17 | assert {var} is a Square 18 | return true 19 | -------------------------------------------------------------------------------- /src/test/resources/tests/externalfunction.bsk: -------------------------------------------------------------------------------- 1 | 2 | function box(a, b): 3 | trigger: 4 | set {!var} to {a} + {b} 5 | 6 | function box: 7 | trigger: 8 | set {!var} to 10 9 | 10 | function test: 11 | trigger: 12 | set {!var} to 1 13 | assert {!var} is 1 14 | run box() from skript/externalfunction 15 | assert {!var} is 10 16 | run box(2, 3) from skript/externalfunction 17 | assert {!var} is 5 18 | delete {!var} 19 | return true 20 | -------------------------------------------------------------------------------- /src/test/resources/tests/finalmember.bsk: -------------------------------------------------------------------------------- 1 | 2 | type Box: 3 | property test: 4 | final: true 5 | 6 | function test: 7 | trigger: 8 | set {var} to a new box 9 | assert {var} exists 10 | assert {var} is a box 11 | try: 12 | set test of {var} to "hello" 13 | catch {error}: 14 | assert {error} exists 15 | return true 16 | -------------------------------------------------------------------------------- /src/test/resources/tests/functionexpression.bsk: -------------------------------------------------------------------------------- 1 | 2 | function box(@a, b): 3 | trigger: 4 | set {@a} to {b} 5 | return 3 6 | 7 | function box: 8 | trigger: 9 | return 10 10 | 11 | function test: 12 | trigger: 13 | assert box() is 10 14 | run box() 15 | assert box(3, 4) is 3 16 | set {@var} to 5 17 | assert box({@var}, 2) is 3 18 | assert {@var} is 2 19 | set {result} to varArgs("hello") from org/byteskript/skript/test/SyntaxTest 20 | assert {result} is false 21 | set {result} to varArgs("hello", "there") from org/byteskript/skript/test/SyntaxTest 22 | assert {result} is false 23 | set {result} to varArgs("hello", "there", "general", "kenobi") from org/byteskript/skript/test/SyntaxTest 24 | assert {result} is true 25 | return true 26 | -------------------------------------------------------------------------------- /src/test/resources/tests/functionmember.bsk: -------------------------------------------------------------------------------- 1 | 2 | function box(@a, b): 3 | return: integer 4 | trigger: 5 | set {@a} to {b} 6 | return 3 7 | 8 | function box: 9 | return: integer 10 | trigger: 11 | return 10 12 | 13 | function test: 14 | trigger: 15 | assert box() is 10 16 | run box() 17 | assert box(3, 4) is 3 18 | set {@var} to 5 19 | assert box({@var}, 2) is 3 20 | assert {@var} is 2 21 | return true 22 | -------------------------------------------------------------------------------- /src/test/resources/tests/globalvariable.bsk: -------------------------------------------------------------------------------- 1 | 2 | function test: 3 | trigger: 4 | set {thread} to the current thread 5 | set {!var} to 1 6 | assert {!var} is 1: "Global variable retrieval failed." 7 | set {!var} to {!var} + 1 8 | assert {!var} is 2: "Global variable set failed." 9 | assert {!var} exists: "Global variable exists check failed." 10 | set {!blob} to 3 11 | assert {!blob} is 3: "Global variable retrieval failed." 12 | delete {!blob} 13 | assert {!blob} is null: "Global variable deletion failed." 14 | run a new runnable: 15 | assert {!var} is 2: "Global variable access from runnable failed." 16 | run a new runnable in the background: 17 | assert {!var} is 2: "Global variable access from background thread failed." 18 | wait 1 ms 19 | wake {thread} 20 | sleep 21 | delete {!var} 22 | return true 23 | -------------------------------------------------------------------------------- /src/test/resources/tests/greaterthan.bsk: -------------------------------------------------------------------------------- 1 | 2 | function test: 3 | trigger: 4 | assert 4 > 3: "Greater than smaller check failed." 5 | assert (4 > 4) is false: "Greater than self check failed." 6 | assert (4 > 5) is false: "Greater than larger check failed." 7 | assert 5 > -2: "Greater than negative check failed." 8 | return true 9 | -------------------------------------------------------------------------------- /src/test/resources/tests/greaterthanequalto.bsk: -------------------------------------------------------------------------------- 1 | 2 | function test: 3 | trigger: 4 | assert 4 >= 3: "Greater than smaller check failed." 5 | assert (4 >= 4): "Greater than self check failed." 6 | assert (4 >= 5) is false: "Greater than larger check failed." 7 | assert 5 >= -2: "Greater than negative check failed." 8 | return true 9 | -------------------------------------------------------------------------------- /src/test/resources/tests/if.bsk: -------------------------------------------------------------------------------- 1 | 2 | function test: 3 | trigger: 4 | set {var} to 0 5 | if {var} is 1: 6 | assert false 7 | if {var} > 0: 8 | assert false 9 | else: 10 | assert true 11 | add 1 to {var} 12 | if {var} is 0: 13 | assert false 14 | else: 15 | add 1 to {var} 16 | assert {var} is 2 17 | if {var} < 2: 18 | assert false 19 | else if {var} is 2: 20 | assert true 21 | add 1 to {var} 22 | else: 23 | assert false 24 | assert {var} is 3 25 | if {var} > 2: 26 | if {var} is 3: 27 | assert true 28 | add 1 to {var} 29 | else: 30 | assert false 31 | else: 32 | assert false 33 | assert {var} is 4 34 | if {var} is 4: 35 | if {var} is 4: 36 | assert true 37 | add 1 to {var} 38 | assert {var} is 5 39 | return true 40 | -------------------------------------------------------------------------------- /src/test/resources/tests/implicitarray.bsk: -------------------------------------------------------------------------------- 1 | 2 | function test: 3 | trigger: 4 | set {var} to (1, 2, 3) 5 | assert {var} contains 1 6 | try: 7 | add 1 to {var} 8 | catch {error}: 9 | assert {error} exists 10 | loop {number} in (1, 2, 3): 11 | assert {number} exists 12 | return true 13 | -------------------------------------------------------------------------------- /src/test/resources/tests/importfunction.bsk: -------------------------------------------------------------------------------- 1 | dictionary: 2 | import type java/util/Objects 3 | import function "equals" from java/util/Objects 4 | import type java/lang/System 5 | import function "nanoTime" from System 6 | 7 | function test: 8 | trigger: 9 | set {var} to nanoTime() 10 | assert {var} > 0 11 | set {var} to equals("hello", "there") 12 | assert {var} is false 13 | set {var} to equals("hello", "hello") 14 | assert {var} is true 15 | return true 16 | -------------------------------------------------------------------------------- /src/test/resources/tests/importtype.bsk: -------------------------------------------------------------------------------- 1 | dictionary: 2 | import type java/util/Objects 3 | import type java/lang/System 4 | import function "equals" from java/util/Objects 5 | 6 | function test: 7 | trigger: 8 | set {var} to nanoTime() from System 9 | assert {var} > 0 10 | set {var} to equals("hello", "there") from Objects 11 | assert {var} is false 12 | set {var} to equals("hello", "hello") from Objects 13 | assert {var} is true 14 | return true 15 | -------------------------------------------------------------------------------- /src/test/resources/tests/indexinlist.bsk: -------------------------------------------------------------------------------- 1 | 2 | function test: 3 | trigger: 4 | set {var} to a new list 5 | add 1 to {var} 6 | assert {var} contains 1 7 | assert index 0 in {var} is 1 8 | add "hello" to {var} 9 | assert index 1 in {var} is "hello" 10 | set index 1 in {var} to "hello there" 11 | assert index 1 in {var} is "hello there" 12 | return true 13 | -------------------------------------------------------------------------------- /src/test/resources/tests/io.bsk: -------------------------------------------------------------------------------- 1 | 2 | function test: 3 | trigger: 4 | set {file} to a new file at "test.txt" 5 | assert "" + {file} is "test.txt": "File name is wrong." 6 | set the contents of {file} to "hello there" 7 | assert the contents of {file} is "hello there": "File contents set/retrieval failed." 8 | set {writer} to writer of {file} 9 | write "general kenobi" to {writer} 10 | close {writer} 11 | set {reader} to reader of {file} 12 | set {line} to line of {reader} 13 | assert {line} is "general kenobi": "File read/write by stream failed." 14 | close {reader} 15 | delete file {file} 16 | return true 17 | 18 | -------------------------------------------------------------------------------- /src/test/resources/tests/isarray.bsk: -------------------------------------------------------------------------------- 1 | 2 | function test: 3 | trigger: 4 | assert (1, 2, 3) is an array: "Is array check failed." 5 | set {var1} to (1, 2, 3) 6 | assert {var1} is an array: "Is array check failed." 7 | assert ({x} is an array) is false: "Is array check failed." 8 | return true 9 | -------------------------------------------------------------------------------- /src/test/resources/tests/isequal.bsk: -------------------------------------------------------------------------------- 1 | 2 | function test: 3 | trigger: 4 | assert {x} is {x}: "Equality check failed." 5 | assert (1, 2, 3) is (1, 2, 3): "Equality check failed." 6 | assert "hello" is "hello": "Equality check failed." 7 | assert ("hello" is "there") is false: "Equality check failed." 8 | assert 1 is 1: "Equality check failed." 9 | assert (1 is 2) is false: "Equality check failed." 10 | assert -1 is -1: "Equality check failed." 11 | assert 1 is 1.0: "Equality check failed." 12 | assert 1.0 is 1: "Equality check failed." 13 | set {var} to "hello" 14 | assert {var} is "hello": "Equality check failed." 15 | assert ({var} is "there") is false: "Equality check failed." 16 | assert ({var} is {x}) is false: "Equality check failed." 17 | assert 1 = 1 18 | return true 19 | -------------------------------------------------------------------------------- /src/test/resources/tests/isoftype.bsk: -------------------------------------------------------------------------------- 1 | 2 | template type Legume: 3 | function empty_func: 4 | 5 | template type Pulse: 6 | template: Legume 7 | 8 | type Bean: 9 | template: Pulse 10 | 11 | function test: 12 | trigger: 13 | assert "hello" is a string: "Type check failed." 14 | assert "hello" is an object: "Type check failed." 15 | assert 1 is a number: "Type check failed." 16 | assert 1 is an integer: "Type check failed." 17 | assert -1 is an integer: "Type check failed." 18 | assert 1.0 is a number: "Type check failed." 19 | assert 1.0 is a double: "Type check failed." 20 | set {var} to "hello" 21 | assert {var} is a string: "Type check failed." 22 | set {bean} to a new bean 23 | assert {bean} is a bean: "Type check failed." 24 | assert {bean} is a pulse: "Type check failed." 25 | assert {bean} is a legume: "Type check failed." 26 | return true 27 | -------------------------------------------------------------------------------- /src/test/resources/tests/javaversion.bsk: -------------------------------------------------------------------------------- 1 | 2 | function test: 3 | trigger: 4 | assert the java version exists 5 | return true 6 | -------------------------------------------------------------------------------- /src/test/resources/tests/keyinconfig.bsk: -------------------------------------------------------------------------------- 1 | 2 | function test: 3 | trigger: 4 | assert hello.csk exists 5 | set {config} to hello.csk: 6 | add "hello: there" to {config} 7 | assert "hello" from config {config} is "there" 8 | set {var} to "hello" from config {config} 9 | assert {var} is a string 10 | assert {var} is "there" 11 | assert {config} exists 12 | delete {config} 13 | delete hello.csk 14 | return true 15 | -------------------------------------------------------------------------------- /src/test/resources/tests/keyinmap.bsk: -------------------------------------------------------------------------------- 1 | 2 | function test: 3 | trigger: 4 | set {var} to a new map 5 | set "blob" in {var} to 1 6 | assert "blob" in {var} is 1 7 | set 3 in {var} to 2 8 | assert 3 in {var} is 2 9 | assert size of {var} is 2 10 | return true 11 | -------------------------------------------------------------------------------- /src/test/resources/tests/lemma.bsk: -------------------------------------------------------------------------------- 1 | 2 | function test: 3 | trigger: 4 | assert true 5 | return true 6 | -------------------------------------------------------------------------------- /src/test/resources/tests/lessthan.bsk: -------------------------------------------------------------------------------- 1 | 2 | function test: 3 | trigger: 4 | assert 3 < 4: "Less than greater check failed." 5 | assert (4 < 4) is false: "Less than self check failed." 6 | assert (5 < 4) is false: "Less than smaller check failed." 7 | assert -2 < 5: "Less than negative check failed." 8 | assert -3 < -2: "Less than negative check failed." 9 | return true 10 | -------------------------------------------------------------------------------- /src/test/resources/tests/lessthanequalto.bsk: -------------------------------------------------------------------------------- 1 | 2 | function test: 3 | trigger: 4 | assert 3 <= 4: "Less than greater check failed." 5 | assert (4 <= 4): "Less than self check failed." 6 | assert (5 <= 4) is false: "Less than smaller check failed." 7 | assert -2 <= 5: "Less than negative check failed." 8 | assert -3 <= -2: "Less than negative check failed." 9 | return true 10 | -------------------------------------------------------------------------------- /src/test/resources/tests/literals.bsk: -------------------------------------------------------------------------------- 1 | 2 | function test: 3 | trigger: 4 | assert true is true 5 | assert false is false 6 | assert true is not false 7 | assert false is not true 8 | assert true is a boolean 9 | assert 1 is an integer 10 | assert 1 is a number 11 | assert (1.0 is an integer) is false 12 | assert 1.0 is a number 13 | assert -1 is an integer 14 | assert -1.0 is a number 15 | assert 1.0F is a float 16 | assert 1.0D is a double 17 | assert 10L is a long 18 | assert 10L is a number 19 | assert (null exists) is false 20 | assert "hello" exists 21 | assert /hello/ exists 22 | assert /.+/ exists 23 | return true 24 | -------------------------------------------------------------------------------- /src/test/resources/tests/loadedscripts.bsk: -------------------------------------------------------------------------------- 1 | 2 | function test: 3 | trigger: 4 | assert loaded scripts exists 5 | assert size of (loaded scripts) > 0 6 | set {list} to all loaded scripts 7 | assert {list} exists: "Couldn't get loaded scripts" 8 | loop {script} in {list}: 9 | assert {script} exists: "Loop extracted null-value." 10 | assert {script} exists: "Nothing was looped." 11 | return true 12 | -------------------------------------------------------------------------------- /src/test/resources/tests/loadevent.bsk: -------------------------------------------------------------------------------- 1 | 2 | on load: 3 | trigger: 4 | set {!load} to 5 5 | 6 | function test: 7 | trigger: 8 | while {!load} is not 5: 9 | wait 1 millisecond 10 | assert {!load} is 5 11 | return true 12 | -------------------------------------------------------------------------------- /src/test/resources/tests/loadscript.bsk: -------------------------------------------------------------------------------- 1 | 2 | function test: 3 | trigger: 4 | assert the compiler exists 5 | set {code} to "" 6 | load script {code} as "skript/testing/nothing" 7 | assert skript/testing/nothing exists 8 | return true 9 | -------------------------------------------------------------------------------- /src/test/resources/tests/localmember.bsk: -------------------------------------------------------------------------------- 1 | 2 | function blob: 3 | local: true 4 | trigger: 5 | return 4 6 | 7 | function test: 8 | trigger: 9 | assert blob() is 4 10 | return true 11 | -------------------------------------------------------------------------------- /src/test/resources/tests/localvariable.bsk: -------------------------------------------------------------------------------- 1 | 2 | function test: 3 | trigger: 4 | set {var} to 1 5 | assert {var} is 1: "Variable set/retrieval failed." 6 | set {var} to {var} + 1 7 | assert {var} is 2: "Variable set/retrieval failed." 8 | assert {var} exists: "Variable exists check failed." 9 | delete {var} 10 | assert {var} is null: "Variable deletion failed." 11 | return true 12 | -------------------------------------------------------------------------------- /src/test/resources/tests/loopin.bsk: -------------------------------------------------------------------------------- 1 | 2 | function bean(value): 3 | trigger: 4 | assert {value} is a string 5 | add 1 to {_var} 6 | 7 | function test: 8 | trigger: 9 | set {var} to a new list 10 | add "hello" to {var} 11 | add "there" to {var} 12 | loop {word} in {var}: 13 | assert {word} is a string 14 | assert {word} exists 15 | add 1 to {var} 16 | loop {thing} in {var}: 17 | assert {thing} exists 18 | assert {thing} is a number 19 | assert {thing} is 1 20 | loop {@thing} in {var}: 21 | assert {@thing} exists 22 | assert {@thing} is 1 23 | delete {@thing} 24 | loop {thing} in {var} 25 | assert {thing} exists 26 | assert {thing} is 1 27 | remove 1 from {var} 28 | loop bean(null) in {var} 29 | assert {_var} is 2 30 | return true 31 | -------------------------------------------------------------------------------- /src/test/resources/tests/looptimes.bsk: -------------------------------------------------------------------------------- 1 | 2 | function test: 3 | trigger: 4 | set {var} to 0 5 | loop 5 times: 6 | add 1 to {var} 7 | assert {var} is 5 8 | loop {var} times: 9 | remove 1 from {var} 10 | assert {var} is 0 11 | return true 12 | -------------------------------------------------------------------------------- /src/test/resources/tests/matches.bsk: -------------------------------------------------------------------------------- 1 | 2 | function test: 3 | trigger: 4 | assert "hello" matches /hello/ 5 | assert "hello" matches /.+/ 6 | assert "hello" matches /h.llo/ 7 | assert "hello" matches /[a-z]{5}/ 8 | assert "there" matches /[a-z]{5}/ 9 | assert ("hello" matches /[a-z]{6}/) is false 10 | set {var} to "hello there" 11 | assert ({var} matches /hello/) is false 12 | assert {var} matches /hello there/ 13 | assert {var} matches /hello .+/ 14 | assert {var} matches /[a-z]{5} [a-z]{5}/ 15 | return true 16 | -------------------------------------------------------------------------------- /src/test/resources/tests/maths.bsk: -------------------------------------------------------------------------------- 1 | 2 | function looping: 3 | trigger: 4 | set {a} to 0 5 | while {a} is less than 10: 6 | set {a} to {a} + 1 7 | exit section if {a} is 5 8 | assert {a} is less than 5: "Exit-section with condition failed." 9 | assert {a} is 5: "Section did not exit upon condition." 10 | 11 | function basic: 12 | trigger: 13 | set {a} to 2 + 2 14 | set {b} to 6 - {a} 15 | set {c} to {a} / {b} 16 | set {d} to {c} * {c} 17 | set {e} to square root of {d} 18 | assert {a} is 4: "Addition failed." 19 | assert {b} is 2: "Subtraction failed." 20 | assert {c} is 2: "Division failed." 21 | assert {d} is 4: "Multiplication failed." 22 | assert {e} is 2: "Square root (syntax) failed." 23 | assert "hello " + "there" is "hello there": "String joining failed." 24 | assert "Hello " + " 22 13 | return true 14 | -------------------------------------------------------------------------------- /src/test/resources/tests/returneffect.bsk: -------------------------------------------------------------------------------- 1 | function test: 2 | trigger: 3 | return true 4 | assert false 5 | -------------------------------------------------------------------------------- /src/test/resources/tests/returntype.bsk: -------------------------------------------------------------------------------- 1 | 2 | function bean: 3 | return: String 4 | trigger: 5 | return "hello" 6 | 7 | function blob: 8 | return: none 9 | trigger: 10 | stop 11 | 12 | function blob2: 13 | return: none 14 | trigger: 15 | assert true 16 | 17 | function test: 18 | trigger: 19 | set {var} to bean() 20 | assert {var} is a string 21 | set {var} to blob() 22 | assert {var} is null 23 | set {var} to blob2() 24 | assert {var} is null 25 | return true 26 | -------------------------------------------------------------------------------- /src/test/resources/tests/run.bsk: -------------------------------------------------------------------------------- 1 | 2 | function blob: 3 | trigger: 4 | set {_var} to 1 5 | 6 | function blob (number): 7 | trigger: 8 | set {_var} to {number} 9 | 10 | function test: 11 | trigger: 12 | set {var} to a new runnable: 13 | set {_var} to 3 14 | run {var} 15 | assert {_var} is 3 16 | run blob() 17 | assert {_var} is 1 18 | run blob(2) 19 | assert {_var} is 2 20 | return true 21 | -------------------------------------------------------------------------------- /src/test/resources/tests/runasync.bsk: -------------------------------------------------------------------------------- 1 | 2 | function blob (@var): 3 | trigger: 4 | set {@var} to 1 5 | 6 | function test: 7 | trigger: 8 | set {thread} to the current process 9 | set {@thing} to false 10 | set {var} to a new runnable: 11 | wait 1 milliseconds 12 | set {@thing} to true 13 | wake {thread} 14 | assert {@thing} is false 15 | run {var} in the background 16 | delete {@thing} 17 | assert {@thing} is null 18 | sleep 19 | assert {@thing} is true 20 | delete {@thing} 21 | set {@var} to 0 22 | set {var} to a new runnable: 23 | set {@var} to 3 24 | run {var} in the background 25 | while {@var} is not 3: 26 | wait 1 millisecond 27 | assert {@var} is 3 28 | run blob({@var}) in the background 29 | while {@var} is not 1: 30 | wait 1 millisecond 31 | assert {@var} is 1 32 | return true 33 | -------------------------------------------------------------------------------- /src/test/resources/tests/runnable.bsk: -------------------------------------------------------------------------------- 1 | 2 | function get: 3 | trigger: 4 | return a new runnable: 5 | set {_var} to 10 6 | 7 | function give (runnable): 8 | trigger: 9 | run {runnable} 10 | 11 | function test: 12 | trigger: 13 | set {@var} to 1 14 | set {_var} to 1 15 | set {!var} to 1 16 | set {lvar} to 1 17 | set {var} to a new runnable: 18 | set {@var} to 2 19 | set {_var} to 2 20 | set {!var} to 2 21 | set {lvar} to 2 22 | assert {@var} is 1 23 | assert {_var} is 1 24 | assert {!var} is 1 25 | assert {lvar} is 1 26 | run {var} 27 | assert {@var} is 2 28 | assert {_var} is 2 29 | assert {!var} is 2 30 | assert {lvar} is 1 31 | run a new runnable: 32 | set {@var} to 3 33 | set {_var} to 3 34 | set {!var} to 3 35 | set {lvar} to 3 36 | assert {@var} is 3 37 | assert {_var} is 3 38 | assert {!var} is 3 39 | assert {lvar} is 1 40 | run (result of get()) 41 | assert {_var} is 10 42 | set {var} to get() 43 | set {_var} to 1 44 | assert {_var} is 1 45 | run {var} 46 | assert {_var} is 10 47 | run give(a new runnable): 48 | set {_var} to 5 49 | assert {_var} is 5 50 | set {var} to a new runnable: 51 | set {_var} to 6 52 | run give({var}) 53 | assert {_var} is 6 54 | delete {!var} 55 | return true 56 | -------------------------------------------------------------------------------- /src/test/resources/tests/runwith.bsk: -------------------------------------------------------------------------------- 1 | 2 | 3 | function blob (a, b): 4 | trigger: 5 | set {_var} to {a} + " " + {b} 6 | 7 | function blob (number): 8 | trigger: 9 | set {_var} to {number} 10 | 11 | function test: 12 | trigger: 13 | set {func} to function "blob(number)" 14 | run {func} with 2 15 | assert {_var} is 2 16 | set {func} to function "blob(a, b)" 17 | run {func} with ("hello", "there") 18 | assert {_var} is "hello there" 19 | return true 20 | -------------------------------------------------------------------------------- /src/test/resources/tests/runwithasync.bsk: -------------------------------------------------------------------------------- 1 | 2 | function blob (var): 3 | trigger: 4 | set {!var} to {var} 5 | 6 | function test: 7 | trigger: 8 | set {func} to function "blob(@var)" 9 | run {func} with 3 in the background 10 | while {!var} is not 3: 11 | wait 1 millisecond 12 | assert {!var} is 3 13 | delete {!var} 14 | return true 15 | -------------------------------------------------------------------------------- /src/test/resources/tests/saveconfig.bsk: -------------------------------------------------------------------------------- 1 | 2 | function test: 3 | trigger: 4 | assert hello.csk exists 5 | set {config} to hello.csk 6 | add "hello: there" to {config} 7 | save config {config} to hello2.csk 8 | set {config} to hello2.csk 9 | assert "hello" from config {config} is "there" 10 | delete hello2.csk 11 | delete hello.csk 12 | return true 13 | -------------------------------------------------------------------------------- /src/test/resources/tests/seteffect.bsk: -------------------------------------------------------------------------------- 1 | 2 | function test: 3 | trigger: 4 | set {var} to "hello" 5 | assert {var} is "hello" 6 | set {var} to "there" 7 | assert {var} is "there" 8 | set {var} to null 9 | assert {var} is not "hello" 10 | set {_var} to "hello" 11 | assert {_var} is "hello" 12 | delete {_var} 13 | assert {_var} is not "hello" 14 | return true 15 | -------------------------------------------------------------------------------- /src/test/resources/tests/sizeoflist.bsk: -------------------------------------------------------------------------------- 1 | 2 | function test: 3 | trigger: 4 | set {var} to a new list 5 | add 1 to {var} 6 | assert {var} contains 1 7 | assert size of {var} is 1 8 | add "hello" to {var} 9 | assert size of {var} is 2 10 | assert size of (1, 2, 3) is 3 11 | return true 12 | -------------------------------------------------------------------------------- /src/test/resources/tests/sleep.bsk: -------------------------------------------------------------------------------- 1 | 2 | function test: 3 | trigger: 4 | set {thread} to the current process 5 | set {@thing} to false 6 | set {var} to a new runnable: 7 | wait 1 milliseconds 8 | set {@thing} to true 9 | wake {thread} 10 | assert {@thing} is false 11 | run {var} in the background 12 | delete {@thing} 13 | assert {@thing} is null 14 | sleep 15 | assert {@thing} is true 16 | delete {@thing} 17 | return true 18 | -------------------------------------------------------------------------------- /src/test/resources/tests/supplier.bsk: -------------------------------------------------------------------------------- 1 | 2 | function give (supplier): 3 | trigger: 4 | return result of {supplier} 5 | 6 | function test: 7 | trigger: 8 | set {@var} to 1 9 | set {_var} to 1 10 | set {!var} to 1 11 | set {lvar} to 1 12 | set {var} to a new supplier: 13 | set {@var} to 2 14 | set {_var} to 2 15 | set {!var} to 2 16 | set {lvar} to 2 17 | return true 18 | assert {@var} is 1 19 | assert {_var} is 1 20 | assert {!var} is 1 21 | assert {lvar} is 1 22 | assert result of {var} is true 23 | assert {@var} is 2 24 | assert {_var} is 2 25 | assert {!var} is 2 26 | assert {lvar} is 1 27 | set {x} to give(a new supplier): 28 | return 5 29 | assert {x} is 5 30 | delete {!var} 31 | return true 32 | -------------------------------------------------------------------------------- /src/test/resources/tests/systemproperty.bsk: -------------------------------------------------------------------------------- 1 | 2 | function test: 3 | trigger: 4 | set system property "blob" to "hello" 5 | set {var} to system property "blob" 6 | assert {var} is "hello": "System property setting failed." 7 | delete system property "blob" 8 | return true 9 | -------------------------------------------------------------------------------- /src/test/resources/tests/template.bsk: -------------------------------------------------------------------------------- 1 | 2 | template type Cardboard: 3 | function something: 4 | return: String 5 | 6 | template type Shape: 7 | function something: 8 | return: String 9 | 10 | type Square: 11 | template: Shape 12 | function something: 13 | return: String 14 | trigger: 15 | return "hello" 16 | 17 | type Box: 18 | extend: Square 19 | template: Cardboard 20 | 21 | function test: 22 | trigger: 23 | set {var} to a new Box 24 | assert {var} is a Box 25 | assert {var} is a Cardboard 26 | assert {var} is a Square 27 | assert {var} is a Shape 28 | set {var} to a new Square 29 | assert {var} is a Square 30 | assert {var} is a Shape 31 | return true 32 | -------------------------------------------------------------------------------- /src/test/resources/tests/templatetype.bsk: -------------------------------------------------------------------------------- 1 | 2 | template type Foo: 3 | function box: 4 | trigger: 5 | return 3 6 | 7 | type Bar: 8 | template: Foo 9 | 10 | type Cee: 11 | template: Foo 12 | function box: 13 | trigger: 14 | return 2 15 | 16 | function test: 17 | trigger: 18 | set {bar} to a new bar 19 | assert {bar} is a bar 20 | assert {bar} is a foo 21 | assert box() of {bar} is 3 22 | set {cee} to a new cee 23 | assert {cee} is a cee 24 | assert {cee} is a foo 25 | assert box() of {cee} is 2 26 | return true 27 | -------------------------------------------------------------------------------- /src/test/resources/tests/ternaryotherwise.bsk: -------------------------------------------------------------------------------- 1 | 2 | function box: 3 | trigger: 4 | assert false 5 | return 5 6 | 7 | function test: 8 | trigger: 9 | set {var} to (if "hello" is a string then "a" otherwise "b") 10 | assert {var} is "a": "Ternary otherwise (long form) failed." 11 | set {var} to (false ? "a" : "b") 12 | assert {var} is "b": "Ternary otherwise (short form) failed." 13 | set {var} to true ? 1 : 2 14 | assert {var} is 1 15 | assert (true ? 1 : 2) is 1 16 | assert (false ? 1 : 2) is 2 17 | assert (true ? 1 : box()) is 1 18 | assert (false ? box() : 2) is 2 19 | return true 20 | -------------------------------------------------------------------------------- /src/test/resources/tests/testeffect.bsk: -------------------------------------------------------------------------------- 1 | 2 | function test: 3 | trigger: 4 | set {var} to 1 5 | set system property "skript.test_mode" to "false" 6 | test: set {var} to 2 7 | assert {var} is 1 8 | set system property "skript.test_mode" to "true" 9 | test: set {var} to 2 10 | assert {var} is 2 11 | return true 12 | -------------------------------------------------------------------------------- /src/test/resources/tests/threadexpression.bsk: -------------------------------------------------------------------------------- 1 | 2 | function test: 3 | trigger: 4 | set {thread} to the current process 5 | set {@thing} to false 6 | set {var} to a new runnable: 7 | wait 1 milliseconds 8 | set {@thing} to true 9 | wake {thread} 10 | assert {@thing} is false 11 | run {var} in the background 12 | delete {@thing} 13 | assert {@thing} is null 14 | sleep 15 | assert {@thing} is true 16 | delete {@thing} 17 | return true 18 | -------------------------------------------------------------------------------- /src/test/resources/tests/threadvariable.bsk: -------------------------------------------------------------------------------- 1 | 2 | function test: 3 | trigger: 4 | set {thread} to the current thread 5 | set {_var} to 1 6 | assert {_var} is 1: "Thread variable retrieval failed." 7 | set {_var} to {_var} + 1 8 | assert {_var} is 2: "Thread variable set failed." 9 | assert {_var} exists: "Thread variable exists check failed." 10 | assert {_blob} is null: "Thread variable unset check failed." 11 | run a new runnable: 12 | assert {_var} is 2: "Thread variable access from runnable failed." 13 | wait for a new runnable: 14 | assert {_var} is null: "Thread variable access from wrong thread passed." 15 | wait for a new runnable: 16 | run copy_threadlocals_from({thread}) 17 | assert {_var} is 2: "Thread locals copying failed." 18 | delete {_var} 19 | assert {_var} is null: "Thread variable deletion failed." 20 | return true 21 | 22 | on load: 23 | trigger: 24 | assert {_var} is null: "Thread variable set at thread start." 25 | set {_var} to 10 26 | assert {_var} is 10 27 | 28 | on load: 29 | trigger: 30 | assert {_var} is null: "Thread variable set at thread start." 31 | set {_var} to 10 32 | assert {_var} is 10 33 | -------------------------------------------------------------------------------- /src/test/resources/tests/timespans.bsk: -------------------------------------------------------------------------------- 1 | 2 | function test: 3 | trigger: 4 | wait 0 milliseconds 5 | wait 0 seconds 6 | wait 0 minutes 7 | wait 0 hours 8 | wait 0 days 9 | wait 0 weeks 10 | wait 0 months 11 | wait 0 years 12 | return true 13 | -------------------------------------------------------------------------------- /src/test/resources/tests/trigger.bsk: -------------------------------------------------------------------------------- 1 | 2 | function bean: 3 | trigger: 4 | return "there" 5 | 6 | type Box: 7 | function bean: 8 | trigger: 9 | return "hello" 10 | 11 | function test: 12 | trigger: 13 | set {var} to a new Box 14 | assert {var} is a Box 15 | assert bean() of {var} is "hello" 16 | assert bean() is "there" 17 | return true 18 | -------------------------------------------------------------------------------- /src/test/resources/tests/trycatch.bsk: -------------------------------------------------------------------------------- 1 | 2 | function test: 3 | trigger: 4 | set {var} to 3 5 | try: 6 | assert {var} is 4 7 | set {var} to 4 8 | assert {var} is 3 9 | try: 10 | assert {var} is 4 11 | set {var} to 4 12 | catch {error}: 13 | set {var} to 5 14 | assert {var} is 5 15 | assert {error} exists 16 | try: 17 | assert false 18 | assert false: "Error failed to throw." 19 | catch {error}: 20 | assert true 21 | assert {error} exists: "Error not stored when caught." 22 | assert {error} exists: "Error was not caught." 23 | try: assert false 24 | delete {error} 25 | try: 26 | assert true 27 | break section 28 | assert false: "Section failed to break." 29 | catch {error}: 30 | assert false: "Catch section was run with no failed to break." 31 | assert {error} is null: "Error was erroneously set." 32 | try: 33 | assert false 34 | catch {@error} 35 | assert {@error} exists 36 | delete {@error} 37 | return true 38 | -------------------------------------------------------------------------------- /src/test/resources/tests/tryeffect.bsk: -------------------------------------------------------------------------------- 1 | 2 | function test: 3 | trigger: 4 | set {var} to 3 5 | try: assert {var} is 4 6 | try: remove "hello" from {var} 7 | assert {var} is 3 8 | return true 9 | -------------------------------------------------------------------------------- /src/test/resources/tests/typecreator.bsk: -------------------------------------------------------------------------------- 1 | 2 | type Foo: 3 | function box: 4 | trigger: 5 | return 2 6 | 7 | function test: 8 | trigger: 9 | set {foo} to a new foo 10 | assert {foo} is a foo 11 | assert box() of {foo} is 2 12 | return true 13 | -------------------------------------------------------------------------------- /src/test/resources/tests/unloadscript.bsk: -------------------------------------------------------------------------------- 1 | 2 | function test: 3 | trigger: 4 | assert the compiler exists 5 | set {code} to "" 6 | load script {code} as "skript/testing/unload" 7 | assert skript/testing/unload exists 8 | unload script skript/testing/unload 9 | return true 10 | -------------------------------------------------------------------------------- /src/test/resources/tests/verify.bsk: -------------------------------------------------------------------------------- 1 | 2 | function there: 3 | verify: 4 | assert true is true 5 | assert 1 is 1 6 | assert 1 > 0 7 | assert 0 < 1 8 | trigger: 9 | return "there" 10 | 11 | function test: 12 | trigger: 13 | assert "hello " + there() is "hello there" 14 | return true 15 | -------------------------------------------------------------------------------- /src/test/resources/tests/waitfor.bsk: -------------------------------------------------------------------------------- 1 | 2 | function test: 3 | trigger: 4 | set {thread} to the current process 5 | set {@thing} to false 6 | set {var} to a new runnable: 7 | set {@thing} to true 8 | wake {thread} 9 | wait for {var} 10 | assert {@thing} is true 11 | set {@thing} to false 12 | set {var} to a new runnable: 13 | set {@thing} to true 14 | wait for {var} 15 | assert {@thing} is true 16 | set {@thing} to false 17 | wait for a new runnable: 18 | set {@thing} to true 19 | assert {@thing} is true 20 | set {_var} to false 21 | wait for a new runnable: 22 | set {_var} to true 23 | assert {_var} is false 24 | return true 25 | -------------------------------------------------------------------------------- /src/test/resources/tests/wake.bsk: -------------------------------------------------------------------------------- 1 | 2 | function test: 3 | trigger: 4 | set {thread} to the current process 5 | set {@thing} to false 6 | set {var} to a new runnable: 7 | wait 1 milliseconds 8 | set {@thing} to true 9 | wake {thread} 10 | assert {@thing} is false 11 | run {var} in the background 12 | delete {@thing} 13 | assert {@thing} is null 14 | sleep 15 | assert {@thing} is true 16 | delete {@thing} 17 | return true 18 | -------------------------------------------------------------------------------- /src/test/resources/tests/while.bsk: -------------------------------------------------------------------------------- 1 | 2 | function test: 3 | trigger: 4 | set {var} to 0 5 | while {var} is less than 5: 6 | add 1 to {var} 7 | assert {var} is 5 8 | while 1 is 2: 9 | assert false 10 | while 1 is 1: 11 | assert true 12 | break section 13 | assert false 14 | assert true 15 | return true 16 | --------------------------------------------------------------------------------