diff --git a/examples/package_manager/panda.hjson b/examples/package_manager/panda.hjson index 8554d1c4a..de9ee254f 100644 --- a/examples/package_manager/panda.hjson +++ b/examples/package_manager/panda.hjson @@ -7,6 +7,6 @@ scripts: { } dependencies: [ - github:dzikoysk/panda-dependency@1.0.2 + github:dzikoysk/panda-dependency@1.0.3 ] diff --git a/examples/tests/class_test.panda b/examples/tests/class_test.panda index d90b2989b..31d5fff54 100644 --- a/examples/tests/class_test.panda +++ b/examples/tests/class_test.panda @@ -17,7 +17,7 @@ class Methods { log count } - shared Int count(Int count) { + shared count(Int count) -> Int { return count } diff --git a/examples/tests/current_test.panda b/examples/tests/current_test.panda index 40ff69cea..6c5e804c4 100644 --- a/examples/tests/current_test.panda +++ b/examples/tests/current_test.panda @@ -180,29 +180,29 @@ main { shared interface IEcho { // yes, we require implementation of static method - shared static anotherEcho(String doSth) + shared static anotherEcho (String doSth) // standard method to impl - internal test() + internal test () } // simple class that extends class Test and implements interface IEcho shared class Foo : Test, IEcho { - constructor() { + constructor () { base('We need to call base constructor if we extend another type with custom constructor') } // we need to mark overridden methods by the keyword - override static anotherEcho(String message1) { + override static anotherEcho (String message1) { log message1 } // we need to impl all methods - override test() { } + override test () { } - override String toString() { + override toString () -> String { return 'Foo' } @@ -213,12 +213,12 @@ internal class Entity { internal String name - constructor(String name) { + constructor (String name) { this.name = name } // override native equals and name-based equality - override PrimitiveBool equals(Object obj) { + override equals (Object obj) -> PrimitiveBool { return obj is Entity && name == (obj as Entity).name } @@ -238,7 +238,7 @@ internal class Test { internal String message2 // constructor prints random message and assigns itself to testField field - constructor(String message2) { + constructor (String message2) { log message2 this.testField = this this.message2 = message2 @@ -247,17 +247,17 @@ internal class Test { // static field that creates instance of the current class public static Test TEST = new Test('Static initialization of class instance') - shared echo(Object message3) { + shared echo (Object message3) { log message3 } // method with string based name - shared Bool 'should return true' () { + shared 'should return true' () -> Bool { return true } // get test instance - shared Test getTestField() { + shared getTestField () -> Test { if true { return this.testField } @@ -266,7 +266,7 @@ internal class Test { } } - override String toString() { + override toString () -> String { return 'Custom toString() in Test type #' + Int.toHexString(System.identityHashCode(this)) } @@ -279,12 +279,12 @@ internal class TestArray { shared String[] array // create TestArray and define array size - constructor(Int size) { + constructor (Int size) { this.array = new String[size] } // modify some values in array - shared modify(Test test) { + shared modify (Test test) { this.getArray()[Test.INDEX] = "Hello Array" array[6] = String.valueOf(this) @@ -292,12 +292,12 @@ internal class TestArray { varargs(array) } - shared varargs(nil mut String... varargs) { + shared varargs (nil mut String... varargs) { log varargs.asString() } // get array - internal String[] getArray() { + internal getArray() -> String[] { return array } @@ -305,11 +305,11 @@ internal class TestArray { internal class CustomThread : Thread { - constructor() { + constructor () { base('CustomThread') } - override run() { + override run () { log 'Called in ' + Thread.currentThread().getName() } diff --git a/examples/tests/current_test_required.panda b/examples/tests/current_test_required.panda index 769e00df8..03a0b4398 100644 --- a/examples/tests/current_test_required.panda +++ b/examples/tests/current_test_required.panda @@ -4,7 +4,7 @@ module example-test export org.panda_lang.utilities.commons.StringUtils // shared class to test visibility access -shared class Required { +shared type Required { shared hello() { log "Required print" diff --git a/examples/tests/literal_methods.panda b/examples/tests/literal_methods.panda index 2c611feeb..a81221a48 100644 --- a/examples/tests/literal_methods.panda +++ b/examples/tests/literal_methods.panda @@ -6,7 +6,7 @@ main { type LiteralMethod { - shared static Bool 'should return true' () { + shared static 'should return true' () -> Bool { return true } diff --git a/examples/tests/performance/matmul.panda b/examples/tests/performance/matmul.panda index 851cc0c17..de3686df7 100644 --- a/examples/tests/performance/matmul.panda +++ b/examples/tests/performance/matmul.panda @@ -32,7 +32,7 @@ module performance internal class Matmul { - internal Double[][] matgen(Int n) { + internal matgen(Int n) -> Double[][] { Double[][] a = new Double[n][n] Double tmp = 1.0 / n / n @@ -45,7 +45,7 @@ internal class Matmul { return a } - internal Double[][] matmul(Double[][] a, Double[][] b) { + internal matmul(Double[][] a, Double[][] b) -> Double[][] { Int m = a.size() Int n = a[0].size() Int p = b[0].size() diff --git a/panda-framework/src/main/java/org/panda_lang/framework/language/interpreter/pattern/custom/elements/SectionElement.java b/panda-framework/src/main/java/org/panda_lang/framework/language/interpreter/pattern/custom/elements/SectionElement.java index 624503a1e..e7f087afd 100644 --- a/panda-framework/src/main/java/org/panda_lang/framework/language/interpreter/pattern/custom/elements/SectionElement.java +++ b/panda-framework/src/main/java/org/panda_lang/framework/language/interpreter/pattern/custom/elements/SectionElement.java @@ -19,17 +19,17 @@ import org.panda_lang.framework.design.interpreter.token.Snippet; import org.panda_lang.framework.language.interpreter.pattern.custom.Buildable; import org.panda_lang.framework.language.interpreter.pattern.custom.CustomPatternElementBuilder; -import org.panda_lang.framework.language.interpreter.pattern.custom.verifiers.TokenTypeVerifier; -import org.panda_lang.framework.language.resource.syntax.TokenTypes; +import org.panda_lang.framework.language.interpreter.pattern.custom.verifiers.SectionVerifier; import org.panda_lang.framework.language.resource.syntax.auxiliary.Section; +import org.panda_lang.framework.language.resource.syntax.separator.Separator; public final class SectionElement { private SectionElement() { } - public static CustomPatternElementBuilder> create(String id) { + public static CustomPatternElementBuilder> create(String id, Separator separator) { return WildcardElement.create(id) - .verify(new TokenTypeVerifier(TokenTypes.SECTION)) + .verify(new SectionVerifier(separator)) .map(snippetable -> snippetable.toSnippet().getFirst().toToken(Section.class).getContent()); } diff --git a/panda-framework/src/main/java/org/panda_lang/framework/language/interpreter/pattern/custom/verifiers/NextSectionVerifier.java b/panda-framework/src/main/java/org/panda_lang/framework/language/interpreter/pattern/custom/verifiers/NextSectionVerifier.java new file mode 100644 index 000000000..c76040def --- /dev/null +++ b/panda-framework/src/main/java/org/panda_lang/framework/language/interpreter/pattern/custom/verifiers/NextSectionVerifier.java @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2020 Dzikoysk + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.panda_lang.framework.language.interpreter.pattern.custom.verifiers; + +import org.panda_lang.framework.language.resource.syntax.auxiliary.Section; +import org.panda_lang.framework.language.resource.syntax.separator.Separator; +import org.panda_lang.utilities.commons.ObjectUtils; + +public final class NextSectionVerifier extends NextVerifier { + + public NextSectionVerifier(Separator separator) { + super((res, src, s, next) -> { + Section section = ObjectUtils.cast(Section.class, next.getToken()); + return section != null && section.getSeparator().equals(separator); + }); + } + +} diff --git a/panda-framework/src/main/java/org/panda_lang/framework/language/interpreter/pattern/custom/verifiers/NextVerifier.java b/panda-framework/src/main/java/org/panda_lang/framework/language/interpreter/pattern/custom/verifiers/NextVerifier.java new file mode 100644 index 000000000..fb575eaae --- /dev/null +++ b/panda-framework/src/main/java/org/panda_lang/framework/language/interpreter/pattern/custom/verifiers/NextVerifier.java @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2020 Dzikoysk + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.panda_lang.framework.language.interpreter.pattern.custom.verifiers; + +import org.panda_lang.framework.design.interpreter.token.Snippetable; +import org.panda_lang.framework.design.interpreter.token.TokenInfo; +import org.panda_lang.framework.language.interpreter.pattern.custom.CustomVerify; +import org.panda_lang.framework.language.interpreter.token.SynchronizedSource; +import org.panda_lang.utilities.commons.function.QuadPredicate; + +import java.util.Map; + +public class NextVerifier implements CustomVerify { + + private final QuadPredicate, SynchronizedSource, Snippetable, TokenInfo> predicate; + + public NextVerifier(QuadPredicate, SynchronizedSource, Snippetable, TokenInfo> predicate) { + this.predicate = predicate; + } + + @Override + public boolean verify(Map results, SynchronizedSource source, Snippetable content) { + if (!source.hasNext()) { + return false; + } + + return predicate.test(results, source, content, source.getNext()); + } + +} diff --git a/panda-framework/src/main/java/org/panda_lang/framework/language/interpreter/pattern/custom/verifiers/SectionVerifier.java b/panda-framework/src/main/java/org/panda_lang/framework/language/interpreter/pattern/custom/verifiers/SectionVerifier.java new file mode 100644 index 000000000..0a412a592 --- /dev/null +++ b/panda-framework/src/main/java/org/panda_lang/framework/language/interpreter/pattern/custom/verifiers/SectionVerifier.java @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2020 Dzikoysk + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.panda_lang.framework.language.interpreter.pattern.custom.verifiers; + +import org.panda_lang.framework.design.interpreter.token.TokenInfo; +import org.panda_lang.framework.language.interpreter.pattern.custom.CustomVerify; +import org.panda_lang.framework.language.interpreter.token.SynchronizedSource; +import org.panda_lang.framework.language.resource.syntax.auxiliary.Section; +import org.panda_lang.framework.language.resource.syntax.separator.Separator; +import org.panda_lang.utilities.commons.ObjectUtils; + +import java.util.Map; + +public final class SectionVerifier implements CustomVerify { + + private final Separator separator; + + public SectionVerifier(Separator separator) { + this.separator = separator; + } + + @Override + public boolean verify(Map results, SynchronizedSource source, TokenInfo token) { + Section section = ObjectUtils.cast(Section.class, token.getToken()); + return section != null && section.getSeparator().equals(separator); + } + +} diff --git a/panda-framework/src/main/java/org/panda_lang/framework/language/resource/syntax/operator/Operators.java b/panda-framework/src/main/java/org/panda_lang/framework/language/resource/syntax/operator/Operators.java index f91a05b6e..3305f6dd7 100644 --- a/panda-framework/src/main/java/org/panda_lang/framework/language/resource/syntax/operator/Operators.java +++ b/panda-framework/src/main/java/org/panda_lang/framework/language/resource/syntax/operator/Operators.java @@ -28,6 +28,10 @@ */ public final class Operators { + /* + Math + */ + private static final Collection VALUES = new ArrayList<>(); public static final Operator ADDITION = add(VALUES, new Operator(OperatorFamilies.MATH, "+")); @@ -40,6 +44,9 @@ public final class Operators { public static final Operator MODULE = add(VALUES, new Operator(OperatorFamilies.MATH, "%")); + /* + Logic + */ public static final Operator BITWISE_NOT = add(VALUES, new Operator(OperatorFamilies.MATH, "~")); @@ -53,6 +60,9 @@ public final class Operators { public static final Operator BITWISE_RIGHT_SHIFT = add(VALUES, new Operator(OperatorFamilies.MATH, ">>")); + /* + Logical + */ public static final Operator EQUAL_TO = add(VALUES, new Operator(OperatorFamilies.LOGICAL, "==")); @@ -72,11 +82,17 @@ public final class Operators { public static final Operator NOT = add(VALUES, new Operator(OperatorFamilies.LOGICAL, "!")); + /* + Crease + */ public static final Operator INCREMENT = add(VALUES, new Operator(OperatorFamilies.CREASE, "++")); public static final Operator DECREMENT = add(VALUES, new Operator(OperatorFamilies.CREASE, "--")); + /* + Assignation + */ public static final Operator ASSIGNMENT = add(VALUES, new Operator(OperatorFamilies.ASSIGNATION, "=")); @@ -90,11 +106,17 @@ public final class Operators { public static final Operator REMAINDER_ASSIGNMENT = add(VALUES, new Operator(OperatorFamilies.ASSIGNATION, "%=")); + /* + Undefined + */ public static final Operator EROTEME = add(VALUES, new Operator(OperatorFamilies.UNDEFINED, "?")); public static final Operator COLON = add(VALUES, new Operator(OperatorFamilies.UNDEFINED, ":")); + public static final Operator ARROW = add(VALUES, new Operator(OperatorFamilies.UNDEFINED, "->")); + + public static final Operator LAMBDA = add(VALUES, new Operator(OperatorFamilies.UNDEFINED, "=>")); private Operators() { } diff --git a/panda-framework/src/test/java/org/panda_lang/framework/language/interpreter/BenchmarkRunner.java b/panda-framework/src/test/java/org/panda_lang/framework/language/interpreter/BenchmarkRunner.java new file mode 100644 index 000000000..4c8961aed --- /dev/null +++ b/panda-framework/src/test/java/org/panda_lang/framework/language/interpreter/BenchmarkRunner.java @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2020 Dzikoysk + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.panda_lang.framework.language.interpreter; + +import org.openjdk.jmh.runner.Runner; +import org.openjdk.jmh.runner.RunnerException; +import org.openjdk.jmh.runner.options.Options; +import org.openjdk.jmh.runner.options.OptionsBuilder; + +public final class BenchmarkRunner { + + public static void run(Class clazz) throws RunnerException { + Options options = new OptionsBuilder() + .include(clazz.getName()) + .build(); + + Runner runner = new Runner(options); + runner.run(); + } + +} diff --git a/panda-framework/src/test/java/org/panda_lang/framework/language/interpreter/pattern/PatternBenchmark.java b/panda-framework/src/test/java/org/panda_lang/framework/language/interpreter/pattern/PatternBenchmark.java new file mode 100644 index 000000000..6a3e94757 --- /dev/null +++ b/panda-framework/src/test/java/org/panda_lang/framework/language/interpreter/pattern/PatternBenchmark.java @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2020 Dzikoysk + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.panda_lang.framework.language.interpreter.pattern; + +import org.openjdk.jmh.annotations.Benchmark; +import org.openjdk.jmh.annotations.Fork; +import org.openjdk.jmh.annotations.Measurement; +import org.openjdk.jmh.annotations.OutputTimeUnit; +import org.openjdk.jmh.annotations.Warmup; +import org.panda_lang.framework.design.interpreter.token.Snippet; +import org.panda_lang.framework.language.interpreter.BenchmarkRunner; +import org.panda_lang.framework.language.interpreter.lexer.PandaLexerUtils; +import org.panda_lang.framework.language.interpreter.pattern.custom.CustomPattern; +import org.panda_lang.framework.language.interpreter.pattern.custom.Result; +import org.panda_lang.framework.language.interpreter.pattern.custom.elements.KeywordElement; +import org.panda_lang.framework.language.interpreter.pattern.linear.LinearPattern; +import org.panda_lang.framework.language.interpreter.pattern.linear.LinearPatternResult; +import org.panda_lang.framework.language.resource.syntax.keyword.Keywords; + +import java.util.concurrent.TimeUnit; + +@Fork(value = 1) +@Warmup(iterations = 1) +@Measurement(iterations = 2) +@OutputTimeUnit(TimeUnit.MILLISECONDS) +public class PatternBenchmark { + + private static final Snippet SINGLE_KEYWORD = PandaLexerUtils.convert("PatternBenchmark", "while"); + private static final CustomPattern SINGLE_KEYWORD_CUSTOM = CustomPattern.of(KeywordElement.create(Keywords.WHILE)); + private static final LinearPattern SINGLE_KEYWORD_LINEAR = LinearPattern.compile("while"); + + @Benchmark + public Result singleKeywordCustom() { + return SINGLE_KEYWORD_CUSTOM.match(SINGLE_KEYWORD); + } + + @Benchmark + public LinearPatternResult singleKeywordLinear() { + return SINGLE_KEYWORD_LINEAR.match(SINGLE_KEYWORD); + } + + public static void main(String[] args) throws Exception { + BenchmarkRunner.run(PatternBenchmark.class); + } + +} diff --git a/panda-framework/src/test/java/org/panda_lang/framework/language/interpreter/pattern/custom/CustomPatternTest.java b/panda-framework/src/test/java/org/panda_lang/framework/language/interpreter/pattern/custom/CustomPatternTest.java index b9fccb986..e85fcb28b 100644 --- a/panda-framework/src/test/java/org/panda_lang/framework/language/interpreter/pattern/custom/CustomPatternTest.java +++ b/panda-framework/src/test/java/org/panda_lang/framework/language/interpreter/pattern/custom/CustomPatternTest.java @@ -37,6 +37,7 @@ import org.panda_lang.framework.language.interpreter.pattern.custom.verifiers.TokenTypeVerifier; import org.panda_lang.framework.language.resource.syntax.TokenTypes; import org.panda_lang.framework.language.resource.syntax.keyword.Keywords; +import org.panda_lang.framework.language.resource.syntax.separator.Separators; import java.util.Collections; @@ -49,8 +50,8 @@ void method() { UnitElement.create("isStatic").content("static").optional(), TypeElement.create("type").optional().verify(new NextTokenTypeVerifier(TokenTypes.UNKNOWN, TokenTypes.SEQUENCE)), WildcardElement.create("name").verify(new TokenTypeVerifier(TokenTypes.UNKNOWN, TokenTypes.SEQUENCE)), - SectionElement.create("parameters"), - SectionElement.create("body") + SectionElement.create("parameters", Separators.PARENTHESIS_LEFT), + SectionElement.create("body", Separators.BRACE_LEFT) ); Snippet source = convert("shared static String[] 'of'(String a, Int[] b) { /* content */ } another content"); @@ -97,7 +98,7 @@ void condition() { VariantElement.create("variant").content( SubPatternElement.create("with-condition").of( VariantElement.create("type").content("if", "else if"), - SectionElement.create("section") + SectionElement.create("section", Separators.PARENTHESIS_LEFT) ), KeywordElement.create(Keywords.ELSE) ) diff --git a/panda-utilities/src/test/java/org/panda_lang/utilities/BenchmarkUtils.java b/panda-utilities/src/test/java/org/panda_lang/utilities/BenchmarkRunner.java similarity index 96% rename from panda-utilities/src/test/java/org/panda_lang/utilities/BenchmarkUtils.java rename to panda-utilities/src/test/java/org/panda_lang/utilities/BenchmarkRunner.java index 7c29bd57b..acdd19fb2 100644 --- a/panda-utilities/src/test/java/org/panda_lang/utilities/BenchmarkUtils.java +++ b/panda-utilities/src/test/java/org/panda_lang/utilities/BenchmarkRunner.java @@ -21,7 +21,7 @@ import org.openjdk.jmh.runner.options.Options; import org.openjdk.jmh.runner.options.OptionsBuilder; -public final class BenchmarkUtils { +public final class BenchmarkRunner { public static void run(Class clazz) throws RunnerException { Options options = new OptionsBuilder() diff --git a/panda-utilities/src/test/java/org/panda_lang/utilities/inject/DependencyInjectionBenchmark.java b/panda-utilities/src/test/java/org/panda_lang/utilities/inject/DependencyInjectionBenchmark.java index ddc077719..44443ef92 100644 --- a/panda-utilities/src/test/java/org/panda_lang/utilities/inject/DependencyInjectionBenchmark.java +++ b/panda-utilities/src/test/java/org/panda_lang/utilities/inject/DependencyInjectionBenchmark.java @@ -25,7 +25,7 @@ import org.openjdk.jmh.annotations.Setup; import org.openjdk.jmh.annotations.State; import org.openjdk.jmh.annotations.Warmup; -import org.panda_lang.utilities.BenchmarkUtils; +import org.panda_lang.utilities.BenchmarkRunner; import org.panda_lang.utilities.commons.ReflectionUtils; import org.panda_lang.utilities.inject.annotations.Inject; @@ -68,7 +68,7 @@ public void setup() throws Exception { } public static void main(String[] args) throws Exception { - BenchmarkUtils.run(DependencyInjectionBenchmark.class); + BenchmarkRunner.run(DependencyInjectionBenchmark.class); } } diff --git a/panda/src/main/java/org/panda_lang/panda/language/interpreter/parser/block/BlockParser.java b/panda/src/main/java/org/panda_lang/panda/language/interpreter/parser/block/BlockParser.java index 13bded09c..c291fdcdb 100644 --- a/panda/src/main/java/org/panda_lang/panda/language/interpreter/parser/block/BlockParser.java +++ b/panda/src/main/java/org/panda_lang/panda/language/interpreter/parser/block/BlockParser.java @@ -61,7 +61,7 @@ protected BootstrapInitializer initialize(Context context, BootstrapInitia .initializer(new CustomPatternInitializer()) .pattern(CustomPattern.of( ContentBeforeElement.create("declaration").before(Separators.BRACE_LEFT), - SectionElement.create("body") + SectionElement.create("body", Separators.BRACE_LEFT) )); } diff --git a/panda/src/main/java/org/panda_lang/panda/language/resource/syntax/type/FieldParser.java b/panda/src/main/java/org/panda_lang/panda/language/resource/syntax/type/FieldParser.java index abbc3334c..52a216150 100644 --- a/panda/src/main/java/org/panda_lang/panda/language/resource/syntax/type/FieldParser.java +++ b/panda/src/main/java/org/panda_lang/panda/language/resource/syntax/type/FieldParser.java @@ -72,10 +72,10 @@ protected BootstrapInitializer initialize(Context context, BootstrapInitia KeywordElement.create(Keywords.NIL).optional(), TypeElement.create("type").verify(new NextTokenTypeVerifier(TokenTypes.UNKNOWN)), WildcardElement.create("name").verify(new TokenTypeVerifier(TokenTypes.UNKNOWN)), - SubPatternElement.create("assign").optional().of( + SubPatternElement.create("assign").of( UnitElement.create("operator").content("="), ExpressionElement.create("assignation").map(ExpressionTransaction::getExpression) - ) + ).optional() )); } diff --git a/panda/src/main/java/org/panda_lang/panda/language/resource/syntax/type/MethodParser.java b/panda/src/main/java/org/panda_lang/panda/language/resource/syntax/type/MethodParser.java index e9897660d..4e2b83a92 100644 --- a/panda/src/main/java/org/panda_lang/panda/language/resource/syntax/type/MethodParser.java +++ b/panda/src/main/java/org/panda_lang/panda/language/resource/syntax/type/MethodParser.java @@ -40,23 +40,26 @@ import org.panda_lang.framework.language.interpreter.pattern.custom.Result; import org.panda_lang.framework.language.interpreter.pattern.custom.elements.KeywordElement; import org.panda_lang.framework.language.interpreter.pattern.custom.elements.SectionElement; +import org.panda_lang.framework.language.interpreter.pattern.custom.elements.SubPatternElement; import org.panda_lang.framework.language.interpreter.pattern.custom.elements.TypeElement; import org.panda_lang.framework.language.interpreter.pattern.custom.elements.UnitElement; import org.panda_lang.framework.language.interpreter.pattern.custom.elements.VariantElement; import org.panda_lang.framework.language.interpreter.pattern.custom.elements.WildcardElement; -import org.panda_lang.framework.language.interpreter.pattern.custom.verifiers.NextTokenTypeVerifier; +import org.panda_lang.framework.language.interpreter.pattern.custom.verifiers.NextSectionVerifier; import org.panda_lang.framework.language.interpreter.pattern.custom.verifiers.TokenTypeVerifier; import org.panda_lang.framework.language.resource.syntax.TokenTypes; import org.panda_lang.framework.language.resource.syntax.keyword.Keywords; +import org.panda_lang.framework.language.resource.syntax.operator.Operators; +import org.panda_lang.framework.language.resource.syntax.separator.Separators; import org.panda_lang.panda.language.interpreter.parser.RegistrableParser; import org.panda_lang.panda.language.interpreter.parser.ScopeParser; import org.panda_lang.panda.language.interpreter.parser.context.BootstrapInitializer; +import org.panda_lang.panda.language.interpreter.parser.context.Delegation; import org.panda_lang.panda.language.interpreter.parser.context.ParserBootstrap; import org.panda_lang.panda.language.interpreter.parser.context.annotations.Autowired; import org.panda_lang.panda.language.interpreter.parser.context.annotations.Channel; import org.panda_lang.panda.language.interpreter.parser.context.annotations.Ctx; import org.panda_lang.panda.language.interpreter.parser.context.annotations.Src; -import org.panda_lang.panda.language.interpreter.parser.context.Delegation; import org.panda_lang.panda.language.interpreter.parser.context.handlers.CustomPatternHandler; import org.panda_lang.panda.language.interpreter.parser.context.initializers.CustomPatternInitializer; import org.panda_lang.panda.language.resource.syntax.PandaPriorities; @@ -80,10 +83,13 @@ protected BootstrapInitializer initialize(Context context, BootstrapInitia KeywordElement.create(Keywords.OVERRIDE).optional(), VariantElement.create("visibility").optional().content("public", "shared", "internal").map(value -> Visibility.valueOf(value.toString().toUpperCase())), UnitElement.create("static").content("static").optional(), - TypeElement.create("type").optional().verify(new NextTokenTypeVerifier(TokenTypes.UNKNOWN, TokenTypes.SEQUENCE)), WildcardElement.create("name").verify(new TokenTypeVerifier(TokenTypes.UNKNOWN, TokenTypes.SEQUENCE)), - SectionElement.create("parameters"), - SectionElement.create("body").optional() + SectionElement.create("parameters", Separators.PARENTHESIS_LEFT), + SubPatternElement.create("return-type").of( + UnitElement.create("arrow").content(Operators.ARROW.getValue()), + TypeElement.create("type").verify(new NextSectionVerifier(Separators.BRACE_LEFT)) + ).optional(), + SectionElement.create("body", Separators.BRACE_LEFT).optional() )); } diff --git a/panda/src/main/java/org/panda_lang/panda/language/resource/syntax/type/TypeParser.java b/panda/src/main/java/org/panda_lang/panda/language/resource/syntax/type/TypeParser.java index 12d3708a9..f7911922f 100644 --- a/panda/src/main/java/org/panda_lang/panda/language/resource/syntax/type/TypeParser.java +++ b/panda/src/main/java/org/panda_lang/panda/language/resource/syntax/type/TypeParser.java @@ -50,6 +50,7 @@ import org.panda_lang.framework.language.interpreter.token.PandaSourceStream; import org.panda_lang.framework.language.resource.syntax.TokenTypes; import org.panda_lang.framework.language.resource.syntax.keyword.Keywords; +import org.panda_lang.framework.language.resource.syntax.separator.Separators; import org.panda_lang.panda.language.interpreter.parser.RegistrableParser; import org.panda_lang.panda.language.interpreter.parser.context.BootstrapInitializer; import org.panda_lang.panda.language.interpreter.parser.context.ParserBootstrap; @@ -82,7 +83,7 @@ protected BootstrapInitializer initialize(Context context, BootstrapInitia UnitElement.create("extends").content(":"), CustomElement.create("inherited").custom((data, source) -> TypeParserUtils.readTypes(source)) ), - SectionElement.create("body") + SectionElement.create("body", Separators.BRACE_LEFT) )); }