forked from Orchid/orchid
temp commit
This commit is contained in:
@@ -4,11 +4,21 @@ use std::num::NonZeroU64;
|
||||
use orchid_api_derive::{Coding, Hierarchy};
|
||||
use orchid_api_traits::Request;
|
||||
|
||||
use crate::{HostExtReq, OrcResult, SysId, TStr, TStrv, TokenTree};
|
||||
use crate::{
|
||||
Expression, ExtHostReq, HostExtReq, OrcResult, SourceRange, SysId, TStr, TStrv, TokenTree,
|
||||
};
|
||||
|
||||
#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord, Coding)]
|
||||
pub struct ParsId(pub NonZeroU64);
|
||||
|
||||
#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord, Coding)]
|
||||
pub struct ParsedConstId(pub NonZeroU64);
|
||||
|
||||
/// Parse a single source line. Return values can be modules, constants, or
|
||||
/// token sequences for re-parsing. These re-parsed token sequences can also
|
||||
/// represent raw language items such as modules, imports, and const. This is
|
||||
/// how we enable generating imports without forcing import syntax to affect API
|
||||
/// versioning
|
||||
#[derive(Clone, Debug, Coding, Hierarchy)]
|
||||
#[extends(HostExtReq)]
|
||||
pub struct ParseLine {
|
||||
@@ -23,7 +33,46 @@ pub struct ParseLine {
|
||||
pub line: Vec<TokenTree>,
|
||||
}
|
||||
impl Request for ParseLine {
|
||||
type Response = OrcResult<Vec<TokenTree>>;
|
||||
type Response = OrcResult<Vec<ParsedLine>>;
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Coding)]
|
||||
pub struct ParsedLine {
|
||||
pub comments: Vec<Comment>,
|
||||
pub source_range: SourceRange,
|
||||
pub kind: ParsedLineKind,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Coding)]
|
||||
pub enum ParsedLineKind {
|
||||
Recursive(Vec<TokenTree>),
|
||||
Member(ParsedMember),
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Coding)]
|
||||
pub struct ParsedMember {
|
||||
pub name: TStr,
|
||||
pub exported: bool,
|
||||
pub kind: ParsedMemberKind,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Coding)]
|
||||
pub enum ParsedMemberKind {
|
||||
Constant(ParsedConstId),
|
||||
Module(Vec<ParsedLine>),
|
||||
}
|
||||
|
||||
/// Obtain the value of a parsed constant. This is guaranteed to be called after
|
||||
/// the last [ParseLine] but before any [crate::AtomReq]. As such, in principle
|
||||
/// the macro engine could run here.
|
||||
#[derive(Clone, Debug, Coding, Hierarchy)]
|
||||
#[extends(HostExtReq)]
|
||||
pub struct FetchParsedConst {
|
||||
pub sys: SysId,
|
||||
pub id: ParsedConstId,
|
||||
}
|
||||
impl Request for FetchParsedConst {
|
||||
type Response = Expression;
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Coding)]
|
||||
@@ -31,3 +80,25 @@ pub struct Comment {
|
||||
pub text: TStr,
|
||||
pub range: Range<u32>,
|
||||
}
|
||||
|
||||
/// Resolve relative names from the perspective of a constant. This can only be
|
||||
/// called during a [FetchParsedConst] call, but it can be called for a
|
||||
/// different [ParsedConstId] from the one in [FetchParsedConst].
|
||||
///
|
||||
/// Each name is either resolved to an alias or existing constant `Some(TStrv)`
|
||||
/// or not resolved `None`. An error is never raised, as names may have a
|
||||
/// primary meaning such as a local binding which can be overridden by specific
|
||||
/// true names such as those triggering macro keywords. It is not recommended to
|
||||
/// define syntax that can break by defining arbitrary constants, as line
|
||||
/// parsers can define new ones at will.
|
||||
#[derive(Clone, Debug, Coding, Hierarchy)]
|
||||
#[extends(ExtHostReq)]
|
||||
pub struct ResolveNames {
|
||||
pub sys: SysId,
|
||||
pub constid: ParsedConstId,
|
||||
pub names: Vec<TStrv>,
|
||||
}
|
||||
|
||||
impl Request for ResolveNames {
|
||||
type Response = Vec<Option<TStrv>>;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user