Skip to content

Commit

Permalink
Merge pull request #102
Browse files Browse the repository at this point in the history
  • Loading branch information
delasy authored Oct 7, 2024
2 parents 895bd28 + 7ae746c commit 51024be
Show file tree
Hide file tree
Showing 125 changed files with 14,812 additions and 1,910 deletions.
25 changes: 0 additions & 25 deletions LICENSE.txt
Original file line number Diff line number Diff line change
Expand Up @@ -174,28 +174,3 @@
of your accepting any such warranty or additional liability.

END OF TERMS AND CONDITIONS

APPENDIX: How to apply the Apache License to your work.

To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.

Copyright [yyyy] [name of copyright owner]

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.
8 changes: 4 additions & 4 deletions packages/analyzer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import analyzer from "the/analyzer"

## API

### `analyze (f: ref Parser.File) str[]`
Analyzes and generates errors for parsed file.
### `analyze (mut f: ref Parser.File) str[]`
Analyzes and generates errors for parsed file. Also, assigned context on all possible nodes.

**Parameters**

Expand Down Expand Up @@ -196,7 +196,7 @@ Whether expression's body contains corresponding type.
type.isAlias()
```

### `Type.canBe (t: ref Type) bool`
### `Type.canCastTo (t: ref Type) bool`
Checks whether type can be cast to another type (should be used only on union type).

**Parameters**
Expand All @@ -211,7 +211,7 @@ Whether type can be cast to another type.

```the
mut tm := TypeMap{}
type.canBe(tm.get("int"))
type.canCastTo(tm.get("int"))
```

### `Type.get (nameOrIndex: int | str) TypeProperty`
Expand Down
76 changes: 21 additions & 55 deletions packages/analyzer/api/builtin
Original file line number Diff line number Diff line change
Expand Up @@ -18,48 +18,6 @@ obj ArrayElement {}
obj MapKey {}
obj MapValue {}

/* Used to represent a fixed-length sequence of bytes. */
export obj Buffer {
/* Whether array has elements. */
empty: bool
/* Number of buffer items. */
len: int

/**
* Accesses element by index and return its reference.
*
* @name [idx: int]
* @return ref byte
*/

/**
* Concatenates two arrays into one and returns resulting array.
*
* @param other - Another arrays you want to concatenate.
*/
fn concat (self: ref Self, other: Self) Self

/**
* Merges other array's elements into calling array.
*
* @param other - Another array you want to merge.
*/
fn merge (mut self: ref Self, other: Self) ref Self

/* Removes last element and returns it. */
fn pop (mut self: ref Self) byte

/**
* Adds new elements.
*
* @param elements - New elements to add.
*/
fn push (mut self: ref Self, elements: byte...) void

/* Returns a string representation. */
fn str (self: ref Self) str
}

/* Allows storing any variable of any type. */
export obj any {
/* Returns a string representation. */
Expand Down Expand Up @@ -164,6 +122,9 @@ export obj isize {
fn str (self: ref Self) str
}

/* Used when accessing this data is not possible. */
export obj never {}

/* Allows storing wide character as four byte. */
export obj rune {
/* Whether wide character is digit. */
Expand Down Expand Up @@ -299,9 +260,6 @@ export obj str {
*/
fn split (self: ref Self, delimiter := "") Self[]

/* Converts a string to `Buffer` object. */
fn toBuffer (self: ref Self) Buffer

/* Converts a string to `float` representation. */
fn toFloat (self: ref Self) float

Expand All @@ -318,6 +276,13 @@ export obj str {
*/
fn toInt (self: ref Self, radix := 10) int

/**
* Converts a string to `isize` representation.
*
* @param radix - Number between `2` and `36` that represents radix of the string. Use `0` to auto-guess radix.
*/
fn toIsize (self: ref Self, radix := 10) isize

/**
* Converts a string to `i8` representation.
*
Expand Down Expand Up @@ -374,6 +339,13 @@ export obj str {
*/
fn toU64 (self: ref Self, radix := 10) u64

/**
* Converts a string to `usize` representation.
*
* @param radix - Number between `2` and `36` that represents radix of the string. Use `0` to auto-guess radix.
*/
fn toUsize (self: ref Self, radix := 10) usize

/* Returns a string with whitespaces removed from both ends. */
fn trim (self: ref Self) Self

Expand Down Expand Up @@ -428,14 +400,14 @@ export obj Array {
* @param predicate - Function to execute on each element of the array.
* Should return a truthy value to keep the element in the resulting array.
*/
fn filter (self: ref Self, predicate: (it: ArrayElement) -> bool) Self
fn filter (self: ref Self, predicate: (it: ref ArrayElement) -> bool) Self

/**
* Calls `iterator` on every element.
*
* @param iterator - Function to execute on each element of the array.
*/
fn forEach (self: ref Self, iterator: (it: ArrayElement, idx: int) -> void) void
fn forEach (self: ref Self, iterator: (it: ref ArrayElement, idx: int) -> void) void

/**
* Calls `str` method on every element and joins result with separator.
Expand Down Expand Up @@ -491,7 +463,7 @@ export obj Array {
*
* @param comparator - Function that defines the sort order.
*/
fn sort (mut self: ref Self, comparator: (a: ArrayElement, b: ArrayElement) -> int) ref Self
fn sort (mut self: ref Self, comparator: (a: ref ArrayElement, b: ref ArrayElement) -> int) ref Self

/* Returns a string representation. */
fn str (self: ref Self) str
Expand Down Expand Up @@ -533,7 +505,7 @@ export obj Map {
*
* @param key - Key you want to get a value of.
*/
fn get (self: ref Self, key: MapKey) MapValue
fn get (self: ref Self, key: MapKey) ref MapValue

/**
* Checks whether certain key exists.
Expand Down Expand Up @@ -578,12 +550,6 @@ export obj Map {
fn str (self: ref Self) str
}

/* Object representation of object method. */
export obj Method {
/* Name of the object method. */
name: str
}

/* Allows storing various keyed collections and more complex entities. */
export obj Object {
/* Returns a string representation. */
Expand Down
2 changes: 1 addition & 1 deletion packages/analyzer/scripts/precompile-builtin
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import Analyzer, AnalyzerFile from "../src/analyzer"
import Type, TypeParameter, TypeProperty from "../src/type"
import stringifyType from "./stringify-type"

const CONSTRUCTORS := ["Array", "Enum", "Function", "Map", "Method", "Object", "Optional", "Reference", "Union"]
const CONSTRUCTORS := ["Array", "Enum", "Function", "Map", "Object", "Optional", "Reference", "Union"]
const IGNORED := ["ArrayElement", "MapKey", "MapValue"]

fn lcfirst (s: str) str {
Expand Down
Loading

0 comments on commit 51024be

Please sign in to comment.