lang: make attrset delims braces

This commit is contained in:
Schrottkatze 2024-04-08 14:04:52 +02:00
parent 8d7401531e
commit 198c74c7ae
No known key found for this signature in database
2 changed files with 22 additions and 9 deletions

View file

@ -25,7 +25,6 @@ pub type Spanned<T> = (T, Span);
pub fn parse<'src>(src: &'src str) -> ParseResult<File<'_>, Rich<'_, Token<'_>>> { pub fn parse<'src>(src: &'src str) -> ParseResult<File<'_>, Rich<'_, Token<'_>>> {
let toks: Vec<_> = Token::lexer(src) let toks: Vec<_> = Token::lexer(src)
.spanned() .spanned()
.into_iter()
.map(|(t, s)| (t.expect("TODO: add lexer error(s)"), Span::from(s))) .map(|(t, s)| (t.expect("TODO: add lexer error(s)"), Span::from(s)))
.collect(); .collect();
let tok_stream = Stream::from_iter(toks).spanned((src.len()..src.len()).into()); let tok_stream = Stream::from_iter(toks).spanned((src.len()..src.len()).into());
@ -55,7 +54,7 @@ pub(crate) fn parser<
.separated_by(just(Token::Comma)) .separated_by(just(Token::Comma))
.collect::<Vec<_>>() .collect::<Vec<_>>()
.map(IndexMap::from_iter) .map(IndexMap::from_iter)
.delimited_by(just(Token::BracketOpen), just(Token::BracketClose)) .delimited_by(just(Token::BraceOpen), just(Token::BraceClose))
.map_with(|v, e| (v, e.span())) .map_with(|v, e| (v, e.span()))
.labelled("attrset"); .labelled("attrset");
@ -100,3 +99,17 @@ pub(crate) fn parser<
decls: IndexMap::from_iter(decls), decls: IndexMap::from_iter(decls),
})) }))
} }
pub mod asg {
use petgraph::graph::DiGraph;
use super::Spanned;
pub struct Asg<'src> {
graph: DiGraph<AsgNode<'src>, String>,
}
enum AsgNode<'src> {
Node(Spanned<&'src str>),
}
}

View file

@ -1,18 +1,18 @@
def main = meow def main = meow
| uwu | uwu
[ foo: @bar { foo: @bar
, hello: world @| test [ more: params ] | yay , hello: world @| test { more: params } | yay
] }
!| awa !| awa
@| nya @| nya
| rawr; | rawr;
def test = meow def test = meow
[ hello: $foo { hello: $foo
, world: @bar , world: @bar
]; };
def blah = [ def blah = {
pipe1: meow | uwu, pipe1: meow | uwu,
pipe2: lorem | ipsum pipe2: lorem | ipsum
] | flkjdsafkjl; } | flkjdsafkjl;