You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
with gabriel vergnaud, we have have created HOTScript, and also created a parser combinator.
I successfully made it allow recursive definition: gvergnaud/hotscript#78
example :
// The grammar is defined as a recursive grammar:// -------------------------------------------------------------// | Value = Object | Array | String | Number | Boolean | Null |// | Object = { (Pair (, Pair)*)? } |// | Pair = String : Value |// | Array = [ (Value (, Value)*)? ] |// | String = " Character* " |// | Character = any character except " |// | Number = -? Digits ( . Digits )? |// | Boolean = true | false |// | Null = null |// -------------------------------------------------------------typeValue=P.Choice<[JSonObject,JSonArray,JSonString,JSonNumber,JsonBoolean,JSonNull]>;typeJSonObject=P.Map<P.Sequence<[P.Trim<P.Skip<P.Literal<"{">>>,P.Optional<P.SepBy<JSonPair,P.Trim<P.Literal<",">>>>,P.Trim<P.Skip<P.Literal<"}">>>]>,Objects.FromArray>;typeJSonPair=P.Sequence<[JSonString,P.Trim<P.Skip<P.Literal<":">>>,Value]>;typeJSonArray=P.Map<P.Sequence<[P.Trim<P.Skip<P.Literal<"[">>>,P.Optional<P.SepBy<Value,P.Trim<P.Literal<",">>>>,P.Trim<P.Skip<P.Literal<"]">>>]>,Objects.Create<[arg0]>>;typeJSonString=P.Map<P.Between<P.TrimLeft<P.Skip<P.Literal<'"'>>>,P.Many<P.NotLiteral<'"'>>,P.TrimRight<P.Skip<P.Literal<'"'>>>>,Tuples.Join<"">>;typeJSonNumber=P.Map<P.Sequence<[P.Optional<P.Literal<"-"|"+">>,P.Digits,P.Optional<P.Sequence<[P.Literal<".">,P.Digits]>>]>,ComposeLeft<[Tuples.Join<"">,Strings.ToNumber]>>;typeJsonBoolean=P.Map<P.Literal<"true"|"false">,Match<[Match.With<"true",true>,Match.With<"false",false>]>>;typeJSonNull=P.Map<P.Literal<"null">,Constant<null>>;typeJson<Textendsstring>=Eval<P.Parse<P.Map<P.Sequence<[Value,P.EndOfInput]>,Tuples.At<0>>,T>>;typeres1=Json<`{"hello": " world! with @", "foo": [1.4, 2, 3]}`>;// ^?typetest1=Expect<Equal<res1,{hello: " world! with @";foo: [1.4,2,3]}>>;typeres2=Json<`[]`>;// ^?typetest2=Expect<Equal<res2,[]>>;typeres3=Json<`{}`>;// ^?typetest3=Expect<Equal<res3,{}>>;// 4 deep nested objectstyperes4=Json<`{"a": {"b": {"c": {"d": 8}}}}`>;// ^?typetest4=Expect<Equal<res4,{a: {b: {c: {d: 8}}}}>>;
but it fails to parse too deep json structures.
did you succeed to make arbitrary big json parsing ?
Thanks for the feedback. I hoped you had found something we didn't. The search continues then.
One tip for you about implementing recursive grammars like EBNF, there is a neat trick that delays TS evaluation to allow recursive declarations to not trigger TS recursive and maybe infinitive errors.
Don't put any constraints on parameters. they trigger typescript eager evaluation.
example here in your code :
delay type checking with extends in the body of your utility type by doing a conditional type check.
This will allow your types to not trigger maybe infinite errors.
Hello Mike,
with gabriel vergnaud, we have have created HOTScript, and also created a parser combinator.
I successfully made it allow recursive definition:
gvergnaud/hotscript#78
example :
but it fails to parse too deep json structures.
did you succeed to make arbitrary big json parsing ?
if you would like we can discuss on HOTScript discord : https://discord.gg/VXESFdD2
The text was updated successfully, but these errors were encountered: