feat: add simple check command
This commit is contained in:
@@ -20,3 +20,4 @@ pallas-traverse = "0.14.0-alpha.3"
|
||||
serde = { version = "1.0.144", features = ["derive"] }
|
||||
serde_json = "1.0.85"
|
||||
uplc = { path = '../uplc', version = "0.0.18" }
|
||||
aiken-lang = { path = "../lang", version = "0.0.17" }
|
||||
|
||||
@@ -9,6 +9,11 @@ use clap::{Parser, Subcommand};
|
||||
pub enum Args {
|
||||
/// Build an aiken project
|
||||
Build,
|
||||
/// Check a file or project
|
||||
Check {
|
||||
/// Specific aiken file to check
|
||||
input: Option<PathBuf>,
|
||||
},
|
||||
/// Start a development server
|
||||
Dev,
|
||||
/// Create a new aiken project
|
||||
|
||||
@@ -33,6 +33,21 @@ fn main() -> anyhow::Result<()> {
|
||||
todo!()
|
||||
}
|
||||
|
||||
Args::Check { input } => {
|
||||
if let Some(input) = input {
|
||||
let src = fs::read_to_string(&input)?;
|
||||
|
||||
match aiken_lang::parser::script(&src) {
|
||||
Ok(_) => (),
|
||||
Err(errs) => {
|
||||
for err in errs {
|
||||
eprintln!("{:#?}", err);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Args::Dev => {
|
||||
// launch a development server
|
||||
// this should allow people to test
|
||||
|
||||
@@ -2,12 +2,26 @@ use chumsky::prelude::*;
|
||||
use vec1::Vec1;
|
||||
|
||||
use crate::{
|
||||
ast::{self, BinOp, Span, TodoKind, CAPTURE_VARIABLE},
|
||||
ast::{self, BinOp, Span, SrcId, TodoKind, CAPTURE_VARIABLE},
|
||||
error::ParseError,
|
||||
expr,
|
||||
expr, lexer,
|
||||
token::Token,
|
||||
};
|
||||
|
||||
pub fn script(src: &str) -> Result<ast::UntypedModule, Vec<ParseError>> {
|
||||
let len = src.chars().count();
|
||||
|
||||
let span = |i| Span::new(SrcId::empty(), i..i + 1);
|
||||
|
||||
let tokens = lexer::lexer().parse(chumsky::Stream::from_iter(
|
||||
span(len),
|
||||
src.chars().enumerate().map(|(i, c)| (c, span(i))),
|
||||
))?;
|
||||
|
||||
module_parser(ast::ModuleKind::Script)
|
||||
.parse(chumsky::Stream::from_iter(span(len), tokens.into_iter()))
|
||||
}
|
||||
|
||||
pub fn module_parser(
|
||||
kind: ast::ModuleKind,
|
||||
) -> impl Parser<Token, ast::UntypedModule, Error = ParseError> {
|
||||
@@ -86,6 +100,7 @@ pub fn data_parser() -> impl Parser<Token, ast::UntypedDefinition, Error = Parse
|
||||
location: span,
|
||||
})
|
||||
.separated_by(just(Token::Comma))
|
||||
.allow_trailing()
|
||||
.delimited_by(just(Token::LeftParen), just(Token::RightParen));
|
||||
|
||||
let constructors = select! {Token::UpName { name } => name}
|
||||
@@ -828,6 +843,7 @@ pub fn labeled_constructor_type_args(
|
||||
location: span,
|
||||
})
|
||||
.separated_by(just(Token::Comma))
|
||||
.allow_trailing()
|
||||
.delimited_by(just(Token::LeftBrace), just(Token::RightBrace))
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user