This commit is contained in:
@@ -1,5 +1,2 @@
|
|||||||
let foo = 1 + 2
|
|
||||||
let ffmain = "hello $foo"
|
|
||||||
|
|
||||||
let user = r[ "foo" 1, "bar" t[3, 4] ]
|
let user = r[ "foo" 1, "bar" t[3, 4] ]
|
||||||
let main = user."bar".1
|
let main = user.bar.1
|
||||||
|
|||||||
@@ -81,6 +81,9 @@ impl LexedData for GenTokTree {
|
|||||||
impl LexedData for Vec<GenTokTree> {
|
impl LexedData for Vec<GenTokTree> {
|
||||||
fn into_vec(self) -> Vec<GenTokTree> { self }
|
fn into_vec(self) -> Vec<GenTokTree> { self }
|
||||||
}
|
}
|
||||||
|
impl<const N: usize> LexedData for [GenTokTree; N] {
|
||||||
|
fn into_vec(self) -> Vec<GenTokTree> { self.to_vec() }
|
||||||
|
}
|
||||||
|
|
||||||
pub trait Lexer: Debug + Send + Sync + Sized + Default + 'static {
|
pub trait Lexer: Debug + Send + Sync + Sized + Default + 'static {
|
||||||
const CHAR_FILTER: &'static [RangeInclusive<char>];
|
const CHAR_FILTER: &'static [RangeInclusive<char>];
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
pub mod subscript_lexer;
|
||||||
|
|
||||||
use orchid_extension::tree::{GenMember, comments, prefix};
|
use orchid_extension::tree::{GenMember, comments, prefix};
|
||||||
|
|
||||||
use crate::proto;
|
use crate::proto;
|
||||||
|
|||||||
29
orchid-std/src/std/ops/subscript_lexer.rs
Normal file
29
orchid-std/src/std/ops/subscript_lexer.rs
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
use orchid_base::error::OrcRes;
|
||||||
|
use orchid_base::interner::is;
|
||||||
|
use orchid_base::parse::{name_char, name_start};
|
||||||
|
use orchid_extension::conv::ToExpr;
|
||||||
|
use orchid_extension::lexer::{LexContext, LexedData, Lexer, err_not_applicable};
|
||||||
|
use orchid_extension::tree::GenTok;
|
||||||
|
|
||||||
|
use crate::std::string::str_atom::IntStrAtom;
|
||||||
|
|
||||||
|
#[derive(Default, Debug)]
|
||||||
|
pub struct SubscriptLexer;
|
||||||
|
impl Lexer for SubscriptLexer {
|
||||||
|
const CHAR_FILTER: &'static [std::ops::RangeInclusive<char>] = &['.'..='.'];
|
||||||
|
async fn lex<'a>(tail: &'a str, lctx: &'a LexContext<'a>) -> OrcRes<(&'a str, impl LexedData)> {
|
||||||
|
if tail.len() <= 1 || !name_start(tail.chars().nth(1).unwrap()) {
|
||||||
|
return Err(err_not_applicable().await);
|
||||||
|
}
|
||||||
|
let name_len = match tail[1..].char_indices().find(|(_, c)| !name_char(*c)) {
|
||||||
|
None => tail.len() - 1,
|
||||||
|
Some((pos, _)) => pos,
|
||||||
|
};
|
||||||
|
let new_tail = &tail[name_len + 1..];
|
||||||
|
Ok((new_tail, [
|
||||||
|
GenTok::Name(is(".").await).at(lctx.pos_lt(1, &tail[1..])),
|
||||||
|
GenTok::NewExpr(IntStrAtom(is(&tail[1..name_len + 1]).await).to_gen().await)
|
||||||
|
.at(lctx.pos_tt(&tail[1..], new_tail)),
|
||||||
|
]))
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -20,6 +20,7 @@ use super::string::str_atom::{IntStrAtom, StrAtom};
|
|||||||
use super::string::str_lib::gen_str_lib;
|
use super::string::str_lib::gen_str_lib;
|
||||||
use crate::std::number::num_lexer::NumLexer;
|
use crate::std::number::num_lexer::NumLexer;
|
||||||
use crate::std::ops::gen_ops_lib;
|
use crate::std::ops::gen_ops_lib;
|
||||||
|
use crate::std::ops::subscript_lexer::SubscriptLexer;
|
||||||
use crate::std::option::{OptAtom, gen_option_lib};
|
use crate::std::option::{OptAtom, gen_option_lib};
|
||||||
use crate::std::protocol::proto_parser::{AsProtoParser, ProtoParser};
|
use crate::std::protocol::proto_parser::{AsProtoParser, ProtoParser};
|
||||||
use crate::std::protocol::type_parser::{AsTypeParser, TypeParser};
|
use crate::std::protocol::type_parser::{AsTypeParser, TypeParser};
|
||||||
@@ -105,7 +106,7 @@ impl System for StdSystem {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fn lexers() -> Vec<LexerObj> { vec![&StringLexer, &NumLexer] }
|
fn lexers() -> Vec<LexerObj> { vec![&StringLexer, &NumLexer, &SubscriptLexer] }
|
||||||
fn parsers() -> Vec<ParserObj> { vec![&AsTypeParser, &TypeParser, &AsProtoParser, &ProtoParser] }
|
fn parsers() -> Vec<ParserObj> { vec![&AsTypeParser, &TypeParser, &AsProtoParser, &ProtoParser] }
|
||||||
async fn env() -> Vec<GenMember> {
|
async fn env() -> Vec<GenMember> {
|
||||||
merge_trivial([
|
merge_trivial([
|
||||||
|
|||||||
Reference in New Issue
Block a user