Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion packages/zenscript/src/builtins/bool.dzs
Original file line number Diff line number Diff line change
@@ -1 +1,12 @@
zenClass bool
zenClass bool {
operator !() as bool;

operator &(value as bool) as bool;
operator |(value as bool) as bool;
operator ^(value as bool) as bool;

operator ==(value as bool) as bool;
operator !=(value as bool) as bool;

operator as() as string;
}
24 changes: 23 additions & 1 deletion packages/zenscript/src/builtins/byte.dzs
Original file line number Diff line number Diff line change
@@ -1 +1,23 @@
zenClass byte
zenClass byte {
operator -() as byte;
operator !() as byte;

operator &(value as byte) as byte;
operator |(value as byte) as byte;
operator ^(value as byte) as byte;

operator +(value as byte) as byte;
operator -(value as byte) as byte;
operator *(value as byte) as byte;
operator /(value as byte) as byte;
operator %(value as byte) as byte;

operator <(value as byte) as bool;
operator >(value as byte) as bool;
operator <=(value as byte) as bool;
operator >=(value as byte) as bool;
operator ==(value as byte) as bool;
operator !=(value as byte) as bool;

operator as() as short, int, long, float, double, string;
}
19 changes: 18 additions & 1 deletion packages/zenscript/src/builtins/double.dzs
Original file line number Diff line number Diff line change
@@ -1 +1,18 @@
zenClass double
zenClass double {
operator -() as double;

operator +(value as double) as double;
operator -(value as double) as double;
operator *(value as double) as double;
operator /(value as double) as double;
operator %(value as double) as double;

operator <(value as double) as bool;
operator >(value as double) as bool;
operator <=(value as double) as bool;
operator >=(value as double) as bool;
operator ==(value as double) as bool;
operator !=(value as double) as bool;

operator as() as byte, short, int, long, float, string;
}
19 changes: 18 additions & 1 deletion packages/zenscript/src/builtins/float.dzs
Original file line number Diff line number Diff line change
@@ -1 +1,18 @@
zenClass float
zenClass float {
operator -() as float;

operator +(value as float) as float;
operator -(value as float) as float;
operator *(value as float) as float;
operator /(value as float) as float;
operator %(value as float) as float;

operator <(value as float) as bool;
operator >(value as float) as bool;
operator <=(value as float) as bool;
operator >=(value as float) as bool;
operator ==(value as float) as bool;
operator !=(value as float) as bool;

operator as() as byte, short, int, long, double, string;
}
28 changes: 27 additions & 1 deletion packages/zenscript/src/builtins/int.dzs
Original file line number Diff line number Diff line change
@@ -1 +1,27 @@
zenClass int
import stanhebben.zenscript.value.IntRange;

zenClass int {
operator -() as int;
operator !() as int;

operator &(value as int) as int;
operator |(value as int) as int;
operator ^(value as int) as int;

operator +(value as int) as int;
operator -(value as int) as int;
operator *(value as int) as int;
operator /(value as int) as int;
operator %(value as int) as int;

operator <(value as int) as bool;
operator >(value as int) as bool;
operator <=(value as int) as bool;
operator >=(value as int) as bool;
operator ==(value as int) as bool;
operator !=(value as int) as bool;

operator ..(to as int) as IntRange;

operator as() as byte, short, long, float, double, string;
}
24 changes: 23 additions & 1 deletion packages/zenscript/src/builtins/long.dzs
Original file line number Diff line number Diff line change
@@ -1 +1,23 @@
zenClass long
zenClass long {
operator -() as long;
operator !() as long;

operator &(value as long) as long;
operator |(value as long) as long;
operator ^(value as long) as long;

operator +(value as long) as long;
operator -(value as long) as long;
operator *(value as long) as long;
operator /(value as long) as long;
operator %(value as long) as long;

operator <(value as long) as bool;
operator >(value as long) as bool;
operator <=(value as long) as bool;
operator >=(value as long) as bool;
operator ==(value as long) as bool;
operator !=(value as long) as bool;

operator as() as byte, short, int, float, double, string;
}
24 changes: 23 additions & 1 deletion packages/zenscript/src/builtins/short.dzs
Original file line number Diff line number Diff line change
@@ -1 +1,23 @@
zenClass short
zenClass short {
operator -() as short;
operator !() as short;

operator &(value as short) as short;
operator |(value as short) as short;
operator ^(value as short) as short;

operator +(value as short) as short;
operator -(value as short) as short;
operator *(value as short) as short;
operator /(value as short) as short;
operator %(value as short) as short;

operator <(value as short) as bool;
operator >(value as short) as bool;
operator <=(value as short) as bool;
operator >=(value as short) as bool;
operator ==(value as short) as bool;
operator !=(value as short) as bool;

operator as() as byte, int, long, float, double, string;
}
12 changes: 12 additions & 0 deletions packages/zenscript/src/builtins/string.dzs
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,16 @@ zenClass string {
function lastIndexOf(needle as string, fromIndex as int) as int;

function split(separator as string, maximum as int = 0) as [string];

operator +(value as string) as string;

operator has(substr as string) as bool;

operator [](index as int) as string;

operator ==(value as string) as bool;

operator !=(value as string) as bool;

operator as() as bool, byte, int, short, long, float, double;
}
11 changes: 8 additions & 3 deletions packages/zenscript/src/reference/member-provider.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
import type { AstNode, Stream } from 'langium'
import type { ZenScriptAstType } from '../generated/ast'
import type { OperatorFunctionDeclaration, ZenScriptAstType } from '../generated/ast'
import type { ZenScriptServices } from '../module'
import type { TypeComputer } from '../typing/type-computer'
import type { ZenScriptSyntheticAstType } from './synthetic'
import { EMPTY_STREAM, stream } from 'langium'
import { isClassDeclaration, isVariableDeclaration } from '../generated/ast'
import { isClassDeclaration, isOperatorFunctionDeclaration, isVariableDeclaration } from '../generated/ast'
import { ClassType, isAnyType, isClassType, isFunctionType, type Type, type ZenScriptType } from '../typing/type-description'
import { isStatic, streamClassChain, streamDeclaredMembers } from '../utils/ast'
import { defineRules } from '../utils/rule'
import { isSyntheticAstNode } from './synthetic'

export interface MemberProvider {
streamMembers: (source: AstNode | Type | undefined) => Stream<AstNode>
streamOperators: (source: AstNode | Type | undefined) => Stream<OperatorFunctionDeclaration>
}

type SourceMap = ZenScriptAstType & ZenScriptType & ZenScriptSyntheticAstType
Expand All @@ -24,10 +25,14 @@ export class ZenScriptMemberProvider implements MemberProvider {
this.typeComputer = services.typing.TypeComputer
}

streamMembers(source: AstNode | Type | undefined): Stream<AstNode> {
public streamMembers(source: AstNode | Type | undefined): Stream<AstNode> {
return this.rules(source?.$type)?.call(this, source) ?? EMPTY_STREAM
}

public streamOperators(source: AstNode | Type | undefined): Stream<OperatorFunctionDeclaration> {
return this.streamMembers(source).filter(isOperatorFunctionDeclaration)
}

private readonly rules = defineRules<RuleMap>({
SyntheticHierarchyNode: (source) => {
const declarations = stream(source.children.values())
Expand Down
Loading