mirror of
https://github.com/zaphar/ucg.git
synced 2025-07-21 18:10:42 -04:00
DEV: Experimental parsing support
Shape Projection syntax support for #55
This commit is contained in:
parent
e2420b061d
commit
577aa5e72a
@ -110,4 +110,16 @@ assert t.ok{
|
|||||||
assert t.ok{
|
assert t.ok{
|
||||||
test = str(false) == "false",
|
test = str(false) == "false",
|
||||||
desc = "You can cast true into a string",
|
desc = "You can cast true into a string",
|
||||||
|
};
|
||||||
|
|
||||||
|
let mystr::"" = "a string";
|
||||||
|
|
||||||
|
let struct_shape = {
|
||||||
|
foo :: "" = "",
|
||||||
|
};
|
||||||
|
|
||||||
|
let func_shape = func(arg :: "", arg2 :: "") => arg + arg2 :: "";
|
||||||
|
|
||||||
|
let module_shape = module{self={}} => (result :: {}) {
|
||||||
|
let result :: {} = self;
|
||||||
};
|
};
|
@ -216,6 +216,7 @@ make_fn!(
|
|||||||
do_each!(
|
do_each!(
|
||||||
field => wrap_err!(either!(match_type!(BOOLEAN), match_type!(BAREWORD), match_type!(STR)),
|
field => wrap_err!(either!(match_type!(BOOLEAN), match_type!(BAREWORD), match_type!(STR)),
|
||||||
"Field names must be a bareword or a string."),
|
"Field names must be a bareword or a string."),
|
||||||
|
_ => optional!(shape_suffix),
|
||||||
_ => must!(punct!("=")),
|
_ => must!(punct!("=")),
|
||||||
value => must!(expression),
|
value => must!(expression),
|
||||||
(field, value)
|
(field, value)
|
||||||
@ -288,6 +289,15 @@ make_fn!(
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
make_fn!(
|
||||||
|
shape_suffix<SliceIter<Token>, Value>,
|
||||||
|
do_each!(
|
||||||
|
_ => punct!("::"),
|
||||||
|
shape => value,
|
||||||
|
(dbg!(shape))
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
fn value_to_expression(v: Value) -> Expression {
|
fn value_to_expression(v: Value) -> Expression {
|
||||||
Expression::Simple(v)
|
Expression::Simple(v)
|
||||||
}
|
}
|
||||||
@ -370,7 +380,11 @@ fn tuple_to_func<'a>(
|
|||||||
|
|
||||||
make_fn!(
|
make_fn!(
|
||||||
arglist<SliceIter<Token>, Vec<Value>>,
|
arglist<SliceIter<Token>, Vec<Value>>,
|
||||||
separated!(punct!(","), symbol)
|
separated!(punct!(","), do_each!(
|
||||||
|
sym => symbol,
|
||||||
|
_ => optional!(shape_suffix),
|
||||||
|
(sym)
|
||||||
|
))
|
||||||
);
|
);
|
||||||
|
|
||||||
fn module_expression(input: SliceIter<Token>) -> Result<SliceIter<Token>, Expression> {
|
fn module_expression(input: SliceIter<Token>) -> Result<SliceIter<Token>, Expression> {
|
||||||
@ -385,7 +399,12 @@ fn module_expression(input: SliceIter<Token>) -> Result<SliceIter<Token>, Expres
|
|||||||
out_expr => optional!(
|
out_expr => optional!(
|
||||||
do_each!(
|
do_each!(
|
||||||
_ => punct!("("),
|
_ => punct!("("),
|
||||||
expr => must!(expression),
|
expr => must!(do_each!(
|
||||||
|
expr => expression,
|
||||||
|
_ => optional!(shape_suffix),
|
||||||
|
(expr)
|
||||||
|
)
|
||||||
|
),
|
||||||
_ => must!(punct!(")")),
|
_ => must!(punct!(")")),
|
||||||
(expr)
|
(expr)
|
||||||
)
|
)
|
||||||
@ -418,6 +437,7 @@ fn func_expression(input: SliceIter<Token>) -> Result<SliceIter<Token>, Expressi
|
|||||||
_ => must!(punct!(")")),
|
_ => must!(punct!(")")),
|
||||||
_ => must!(punct!("=>")),
|
_ => must!(punct!("=>")),
|
||||||
map => trace_parse!(expression),
|
map => trace_parse!(expression),
|
||||||
|
_ => optional!(shape_suffix),
|
||||||
(pos, arglist, map)
|
(pos, arglist, map)
|
||||||
);
|
);
|
||||||
match parsed {
|
match parsed {
|
||||||
@ -788,6 +808,7 @@ make_fn!(
|
|||||||
do_each!(
|
do_each!(
|
||||||
pos => pos,
|
pos => pos,
|
||||||
name => wrap_err!(match_type!(BAREWORD), "Expected name for binding"),
|
name => wrap_err!(match_type!(BAREWORD), "Expected name for binding"),
|
||||||
|
_ => optional!(trace_parse!(shape_suffix)),
|
||||||
_ => punct!("="),
|
_ => punct!("="),
|
||||||
val => trace_parse!(wrap_err!(expression, "Expected Expression to bind")),
|
val => trace_parse!(wrap_err!(expression, "Expected Expression to bind")),
|
||||||
_ => punct!(";"),
|
_ => punct!(";"),
|
||||||
|
@ -271,6 +271,10 @@ make_fn!(semicolontok<OffsetStrIter, Token>,
|
|||||||
do_text_token_tok!(TokenType::PUNCT, ";")
|
do_text_token_tok!(TokenType::PUNCT, ";")
|
||||||
);
|
);
|
||||||
|
|
||||||
|
make_fn!(doublecolontok<OffsetStrIter, Token>,
|
||||||
|
do_text_token_tok!(TokenType::PUNCT, "::")
|
||||||
|
);
|
||||||
|
|
||||||
make_fn!(colontok<OffsetStrIter, Token>,
|
make_fn!(colontok<OffsetStrIter, Token>,
|
||||||
do_text_token_tok!(TokenType::PUNCT, ":")
|
do_text_token_tok!(TokenType::PUNCT, ":")
|
||||||
);
|
);
|
||||||
@ -459,6 +463,7 @@ fn token<'a>(input: OffsetStrIter<'a>) -> Result<OffsetStrIter<'a>, Token> {
|
|||||||
fatcommatok, // Note fatcommatok must come before equaltok
|
fatcommatok, // Note fatcommatok must come before equaltok
|
||||||
equaltok,
|
equaltok,
|
||||||
semicolontok,
|
semicolontok,
|
||||||
|
doublecolontok,
|
||||||
colontok,
|
colontok,
|
||||||
leftsquarebracket,
|
leftsquarebracket,
|
||||||
rightsquarebracket,
|
rightsquarebracket,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user