Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
  • Loading branch information
OmarTawfik committed Aug 11, 2024
1 parent c991bf7 commit 4e2d394
Show file tree
Hide file tree
Showing 10 changed files with 656 additions and 569 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,85 @@
package nomic:slang@{{ model.slang_version }};

world slang {
export parser;
export cst;
export cursor;
export diagnostic;
export kinds;
export language;
export parse-error;
export parse-output;
export query;
export text-index;
}

interface parser {
interface cst {
use kinds.{nonterminal-kind};

variant node {
nonterminal(nonterminal-node),
terminal(terminal-node)
}

resource nonterminal-node {
kind: func() -> nonterminal-kind;
text-len: func() -> text-index;
children: func() -> list<node>;
create-cursor: func(text-offset: text-index) -> cursor;
unparse: func() -> string;
}

resource terminal-node {
kind: func() -> terminal-kind;
text-len: func() -> text-index;
text: func() -> string;
}
}

interface cursor {
resource cursor {
reset: func();
complete: func();
is-completed: func() -> bool;

clone: func() -> cursor;
spawn: func() -> cursor;

node: func() -> node;
label: func() -> option<edge-label>;

text-offset: func() -> text-index;
text-range: func() -> text-range;

depth: func() -> u32;

ancestors: func() -> list<nonterminal-node>;

go-to-next: func() -> bool;
go-to-next-non-descendent: func() -> bool;
go-to-previous: func() -> bool;

go-to-parent: func() -> bool;

go-to-first-child: func() -> bool;
go-to-last-child: func() -> bool;
go-to-nth-child: func(child-number: u32) -> bool;

go-to-next-sibling: func() -> bool;
go-to-previous-sibling: func() -> bool;

go-to-next-terminal: func() -> bool;
go-to-next-terminal-with-kind: func(kind: terminal-kind) -> bool;
go-to-next-terminal-with-kinds: func(kinds: list<terminal-kind>) -> bool;

go-to-next-nonterminal: func() -> bool;
go-to-next-nonterminal-with-kind: func(kind: nonterminal-kind) -> bool;
go-to-next-nonterminal-with-kinds: func(kinds: list<nonterminal-kind>) -> bool;

query: func(queries: list<borrow<query>>) -> query-match-iterator;
}
}

interface kinds {
enum nonterminal-kind {
{%- if rendering_in_stubs %}
stub1,
Expand Down Expand Up @@ -51,89 +125,36 @@ interface parser {
{%- endfor %}
{%- endif %}
}
}

interface language {
resource language {
supported-versions: static func() -> list<string>;
new: static func(version: string) -> result<language, string>;
version: func() -> string;
parse: func(kind: nonterminal-kind, input: string) -> parse-output;
}
}

interface parse-error {
resource parse-error {
// is-a diagnostic
severity: func() -> severity;
text-range: func() -> text-range;
message: func() -> string;
}
}

interface parse-output {
resource parse-output {
tree: func() -> node;
errors: func() -> list<parse-error>;
is-valid: func() -> bool;
create-tree-cursor: func() -> cursor;
}
}

variant node {
nonterminal(nonterminal-node),
terminal(terminal-node)
}

resource nonterminal-node {
kind: func() -> nonterminal-kind;
text-len: func() -> text-index;
children: func() -> list<node>;
create-cursor: func(text-offset: text-index) -> cursor;
unparse: func() -> string;
}

resource terminal-node {
kind: func() -> terminal-kind;
text-len: func() -> text-index;
text: func() -> string;
}

resource cursor {
reset: func();
complete: func();
is-completed: func() -> bool;

clone: func() -> cursor;
spawn: func() -> cursor;

node: func() -> node;
label: func() -> option<edge-label>;

text-offset: func() -> text-index;
text-range: func() -> text-range;

depth: func() -> u32;

ancestors: func() -> list<nonterminal-node>;

go-to-next: func() -> bool;
go-to-next-non-descendent: func() -> bool;
go-to-previous: func() -> bool;

go-to-parent: func() -> bool;

go-to-first-child: func() -> bool;
go-to-last-child: func() -> bool;
go-to-nth-child: func(child-number: u32) -> bool;

go-to-next-sibling: func() -> bool;
go-to-previous-sibling: func() -> bool;

go-to-next-terminal: func() -> bool;
go-to-next-terminal-with-kind: func(kind: terminal-kind) -> bool;
go-to-next-terminal-with-kinds: func(kinds: list<terminal-kind>) -> bool;

go-to-next-nonterminal: func() -> bool;
go-to-next-nonterminal-with-kind: func(kind: nonterminal-kind) -> bool;
go-to-next-nonterminal-with-kinds: func(kinds: list<nonterminal-kind>) -> bool;

query: func(queries: list<borrow<query>>) -> query-match-iterator;
}

interface query {
resource query {
parse: static func(text: string) -> result<query, query-error>;
}
Expand All @@ -152,14 +173,18 @@ interface parser {
resource query-match-iterator {
next: func() -> option<query-match>;
}

}

interface diagnostic {
enum severity {
error,
warning,
information,
hint,
}

}

interface text-index {
record text-index {
utf8: u32,
utf16: u32,
Expand All @@ -171,5 +196,4 @@ interface parser {
start: text-index,
end: text-index,
}

}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 4e2d394

Please sign in to comment.