How to implement array type grammer like typescript with pegjs?

my problem is in the implementation of "array type" like typescript.

according to my grammar. In "array type" you can use "[]" after any type (eg string or int or even array again like int[][]).

this is simplified version of my grammar:

start = type

type = array / bool / string / int

string = "string"
int = "int"
bool = "bool"

// problem
array = t:type "[]" { return { kind: "array",type: t }}

the above code throw an syntax error:

Error: Maximum call stack size exceeded

Leave a Reply

Your email address will not be published.