Skip to content

Commit

Permalink
GH-528 Move return type of method to the end of its declaration (Resolve
Browse files Browse the repository at this point in the history
  • Loading branch information
dzikoysk committed Jul 6, 2020
1 parent 0975abe commit ce90064
Show file tree
Hide file tree
Showing 20 changed files with 287 additions and 44 deletions.
2 changes: 1 addition & 1 deletion examples/package_manager/panda.hjson
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ scripts: {
}

dependencies: [
github:dzikoysk/[email protected].2
github:dzikoysk/[email protected].3
]

2 changes: 1 addition & 1 deletion examples/tests/class_test.panda
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class Methods {
log count
}

shared Int count(Int count) {
shared count(Int count) -> Int {
return count
}

Expand Down
38 changes: 19 additions & 19 deletions examples/tests/current_test.panda
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}

Expand All @@ -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
}

Expand All @@ -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
Expand All @@ -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
}
Expand All @@ -266,7 +266,7 @@ internal class Test {
}
}

override String toString() {
override toString () -> String {
return 'Custom toString() in Test type #' + Int.toHexString(System.identityHashCode(this))
}

Expand All @@ -279,37 +279,37 @@ 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)

log "Value at array[test.index]: " + this.getArray()[test.INDEX]
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
}

}

internal class CustomThread : Thread {

constructor() {
constructor () {
base('CustomThread')
}

override run() {
override run () {
log 'Called in ' + Thread.currentThread().getName()
}

Expand Down
2 changes: 1 addition & 1 deletion examples/tests/current_test_required.panda
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion examples/tests/literal_methods.panda
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ main {

type LiteralMethod {

shared static Bool 'should return true' () {
shared static 'should return true' () -> Bool {
return true
}

Expand Down
4 changes: 2 additions & 2 deletions examples/tests/performance/matmul.panda
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<?, ? extends Buildable<Snippet>> create(String id) {
public static CustomPatternElementBuilder<?, ? extends Buildable<Snippet>> 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());
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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);
});
}

}
Original file line number Diff line number Diff line change
@@ -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<Snippetable> {

private final QuadPredicate<Map<String, Object>, SynchronizedSource, Snippetable, TokenInfo> predicate;

public NextVerifier(QuadPredicate<Map<String, Object>, SynchronizedSource, Snippetable, TokenInfo> predicate) {
this.predicate = predicate;
}

@Override
public boolean verify(Map<String, Object> results, SynchronizedSource source, Snippetable content) {
if (!source.hasNext()) {
return false;
}

return predicate.test(results, source, content, source.getNext());
}

}
Original file line number Diff line number Diff line change
@@ -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<TokenInfo> {

private final Separator separator;

public SectionVerifier(Separator separator) {
this.separator = separator;
}

@Override
public boolean verify(Map<String, Object> results, SynchronizedSource source, TokenInfo token) {
Section section = ObjectUtils.cast(Section.class, token.getToken());
return section != null && section.getSeparator().equals(separator);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@
*/
public final class Operators {

/*
Math
*/

private static final Collection<Operator> VALUES = new ArrayList<>();

public static final Operator ADDITION = add(VALUES, new Operator(OperatorFamilies.MATH, "+"));
Expand All @@ -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, "~"));

Expand All @@ -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, "=="));

Expand All @@ -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, "="));

Expand All @@ -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() { }

Expand Down
Loading

0 comments on commit ce90064

Please sign in to comment.