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{
|
||||
test = str(false) == "false",
|
||||
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!(
|
||||
field => wrap_err!(either!(match_type!(BOOLEAN), match_type!(BAREWORD), match_type!(STR)),
|
||||
"Field names must be a bareword or a string."),
|
||||
_ => optional!(shape_suffix),
|
||||
_ => must!(punct!("=")),
|
||||
value => must!(expression),
|
||||
(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 {
|
||||
Expression::Simple(v)
|
||||
}
|
||||
@ -370,7 +380,11 @@ fn tuple_to_func<'a>(
|
||||
|
||||
make_fn!(
|
||||
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> {
|
||||
@ -385,7 +399,12 @@ fn module_expression(input: SliceIter<Token>) -> Result<SliceIter<Token>, Expres
|
||||
out_expr => optional!(
|
||||
do_each!(
|
||||
_ => punct!("("),
|
||||
expr => must!(expression),
|
||||
expr => must!(do_each!(
|
||||
expr => expression,
|
||||
_ => optional!(shape_suffix),
|
||||
(expr)
|
||||
)
|
||||
),
|
||||
_ => must!(punct!(")")),
|
||||
(expr)
|
||||
)
|
||||
@ -418,6 +437,7 @@ fn func_expression(input: SliceIter<Token>) -> Result<SliceIter<Token>, Expressi
|
||||
_ => must!(punct!(")")),
|
||||
_ => must!(punct!("=>")),
|
||||
map => trace_parse!(expression),
|
||||
_ => optional!(shape_suffix),
|
||||
(pos, arglist, map)
|
||||
);
|
||||
match parsed {
|
||||
@ -788,6 +808,7 @@ make_fn!(
|
||||
do_each!(
|
||||
pos => pos,
|
||||
name => wrap_err!(match_type!(BAREWORD), "Expected name for binding"),
|
||||
_ => optional!(trace_parse!(shape_suffix)),
|
||||
_ => punct!("="),
|
||||
val => trace_parse!(wrap_err!(expression, "Expected Expression to bind")),
|
||||
_ => punct!(";"),
|
||||
|
@ -271,6 +271,10 @@ make_fn!(semicolontok<OffsetStrIter, Token>,
|
||||
do_text_token_tok!(TokenType::PUNCT, ";")
|
||||
);
|
||||
|
||||
make_fn!(doublecolontok<OffsetStrIter, Token>,
|
||||
do_text_token_tok!(TokenType::PUNCT, "::")
|
||||
);
|
||||
|
||||
make_fn!(colontok<OffsetStrIter, Token>,
|
||||
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
|
||||
equaltok,
|
||||
semicolontok,
|
||||
doublecolontok,
|
||||
colontok,
|
||||
leftsquarebracket,
|
||||
rightsquarebracket,
|
||||
|
Loading…
x
Reference in New Issue
Block a user