├── .gitattributes ├── .travis.yml ├── light-core ├── src │ ├── main │ │ ├── java │ │ │ └── org │ │ │ │ └── panda_lang │ │ │ │ └── light │ │ │ │ ├── LightConstants.java │ │ │ │ ├── framework │ │ │ │ ├── design │ │ │ │ │ ├── architecture │ │ │ │ │ │ ├── linguistic │ │ │ │ │ │ │ ├── LinguisticGroup.java │ │ │ │ │ │ │ ├── LinguisticAct.java │ │ │ │ │ │ │ ├── LinguisticUtils.java │ │ │ │ │ │ │ ├── type │ │ │ │ │ │ │ │ ├── TypeSerializer.java │ │ │ │ │ │ │ │ ├── TypeTransformer.java │ │ │ │ │ │ │ │ ├── TypeResolver.java │ │ │ │ │ │ │ │ └── Type.java │ │ │ │ │ │ │ ├── LinguisticExpression.java │ │ │ │ │ │ │ ├── ContextComponent.java │ │ │ │ │ │ │ ├── phraseme │ │ │ │ │ │ │ │ └── Phraseme.java │ │ │ │ │ │ │ └── Context.java │ │ │ │ │ │ └── value │ │ │ │ │ │ │ ├── TypeValue.java │ │ │ │ │ │ │ └── LightTypeValue.java │ │ │ │ │ └── interpreter │ │ │ │ │ │ ├── lexer │ │ │ │ │ │ ├── LightLexer.java │ │ │ │ │ │ ├── IndentationLexer.java │ │ │ │ │ │ ├── AbstractLexer.java │ │ │ │ │ │ ├── LightLexerWorker.java │ │ │ │ │ │ ├── IndentationLexerWorker.java │ │ │ │ │ │ ├── DefaultLightLexer.java │ │ │ │ │ │ ├── LightLineBuilder.java │ │ │ │ │ │ ├── IndentationLexerConverter.java │ │ │ │ │ │ ├── DefaultLightLexerWorker.java │ │ │ │ │ │ └── IndentationLexerTree.java │ │ │ │ │ │ ├── token │ │ │ │ │ │ ├── Sentence.java │ │ │ │ │ │ └── SentenceRepresentation.java │ │ │ │ │ │ ├── pattern │ │ │ │ │ │ └── linguistic │ │ │ │ │ │ │ ├── LinguisticWildcardProcessor.java │ │ │ │ │ │ │ ├── LinguisticPatternCompiler.java │ │ │ │ │ │ │ ├── LinguisticPatternResult.java │ │ │ │ │ │ │ ├── LinguisticPatternBuilder.java │ │ │ │ │ │ │ ├── LinguisticCandidate.java │ │ │ │ │ │ │ ├── LinguisticPattern.java │ │ │ │ │ │ │ └── LinguisticExtractor.java │ │ │ │ │ │ ├── parser │ │ │ │ │ │ ├── LightParserException.java │ │ │ │ │ │ └── LightComponents.java │ │ │ │ │ │ └── source │ │ │ │ │ │ ├── LightSourceStream.java │ │ │ │ │ │ └── LightTokenizedSource.java │ │ │ │ └── language │ │ │ │ │ ├── architecture │ │ │ │ │ ├── linguistic │ │ │ │ │ │ ├── phraseme │ │ │ │ │ │ │ ├── PhrasemeLoaderUtils.java │ │ │ │ │ │ │ ├── loader │ │ │ │ │ │ │ │ ├── annotations │ │ │ │ │ │ │ │ │ ├── PhrasemeVariant.java │ │ │ │ │ │ │ │ │ ├── Id.java │ │ │ │ │ │ │ │ │ ├── PhrasemeGroup.java │ │ │ │ │ │ │ │ │ └── PhrasemeRepresentation.java │ │ │ │ │ │ │ │ ├── PhrasemesLoader.java │ │ │ │ │ │ │ │ ├── PhrasemeMethodLoader.java │ │ │ │ │ │ │ │ ├── PhrasemeRepresentationLoader.java │ │ │ │ │ │ │ │ └── PhrasemeGroupLoader.java │ │ │ │ │ │ │ ├── PhrasemeCallback.java │ │ │ │ │ │ │ ├── LightPhrasemeLinguisticExpression.java │ │ │ │ │ │ │ ├── LightPhraseme.java │ │ │ │ │ │ │ └── Phrasemes.java │ │ │ │ │ │ ├── LinguisticStatement.java │ │ │ │ │ │ ├── LightContextTypeLookup.java │ │ │ │ │ │ ├── LightContextUtils.java │ │ │ │ │ │ ├── LightWildcardProcessor.java │ │ │ │ │ │ ├── type │ │ │ │ │ │ │ ├── LightType.java │ │ │ │ │ │ │ ├── resolvers │ │ │ │ │ │ │ │ └── TransformerTypeResolver.java │ │ │ │ │ │ │ ├── LightTypeBuilder.java │ │ │ │ │ │ │ └── Types.java │ │ │ │ │ │ ├── LightLinguisticGroup.java │ │ │ │ │ │ └── LightContext.java │ │ │ │ │ ├── LightScript.java │ │ │ │ │ ├── LightEnvironment.java │ │ │ │ │ └── LightApplication.java │ │ │ │ │ ├── resource │ │ │ │ │ ├── phrasemes │ │ │ │ │ │ ├── TestPhrasemes.java │ │ │ │ │ │ └── ConsolePhraseme.java │ │ │ │ │ ├── DefaultLightPhrasemes.java │ │ │ │ │ ├── LightSyntax.java │ │ │ │ │ └── DefaultLightTypes.java │ │ │ │ │ ├── interpreter │ │ │ │ │ ├── parser │ │ │ │ │ │ ├── LightPriorities.java │ │ │ │ │ │ ├── LightPipelines.java │ │ │ │ │ │ ├── scope │ │ │ │ │ │ │ ├── main │ │ │ │ │ │ │ │ ├── MainScopeParserHandler.java │ │ │ │ │ │ │ │ ├── MainScope.java │ │ │ │ │ │ │ │ ├── MainInstance.java │ │ │ │ │ │ │ │ └── MainScopeParser.java │ │ │ │ │ │ │ ├── ScopeParserHandler.java │ │ │ │ │ │ │ ├── ScopeComponents.java │ │ │ │ │ │ │ └── ScopeParser.java │ │ │ │ │ │ └── defaults │ │ │ │ │ │ │ ├── SentenceParser.java │ │ │ │ │ │ │ ├── ContentParser.java │ │ │ │ │ │ │ └── ApplicationParser.java │ │ │ │ │ └── LightInterpreter.java │ │ │ │ │ └── LightLanguage.java │ │ │ │ ├── LightException.java │ │ │ │ ├── LightLogger.java │ │ │ │ ├── LightCore.java │ │ │ │ └── LightLoader.java │ │ └── resources │ │ │ └── log4j2.xml │ └── test │ │ └── java │ │ └── org │ │ └── panda_lang │ │ └── light │ │ ├── framework │ │ ├── design │ │ │ └── interpreter │ │ │ │ ├── lexer │ │ │ │ ├── IndentationLexerTest.java │ │ │ │ ├── LightLexerTest.java │ │ │ │ └── MultilineLexerTest.java │ │ │ │ └── pattern │ │ │ │ └── linguistic │ │ │ │ └── LexicalPatternTest.java │ │ └── language │ │ │ └── interpreter │ │ │ └── pattern │ │ │ └── PhrasemeMatcherTest.java │ │ └── LightTest.java └── pom.xml ├── examples ├── lexer │ ├── indentation.light │ └── multiline_test.light ├── current_test.light └── concept.light ├── light ├── src │ ├── main │ │ └── java │ │ │ └── org │ │ │ └── panda_lang │ │ │ └── light │ │ │ └── Light.java │ └── test │ │ └── java │ │ └── org │ │ └── panda_lang │ │ └── light │ │ └── LightLauncherTest.java └── pom.xml ├── notes └── concepts.txt ├── .gitignore ├── README.md ├── pom.xml └── LICENSE /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: java 2 | sudo: true 3 | 4 | jdk: 5 | - openjdk8 6 | - openjdk10 7 | 8 | notifications: 9 | email: false 10 | -------------------------------------------------------------------------------- /light-core/src/main/java/org/panda_lang/light/LightConstants.java: -------------------------------------------------------------------------------- 1 | package org.panda_lang.light; 2 | 3 | public class LightConstants { 4 | 5 | public static final String VERSION = "indev-18.10.6"; 6 | 7 | } 8 | -------------------------------------------------------------------------------- /light-core/src/main/java/org/panda_lang/light/framework/design/architecture/linguistic/LinguisticGroup.java: -------------------------------------------------------------------------------- 1 | package org.panda_lang.light.framework.design.architecture.linguistic; 2 | 3 | public interface LinguisticGroup extends LinguisticAct { 4 | 5 | LinguisticAct select(LinguisticAct... parameters); 6 | 7 | } 8 | -------------------------------------------------------------------------------- /examples/lexer/indentation.light: -------------------------------------------------------------------------------- 1 | @ legacy indentation 2 | 3 | statement 1 4 | statement 2 5 | 6 | main: 7 | statement 3 8 | 9 | foreach statement: 10 | statement 4 11 | 12 | statement 5 13 | 14 | if statement 6: 15 | statement 7 16 | 17 | function 1: 18 | statement 8 19 | 20 | statement 9 -------------------------------------------------------------------------------- /examples/lexer/multiline_test.light: -------------------------------------------------------------------------------- 1 | main { 2 | send > 3 | "Hello Light" > 4 | to console 5 | } 6 | 7 | main { 8 | send 9 | > "Hello Light" 10 | > to console 11 | } 12 | 13 | main { 14 | send > 15 | > "Hello Light" 16 | > to console 17 | } 18 | 19 | main { 20 | send > 21 | "Hello Light" to console 22 | } 23 | -------------------------------------------------------------------------------- /light-core/src/main/java/org/panda_lang/light/framework/language/architecture/linguistic/phraseme/PhrasemeLoaderUtils.java: -------------------------------------------------------------------------------- 1 | package org.panda_lang.light.framework.language.architecture.linguistic.phraseme; 2 | 3 | class PhrasemeLoaderUtils { 4 | 5 | static Object[] cast(Object[] parameters, Class[] types) { 6 | for (int i = 0; i < parameters.length; i++) { 7 | parameters[i] = types[i].cast(parameters[i]); 8 | } 9 | 10 | return parameters; 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /examples/current_test.light: -------------------------------------------------------------------------------- 1 | main: 2 | // Print type 3 | send "Hello Light" to console 4 | 5 | // Print type 6 | send true to the console 7 | 8 | // Print phraseme (return type: string) 9 | send light version to the console 10 | 11 | // Print phrasemes sequence 12 | send string of light version to the console 13 | 14 | // Print phrasemes tree 15 | send 16 | > joined 17 | > "Light " 18 | > and 19 | > string of light version 20 | > to the console -------------------------------------------------------------------------------- /light-core/src/main/java/org/panda_lang/light/framework/language/architecture/linguistic/phraseme/loader/annotations/PhrasemeVariant.java: -------------------------------------------------------------------------------- 1 | package org.panda_lang.light.framework.language.architecture.linguistic.phraseme.loader.annotations; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | @Target(ElementType.METHOD) 9 | @Retention(RetentionPolicy.RUNTIME) 10 | public @interface PhrasemeVariant { 11 | 12 | } 13 | -------------------------------------------------------------------------------- /light-core/src/main/java/org/panda_lang/light/framework/language/architecture/linguistic/phraseme/loader/annotations/Id.java: -------------------------------------------------------------------------------- 1 | package org.panda_lang.light.framework.language.architecture.linguistic.phraseme.loader.annotations; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | @Target(ElementType.PARAMETER) 9 | @Retention(RetentionPolicy.RUNTIME) 10 | public @interface Id { 11 | 12 | String value(); 13 | 14 | } 15 | -------------------------------------------------------------------------------- /light-core/src/main/java/org/panda_lang/light/framework/design/architecture/linguistic/LinguisticAct.java: -------------------------------------------------------------------------------- 1 | package org.panda_lang.light.framework.design.architecture.linguistic; 2 | 3 | import org.panda_lang.light.framework.design.architecture.linguistic.type.Type; 4 | import org.panda_lang.panda.framework.design.runtime.ExecutableBranch; 5 | 6 | public interface LinguisticAct { 7 | 8 | Object perform(ExecutableBranch branch, LinguisticAct... parameters); 9 | 10 | boolean compare(LinguisticAct another); 11 | 12 | Type getType(); 13 | 14 | } 15 | -------------------------------------------------------------------------------- /examples/concept.light: -------------------------------------------------------------------------------- 1 | module ExampleProject 2 | 3 | import light by dzikoysk > 1.0.0 4 | import bukkit by dzikoysk > 2.0.0 5 | import lib-utils by lily > * 6 | 7 | command /version { 8 | send "ExampleProject {version of ExampleProject}" to player 9 | } 10 | 11 | on player join { 12 | if player has played before { 13 | send "Hello {player's name}!" to player and end 14 | } 15 | 16 | set <{player}:account:balance> to {configuration:default balance as number} 17 | } 18 | 19 | phraseme 'version of ExampleProject' { 20 | return version of project 21 | } -------------------------------------------------------------------------------- /light-core/src/main/java/org/panda_lang/light/framework/design/interpreter/lexer/LightLexer.java: -------------------------------------------------------------------------------- 1 | package org.panda_lang.light.framework.design.interpreter.lexer; 2 | 3 | import org.panda_lang.panda.framework.design.interpreter.token.TokenizedSource; 4 | 5 | public class LightLexer extends AbstractLexer { 6 | 7 | public LightLexer(String source) { 8 | super(source); 9 | } 10 | 11 | @Override 12 | public TokenizedSource convert() { 13 | LightLexerWorker worker = new LightLexerWorker(this); 14 | return worker.convert(); 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /light-core/src/main/java/org/panda_lang/light/framework/language/architecture/linguistic/phraseme/loader/annotations/PhrasemeGroup.java: -------------------------------------------------------------------------------- 1 | package org.panda_lang.light.framework.language.architecture.linguistic.phraseme.loader.annotations; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | @Target(ElementType.TYPE) 9 | @Retention(RetentionPolicy.RUNTIME) 10 | public @interface PhrasemeGroup { 11 | 12 | String value(); 13 | 14 | Class returnType() default void.class; 15 | 16 | } 17 | -------------------------------------------------------------------------------- /light-core/src/main/java/org/panda_lang/light/framework/language/architecture/linguistic/phraseme/loader/annotations/PhrasemeRepresentation.java: -------------------------------------------------------------------------------- 1 | package org.panda_lang.light.framework.language.architecture.linguistic.phraseme.loader.annotations; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | @Target(ElementType.METHOD) 9 | @Retention(RetentionPolicy.RUNTIME) 10 | public @interface PhrasemeRepresentation { 11 | 12 | /** 13 | * @return Linguistic Pattern 14 | */ 15 | String value(); 16 | 17 | } 18 | -------------------------------------------------------------------------------- /light-core/src/main/java/org/panda_lang/light/framework/design/interpreter/lexer/IndentationLexer.java: -------------------------------------------------------------------------------- 1 | package org.panda_lang.light.framework.design.interpreter.lexer; 2 | 3 | import org.panda_lang.panda.framework.design.interpreter.token.TokenizedSource; 4 | 5 | public class IndentationLexer extends AbstractLexer { 6 | 7 | public IndentationLexer(String source, String lineSeparator) { 8 | super(source, lineSeparator); 9 | } 10 | 11 | public IndentationLexer(String content) { 12 | super(content); 13 | } 14 | 15 | @Override 16 | public TokenizedSource convert() { 17 | IndentationLexerWorker worker = new IndentationLexerWorker(this); 18 | return worker.convert(); 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /light/src/main/java/org/panda_lang/light/Light.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2018 Dzikoysk 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.panda_lang.light; 18 | 19 | public class Light { 20 | 21 | } 22 | -------------------------------------------------------------------------------- /light-core/src/test/java/org/panda_lang/light/framework/design/interpreter/lexer/IndentationLexerTest.java: -------------------------------------------------------------------------------- 1 | package org.panda_lang.light.framework.design.interpreter.lexer; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.panda_lang.panda.framework.design.interpreter.token.TokenizedSource; 5 | import org.panda_lang.panda.framework.language.interpreter.source.PandaURLSource; 6 | 7 | class IndentationLexerTest { 8 | 9 | private static final String PATH = "../examples/lexer/indentation.light"; 10 | 11 | @Test 12 | public void testLexer() { 13 | IndentationLexer indentationLexer = new IndentationLexer(PandaURLSource.fromPath(PATH).getContent()); 14 | TokenizedSource source = indentationLexer.convert(); 15 | 16 | System.out.println(source); 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /light-core/src/main/java/org/panda_lang/light/framework/design/architecture/linguistic/LinguisticUtils.java: -------------------------------------------------------------------------------- 1 | package org.panda_lang.light.framework.design.architecture.linguistic; 2 | 3 | import org.panda_lang.light.framework.design.architecture.linguistic.type.Type; 4 | import org.panda_lang.panda.framework.design.runtime.ExecutableBranch; 5 | 6 | public class LinguisticUtils { 7 | 8 | public static final Type[] TYPELESS = new Type[0]; 9 | 10 | public static Object[] perform(ExecutableBranch branch, LinguisticAct[] acts) { 11 | Object[] convertedParameters = new Object[acts.length]; 12 | 13 | for (int i = 0; i < acts.length; i++) { 14 | convertedParameters[i] = acts[i].perform(branch); 15 | } 16 | 17 | return convertedParameters; 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /light/src/test/java/org/panda_lang/light/LightLauncherTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2018 Dzikoysk 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.panda_lang.light; 18 | 19 | public class LightLauncherTest { 20 | 21 | } 22 | -------------------------------------------------------------------------------- /light-core/src/main/java/org/panda_lang/light/framework/design/interpreter/lexer/AbstractLexer.java: -------------------------------------------------------------------------------- 1 | package org.panda_lang.light.framework.design.interpreter.lexer; 2 | 3 | import org.panda_lang.panda.framework.design.interpreter.lexer.Lexer; 4 | 5 | abstract class AbstractLexer implements Lexer { 6 | 7 | private final String source; 8 | private final String lineSeparator; 9 | 10 | AbstractLexer(String source, String lineSeparator) { 11 | this.source = source; 12 | this.lineSeparator = lineSeparator; 13 | } 14 | 15 | AbstractLexer(String source) { 16 | this(source, System.lineSeparator()); 17 | } 18 | 19 | protected String getLineSeparator() { 20 | return lineSeparator; 21 | } 22 | 23 | protected String getSource() { 24 | return source; 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /light-core/src/main/java/org/panda_lang/light/framework/language/resource/phrasemes/TestPhrasemes.java: -------------------------------------------------------------------------------- 1 | package org.panda_lang.light.framework.language.resource.phrasemes; 2 | 3 | import org.panda_lang.light.LightConstants; 4 | import org.panda_lang.light.framework.language.architecture.linguistic.phraseme.loader.annotations.PhrasemeRepresentation; 5 | 6 | public class TestPhrasemes { 7 | 8 | @PhrasemeRepresentation("light version") 9 | public String lightVersion() { 10 | return LightConstants.VERSION; 11 | } 12 | 13 | @PhrasemeRepresentation("string of ") 14 | public String stringOf(Object obj) { 15 | return obj.toString(); 16 | } 17 | 18 | @PhrasemeRepresentation("joined and ") 19 | public String join(String a, String b) { 20 | return a + b; 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /light-core/src/main/java/org/panda_lang/light/framework/language/interpreter/parser/LightPriorities.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2018 Dzikoysk 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.panda_lang.light.framework.language.interpreter.parser; 18 | 19 | public class LightPriorities { 20 | 21 | } 22 | -------------------------------------------------------------------------------- /light-core/src/main/java/org/panda_lang/light/framework/design/architecture/linguistic/type/TypeSerializer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2018 Dzikoysk 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.panda_lang.light.framework.design.architecture.linguistic.type; 18 | 19 | public interface TypeSerializer { 20 | 21 | T serialize(String data); 22 | 23 | String deserialize(T object); 24 | 25 | } 26 | -------------------------------------------------------------------------------- /light-core/src/main/java/org/panda_lang/light/framework/design/architecture/linguistic/type/TypeTransformer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2018 Dzikoysk 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.panda_lang.light.framework.design.architecture.linguistic.type; 18 | 19 | import org.jetbrains.annotations.Nullable; 20 | 21 | public interface TypeTransformer { 22 | 23 | @Nullable T transform(String sentence); 24 | 25 | } 26 | -------------------------------------------------------------------------------- /light-core/src/main/java/org/panda_lang/light/framework/design/architecture/linguistic/LinguisticExpression.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2018 Dzikoysk 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.panda_lang.light.framework.design.architecture.linguistic; 18 | 19 | import org.panda_lang.light.framework.design.architecture.linguistic.type.Type; 20 | 21 | public interface LinguisticExpression extends LinguisticAct { 22 | 23 | Type[] getParameterTypes(); 24 | 25 | } 26 | -------------------------------------------------------------------------------- /light-core/src/main/java/org/panda_lang/light/framework/language/architecture/LightScript.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2018 Dzikoysk 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.panda_lang.light.framework.language.architecture; 18 | 19 | import org.panda_lang.panda.framework.language.architecture.AbstractScript; 20 | 21 | public class LightScript extends AbstractScript { 22 | 23 | public LightScript(String scriptName) { 24 | super(scriptName); 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /light-core/src/main/java/org/panda_lang/light/framework/language/interpreter/parser/LightPipelines.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2018 Dzikoysk 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.panda_lang.light.framework.language.interpreter.parser; 18 | 19 | public class LightPipelines { 20 | 21 | public static final String OVERALL = "light-overall"; 22 | 23 | public static final String SCOPE = "light-scope"; 24 | 25 | public static final String BLOCK = "light-block"; 26 | 27 | } 28 | -------------------------------------------------------------------------------- /light-core/src/main/java/org/panda_lang/light/framework/design/architecture/value/TypeValue.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2018 Dzikoysk 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.panda_lang.light.framework.design.architecture.value; 18 | 19 | import org.panda_lang.light.framework.design.architecture.linguistic.type.Type; 20 | import org.panda_lang.panda.framework.design.architecture.value.Value; 21 | 22 | public interface TypeValue extends Value { 23 | 24 | @Override 25 | Type getType(); 26 | 27 | } 28 | -------------------------------------------------------------------------------- /light-core/src/main/resources/log4j2.xml: -------------------------------------------------------------------------------- 1 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /light-core/src/main/java/org/panda_lang/light/framework/language/architecture/linguistic/phraseme/PhrasemeCallback.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2018 Dzikoysk 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.panda_lang.light.framework.language.architecture.linguistic.phraseme; 18 | 19 | import org.jetbrains.annotations.Nullable; 20 | import org.panda_lang.panda.framework.design.runtime.ExecutableBranch; 21 | 22 | public abstract class PhrasemeCallback { 23 | 24 | public abstract @Nullable Object call(ExecutableBranch branch, Object[] convertedParameters); 25 | 26 | } 27 | -------------------------------------------------------------------------------- /light-core/src/main/java/org/panda_lang/light/framework/design/interpreter/token/Sentence.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2018 Dzikoysk 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.panda_lang.light.framework.design.interpreter.token; 18 | 19 | import org.panda_lang.panda.framework.design.interpreter.token.TokenType; 20 | import org.panda_lang.panda.framework.language.interpreter.token.PandaToken; 21 | 22 | public class Sentence extends PandaToken { 23 | 24 | private static final TokenType TYPE = new TokenType("sentence"); 25 | 26 | public Sentence(String phrase) { 27 | super(TYPE, phrase); 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /light-core/src/main/java/org/panda_lang/light/framework/design/architecture/linguistic/type/TypeResolver.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2018 Dzikoysk 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.panda_lang.light.framework.design.architecture.linguistic.type; 18 | 19 | import org.jetbrains.annotations.Nullable; 20 | import org.panda_lang.light.framework.design.architecture.linguistic.ContextComponent; 21 | import org.panda_lang.light.framework.design.architecture.linguistic.LinguisticAct; 22 | 23 | public interface TypeResolver { 24 | 25 | @Nullable LinguisticAct resolve(ContextComponent> component, String sentence); 26 | 27 | } 28 | -------------------------------------------------------------------------------- /light-core/src/main/java/org/panda_lang/light/framework/design/interpreter/lexer/LightLexerWorker.java: -------------------------------------------------------------------------------- 1 | package org.panda_lang.light.framework.design.interpreter.lexer; 2 | 3 | import org.panda_lang.panda.framework.design.interpreter.lexer.Lexer; 4 | import org.panda_lang.panda.framework.design.interpreter.token.TokenizedSource; 5 | 6 | class LightLexerWorker implements Lexer { 7 | 8 | private final LightLexer lexer; 9 | 10 | public LightLexerWorker(LightLexer lexer) { 11 | this.lexer = lexer; 12 | } 13 | 14 | @Override 15 | public TokenizedSource convert() { 16 | Lexer matchedLexer = findLexer(lexer.getSource()); 17 | return matchedLexer.convert(); 18 | } 19 | 20 | private Lexer findLexer(String source) { 21 | return endsWith(source, ":") ? new IndentationLexer(source, lexer.getLineSeparator()) : new DefaultLightLexer(source, lexer.getLineSeparator()); 22 | } 23 | 24 | private boolean endsWith(String source, String element) { 25 | for (String line : source.split(lexer.getLineSeparator())) { 26 | if (line.endsWith(element)) { 27 | return true; 28 | } 29 | } 30 | 31 | return false; 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /light-core/src/main/java/org/panda_lang/light/framework/design/interpreter/lexer/IndentationLexerWorker.java: -------------------------------------------------------------------------------- 1 | package org.panda_lang.light.framework.design.interpreter.lexer; 2 | 3 | import org.panda_lang.light.framework.design.interpreter.source.LightTokenizedSource; 4 | import org.panda_lang.panda.framework.design.interpreter.lexer.Lexer; 5 | import org.panda_lang.panda.framework.design.interpreter.token.TokenRepresentation; 6 | import org.panda_lang.panda.framework.design.interpreter.token.TokenizedSource; 7 | 8 | import java.util.List; 9 | 10 | class IndentationLexerWorker implements Lexer { 11 | 12 | private final IndentationLexer lexer; 13 | 14 | protected IndentationLexerWorker(IndentationLexer lexer) { 15 | this.lexer = lexer; 16 | } 17 | 18 | @Override 19 | public TokenizedSource convert() { 20 | String[] lines = lexer.getSource().split(lexer.getLineSeparator()); 21 | 22 | IndentationLexerTree tree = new IndentationLexerTree(); 23 | List result = tree.build(lines); 24 | 25 | IndentationLexerConverter converter = new IndentationLexerConverter(); 26 | List tokens = converter.convert(result); 27 | 28 | return new LightTokenizedSource(tokens); 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /light-core/src/main/java/org/panda_lang/light/framework/language/interpreter/parser/scope/main/MainScopeParserHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2018 Dzikoysk 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.panda_lang.light.framework.language.interpreter.parser.scope.main; 18 | 19 | import org.panda_lang.panda.framework.design.interpreter.parser.pipeline.ParserHandler; 20 | import org.panda_lang.panda.framework.design.interpreter.token.stream.TokenReader; 21 | 22 | public class MainScopeParserHandler implements ParserHandler { 23 | 24 | @Override 25 | public boolean handle(TokenReader reader) { 26 | return "main".equals(reader.read().getTokenValue()); 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /light-core/src/main/java/org/panda_lang/light/LightException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2018 Dzikoysk 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.panda_lang.light; 18 | 19 | import org.panda_lang.panda.framework.PandaFrameworkException; 20 | 21 | public class LightException extends PandaFrameworkException { 22 | 23 | public LightException() { 24 | super(); 25 | } 26 | 27 | public LightException(String message) { 28 | super(message); 29 | } 30 | 31 | public LightException(String message, Throwable cause) { 32 | super(message, cause); 33 | } 34 | 35 | public LightException(Throwable cause) { 36 | super(cause); 37 | } 38 | 39 | } 40 | 41 | -------------------------------------------------------------------------------- /light-core/src/main/java/org/panda_lang/light/framework/design/interpreter/pattern/linguistic/LinguisticWildcardProcessor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2018 Dzikoysk 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.panda_lang.light.framework.design.interpreter.pattern.linguistic; 18 | 19 | import org.jetbrains.annotations.Nullable; 20 | import org.panda_lang.light.framework.design.architecture.linguistic.Context; 21 | import org.panda_lang.light.framework.design.architecture.linguistic.LinguisticAct; 22 | 23 | public interface LinguisticWildcardProcessor { 24 | 25 | @Nullable 26 | LinguisticAct handle(Context context, @Nullable String details, String wildcard, @Nullable LinguisticCandidate previousCandidate); 27 | 28 | } 29 | -------------------------------------------------------------------------------- /light-core/src/main/java/org/panda_lang/light/framework/language/interpreter/parser/scope/main/MainScope.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2018 Dzikoysk 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.panda_lang.light.framework.language.interpreter.parser.scope.main; 18 | 19 | import org.panda_lang.panda.framework.design.architecture.dynamic.ScopeInstance; 20 | import org.panda_lang.panda.framework.design.runtime.ExecutableBranch; 21 | import org.panda_lang.panda.framework.language.architecture.statement.AbstractScope; 22 | 23 | public class MainScope extends AbstractScope { 24 | 25 | @Override 26 | public ScopeInstance createInstance(ExecutableBranch branch) { 27 | return new MainInstance(this); 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /notes/concepts.txt: -------------------------------------------------------------------------------- 1 | # 2 | # Unknown Pattern Concept 3 | # 4 | 5 | PATTERN: set * to * 6 | MESSAGE: set variable1 to 14 to value of set variable2 to 99999 7 | index: 0 1 2 3 4 5 6 7 8 9 10 8 | 9 | --- Analyze Pattern 10 | hardunits: [set, to] 11 | content: 2 12 | 13 | --- Analyze Message 14 | hardunits in message: 15 | set: [0, 7] 16 | to: [2, 4, 9] 17 | 18 | --- Matches 19 | * [variable1] [14 to value of set variable2 to 99999] 20 | * [variable1 to 14] [value of set variable2 to 99999] 21 | * [variable1 to 14 to value of set variable2] [99999] 22 | 23 | # 24 | # Phraseme Concept 25 | # 26 | 27 | Phraseme -> Phrasemes -> PhrasemesGroup 28 | 29 | --- Phraseme Parser 30 | 0: get current PhrasemesGroup 31 | 1: find PhrasemeCandidate in PhrasemesGroup 32 | 2: compare candidate types: 33 | 2.1: if candidate types != required, continue 34 | 2.2: save current candidate 35 | 2.3: goto 1 36 | 3: create phraseme statement 37 | 38 | --- Methods 39 | 40 | PhrasemesGroup: 41 | PhrasemesCandidate find(String sentence, @Nullable PhrasemeCandidate previousResult) 42 | 43 | Phrasemes: 44 | PhrasemesCandidate find(String sentence, @Nullable PhrasemeCandidate previousResult) 45 | 46 | # 47 | # Context, LinguisticUnit 48 | # 49 | 50 | LinguisticAct -------------------------------------------------------------------------------- /light-core/src/main/java/org/panda_lang/light/framework/design/architecture/linguistic/type/Type.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2018 Dzikoysk 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.panda_lang.light.framework.design.architecture.linguistic.type; 18 | 19 | import org.panda_lang.panda.framework.design.architecture.prototype.ClassPrototype; 20 | 21 | import java.util.List; 22 | import java.util.function.Function; 23 | 24 | public interface Type extends ClassPrototype { 25 | 26 | boolean isAssignableFrom(Type type); 27 | 28 | List getTypeTransformer(); 29 | 30 | Function getStringifier(); 31 | 32 | TypeSerializer getSerializer(); 33 | 34 | List getPlurals(); 35 | 36 | } 37 | -------------------------------------------------------------------------------- /light-core/src/main/java/org/panda_lang/light/framework/design/architecture/linguistic/ContextComponent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2018 Dzikoysk 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.panda_lang.light.framework.design.architecture.linguistic; 18 | 19 | import org.jetbrains.annotations.Nullable; 20 | import org.panda_lang.light.framework.design.interpreter.pattern.linguistic.LinguisticCandidate; 21 | 22 | import java.util.Collection; 23 | 24 | public interface ContextComponent { 25 | 26 | LinguisticCandidate recognize(Context context, String sentence, @Nullable LinguisticCandidate previousCandidate); 27 | 28 | void registerElement(T element); 29 | 30 | Collection getElements(); 31 | 32 | Class getComponentType(); 33 | 34 | } 35 | -------------------------------------------------------------------------------- /light-core/src/main/java/org/panda_lang/light/framework/language/interpreter/parser/scope/main/MainInstance.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2018 Dzikoysk 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.panda_lang.light.framework.language.interpreter.parser.scope.main; 18 | 19 | import org.panda_lang.panda.framework.design.runtime.ExecutableBranch; 20 | import org.panda_lang.panda.framework.language.architecture.dynamic.AbstractScopeInstance; 21 | 22 | public class MainInstance extends AbstractScopeInstance { 23 | 24 | protected MainInstance(MainScope scope) { 25 | super(scope); 26 | } 27 | 28 | @Override 29 | public void execute(ExecutableBranch branch) { 30 | branch.call(super.getScope().getStatementCells()); 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /light-core/src/main/java/org/panda_lang/light/framework/design/interpreter/parser/LightParserException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2018 Dzikoysk 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.panda_lang.light.framework.design.interpreter.parser; 18 | 19 | import org.panda_lang.light.LightException; 20 | 21 | public class LightParserException extends LightException { 22 | 23 | public LightParserException() { 24 | super(); 25 | } 26 | 27 | public LightParserException(String message) { 28 | super(message); 29 | } 30 | 31 | public LightParserException(String message, Throwable cause) { 32 | super(message, cause); 33 | } 34 | 35 | public LightParserException(Throwable cause) { 36 | super(cause); 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /light-core/src/main/java/org/panda_lang/light/LightLogger.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2018 Dzikoysk 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.panda_lang.light; 18 | 19 | import org.slf4j.Logger; 20 | import org.slf4j.LoggerFactory; 21 | 22 | import java.lang.management.ManagementFactory; 23 | 24 | public class LightLogger { 25 | 26 | protected static Logger LIGHT_LOGGER = LoggerFactory.getLogger("Light"); 27 | 28 | public static void setLogger(Logger logger) { 29 | LIGHT_LOGGER = logger; 30 | } 31 | 32 | public static void printJVMUptime() { 33 | long jvmStartTime = ManagementFactory.getRuntimeMXBean().getStartTime(); 34 | LIGHT_LOGGER.info("JVM launch time: " + (System.currentTimeMillis() - jvmStartTime) + "ms"); 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /light-core/src/main/java/org/panda_lang/light/framework/design/interpreter/parser/LightComponents.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2018 Dzikoysk 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.panda_lang.light.framework.design.interpreter.parser; 18 | 19 | import org.panda_lang.light.framework.design.architecture.linguistic.Context; 20 | import org.panda_lang.light.framework.language.interpreter.LightInterpreter; 21 | import org.panda_lang.panda.framework.design.interpreter.parser.component.Component; 22 | 23 | public class LightComponents { 24 | 25 | public static final Component INTERPRETER = Component.of("light-interpreter", LightInterpreter.class); 26 | 27 | public static final Component CONTEXT = Component.of("light-context", Context.class); 28 | 29 | } 30 | -------------------------------------------------------------------------------- /light-core/src/main/java/org/panda_lang/light/framework/design/interpreter/token/SentenceRepresentation.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2018 Dzikoysk 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.panda_lang.light.framework.design.interpreter.token; 18 | 19 | import org.panda_lang.panda.framework.design.interpreter.token.Token; 20 | import org.panda_lang.panda.framework.language.interpreter.token.PandaTokenRepresentation; 21 | 22 | public class SentenceRepresentation extends PandaTokenRepresentation { 23 | 24 | public SentenceRepresentation(Token token, int line) { 25 | super(token, line); 26 | } 27 | 28 | public static SentenceRepresentation of(String sentence, int line) { 29 | return new SentenceRepresentation(new Sentence(sentence), line); 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /light-core/src/test/java/org/panda_lang/light/framework/design/interpreter/lexer/LightLexerTest.java: -------------------------------------------------------------------------------- 1 | package org.panda_lang.light.framework.design.interpreter.lexer; 2 | 3 | import org.junit.jupiter.api.Assertions; 4 | import org.junit.jupiter.api.Test; 5 | import org.panda_lang.panda.framework.design.interpreter.lexer.Lexer; 6 | import org.panda_lang.panda.framework.design.interpreter.token.TokenizedSource; 7 | import org.panda_lang.panda.framework.language.interpreter.source.PandaURLSource; 8 | 9 | class LightLexerTest { 10 | 11 | private static final String DEFAULT = "../examples/lexer/multiline_test.light"; 12 | private static final String INDENTATION = "../examples/lexer/indentation.light"; 13 | 14 | @Test 15 | public void testDefaultLexer() { 16 | Lexer indentationLexer = new LightLexer(PandaURLSource.fromPath(DEFAULT).getContent()); 17 | TokenizedSource source = indentationLexer.convert(); 18 | 19 | Assertions.assertNotNull(source); 20 | Assertions.assertTrue(source.size() > 0); 21 | } 22 | 23 | @Test 24 | public void testIndentationLexer() { 25 | Lexer indentationLexer = new LightLexer(PandaURLSource.fromPath(INDENTATION).getContent()); 26 | TokenizedSource source = indentationLexer.convert(); 27 | 28 | Assertions.assertNotNull(source); 29 | Assertions.assertTrue(source.size() > 0); 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /light-core/src/main/java/org/panda_lang/light/framework/design/architecture/linguistic/phraseme/Phraseme.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2018 Dzikoysk 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.panda_lang.light.framework.design.architecture.linguistic.phraseme; 18 | 19 | import org.panda_lang.light.framework.design.architecture.linguistic.LinguisticExpression; 20 | import org.panda_lang.light.framework.design.architecture.linguistic.type.Type; 21 | import org.panda_lang.light.framework.design.interpreter.pattern.linguistic.LinguisticPattern; 22 | 23 | import java.util.Collection; 24 | 25 | public interface Phraseme { 26 | 27 | void increaseUsages(); 28 | 29 | Collection getExpressions(); 30 | 31 | Type getReturnType(); 32 | 33 | LinguisticPattern getPattern(); 34 | 35 | } 36 | -------------------------------------------------------------------------------- /light-core/src/main/java/org/panda_lang/light/framework/design/interpreter/lexer/DefaultLightLexer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2018 Dzikoysk 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.panda_lang.light.framework.design.interpreter.lexer; 18 | 19 | import org.panda_lang.panda.framework.design.interpreter.token.TokenizedSource; 20 | 21 | public class DefaultLightLexer extends AbstractLexer { 22 | 23 | public DefaultLightLexer(String source, String lineSeparator) { 24 | super(source, lineSeparator); 25 | } 26 | 27 | public DefaultLightLexer(String content) { 28 | super(content); 29 | } 30 | 31 | @Override 32 | public TokenizedSource convert() { 33 | DefaultLightLexerWorker worker = new DefaultLightLexerWorker(this); 34 | return worker.convert(); 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /light-core/src/main/java/org/panda_lang/light/LightCore.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2018 Dzikoysk 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.panda_lang.light; 18 | 19 | import org.panda_lang.light.framework.language.LightLanguage; 20 | import org.slf4j.Logger; 21 | 22 | public class LightCore { 23 | 24 | private final LightLanguage language; 25 | private final LightLoader loader; 26 | 27 | public LightCore() { 28 | this.language = new LightLanguage(); 29 | this.loader = new LightLoader(this); 30 | } 31 | 32 | public LightLoader getLoader() { 33 | return loader; 34 | } 35 | 36 | public LightLanguage getLanguage() { 37 | return language; 38 | } 39 | 40 | public static Logger getLogger() { 41 | return LightLogger.LIGHT_LOGGER; 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /light-core/src/main/java/org/panda_lang/light/framework/language/architecture/linguistic/phraseme/loader/PhrasemesLoader.java: -------------------------------------------------------------------------------- 1 | package org.panda_lang.light.framework.language.architecture.linguistic.phraseme.loader; 2 | 3 | import org.panda_lang.light.LightException; 4 | import org.panda_lang.light.framework.design.architecture.linguistic.Context; 5 | import org.panda_lang.light.framework.design.architecture.linguistic.phraseme.Phraseme; 6 | import org.panda_lang.panda.utilities.annotations.AnnotationsScannerProcess; 7 | 8 | import java.util.Collection; 9 | 10 | public class PhrasemesLoader { 11 | 12 | public Collection load(Context context, AnnotationsScannerProcess process) { 13 | try { 14 | return loadAll(context, process); 15 | } catch (Exception e) { 16 | throw new LightException("Cannot load phrasemes: " + e.getMessage(), e); 17 | } 18 | } 19 | 20 | private Collection loadAll(Context context, AnnotationsScannerProcess process) throws Exception { 21 | Collection phrasemes; 22 | 23 | PhrasemeRepresentationLoader representationLoader = new PhrasemeRepresentationLoader(); 24 | phrasemes = representationLoader.load(context, process); 25 | 26 | PhrasemeGroupLoader groupLoader = new PhrasemeGroupLoader(); 27 | phrasemes.addAll(groupLoader.load(context, process)); 28 | 29 | return phrasemes; 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /light-core/src/main/java/org/panda_lang/light/framework/language/architecture/linguistic/LinguisticStatement.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2018 Dzikoysk 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.panda_lang.light.framework.language.architecture.linguistic; 18 | 19 | import org.panda_lang.light.framework.design.architecture.linguistic.LinguisticAct; 20 | import org.panda_lang.panda.framework.design.architecture.dynamic.ExecutableStatement; 21 | import org.panda_lang.panda.framework.design.runtime.ExecutableBranch; 22 | 23 | public class LinguisticStatement extends ExecutableStatement { 24 | 25 | private final LinguisticAct act; 26 | 27 | public LinguisticStatement(LinguisticAct act) { 28 | this.act = act; 29 | } 30 | 31 | @Override 32 | public void execute(ExecutableBranch branch) { 33 | act.perform(branch); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /light-core/src/main/java/org/panda_lang/light/framework/language/interpreter/parser/scope/ScopeParserHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2018 Dzikoysk 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.panda_lang.light.framework.language.interpreter.parser.scope; 18 | 19 | import org.panda_lang.panda.framework.design.interpreter.parser.pipeline.ParserHandler; 20 | import org.panda_lang.panda.framework.design.interpreter.token.TokenizedSource; 21 | import org.panda_lang.panda.framework.design.interpreter.token.stream.TokenReader; 22 | 23 | import java.util.List; 24 | 25 | public class ScopeParserHandler implements ParserHandler { 26 | 27 | @Override 28 | public boolean handle(TokenReader reader) { 29 | List hollows = ScopeParser.PATTERN.extractor().extract(reader); 30 | return hollows != null && hollows.size() == 2; 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /light-core/src/main/java/org/panda_lang/light/framework/design/architecture/linguistic/Context.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2018 Dzikoysk 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.panda_lang.light.framework.design.architecture.linguistic; 18 | 19 | import org.jetbrains.annotations.Nullable; 20 | import org.panda_lang.light.framework.design.architecture.linguistic.type.Type; 21 | import org.panda_lang.light.framework.design.interpreter.pattern.linguistic.LinguisticCandidate; 22 | 23 | public interface Context { 24 | 25 | @Nullable LinguisticAct find(String sentence); 26 | 27 | @Nullable LinguisticAct find(String sentence, @Nullable LinguisticCandidate previousCandidate); 28 | 29 | void importComponent(ContextComponent component); 30 | 31 | Context fork(); 32 | 33 | @Nullable Type getType(Class clazz); 34 | 35 | @Nullable Type getType(String type); 36 | 37 | } 38 | -------------------------------------------------------------------------------- /light-core/src/main/java/org/panda_lang/light/framework/language/interpreter/parser/scope/ScopeComponents.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2018 Dzikoysk 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.panda_lang.light.framework.language.interpreter.parser.scope; 18 | 19 | import org.panda_lang.panda.framework.design.architecture.statement.Scope; 20 | import org.panda_lang.panda.framework.design.interpreter.parser.component.Component; 21 | import org.panda_lang.panda.framework.design.interpreter.token.TokenizedSource; 22 | 23 | public class ScopeComponents { 24 | 25 | public static final Component DECLARATION = Component.of("light-scope-declaration", TokenizedSource.class); 26 | 27 | public static final Component CONTENT = Component.of("light-scope-content", TokenizedSource.class); 28 | 29 | public static final Component SCOPE = Component.of("light-scope", Scope.class); 30 | 31 | } 32 | -------------------------------------------------------------------------------- /light-core/src/test/java/org/panda_lang/light/framework/design/interpreter/lexer/MultilineLexerTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2018 Dzikoysk 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.panda_lang.light.framework.design.interpreter.lexer; 18 | 19 | import org.junit.jupiter.api.Test; 20 | import org.panda_lang.panda.framework.design.interpreter.lexer.Lexer; 21 | import org.panda_lang.panda.framework.design.interpreter.token.TokenizedSource; 22 | import org.panda_lang.panda.framework.language.interpreter.source.PandaURLSource; 23 | 24 | class MultilineLexerTest { 25 | 26 | private final PandaURLSource source = PandaURLSource.fromPath("../examples/lexer/multiline_test.light"); 27 | 28 | @Test 29 | public void testLexer() { 30 | Lexer lexer = new DefaultLightLexer(source.getContent()); 31 | TokenizedSource tokenizedSource = lexer.convert(); 32 | 33 | System.out.println(tokenizedSource); 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /light-core/src/main/java/org/panda_lang/light/framework/design/interpreter/source/LightSourceStream.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2018 Dzikoysk 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.panda_lang.light.framework.design.interpreter.source; 18 | 19 | import org.panda_lang.panda.framework.design.interpreter.token.TokenRepresentation; 20 | import org.panda_lang.panda.framework.design.interpreter.token.TokenizedSource; 21 | import org.panda_lang.panda.framework.language.interpreter.token.PandaTokenizedSource; 22 | import org.panda_lang.panda.framework.language.interpreter.token.stream.PandaSourceStream; 23 | 24 | public class LightSourceStream extends PandaSourceStream { 25 | 26 | public LightSourceStream(TokenizedSource tokenizedSource) { 27 | super(tokenizedSource); 28 | } 29 | 30 | public LightSourceStream(TokenRepresentation tokenRepresentation) { 31 | super(new PandaTokenizedSource().addToken(tokenRepresentation)); 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /light-core/src/test/java/org/panda_lang/light/LightTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2018 Dzikoysk 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.panda_lang.light; 18 | 19 | import org.junit.jupiter.api.Test; 20 | import org.panda_lang.light.framework.language.architecture.LightApplication; 21 | import org.panda_lang.panda.utilities.commons.LoggingUtils; 22 | 23 | public class LightTest { 24 | 25 | static { 26 | LoggingUtils.skipJansi(); 27 | } 28 | 29 | @Test 30 | public void testLight() { 31 | LightLogger.printJVMUptime(); 32 | 33 | LightCore core = new LightCore(); 34 | LightLoader loader = core.getLoader(); 35 | LightApplication application = loader.loadFiles("../examples/current_test.light"); 36 | 37 | if (application == null) { 38 | LightCore.getLogger().warn("Cannot launch this application"); 39 | return; 40 | } 41 | 42 | application.launch(); 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /light-core/src/main/java/org/panda_lang/light/framework/language/resource/phrasemes/ConsolePhraseme.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2018 Dzikoysk 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.panda_lang.light.framework.language.resource.phrasemes; 18 | 19 | import org.panda_lang.light.framework.language.architecture.linguistic.phraseme.loader.annotations.Id; 20 | import org.panda_lang.light.framework.language.architecture.linguistic.phraseme.loader.annotations.PhrasemeGroup; 21 | import org.panda_lang.light.framework.language.architecture.linguistic.phraseme.loader.annotations.PhrasemeVariant; 22 | 23 | @PhrasemeGroup("send message: to [the] console") 24 | public class ConsolePhraseme { 25 | 26 | @PhrasemeVariant 27 | public void sendMessageToConsole(String message) { 28 | System.out.println(message); 29 | } 30 | 31 | @PhrasemeVariant 32 | public void sendMessageToConsole(@Id("message") boolean message) { 33 | System.out.println("boolean::" + message); 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /light-core/src/main/java/org/panda_lang/light/framework/design/interpreter/pattern/linguistic/LinguisticPatternCompiler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2018 Dzikoysk 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.panda_lang.light.framework.design.interpreter.pattern.linguistic; 18 | 19 | import org.panda_lang.light.framework.design.architecture.linguistic.LinguisticAct; 20 | import org.panda_lang.panda.framework.language.interpreter.pattern.lexical.LexicalPattern; 21 | 22 | class LinguisticPatternCompiler { 23 | 24 | private final String pattern; 25 | private LexicalPattern lexicalPattern; 26 | 27 | LinguisticPatternCompiler(String pattern) { 28 | this.pattern = pattern; 29 | } 30 | 31 | protected void compile() { 32 | this.lexicalPattern = LexicalPattern. builder() 33 | .compile(pattern) 34 | .build(); 35 | } 36 | 37 | protected LexicalPattern getLexicalPattern() { 38 | return lexicalPattern; 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /light-core/src/main/java/org/panda_lang/light/framework/design/interpreter/lexer/LightLineBuilder.java: -------------------------------------------------------------------------------- 1 | package org.panda_lang.light.framework.design.interpreter.lexer; 2 | 3 | import org.panda_lang.panda.utilities.commons.StringUtils; 4 | 5 | class LightLineBuilder { 6 | 7 | private StringBuilder lineBuilder = new StringBuilder(); 8 | private boolean multiline = false; 9 | 10 | protected void next(String line, Runnable processor) { 11 | String preparedLine = line.trim(); 12 | String indentation = StringUtils.extractParagraph(line); 13 | 14 | boolean startsWithMultiline = preparedLine.startsWith(">"); 15 | boolean endsWithMultiline = preparedLine.endsWith(">"); 16 | 17 | if (!multiline && !startsWithMultiline && lineBuilder.length() > 0) { 18 | processor.run(); 19 | } 20 | 21 | if (startsWithMultiline) { 22 | preparedLine = preparedLine.substring(2); 23 | } 24 | 25 | if (endsWithMultiline) { 26 | preparedLine = preparedLine.substring(0, preparedLine.length() - 2); 27 | } 28 | 29 | if (lineBuilder.length() > 0) { 30 | lineBuilder.append(" "); 31 | } 32 | 33 | lineBuilder.append(indentation); 34 | lineBuilder.append(preparedLine); 35 | 36 | multiline = endsWithMultiline; 37 | } 38 | 39 | protected void clear() { 40 | lineBuilder.setLength(0); 41 | } 42 | 43 | protected int getLength() { 44 | return lineBuilder.length(); 45 | } 46 | 47 | protected String getLine() { 48 | return lineBuilder.toString(); 49 | } 50 | 51 | } 52 | -------------------------------------------------------------------------------- /light-core/src/test/java/org/panda_lang/light/framework/design/interpreter/pattern/linguistic/LexicalPatternTest.java: -------------------------------------------------------------------------------- 1 | package org.panda_lang.light.framework.design.interpreter.pattern.linguistic; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.panda_lang.panda.framework.language.interpreter.pattern.lexical.LexicalPattern; 5 | import org.panda_lang.panda.framework.language.interpreter.pattern.lexical.extractor.LexicalExtractorResult; 6 | import org.panda_lang.panda.utilities.commons.BenchmarkUtils; 7 | 8 | import java.util.ArrayList; 9 | import java.util.Collection; 10 | 11 | public class LexicalPatternTest { 12 | 13 | private final Collection> patterns = new ArrayList<>(1_000_000); 14 | 15 | @Test 16 | public void testPerformance() { 17 | fill(); 18 | 19 | BenchmarkUtils.execute("LexicalPattern ", () -> { 20 | for (int i = 0; i < 10000; i++) { 21 | match(); 22 | } 23 | }); 24 | } 25 | 26 | private void match() { 27 | for (LexicalPattern pattern : patterns) { 28 | LexicalExtractorResult result = pattern.extract("matched"); 29 | 30 | if (result.isMatched()) { 31 | break; 32 | } 33 | } 34 | } 35 | 36 | private void fill() { 37 | LexicalPattern pattern = LexicalPattern.builder() 38 | .compile("send message: to [the] console") 39 | .build(); 40 | 41 | for (int i = 0; i < 1000; i++) { 42 | patterns.add(pattern); 43 | } 44 | 45 | patterns.add(LexicalPattern.builder() 46 | .compile("matched") 47 | .build()); 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /light-core/src/main/java/org/panda_lang/light/framework/design/interpreter/pattern/linguistic/LinguisticPatternResult.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2018 Dzikoysk 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.panda_lang.light.framework.design.interpreter.pattern.linguistic; 18 | 19 | import org.panda_lang.light.framework.design.architecture.linguistic.LinguisticAct; 20 | import org.panda_lang.panda.framework.language.interpreter.pattern.lexical.extractor.LexicalExtractorResult; 21 | 22 | public class LinguisticPatternResult { 23 | 24 | private final boolean matched; 25 | private LexicalExtractorResult lexicalResult; 26 | 27 | LinguisticPatternResult(boolean matched) { 28 | this.matched = matched; 29 | } 30 | 31 | LinguisticPatternResult(LexicalExtractorResult result) { 32 | this.matched = result.isMatched(); 33 | this.lexicalResult = result; 34 | } 35 | 36 | public boolean isMatched() { 37 | return matched; 38 | } 39 | 40 | public LexicalExtractorResult getLexicalResult() { 41 | return lexicalResult; 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /light-core/src/main/java/org/panda_lang/light/framework/language/LightLanguage.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2018 Dzikoysk 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.panda_lang.light.framework.language; 18 | 19 | import org.panda_lang.light.LightException; 20 | import org.panda_lang.panda.framework.design.interpreter.parser.pipeline.registry.PipelineRegistry; 21 | import org.panda_lang.panda.framework.design.resource.Language; 22 | import org.panda_lang.panda.framework.design.resource.Syntax; 23 | import org.panda_lang.panda.framework.language.interpreter.parser.pipeline.ParserRegistrationLoader; 24 | import org.panda_lang.panda.util.PandaUtils; 25 | 26 | public class LightLanguage implements Language { 27 | 28 | private PipelineRegistry pipelineRegistry; 29 | 30 | public LightLanguage() { 31 | this.pipelineRegistry = new ParserRegistrationLoader().load(PandaUtils.DEFAULT_PANDA_SCANNER); 32 | } 33 | 34 | @Override 35 | public PipelineRegistry getParserPipelineRegistry() { 36 | return pipelineRegistry; 37 | } 38 | 39 | @Override 40 | public Syntax getSyntax() { 41 | throw new LightException("Light does not have declared syntax"); 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /light-core/src/main/java/org/panda_lang/light/framework/language/interpreter/parser/scope/main/MainScopeParser.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2018 Dzikoysk 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.panda_lang.light.framework.language.interpreter.parser.scope.main; 18 | 19 | 20 | import org.panda_lang.light.framework.language.interpreter.parser.LightPipelines; 21 | import org.panda_lang.light.framework.language.interpreter.parser.scope.ScopeComponents; 22 | import org.panda_lang.panda.framework.design.interpreter.parser.ParserData; 23 | import org.panda_lang.panda.framework.design.interpreter.parser.UnifiedParser; 24 | import org.panda_lang.panda.framework.design.interpreter.parser.generation.casual.GenerationLayer; 25 | import org.panda_lang.panda.framework.language.interpreter.parser.pipeline.ParserRegistration; 26 | 27 | @ParserRegistration(target = LightPipelines.SCOPE, parserClass = MainScopeParser.class, handlerClass = MainScopeParserHandler.class) 28 | public class MainScopeParser implements UnifiedParser { 29 | 30 | @Override 31 | public boolean parse(ParserData data, GenerationLayer nextLayer) { 32 | data.setComponent(ScopeComponents.SCOPE, new MainScope()); 33 | return true; 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /light-core/src/main/java/org/panda_lang/light/framework/language/resource/DefaultLightPhrasemes.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2018 Dzikoysk 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.panda_lang.light.framework.language.resource; 18 | 19 | import org.panda_lang.light.framework.design.architecture.linguistic.Context; 20 | import org.panda_lang.light.framework.design.architecture.linguistic.phraseme.Phraseme; 21 | import org.panda_lang.light.framework.language.architecture.linguistic.phraseme.Phrasemes; 22 | import org.panda_lang.light.framework.language.architecture.linguistic.phraseme.loader.PhrasemesLoader; 23 | import org.panda_lang.panda.utilities.annotations.AnnotationsScannerProcess; 24 | 25 | import java.util.Collection; 26 | 27 | public class DefaultLightPhrasemes { 28 | 29 | public Phrasemes generate(Context context, AnnotationsScannerProcess process) { 30 | Phrasemes defaultPhrasemes = new Phrasemes(); 31 | 32 | PhrasemesLoader loader = new PhrasemesLoader(); 33 | Collection phrasemes = loader.load(context, process); 34 | 35 | for (Phraseme phraseme : phrasemes) { 36 | defaultPhrasemes.registerElement(phraseme); 37 | } 38 | 39 | return defaultPhrasemes; 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /light-core/src/main/java/org/panda_lang/light/framework/language/architecture/LightEnvironment.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2018 Dzikoysk 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.panda_lang.light.framework.language.architecture; 18 | 19 | import org.panda_lang.light.LightCore; 20 | import org.panda_lang.light.framework.language.LightLanguage; 21 | import org.panda_lang.light.framework.language.interpreter.LightInterpreter; 22 | import org.panda_lang.panda.framework.design.architecture.Environment; 23 | import org.panda_lang.panda.framework.design.architecture.module.ModulePath; 24 | 25 | public class LightEnvironment implements Environment { 26 | 27 | private final LightLanguage language; 28 | private final LightInterpreter interpreter; 29 | 30 | public LightEnvironment(LightCore lightCore) { 31 | this.language = lightCore.getLanguage(); 32 | this.interpreter = new LightInterpreter(this); 33 | } 34 | 35 | @Override 36 | public ModulePath getModulePath() { 37 | throw new RuntimeException("Not implemented"); 38 | } 39 | 40 | @Override 41 | public LightInterpreter getInterpreter() { 42 | return interpreter; 43 | } 44 | 45 | public LightLanguage getLanguage() { 46 | return language; 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /light-core/src/main/java/org/panda_lang/light/framework/language/architecture/linguistic/phraseme/LightPhrasemeLinguisticExpression.java: -------------------------------------------------------------------------------- 1 | package org.panda_lang.light.framework.language.architecture.linguistic.phraseme; 2 | 3 | import org.panda_lang.light.framework.design.architecture.linguistic.LinguisticAct; 4 | import org.panda_lang.light.framework.design.architecture.linguistic.LinguisticExpression; 5 | import org.panda_lang.light.framework.design.architecture.linguistic.LinguisticUtils; 6 | import org.panda_lang.light.framework.design.architecture.linguistic.type.Type; 7 | import org.panda_lang.panda.framework.design.runtime.ExecutableBranch; 8 | import org.panda_lang.panda.utilities.commons.ArrayUtils; 9 | 10 | public class LightPhrasemeLinguisticExpression implements LinguisticExpression { 11 | 12 | private final Type[] parameterTypes; 13 | private final PhrasemeCallback callback; 14 | private final Type returnType; 15 | 16 | public LightPhrasemeLinguisticExpression(Type[] parameterTypes, PhrasemeCallback callback, Type returnType) { 17 | if (ArrayUtils.contains(parameterTypes, null)) { 18 | throw new IllegalArgumentException("Parameter types cannot contain null"); 19 | } 20 | 21 | this.parameterTypes = parameterTypes; 22 | this.callback = callback; 23 | this.returnType = returnType; 24 | } 25 | 26 | @Override 27 | public Object perform(ExecutableBranch branch, LinguisticAct... parameters) { 28 | return callback.call(branch, LinguisticUtils.perform(branch, parameters)); 29 | } 30 | 31 | @Override 32 | public boolean compare(LinguisticAct another) { 33 | return another.equals(this); 34 | } 35 | 36 | @Override 37 | public Type[] getParameterTypes() { 38 | return parameterTypes; 39 | } 40 | 41 | @Override 42 | public Type getType() { 43 | return returnType; 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /light-core/src/main/java/org/panda_lang/light/framework/design/interpreter/source/LightTokenizedSource.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2018 Dzikoysk 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.panda_lang.light.framework.design.interpreter.source; 18 | 19 | import org.panda_lang.panda.framework.design.interpreter.token.TokenRepresentation; 20 | import org.panda_lang.panda.framework.language.interpreter.token.PandaTokenizedSource; 21 | 22 | import java.util.List; 23 | 24 | public class LightTokenizedSource extends PandaTokenizedSource { 25 | 26 | public LightTokenizedSource(List tokenRepresentations) { 27 | super(tokenRepresentations); 28 | } 29 | 30 | @Override 31 | public String toString() { 32 | StringBuilder messageBuilder = new StringBuilder() 33 | .append("src: { ") 34 | .append(System.lineSeparator()); 35 | 36 | for (TokenRepresentation representation : super.getTokensRepresentations()) { 37 | messageBuilder 38 | .append(" ") 39 | .append(representation.getTokenType()) 40 | .append(" [at ").append(representation.getLine() + 1).append("]: ") 41 | .append(representation.getTokenValue()) 42 | .append(System.lineSeparator()); 43 | } 44 | 45 | return messageBuilder.append("}").toString(); 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /light-core/src/main/java/org/panda_lang/light/framework/language/architecture/linguistic/LightContextTypeLookup.java: -------------------------------------------------------------------------------- 1 | package org.panda_lang.light.framework.language.architecture.linguistic; 2 | 3 | import org.jetbrains.annotations.Nullable; 4 | import org.panda_lang.light.framework.design.architecture.linguistic.ContextComponent; 5 | import org.panda_lang.light.framework.design.architecture.linguistic.type.Type; 6 | 7 | import java.util.Collection; 8 | import java.util.function.Predicate; 9 | import java.util.stream.Collectors; 10 | 11 | class LightContextTypeLookup { 12 | 13 | protected final LightContext lightContext; 14 | 15 | protected LightContextTypeLookup(LightContext lightContext) { 16 | this.lightContext = lightContext; 17 | } 18 | 19 | protected @Nullable Type getType(Predicate> condition) { 20 | return getType(getTypes(), condition); 21 | } 22 | 23 | private @Nullable Type getType(Collection>> types, Predicate> condition) { 24 | for (ContextComponent> type : types) { 25 | Type matched = getType(type, condition); 26 | 27 | if (matched != null) { 28 | return matched; 29 | } 30 | } 31 | 32 | return null; 33 | } 34 | 35 | private @Nullable Type getType(ContextComponent> types, Predicate> condition) { 36 | for (Type element : types.getElements()) { 37 | if (condition.test(element)) { 38 | return element; 39 | } 40 | } 41 | 42 | return null; 43 | } 44 | 45 | @SuppressWarnings("unchecked") 46 | private Collection>> getTypes() { 47 | return lightContext.context.stream() 48 | .filter(component -> component.getComponentType() == Type.class) 49 | .map(component -> (ContextComponent>) component) 50 | .collect(Collectors.toList()); 51 | } 52 | 53 | } 54 | -------------------------------------------------------------------------------- /light-core/src/main/java/org/panda_lang/light/framework/design/architecture/value/LightTypeValue.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2018 Dzikoysk 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.panda_lang.light.framework.design.architecture.value; 18 | 19 | import org.panda_lang.light.framework.design.architecture.linguistic.type.Type; 20 | 21 | import java.util.Objects; 22 | 23 | public class LightTypeValue implements TypeValue { 24 | 25 | private final Type type; 26 | private final Object value; 27 | 28 | public LightTypeValue(Type type, Object value) { 29 | this.type = type; 30 | this.value = value; 31 | } 32 | 33 | @Override 34 | @SuppressWarnings("unchecked") 35 | public T getValue() { 36 | return (T) value; 37 | } 38 | 39 | @Override 40 | public Object getObject() { 41 | return value; 42 | } 43 | 44 | @Override 45 | public Type getType() { 46 | return type; 47 | } 48 | 49 | @Override 50 | public int hashCode() { 51 | return Objects.hash(type, value); 52 | } 53 | 54 | @Override 55 | public boolean equals(Object o) { 56 | if (this == o) { 57 | return true; 58 | } 59 | 60 | if (o == null || getClass() != o.getClass()) { 61 | return false; 62 | } 63 | 64 | LightTypeValue that = (LightTypeValue) o; 65 | 66 | return type.equals(that.type) && 67 | Objects.equals(value, that.value); 68 | } 69 | 70 | } 71 | -------------------------------------------------------------------------------- /light-core/src/main/java/org/panda_lang/light/framework/design/interpreter/pattern/linguistic/LinguisticPatternBuilder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2018 Dzikoysk 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.panda_lang.light.framework.design.interpreter.pattern.linguistic; 18 | 19 | import org.panda_lang.light.framework.design.architecture.linguistic.LinguisticAct; 20 | import org.panda_lang.panda.framework.language.interpreter.pattern.lexical.LexicalPattern; 21 | import org.panda_lang.panda.framework.language.interpreter.pattern.lexical.extractor.processed.WildcardProcessor; 22 | 23 | public class LinguisticPatternBuilder { 24 | 25 | private LexicalPattern pattern; 26 | private LinguisticWildcardProcessor wildcardProcessor; 27 | 28 | public LinguisticPatternBuilder compile(String pattern) { 29 | LinguisticPatternCompiler compiler = new LinguisticPatternCompiler(pattern); 30 | compiler.compile(); 31 | 32 | this.pattern = compiler.getLexicalPattern(); 33 | return this; 34 | } 35 | 36 | public LinguisticPatternBuilder wildcardProcessor(WildcardProcessor wildcardProcessor) { 37 | pattern.setWildcardProcessor(wildcardProcessor); 38 | return this; 39 | } 40 | 41 | public LinguisticPatternBuilder wildcardProcessor(LinguisticWildcardProcessor wildcardProcessor) { 42 | this.wildcardProcessor = wildcardProcessor; 43 | return this; 44 | } 45 | 46 | public LinguisticPattern build() { 47 | return new LinguisticPattern(pattern, wildcardProcessor); 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /light-core/src/main/java/org/panda_lang/light/framework/language/interpreter/parser/defaults/SentenceParser.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2018 Dzikoysk 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.panda_lang.light.framework.language.interpreter.parser.defaults; 18 | 19 | import org.panda_lang.light.framework.design.architecture.linguistic.Context; 20 | import org.panda_lang.light.framework.design.architecture.linguistic.LinguisticAct; 21 | import org.panda_lang.light.framework.design.interpreter.parser.LightComponents; 22 | import org.panda_lang.light.framework.design.interpreter.token.SentenceRepresentation; 23 | import org.panda_lang.light.framework.language.architecture.linguistic.LinguisticStatement; 24 | import org.panda_lang.panda.framework.design.architecture.statement.Statement; 25 | import org.panda_lang.panda.framework.design.interpreter.parser.Parser; 26 | import org.panda_lang.panda.framework.design.interpreter.parser.ParserData; 27 | import org.panda_lang.panda.framework.language.interpreter.parser.PandaParserFailure; 28 | 29 | public class SentenceParser implements Parser { 30 | 31 | public Statement parse(ParserData data, SentenceRepresentation sentenceRepresentation) { 32 | String sentence = sentenceRepresentation.getTokenValue(); 33 | 34 | Context context = data.getComponent(LightComponents.CONTEXT); 35 | LinguisticAct act = context.find(sentence); 36 | 37 | if (act == null) { 38 | throw new PandaParserFailure("Unrecognized syntax", data); 39 | } 40 | 41 | return new LinguisticStatement(act); 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /light-core/src/main/java/org/panda_lang/light/LightLoader.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2018 Dzikoysk 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.panda_lang.light; 18 | 19 | import org.panda_lang.light.framework.language.architecture.LightApplication; 20 | import org.panda_lang.light.framework.language.architecture.LightEnvironment; 21 | import org.panda_lang.light.framework.language.interpreter.LightInterpreter; 22 | import org.panda_lang.panda.framework.PandaFrameworkException; 23 | import org.panda_lang.panda.framework.design.interpreter.source.SourceProvider; 24 | import org.panda_lang.panda.framework.design.interpreter.source.SourceSet; 25 | import org.panda_lang.panda.framework.language.interpreter.source.providers.FileSourceProvider; 26 | import org.panda_lang.panda.utilities.commons.FileUtils; 27 | 28 | public class LightLoader { 29 | 30 | private final LightCore light; 31 | 32 | public LightLoader(LightCore light) { 33 | this.light = light; 34 | } 35 | 36 | public LightApplication loadFiles(String... paths) { 37 | return load(new FileSourceProvider(FileUtils.toFiles(paths))); 38 | } 39 | 40 | public LightApplication load(SourceProvider provider) { 41 | SourceSet sourceSet = provider.toSourceSet(); 42 | 43 | if (sourceSet.isEmpty()) { 44 | throw new PandaFrameworkException("Sources are not provided"); 45 | } 46 | 47 | LightEnvironment environment = new LightEnvironment(light); 48 | LightInterpreter interpreter = environment.getInterpreter(); 49 | 50 | return interpreter.interpret(sourceSet); 51 | } 52 | 53 | } 54 | -------------------------------------------------------------------------------- /light-core/src/main/java/org/panda_lang/light/framework/language/architecture/linguistic/phraseme/LightPhraseme.java: -------------------------------------------------------------------------------- 1 | package org.panda_lang.light.framework.language.architecture.linguistic.phraseme; 2 | 3 | import org.panda_lang.light.framework.design.architecture.linguistic.LinguisticExpression; 4 | import org.panda_lang.light.framework.design.architecture.linguistic.phraseme.Phraseme; 5 | import org.panda_lang.light.framework.design.architecture.linguistic.type.Type; 6 | import org.panda_lang.light.framework.design.interpreter.pattern.linguistic.LinguisticPattern; 7 | 8 | import java.util.ArrayList; 9 | import java.util.Arrays; 10 | import java.util.Collection; 11 | 12 | public class LightPhraseme implements Phraseme { 13 | 14 | private final LinguisticPattern pattern; 15 | private final Type returnType; 16 | private final Collection expressions; 17 | private int usages; 18 | 19 | public LightPhraseme(LinguisticPattern pattern, Type returnType, LinguisticExpression... acts) { 20 | this.pattern = pattern; 21 | this.returnType = returnType; 22 | this.expressions = new ArrayList<>(1); 23 | this.addAssociatedExpressions(acts); 24 | } 25 | 26 | @Override 27 | public void increaseUsages() { 28 | ++usages; 29 | } 30 | 31 | public void merge(Phraseme phraseme) { 32 | if (!returnType.isAssignableFrom(phraseme.getReturnType())) { 33 | throw new IllegalArgumentException("Cannot merge a phraseme of another type (" + returnType.getClassName() + " != " + phraseme.getReturnType().getClassName() + ")"); 34 | } 35 | 36 | expressions.addAll(phraseme.getExpressions()); 37 | } 38 | 39 | public void addAssociatedExpressions(LinguisticExpression... acts) { 40 | expressions.addAll(Arrays.asList(acts)); 41 | } 42 | 43 | @Override 44 | public Collection getExpressions() { 45 | return expressions; 46 | } 47 | 48 | @Override 49 | public Type getReturnType() { 50 | return returnType; 51 | } 52 | 53 | @Override 54 | public LinguisticPattern getPattern() { 55 | return pattern; 56 | } 57 | 58 | } 59 | -------------------------------------------------------------------------------- /light-core/src/main/java/org/panda_lang/light/framework/language/resource/LightSyntax.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2018 Dzikoysk 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.panda_lang.light.framework.language.resource; 18 | 19 | import org.panda_lang.panda.framework.design.resource.Syntax; 20 | import org.panda_lang.panda.framework.language.resource.syntax.keyword.Keyword; 21 | import org.panda_lang.panda.framework.language.resource.syntax.literal.Literal; 22 | import org.panda_lang.panda.framework.language.resource.syntax.operator.Operator; 23 | import org.panda_lang.panda.framework.language.resource.syntax.separator.Separator; 24 | import org.panda_lang.panda.framework.language.resource.syntax.sequence.Sequence; 25 | 26 | import java.util.List; 27 | 28 | public class LightSyntax implements Syntax { 29 | 30 | @Override 31 | public char[] getSpecialCharacters() { 32 | return new char[0]; 33 | } 34 | 35 | @Override 36 | public List getSequences() { 37 | throw new RuntimeException("Not implemented"); 38 | } 39 | 40 | @Override 41 | public List getOperators() { 42 | throw new RuntimeException("Not implemented"); 43 | } 44 | 45 | @Override 46 | public List getSeparators() { 47 | throw new RuntimeException("Not implemented"); 48 | } 49 | 50 | @Override 51 | public List getLiterals() { 52 | throw new RuntimeException("Not implemented"); 53 | } 54 | 55 | @Override 56 | public List getKeywords() { 57 | throw new RuntimeException("Not implemented"); 58 | } 59 | 60 | } 61 | -------------------------------------------------------------------------------- /light-core/src/main/java/org/panda_lang/light/framework/design/interpreter/lexer/IndentationLexerConverter.java: -------------------------------------------------------------------------------- 1 | package org.panda_lang.light.framework.design.interpreter.lexer; 2 | 3 | import org.panda_lang.light.LightException; 4 | import org.panda_lang.panda.framework.design.interpreter.token.TokenRepresentation; 5 | import org.panda_lang.panda.framework.language.interpreter.token.PandaTokenRepresentation; 6 | import org.panda_lang.panda.framework.language.resource.syntax.separator.Separators; 7 | 8 | import java.util.ArrayList; 9 | import java.util.Collections; 10 | import java.util.List; 11 | 12 | class IndentationLexerConverter { 13 | 14 | private static final TokenRepresentation START = new PandaTokenRepresentation(Separators.LEFT_BRACE_DELIMITER, -2); 15 | private static final TokenRepresentation END = new PandaTokenRepresentation(Separators.RIGHT_BRACE_DELIMITER, -2); 16 | 17 | public List convert(List elements) { 18 | List tokens = new ArrayList<>(elements.size() * 2); 19 | 20 | for (Object element : elements) { 21 | tokens.addAll(convertElement(element)); 22 | } 23 | 24 | return tokens; 25 | } 26 | 27 | private List convertElement(Object element) { 28 | if (element instanceof TokenRepresentation) { 29 | return convertRepresentation((TokenRepresentation) element); 30 | } 31 | else if (element instanceof IndentationLexerTree.Group) { 32 | return convertGroup((IndentationLexerTree.Group) element); 33 | } 34 | 35 | throw new LightException("Unknown element type: " + element.getClass()); 36 | } 37 | 38 | private List convertRepresentation(TokenRepresentation element) { 39 | return Collections.singletonList(element); 40 | } 41 | 42 | private List convertGroup(IndentationLexerTree.Group group) { 43 | List tokens = new ArrayList<>(); 44 | 45 | tokens.add(group.getMaster()); 46 | tokens.add(START); 47 | 48 | List body = convert(group.getElements()); 49 | tokens.addAll(body); 50 | 51 | tokens.add(END); 52 | return tokens; 53 | } 54 | 55 | } 56 | -------------------------------------------------------------------------------- /light-core/src/main/java/org/panda_lang/light/framework/language/architecture/linguistic/LightContextUtils.java: -------------------------------------------------------------------------------- 1 | package org.panda_lang.light.framework.language.architecture.linguistic; 2 | 3 | import org.jetbrains.annotations.NotNull; 4 | import org.jetbrains.annotations.Nullable; 5 | import org.panda_lang.light.framework.design.architecture.linguistic.LinguisticAct; 6 | import org.panda_lang.light.framework.design.architecture.linguistic.type.Type; 7 | import org.panda_lang.light.framework.design.interpreter.pattern.linguistic.LinguisticCandidate; 8 | import org.panda_lang.panda.framework.design.runtime.ExecutableBranch; 9 | 10 | import java.util.Collection; 11 | import java.util.stream.Collectors; 12 | 13 | class LightContextUtils { 14 | 15 | private LightContextUtils() { 16 | } 17 | 18 | protected static @Nullable LinguisticAct prepare(Collection candidates) { 19 | if (candidates.size() == 0) { 20 | return null; 21 | } 22 | 23 | LinguisticCandidate first = candidates.iterator().next(); 24 | 25 | if (candidates.size() == 1) { 26 | return createElement(first); 27 | } 28 | 29 | Collection elements = candidates.stream() 30 | .map(LightContextUtils::createElement) 31 | .collect(Collectors.toList()); 32 | 33 | return new LightLinguisticGroup(first.getMatchedElement().getType(), elements); 34 | } 35 | 36 | @NotNull 37 | protected static LinguisticAct createElement(LinguisticCandidate candidate) { 38 | LinguisticAct matched = candidate.getMatchedElement(); 39 | LinguisticAct[] matchedParameters = candidate.getMatchedParameters(); 40 | 41 | return new LinguisticAct() { 42 | @Override 43 | public Object perform(ExecutableBranch branch, LinguisticAct... parameters) { 44 | return matched.perform(branch, matchedParameters); 45 | } 46 | 47 | @Override 48 | public boolean compare(LinguisticAct another) { 49 | return another.equals(this); 50 | } 51 | 52 | @Override 53 | public Type getType() { 54 | return matched.getType(); 55 | } 56 | }; 57 | } 58 | 59 | } 60 | -------------------------------------------------------------------------------- /light-core/src/main/java/org/panda_lang/light/framework/language/architecture/linguistic/phraseme/loader/PhrasemeMethodLoader.java: -------------------------------------------------------------------------------- 1 | package org.panda_lang.light.framework.language.architecture.linguistic.phraseme.loader; 2 | 3 | import org.panda_lang.light.LightException; 4 | import org.panda_lang.light.framework.design.architecture.linguistic.Context; 5 | import org.panda_lang.light.framework.design.architecture.linguistic.LinguisticExpression; 6 | import org.panda_lang.light.framework.design.architecture.linguistic.type.Type; 7 | import org.panda_lang.light.framework.language.architecture.linguistic.phraseme.LightPhrasemeLinguisticExpression; 8 | import org.panda_lang.light.framework.language.architecture.linguistic.phraseme.PhrasemeCallback; 9 | import org.panda_lang.panda.framework.design.runtime.ExecutableBranch; 10 | 11 | import java.lang.reflect.InvocationTargetException; 12 | import java.lang.reflect.Method; 13 | 14 | class PhrasemeMethodLoader { 15 | 16 | protected LinguisticExpression load(Context context, Method method) throws Exception { 17 | Object instance = method.getDeclaringClass().newInstance(); 18 | Type returnType = context.getType(method.getReturnType()); 19 | 20 | PhrasemeCallback callback = new PhrasemeCallback() { 21 | @Override 22 | public Object call(ExecutableBranch branch, Object[] convertedParameters) { 23 | try { 24 | return method.invoke(instance, convertedParameters); 25 | } catch (IllegalAccessException | InvocationTargetException e) { 26 | e.printStackTrace(); 27 | } 28 | 29 | return null; 30 | } 31 | }; 32 | 33 | Type[] parameterTypes = new Type[method.getParameterCount()]; 34 | 35 | for (int i = 0; i < parameterTypes.length; i++) { 36 | Class typeClass = method.getParameterTypes()[i]; 37 | Type type = context.getType(typeClass); 38 | 39 | if (type == null) { 40 | throw new LightException("Cannot recognize type " + typeClass); 41 | } 42 | 43 | parameterTypes[i] = type; 44 | } 45 | 46 | return new LightPhrasemeLinguisticExpression(parameterTypes, callback, returnType); 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /light-core/src/main/java/org/panda_lang/light/framework/language/architecture/linguistic/LightWildcardProcessor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2018 Dzikoysk 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.panda_lang.light.framework.language.architecture.linguistic; 18 | 19 | import org.jetbrains.annotations.Nullable; 20 | import org.panda_lang.light.framework.design.architecture.linguistic.Context; 21 | import org.panda_lang.light.framework.design.architecture.linguistic.LinguisticAct; 22 | import org.panda_lang.light.framework.design.architecture.linguistic.type.Type; 23 | import org.panda_lang.light.framework.design.interpreter.pattern.linguistic.LinguisticCandidate; 24 | import org.panda_lang.light.framework.design.interpreter.pattern.linguistic.LinguisticWildcardProcessor; 25 | 26 | public class LightWildcardProcessor implements LinguisticWildcardProcessor { 27 | 28 | private static final LightWildcardProcessor INSTANCE = new LightWildcardProcessor(); 29 | 30 | @Override 31 | public @Nullable LinguisticAct handle(Context context, String details, String wildcard, @Nullable LinguisticCandidate previousCandidate) { 32 | LinguisticAct matchedAct = context.find(wildcard, previousCandidate); 33 | 34 | if (matchedAct == null) { 35 | return null; 36 | } 37 | 38 | Type required = context.getType(details); 39 | Type matched = matchedAct.getType(); 40 | 41 | if (required == null || matched == null) { 42 | return null; 43 | } 44 | 45 | if (!required.isAssignableFrom(matched)) { 46 | return null; 47 | } 48 | 49 | return matchedAct; 50 | } 51 | 52 | public static LightWildcardProcessor getInstance() { 53 | return INSTANCE; 54 | } 55 | 56 | } 57 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ### Maven ### 2 | target/ 3 | pom.xml.tag 4 | pom.xml.releaseBackup 5 | pom.xml.versionsBackup 6 | pom.xml.next 7 | release.properties 8 | dependency-reduced-pom.xml 9 | buildNumber.properties 10 | .mvn/timing.properties 11 | 12 | 13 | ### Intellij ### 14 | # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio 15 | 16 | *.iml 17 | 18 | ## Directory-based project format: 19 | .idea/ 20 | # if you remove the above rule, at least ignore the following: 21 | 22 | # User-specific stuff: 23 | # .idea/workspace.xml 24 | # .idea/tasks.xml 25 | # .idea/dictionaries 26 | 27 | # Sensitive or high-churn files: 28 | # .idea/dataSources.ids 29 | # .idea/dataSources.xml 30 | # .idea/sqlDataSources.xml 31 | # .idea/dynamic.xml 32 | # .idea/uiDesigner.xml 33 | 34 | # Gradle: 35 | # .idea/gradle.xml 36 | # .idea/libraries 37 | 38 | # Mongo Explorer plugin: 39 | # .idea/mongoSettings.xml 40 | 41 | ## File-based project format: 42 | *.ipr 43 | *.iws 44 | 45 | ## Plugin-specific files: 46 | 47 | # IntelliJ 48 | /out/ 49 | 50 | # mpeltonen/sbt-idea plugin 51 | .idea_modules/ 52 | 53 | # JIRA plugin 54 | atlassian-ide-plugin.xml 55 | 56 | # Crashlytics plugin (for Android Studio and IntelliJ) 57 | com_crashlytics_export_strings.xml 58 | crashlytics.properties 59 | crashlytics-build.properties 60 | 61 | 62 | ### Eclipse ### 63 | *.pydevproject 64 | .metadata 65 | .gradle 66 | bin/ 67 | tmp/ 68 | *.tmp 69 | *.bak 70 | *.swp 71 | *~.nib 72 | local.properties 73 | .settings/ 74 | .loadpath 75 | 76 | # Eclipse Core 77 | .project 78 | 79 | # External tool builders 80 | .externalToolBuilders/ 81 | 82 | # Locally stored "Eclipse launch configurations" 83 | *.launch 84 | 85 | # CDT-specific 86 | .cproject 87 | 88 | # JDT-specific (Eclipse Java Development Tools) 89 | .classpath 90 | 91 | # Java annotation processor (APT) 92 | .factorypath 93 | 94 | # PDT-specific 95 | .buildpath 96 | 97 | # sbteclipse plugin 98 | .target 99 | 100 | # TeXlipse plugin 101 | .texlipse 102 | 103 | 104 | ### Java ### 105 | *.class 106 | 107 | # Mobile Tools for Java (J2ME) 108 | .mtj.tmp/ 109 | 110 | # Package Files # 111 | *.jar 112 | *.war 113 | *.ear 114 | 115 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 116 | hs_err_pid* 117 | -------------------------------------------------------------------------------- /light-core/src/main/java/org/panda_lang/light/framework/language/resource/DefaultLightTypes.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2018 Dzikoysk 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.panda_lang.light.framework.language.resource; 18 | 19 | import org.panda_lang.light.framework.language.architecture.linguistic.type.LightType; 20 | import org.panda_lang.light.framework.language.architecture.linguistic.type.Types; 21 | import org.panda_lang.light.framework.language.architecture.linguistic.type.resolvers.TransformerTypeResolver; 22 | 23 | public class DefaultLightTypes { 24 | 25 | public Types generate() { 26 | Types types = new Types(); 27 | types.registerResolver(new TransformerTypeResolver()); 28 | 29 | types.registerElement(LightType.builder() 30 | .name("object") 31 | .plural("objects") 32 | .build()); 33 | 34 | types.registerElement(LightType. builder() 35 | .name("void") 36 | .associated(Void.class) 37 | .build()); 38 | 39 | types.registerElement(LightType. builder() 40 | .name("boolean") 41 | .plural("booleans") 42 | .associated(boolean.class) 43 | .transformer(sentence -> (sentence.equals("true") || sentence.equals("false")) ? Boolean.parseBoolean(sentence) : null) 44 | .build()); 45 | 46 | types.registerElement(LightType. builder() 47 | .name("string") 48 | .plural("strings") 49 | .associated(String.class) 50 | .transformer(sentence -> (sentence.startsWith("\"") && sentence.endsWith("\"")) ? sentence.substring(1, sentence.length() - 1) : null) 51 | .build()); 52 | 53 | return types; 54 | } 55 | 56 | } 57 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Light [![Build Status](https://travis-ci.org/panda-lang/light.svg?branch=master)](https://travis-ci.org/panda-lang/light) 2 | 3 | Light is an English-like programming language built on the top of the Panda Framework and Panda Programming Language. 4 |
5 |
6 | Website: [light.panda-lang.org](https://light.panda-lang.org/) 7 |
8 | Panda Programming Language: [panda-lang.org](https://panda-lang.org/) 9 |
10 | #### Example 11 | ```javascript 12 | module ExampleProject 13 | 14 | import light by dzikoysk > 1.0.0 15 | import bukkit by dzikoysk > 2.0.0 16 | import lib-utils by lily > * 17 | 18 | command /version { 19 | send "ExampleProject {version of ExampleProject}" to player 20 | } 21 | 22 | on player join { 23 | if player has played before { 24 | send "Hello {player's name}!" to player and end 25 | } 26 | 27 | set <:account:balance> to {configuration:default balance} 28 | } 29 | 30 | phraseme 'version of ExampleProject' { 31 | return version of project 32 | } 33 | ``` 34 | 35 | #### Repository structure 36 | 37 | ``` 38 | light/ 39 | +--examples/ Example scripts written in Light. 40 | +--light/ Light module 41 | +----/src All sources of Panda 42 | +----pom.xml The main maven build script for Light module 43 | +--lightmc/ LightMC module 44 | +------/docs Temporary documentation for LightMC 45 | +------/src All sources of LightMC 46 | +------pom.xml The main maven build script for LightMC module 47 | +--pom.xml The main maven build script 48 | ``` 49 | 50 | #### Maven 51 | 52 | Latest build of Light. Remember, API is not stable yet :o: 53 | ```xml 54 | 55 | org.panda_lang 56 | light 57 | indev-18.10.6 58 | 59 | ``` 60 | The latest build of the previous edition. Remember, this is deprecated! 61 | ```xml 62 | 63 | org.panda_lang 64 | light 65 | 1.0.0-SNAPSHOT 66 | 67 | ``` 68 | Repository: [repo.panda-lang.org](https://repo.panda-lang.org/) 69 | ```xml 70 | 71 | 72 | panda-repository 73 | Panda Repository 74 | https://repo.panda-lang.org/ 75 | 76 | 77 | ``` 78 | -------------------------------------------------------------------------------- /light-core/src/main/java/org/panda_lang/light/framework/design/interpreter/pattern/linguistic/LinguisticCandidate.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2018 Dzikoysk 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.panda_lang.light.framework.design.interpreter.pattern.linguistic; 18 | 19 | import org.panda_lang.light.framework.design.architecture.linguistic.LinguisticAct; 20 | 21 | public class LinguisticCandidate { 22 | 23 | private static final LinguisticCandidate NOT_MATCHED = new LinguisticCandidate(null, null); 24 | 25 | private final LinguisticAct matchedElement; 26 | private final LinguisticPatternResult linguisticResult; 27 | 28 | public LinguisticCandidate(LinguisticAct matchedElement, LinguisticPatternResult linguisticResult) { 29 | this.matchedElement = matchedElement; 30 | this.linguisticResult = linguisticResult; 31 | } 32 | 33 | public boolean isMatched() { 34 | return matchedElement != null; 35 | } 36 | 37 | public LinguisticAct[] getMatchedParameters() { 38 | if (linguisticResult == null || linguisticResult.getLexicalResult() == null) { 39 | return new LinguisticAct[0]; 40 | } 41 | 42 | LinguisticAct[] matchedParameters = new LinguisticAct[linguisticResult.getLexicalResult().getProcessedValues().size()]; 43 | 44 | for (int i = 0; i < matchedParameters.length; i++) { 45 | matchedParameters[i] = linguisticResult.getLexicalResult().getProcessedValues().get(i).getValue(); 46 | } 47 | 48 | return matchedParameters; 49 | } 50 | 51 | public LinguisticPatternResult getLinguisticResult() { 52 | return linguisticResult; 53 | } 54 | 55 | public LinguisticAct getMatchedElement() { 56 | return matchedElement; 57 | } 58 | 59 | public static LinguisticCandidate notMatched() { 60 | return NOT_MATCHED; 61 | } 62 | 63 | } 64 | -------------------------------------------------------------------------------- /light/pom.xml: -------------------------------------------------------------------------------- 1 | 16 | 17 | 18 | 4.0.0 19 | 20 | 21 | light-parent 22 | org.panda-lang 23 | indev-18.10.6 24 | 25 | 26 | light 27 | 28 | 29 | 30 | org.panda-lang 31 | panda 32 | 33 | 34 | 35 | 36 | clean install 37 | 38 | 39 | org.apache.maven.plugins 40 | maven-jar-plugin 41 | 42 | 43 | 44 | org.panda_lang.light.Light 45 | Light 46 | ${project.version} 47 | Light 48 | 49 | 50 | 51 | 52 | 53 | org.apache.maven.plugins 54 | maven-shade-plugin 55 | 56 | 57 | 58 | 59 | -------------------------------------------------------------------------------- /light-core/src/main/java/org/panda_lang/light/framework/language/interpreter/LightInterpreter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2018 Dzikoysk 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.panda_lang.light.framework.language.interpreter; 18 | 19 | import org.jetbrains.annotations.Nullable; 20 | import org.panda_lang.light.framework.language.architecture.LightApplication; 21 | import org.panda_lang.light.framework.language.architecture.LightEnvironment; 22 | import org.panda_lang.light.framework.language.interpreter.parser.defaults.ApplicationParser; 23 | import org.panda_lang.panda.framework.design.interpreter.Interpretation; 24 | import org.panda_lang.panda.framework.design.interpreter.Interpreter; 25 | import org.panda_lang.panda.framework.design.interpreter.messenger.MessengerLevel; 26 | import org.panda_lang.panda.framework.design.interpreter.source.SourceSet; 27 | import org.panda_lang.panda.framework.language.interpreter.PandaInterpretation; 28 | 29 | public class LightInterpreter implements Interpreter { 30 | 31 | private final LightEnvironment environment; 32 | 33 | public LightInterpreter(LightEnvironment environment) { 34 | this.environment = environment; 35 | } 36 | 37 | @Override 38 | public @Nullable LightApplication interpret(SourceSet sources) { 39 | Interpretation interpretation = new PandaInterpretation(environment, this, environment.getLanguage()); 40 | 41 | ApplicationParser parser = new ApplicationParser(interpretation); 42 | LightApplication application = parser.parse(sources); 43 | 44 | if (!interpretation.isHealthy()) { 45 | interpretation.getMessenger().sendMessage(MessengerLevel.FAILURE, "Interpretation failed, cannot parse specified sources"); 46 | return null; 47 | } 48 | 49 | return application; 50 | } 51 | 52 | public LightEnvironment getEnvironment() { 53 | return environment; 54 | } 55 | 56 | } 57 | -------------------------------------------------------------------------------- /light-core/src/main/java/org/panda_lang/light/framework/language/architecture/linguistic/phraseme/loader/PhrasemeRepresentationLoader.java: -------------------------------------------------------------------------------- 1 | package org.panda_lang.light.framework.language.architecture.linguistic.phraseme.loader; 2 | 3 | import org.panda_lang.light.LightException; 4 | import org.panda_lang.light.framework.design.architecture.linguistic.Context; 5 | import org.panda_lang.light.framework.design.architecture.linguistic.LinguisticExpression; 6 | import org.panda_lang.light.framework.design.architecture.linguistic.phraseme.Phraseme; 7 | import org.panda_lang.light.framework.design.interpreter.pattern.linguistic.LinguisticPattern; 8 | import org.panda_lang.light.framework.language.architecture.linguistic.phraseme.LightPhraseme; 9 | import org.panda_lang.light.framework.language.architecture.linguistic.phraseme.loader.annotations.PhrasemeRepresentation; 10 | import org.panda_lang.panda.utilities.annotations.AnnotationsScannerProcess; 11 | import org.panda_lang.panda.utilities.commons.StringUtils; 12 | 13 | import java.lang.reflect.Method; 14 | import java.util.ArrayList; 15 | import java.util.Collection; 16 | 17 | class PhrasemeRepresentationLoader { 18 | 19 | private final PhrasemeMethodLoader methodLoader = new PhrasemeMethodLoader(); 20 | 21 | protected Collection load(Context context, AnnotationsScannerProcess process) throws Exception { 22 | Collection phrasemes = new ArrayList<>(); 23 | 24 | Collection methods = process.createSelector() 25 | .selectMethodsAnnotatedWith(PhrasemeRepresentation.class); 26 | 27 | for (Method method : methods) { 28 | Phraseme phraseme = load(context, method); 29 | phrasemes.add(phraseme); 30 | } 31 | 32 | return phrasemes; 33 | } 34 | 35 | private Phraseme load(Context context, Method method) throws Exception { 36 | PhrasemeRepresentation phrasemeRepresentation = method.getAnnotation(PhrasemeRepresentation.class); 37 | String patternRepresentation = phrasemeRepresentation.value(); 38 | 39 | if (StringUtils.isEmpty(patternRepresentation)) { 40 | throw new LightException("Pattern cannot be empty (source: " + method.getDeclaringClass() + ")"); 41 | } 42 | 43 | LinguisticPattern pattern = LinguisticPattern.builder() 44 | .compile(patternRepresentation) 45 | .build(); 46 | 47 | LinguisticExpression phrasemeBody = methodLoader.load(context, method); 48 | return new LightPhraseme(pattern, phrasemeBody.getType(), phrasemeBody); 49 | } 50 | 51 | } 52 | -------------------------------------------------------------------------------- /light-core/pom.xml: -------------------------------------------------------------------------------- 1 | 16 | 17 | 18 | 4.0.0 19 | 20 | 21 | light-parent 22 | org.panda-lang 23 | indev-18.10.6 24 | 25 | 26 | light-core 27 | 28 | 29 | 30 | org.panda-lang 31 | panda 32 | 33 | 34 | org.junit.jupiter 35 | junit-jupiter-api 36 | test 37 | 38 | 39 | 40 | 41 | clean install 42 | 43 | 44 | org.apache.maven.plugins 45 | maven-jar-plugin 46 | 47 | 48 | 49 | org.panda_lang.light.LightCore 50 | Light 51 | ${project.version} 52 | Light 53 | 54 | 55 | 56 | 57 | 58 | org.apache.maven.plugins 59 | maven-shade-plugin 60 | 61 | 62 | 63 | 64 | -------------------------------------------------------------------------------- /light-core/src/main/java/org/panda_lang/light/framework/language/architecture/linguistic/type/LightType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2018 Dzikoysk 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.panda_lang.light.framework.language.architecture.linguistic.type; 18 | 19 | import org.panda_lang.light.framework.design.architecture.linguistic.type.Type; 20 | import org.panda_lang.light.framework.design.architecture.linguistic.type.TypeSerializer; 21 | import org.panda_lang.light.framework.design.architecture.linguistic.type.TypeTransformer; 22 | import org.panda_lang.panda.framework.language.architecture.prototype.PandaClassPrototype; 23 | 24 | import java.util.List; 25 | import java.util.function.Function; 26 | 27 | public class LightType extends PandaClassPrototype implements Type { 28 | 29 | private final List plurals; 30 | private final TypeSerializer serializer; 31 | private final List> transformer; 32 | private final Function stringifier; 33 | 34 | public LightType(LightTypeBuilder builder) { 35 | super(builder); 36 | 37 | this.plurals = builder.plurals; 38 | this.serializer = builder.serializer; 39 | this.transformer = builder.transformers; 40 | this.stringifier = builder.stringifier; 41 | } 42 | 43 | @Override 44 | public boolean isAssignableFrom(Type type) { 45 | return super.getClassName().equals(type.getClassName()) || type.isAssociatedWith(this); 46 | } 47 | 48 | @Override 49 | public TypeSerializer getSerializer() { 50 | return serializer; 51 | } 52 | 53 | @Override 54 | public List> getTypeTransformer() { 55 | return transformer; 56 | } 57 | 58 | @Override 59 | public Function getStringifier() { 60 | return stringifier; 61 | } 62 | 63 | @Override 64 | public List getPlurals() { 65 | return plurals; 66 | } 67 | 68 | public static LightTypeBuilder builder() { 69 | return new LightTypeBuilder<>(); 70 | } 71 | 72 | } 73 | -------------------------------------------------------------------------------- /light-core/src/main/java/org/panda_lang/light/framework/design/interpreter/pattern/linguistic/LinguisticPattern.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2018 Dzikoysk 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.panda_lang.light.framework.design.interpreter.pattern.linguistic; 18 | 19 | import org.jetbrains.annotations.Nullable; 20 | import org.panda_lang.light.framework.design.architecture.linguistic.Context; 21 | import org.panda_lang.light.framework.design.architecture.linguistic.LinguisticAct; 22 | import org.panda_lang.panda.framework.language.interpreter.pattern.lexical.LexicalPattern; 23 | import org.panda_lang.panda.framework.language.interpreter.pattern.lexical.extractor.LexicalExtractorResult; 24 | 25 | public class LinguisticPattern { 26 | 27 | private final LexicalPattern lexicalPattern; 28 | private @Nullable LinguisticWildcardProcessor wildcardProcessor; 29 | 30 | public LinguisticPattern(LexicalPattern lexicalPattern, @Nullable LinguisticWildcardProcessor wildcardProcessor) { 31 | this.lexicalPattern = lexicalPattern; 32 | this.wildcardProcessor = wildcardProcessor; 33 | } 34 | 35 | public LinguisticPatternResult match(String sentence, Context context, @Nullable LinguisticCandidate previousResult) { 36 | LinguisticExtractor extractor = new LinguisticExtractor(context, this, previousResult); 37 | LexicalExtractorResult result = lexicalPattern.extract(extractor, sentence); 38 | 39 | return new LinguisticPatternResult(result); 40 | } 41 | 42 | public void setWildcardProcessor(@Nullable LinguisticWildcardProcessor wildcardProcessor) { 43 | this.wildcardProcessor = wildcardProcessor; 44 | } 45 | 46 | public boolean hasWildcardProcessor() { 47 | return wildcardProcessor != null; 48 | } 49 | 50 | public @Nullable LinguisticWildcardProcessor getWildcardProcessor() { 51 | return wildcardProcessor; 52 | } 53 | 54 | public LexicalPattern getLexicalPattern() { 55 | return lexicalPattern; 56 | } 57 | 58 | public static LinguisticPatternBuilder builder() { 59 | return new LinguisticPatternBuilder(); 60 | } 61 | 62 | } 63 | -------------------------------------------------------------------------------- /light-core/src/main/java/org/panda_lang/light/framework/language/architecture/LightApplication.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2018 Dzikoysk 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.panda_lang.light.framework.language.architecture; 18 | 19 | import org.panda_lang.light.LightCore; 20 | import org.panda_lang.light.framework.language.interpreter.parser.scope.main.MainScope; 21 | import org.panda_lang.panda.framework.design.architecture.Application; 22 | import org.panda_lang.panda.framework.design.architecture.Script; 23 | import org.panda_lang.panda.framework.design.runtime.ExecutableProcess; 24 | import org.panda_lang.panda.framework.language.runtime.PandaExecutableProcess; 25 | import org.panda_lang.panda.framework.language.runtime.PandaRuntimeException; 26 | 27 | import java.util.ArrayList; 28 | import java.util.List; 29 | 30 | public class LightApplication implements Application { 31 | 32 | private final List