mirror of
https://github.com/HigherOrderCO/Kind1.git
synced 2024-09-11 08:45:32 +03:00
fix: Fix formatting, extra comments, etc
This commit is contained in:
parent
7ea18ae113
commit
78203ef815
@ -52,7 +52,11 @@ pub fn to_book(session: &mut Session, path: &PathBuf) -> Option<concrete::Book>
|
||||
Some(concrete_book)
|
||||
}
|
||||
|
||||
pub fn erase_book(session: &mut Session, path: &PathBuf, entrypoint: &[String]) -> Option<desugared::Book> {
|
||||
pub fn erase_book(
|
||||
session: &mut Session,
|
||||
path: &PathBuf,
|
||||
entrypoint: &[String],
|
||||
) -> Option<desugared::Book> {
|
||||
let concrete_book = to_book(session, path)?;
|
||||
let desugared_book = desugar::desugar_book(session.diagnostic_sender.clone(), &concrete_book)?;
|
||||
erasure::erase_book(
|
||||
|
@ -23,7 +23,10 @@ const EXT: &str = "kind2";
|
||||
/// Tries to accumulate on a buffer all of the
|
||||
/// paths that exists (so we can just throw an
|
||||
/// error about ambiguous resolution to the user)
|
||||
fn accumulate_neighbour_paths(ident: &QualifiedIdent, raw_path: &Path) -> Result<Option<PathBuf>, DiagnosticFrame> {
|
||||
fn accumulate_neighbour_paths(
|
||||
ident: &QualifiedIdent,
|
||||
raw_path: &Path,
|
||||
) -> Result<Option<PathBuf>, DiagnosticFrame> {
|
||||
let mut canon_path = raw_path.to_path_buf();
|
||||
let mut dir_file_path = raw_path.to_path_buf();
|
||||
let dir_path = raw_path.to_path_buf();
|
||||
@ -62,7 +65,7 @@ fn ident_to_path(
|
||||
raw_path.pop();
|
||||
accumulate_neighbour_paths(&ident, &raw_path)
|
||||
}
|
||||
rest => rest
|
||||
rest => rest,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2,7 +2,7 @@ use kind_span::{Locatable, Range};
|
||||
use kind_tree::concrete::expr::*;
|
||||
use kind_tree::concrete::pat::PatIdent;
|
||||
use kind_tree::symbol::{Ident, QualifiedIdent};
|
||||
use kind_tree::{Operator, Number, NumType};
|
||||
use kind_tree::{NumType, Number, Operator};
|
||||
|
||||
use crate::errors::SyntaxError;
|
||||
use crate::lexer::tokens::Token;
|
||||
|
@ -56,15 +56,25 @@ impl<'a> Lexer<'a> {
|
||||
|
||||
/// Lexes a number of base @base@, figuring out it's type
|
||||
/// Lexes 0 if not at a digit position
|
||||
fn lex_num_and_type_with_base(&mut self, num_start: usize, base: u32, err: EncodeSequence) -> (Token, Range) {
|
||||
fn lex_num_and_type_with_base(
|
||||
&mut self,
|
||||
num_start: usize,
|
||||
base: u32,
|
||||
err: EncodeSequence,
|
||||
) -> (Token, Range) {
|
||||
let num = self.accumulate_while(&|x| x.is_digit(base) || x == '_');
|
||||
let num = if num.is_empty() { "0" } else { num };
|
||||
let num = num.to_string();
|
||||
let type_start = self.span();
|
||||
let make_num_err = |x: &Self| (
|
||||
Token::Error(Box::new(SyntaxError::InvalidNumberRepresentation(err, x.mk_range(num_start)))),
|
||||
let make_num_err = |x: &Self| {
|
||||
(
|
||||
Token::Error(Box::new(SyntaxError::InvalidNumberRepresentation(
|
||||
err,
|
||||
x.mk_range(num_start),
|
||||
);
|
||||
))),
|
||||
x.mk_range(num_start),
|
||||
)
|
||||
};
|
||||
match self.peekable.peek() {
|
||||
Some('U' | 'u') => {
|
||||
self.next_char();
|
||||
@ -85,11 +95,14 @@ impl<'a> Lexer<'a> {
|
||||
}
|
||||
}
|
||||
_ => (
|
||||
Token::Error(Box::new(SyntaxError::InvalidNumberType(format!("u{}", type_), self.mk_range(type_start)))),
|
||||
Token::Error(Box::new(SyntaxError::InvalidNumberType(
|
||||
format!("u{}", type_),
|
||||
self.mk_range(type_start),
|
||||
))),
|
||||
self.mk_range(type_start),
|
||||
),
|
||||
}
|
||||
},
|
||||
}
|
||||
Some(_) | None => {
|
||||
if let Ok(res) = u64::from_str_radix(&num.replace('_', ""), base) {
|
||||
(Token::Num60(res), self.mk_range(num_start))
|
||||
@ -120,10 +133,14 @@ impl<'a> Lexer<'a> {
|
||||
self.next_char();
|
||||
self.lex_num_and_type_with_base(start, 2, EncodeSequence::Binary)
|
||||
}
|
||||
Some('0'..='9' | _) | None => self.lex_num_and_type_with_base(start, 10, EncodeSequence::Decimal),
|
||||
Some('0'..='9' | _) | None => {
|
||||
self.lex_num_and_type_with_base(start, 10, EncodeSequence::Decimal)
|
||||
}
|
||||
}
|
||||
Some('0'..='9' | _) => self.lex_num_and_type_with_base(start, 10, EncodeSequence::Decimal),
|
||||
}
|
||||
Some('0'..='9' | _) => {
|
||||
self.lex_num_and_type_with_base(start, 10, EncodeSequence::Decimal)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -303,14 +303,11 @@ impl<'a> DesugarState<'a> {
|
||||
desugared::Expr::var(name)
|
||||
}
|
||||
PatKind::Var(ident) => desugared::Expr::var(ident.0.clone()),
|
||||
// TODO: Add u120 pattern literals
|
||||
PatKind::Num(kind_tree::Number::U60(n)) => desugared::Expr::num60(pat.range, *n),
|
||||
PatKind::Num(kind_tree::Number::U120(n)) => desugared::Expr::num120(pat.range, *n),
|
||||
PatKind::Pair(fst, snd) => self.desugar_pair_pat(pat.range, fst, snd),
|
||||
PatKind::List(ls) => self.desugar_list_pat(pat.range, ls),
|
||||
PatKind::Str(string) => {
|
||||
desugared::Expr::str(pat.range, string.to_owned())
|
||||
}
|
||||
PatKind::Str(string) => desugared::Expr::str(pat.range, string.to_owned()),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -32,9 +32,16 @@ pub fn compile_term(expr: &desugared::Expr) -> Box<Term> {
|
||||
Sub(_, _, _, expr) => compile_term(expr),
|
||||
Num(kind_tree::Number::U60(numb)) => Box::new(Term::Num { numb: *numb }),
|
||||
Num(kind_tree::Number::U120(numb)) => {
|
||||
let hi = Box::new(Term::Num { numb: (numb >> 60) as u64});
|
||||
let lo = Box::new(Term::Num { numb: (numb & 0xFFFFFFFFFFFFFFF) as u64});
|
||||
Box::new(Term::Ctr { name: String::from("U120.new"), args: vec![hi, lo] })
|
||||
let hi = Box::new(Term::Num {
|
||||
numb: (numb >> 60) as u64,
|
||||
});
|
||||
let lo = Box::new(Term::Num {
|
||||
numb: (numb & 0xFFFFFFFFFFFFFFF) as u64,
|
||||
});
|
||||
Box::new(Term::Ctr {
|
||||
name: String::from("U120.new"),
|
||||
args: vec![hi, lo],
|
||||
})
|
||||
}
|
||||
Binary(op, l, r) => Box::new(Term::Ctr {
|
||||
name: op.to_string(),
|
||||
|
Loading…
Reference in New Issue
Block a user