Making Working TS
This commit is contained in:
parent
9870c095ce
commit
6870b27829
@ -22,11 +22,13 @@ STR: /(`.*?`)|(".*?")|(\'.*?\')/
|
|||||||
%ignore COMMENT
|
%ignore COMMENT
|
||||||
%ignore WS
|
%ignore WS
|
||||||
// Ignore Exports
|
// Ignore Exports
|
||||||
|
%ignore "export" "default" /w+/ ";"
|
||||||
%ignore "export" "*" "from" STR ";"
|
%ignore "export" "*" "from" STR ";"
|
||||||
%ignore "export" "*" "as" /w+/ "from" STR ";"
|
%ignore "export" "*" "as" /w+/ "from" STR ";"
|
||||||
%ignore "export" /(?<=export)(.|\n)+?(?=})/ "}" "from" STR ";"
|
%ignore "export" /(?<=export)(.|\n)+?(?=})/ "}" "from" STR ";"
|
||||||
%ignore "export" /(?<=export)(.|\n)+?(?=})/ "}" ";"
|
%ignore "export" /(?<=export)(.|\n)+?(?=})/ "}" ";"
|
||||||
|
|
||||||
|
|
||||||
// --------------------------------------------------------------------------
|
// --------------------------------------------------------------------------
|
||||||
// Summary:
|
// Summary:
|
||||||
// --------------------------------------------------------------------------
|
// --------------------------------------------------------------------------
|
||||||
@ -45,16 +47,16 @@ ret_expr: id
|
|||||||
| instanceof
|
| instanceof
|
||||||
| typeof
|
| typeof
|
||||||
| increment
|
| increment
|
||||||
| decrease
|
| decrement
|
||||||
| invert
|
| invert
|
||||||
| list
|
| list
|
||||||
| dict
|
| dict
|
||||||
| descruct_dict
|
| descruct_dict
|
||||||
| reassign
|
| reassign
|
||||||
| await
|
| await_stmt
|
||||||
| delete
|
| delete_stmt
|
||||||
| reg_ex
|
| reg_ex
|
||||||
| throw
|
| throw_statement
|
||||||
| sum
|
| sum
|
||||||
| product
|
| product
|
||||||
| boolean_operation
|
| boolean_operation
|
||||||
@ -64,19 +66,17 @@ ret_expr: id
|
|||||||
| function_call
|
| function_call
|
||||||
| inline_if
|
| inline_if
|
||||||
| new_class
|
| new_class
|
||||||
| break
|
| break_statement
|
||||||
| continue
|
| continue_statement
|
||||||
| ret_expr ("as" type)+
|
| ret_expr ("as" type)+
|
||||||
| "(" ret_expr ")"
|
| "(" ret_expr ")"
|
||||||
| continue
|
| return_statement
|
||||||
| break
|
|
||||||
| return
|
|
||||||
|
|
||||||
// Now we ar able to provide this expressions wiht a terminator.
|
// Now we ar able to provide this expressions wiht a terminator.
|
||||||
|
|
||||||
ret_expr_with_terminator: ret_expr terminator
|
ret_expr_with_terminator: ret_expr terminator
|
||||||
|
|
||||||
return: "return" [ret_expr]
|
return_statement: "return" [ret_expr]
|
||||||
|
|
||||||
statement: ret_expr_with_terminator
|
statement: ret_expr_with_terminator
|
||||||
| declare
|
| declare
|
||||||
@ -86,9 +86,9 @@ statement: ret_expr_with_terminator
|
|||||||
| declare_var_descructed
|
| declare_var_descructed
|
||||||
| import_stmt
|
| import_stmt
|
||||||
| for
|
| for
|
||||||
| while
|
| while_statement
|
||||||
| do_while
|
| do_while
|
||||||
| if
|
| if_statement
|
||||||
| switch
|
| switch
|
||||||
| interface
|
| interface
|
||||||
| class
|
| class
|
||||||
@ -106,12 +106,13 @@ terminator: ";"
|
|||||||
// Default ID:
|
// Default ID:
|
||||||
id: /[a-zA-Z_$][a-zA-Z0-9_$]*/ -> identifier
|
id: /[a-zA-Z_$][a-zA-Z0-9_$]*/ -> identifier
|
||||||
|
|
||||||
|
|
||||||
// We define valid import statements:
|
// We define valid import statements:
|
||||||
|
|
||||||
import_stmt: "import" str terminator
|
import_stmt: "import" str terminator -> import_stmt_all
|
||||||
| "import" id "from" str terminator
|
| "import" id "from" str terminator -> import_stmt_id
|
||||||
| "import" "*" "as" id "from" str terminator
|
| "import" "*" "as" id "from" str terminator -> import_stmt_as
|
||||||
| "import" "{" import_names "}" "from" str terminator
|
| "import" "{" import_names "}" "from" str terminator -> import_stmt_from
|
||||||
|
|
||||||
// we may import multiple items:
|
// we may import multiple items:
|
||||||
import_names: import_name ("," import_name)* [","]
|
import_names: import_name ("," import_name)* [","]
|
||||||
@ -135,43 +136,46 @@ undefined: "undefined"
|
|||||||
|
|
||||||
increment: accessor "++"
|
increment: accessor "++"
|
||||||
| "++" accessor
|
| "++" accessor
|
||||||
decrease: accessor "--"
|
decrement: accessor "--"
|
||||||
| "--" accessor
|
| "--" accessor
|
||||||
|
|
||||||
invert: "!" ret_expr
|
invert: "!" ret_expr
|
||||||
|
|
||||||
instanceof: id "instanceof" id_typed
|
instanceof: id "instanceof" id_typed
|
||||||
|
|
||||||
typeof: "typeof" accessor
|
typeof: "typeof" accessor
|
||||||
|
|
||||||
delete: "delete" accessor
|
delete_stmt: "delete" accessor
|
||||||
|
|
||||||
await: "await" ret_expr
|
await_stmt: "await" ret_expr
|
||||||
|
|
||||||
reg_ex: "/" /(?<=\/).+(?=\/\w)/ "/" [/\w/]
|
reg_ex: "/" /(?<=\/).+(?=\/\w)/ "/" [/\w/]
|
||||||
|
|
||||||
?sum: product
|
?sum: product
|
||||||
| sum "+" product -> add
|
| sum "+" product -> add
|
||||||
| sum "-" product -> min
|
| sum "-" product -> sub
|
||||||
| id "+=" product
|
| accessor "+=" product -> assigned_add
|
||||||
| id "-=" product
|
| accessor "-=" product -> assigned_sub
|
||||||
|
|
||||||
?product: atom
|
?product: atom
|
||||||
| product "*" atom -> mul
|
| product "*" atom -> mult
|
||||||
| product "/" atom -> div
|
| product "/" atom -> div
|
||||||
| id "*=" atom
|
| accessor "*=" atom -> assigned_mult
|
||||||
| id "/=" atom
|
| accessor "/=" atom -> assigned_div
|
||||||
|
|
||||||
boolean_operation: boolean_input boolean_operator boolean_input
|
boolean_operation: boolean_input boolean_operator boolean_input
|
||||||
|
|
||||||
boolean_operator: ">"
|
boolean_operator: ">" -> bool_op_gt
|
||||||
| "<"
|
| "<" -> bool_op_lt
|
||||||
| "<="
|
| "<=" -> bool_op_lte
|
||||||
| ">="
|
| ">=" -> bool_op_gte
|
||||||
| "=="
|
| "==" -> bool_op_eq
|
||||||
| "==="
|
| "===" -> bool_op_eq
|
||||||
| "!="
|
| "!=" -> bool_op_not_eq
|
||||||
| "!=="
|
| "!==" -> bool_op_not_eq
|
||||||
| "&&"
|
| "&&" -> bool_op_and
|
||||||
| "||"
|
| "||" -> bool_op_or
|
||||||
| "in"
|
| "in" -> bool_op_in
|
||||||
|
|
||||||
boolean_input: ret_expr
|
boolean_input: ret_expr
|
||||||
|
|
||||||
@ -184,19 +188,19 @@ boolean_input: ret_expr
|
|||||||
list: "[" [list_items] "]"
|
list: "[" [list_items] "]"
|
||||||
list_items: (list_item [","])+
|
list_items: (list_item [","])+
|
||||||
list_item: ret_expr
|
list_item: ret_expr
|
||||||
| "..." ret_expr
|
| "..." ret_expr -> list_item_rest
|
||||||
|
|
||||||
descruct_list: "[" ((id | | ("..." id)) [","])* "]" "=" ret_expr
|
descruct_list: "[" ((id | (rest_accessor)) [","])* "]" "=" ret_expr
|
||||||
|
|
||||||
// Define Objects
|
// Define Objects
|
||||||
dict: "{" dict_items? "}"
|
dict: "{" [dict_items] "}"
|
||||||
dict_items: (dict_item [","] )+
|
dict_items: (dict_item [","] )+
|
||||||
dict_item: (id | num | str) ":" ret_expr
|
dict_item: (id | num | str) ":" ret_expr -> dict_item_default
|
||||||
| id "(" func_args? ")" func_body
|
| id "(" func_args? ")" func_body -> dict_item_func
|
||||||
| "..." ret_expr
|
| "..." ret_expr -> dict_item_rest
|
||||||
| id
|
| id -> dict_item_short
|
||||||
|
|
||||||
descruct_dict: "{" ((id | (id ":" id) | ("..." id)) [","])* "}" "=" ret_expr
|
descruct_dict: "{" ((id | (id ":" id) | (rest_accessor)) [","])* "}" "=" ret_expr
|
||||||
|
|
||||||
|
|
||||||
// --------------------------------------------------------------------------
|
// --------------------------------------------------------------------------
|
||||||
@ -225,14 +229,37 @@ declare_var_type: "let"
|
|||||||
// We may want to convert them to
|
// We may want to convert them to
|
||||||
// specific types.
|
// specific types.
|
||||||
|
|
||||||
simple_access: id | str | num | ret_expr
|
bracket_accessor: id
|
||||||
|
| str
|
||||||
accessor: simple_access
|
| str_multi_line
|
||||||
| accessor ["as" type]+
|
| num
|
||||||
| "(" accessor ["as" type]+ ")"
|
| bool
|
||||||
| accessor ["?"] "." accessor
|
| instanceof
|
||||||
| accessor ["?"] "[" ret_expr "]"
|
| typeof
|
||||||
|
| await_stmt
|
||||||
|
| sum
|
||||||
|
| product
|
||||||
|
| boolean_operation
|
||||||
| function_call
|
| function_call
|
||||||
|
| inline_if
|
||||||
|
| bracket_accessor ("as" type)+ -> simple_access
|
||||||
|
| "(" bracket_accessor ")"
|
||||||
|
|
||||||
|
accessor: id -> var_based_access
|
||||||
|
| str
|
||||||
|
| num
|
||||||
|
| list
|
||||||
|
| dict
|
||||||
|
| await_stmt
|
||||||
|
// | ret_expr
|
||||||
|
| accessor ("as" type)+ -> simple_access
|
||||||
|
| "(" accessor ["as" type]+ ")" -> simple_access
|
||||||
|
| accessor ["?"] ("." accessor)+ -> access_dot
|
||||||
|
| accessor ["?"] ("[" bracket_accessor "]")+ -> access_bracket
|
||||||
|
| function_call -> simple_access
|
||||||
|
|
||||||
|
|
||||||
|
rest_accessor: "..." id
|
||||||
|
|
||||||
// --------------------------------------------------------------------------
|
// --------------------------------------------------------------------------
|
||||||
// Reassignment:
|
// Reassignment:
|
||||||
@ -257,9 +284,11 @@ reassign: accessor "=" ret_expr
|
|||||||
|
|
||||||
function_helper: ["<" type ("," type)* ">"] "(" func_args? ")" [":" type] func_body
|
function_helper: ["<" type ("," type)* ">"] "(" func_args? ")" [":" type] func_body
|
||||||
|
|
||||||
function: [export] ["async"] "function" [id] ["<" type ("," type)* ">"] "(" func_args? ")" [":" type] func_body
|
function: [export] "function" [id] ["<" type ("," type)* ">"] "(" func_args? ")" [":" type] func_body -> function
|
||||||
|
| [export] "async" "function" [id] ["<" type ("," type)* ">"] "(" func_args? ")" [":" type] func_body -> async_function
|
||||||
|
|
||||||
arrow_function: [export] ["async"] ["<" type ("," type)* ">"] (( "(" func_args? ")" [":" type] ) | func_arg ) "=>" arrow_func_body
|
arrow_function: ["<" type ("," type)* ">"] (( "(" func_args? ")" [":" type] ) | func_arg ) "=>" func_body -> arrow_function
|
||||||
|
| "async" ["<" type ("," type)* ">"] (( "(" func_args? ")" [":" type] ) | func_arg ) "=>" func_body -> async_arrow_function
|
||||||
|
|
||||||
arrow_function_type: ["<" type ("," type)* ">"] "(" func_args? ")" [":" type] "=>" type
|
arrow_function_type: ["<" type ("," type)* ">"] "(" func_args? ")" [":" type] "=>" type
|
||||||
|
|
||||||
@ -269,10 +298,13 @@ arrow_function_type: ["<" type ("," type)* ">"] "(" func_args? "
|
|||||||
|
|
||||||
func_args: func_arg ("," func_arg)*
|
func_args: func_arg ("," func_arg)*
|
||||||
|
|
||||||
func_arg: implicit_or_typed
|
func_arg: implicit_or_typed -> default_func_arg
|
||||||
| "..." implicit_or_typed
|
| "..." implicit_or_typed -> rest_func_arg
|
||||||
| implicit_or_typed "=" ret_expr
|
| implicit_or_typed "=" ret_expr -> assigend_func_arg
|
||||||
| dict | list
|
|
||||||
|
// We dont want to enable list | dict destruction as a function arg, because
|
||||||
|
// we can not parse it more or less :(
|
||||||
|
// | dict | list
|
||||||
|
|
||||||
implicit_or_typed: id
|
implicit_or_typed: id
|
||||||
| id ["?"] ":" type
|
| id ["?"] ":" type
|
||||||
@ -299,14 +331,14 @@ arrow_func_body: func_body
|
|||||||
// The Defintion of how a function could be called.
|
// The Defintion of how a function could be called.
|
||||||
// In here we consider sync as well as async calls.
|
// In here we consider sync as well as async calls.
|
||||||
|
|
||||||
function_call: ret_expr ["<" type ("," type)* ">"] "(" call_args? ")"
|
function_call: accessor ["<" type ("," type)* ">"] "(" call_args? ")"
|
||||||
|
|
||||||
// We define our call args:
|
// We define our call args:
|
||||||
|
|
||||||
call_args: call_arg ("," call_arg)*
|
call_args: call_arg ("," call_arg)*
|
||||||
|
|
||||||
call_arg: ret_expr
|
call_arg: ret_expr -> call_arg
|
||||||
| "..." ret_expr
|
| "..." ret_expr -> rest_call_arg
|
||||||
|
|
||||||
type: basic_type
|
type: basic_type
|
||||||
| enhanced_type
|
| enhanced_type
|
||||||
@ -344,13 +376,15 @@ id_typed: id | enhanced_type
|
|||||||
// --------------------------------------------------------------------------
|
// --------------------------------------------------------------------------
|
||||||
|
|
||||||
// Define a For - Statement
|
// Define a For - Statement
|
||||||
for: "for" "(" declare_var_type for_iter_var ("of" | "in") ret_expr ")" iter_body
|
for: "for" "(" declare_var_type for_iter_var for_iter_type ret_expr ")" iter_body -> default_for
|
||||||
| "for" "(" declare_var_type "[" (for_iter_var [","])+ "]" ("of" | "in") ret_expr ")" iter_body
|
| "for" "(" declare_var_type "[" (for_iter_var [","])+ "]" for_iter_type ret_expr ")" iter_body -> mutli_for
|
||||||
| "for" "(" declare_var_type id "=" ret_expr ";" ret_expr ";" ret_expr ")" iter_body
|
| "for" "(" declare_var_type id "=" ret_expr ";" ret_expr ";" ret_expr ")" iter_body -> ranged_for
|
||||||
|
|
||||||
|
for_iter_type: "in" | "of"
|
||||||
|
|
||||||
for_iter_var: id | dict | list
|
for_iter_var: id | dict | list
|
||||||
|
|
||||||
while: "while" "(" ret_expr ")" iter_body
|
while_statement: "while" "(" ret_expr ")" iter_body
|
||||||
|
|
||||||
do_while: "do" iter_body "while" "(" ret_expr ")" terminator
|
do_while: "do" iter_body "while" "(" ret_expr ")" terminator
|
||||||
|
|
||||||
@ -358,8 +392,8 @@ iter_body: "{" iter_statements "}" | iter_statement
|
|||||||
iter_statements: iter_statement*
|
iter_statements: iter_statement*
|
||||||
iter_statement: statement
|
iter_statement: statement
|
||||||
|
|
||||||
continue: "continue"
|
continue_statement: "continue"
|
||||||
break: "break"
|
break_statement: "break"
|
||||||
|
|
||||||
// --------------------------------------------------------------------------
|
// --------------------------------------------------------------------------
|
||||||
// IF-Statements
|
// IF-Statements
|
||||||
@ -367,10 +401,14 @@ break: "break"
|
|||||||
|
|
||||||
// Define a If - Statement
|
// Define a If - Statement
|
||||||
// We have to consider "if" "else if" and "else"
|
// We have to consider "if" "else if" and "else"
|
||||||
if: "if" "(" ret_expr ")" if_body ("else" "if" "(" ret_expr ")" if_body)* ["else" if_body]
|
if_statement: "if" "(" ret_expr ")" if_body [else_if_statements] [else_statement]
|
||||||
|
else_if_statements: else_if_statement+
|
||||||
|
else_if_statement: "else" "if" "(" ret_expr ")" if_body
|
||||||
|
else_statement: "else" if_body
|
||||||
|
|
||||||
|
|
||||||
if_body: "{" statement* "}"
|
if_body: "{" statement* "}"
|
||||||
| ret_expr_with_terminator
|
| ret_expr_with_terminator -> if_body_single
|
||||||
|
|
||||||
inline_if: ret_expr "?" ret_expr ":" ret_expr
|
inline_if: ret_expr "?" ret_expr ":" ret_expr
|
||||||
|
|
||||||
@ -383,11 +421,11 @@ switch_body: "{" ((switch_case)* [switch_default])* "}"
|
|||||||
switch_case: "case" ret_expr ":" [switch_case_body]
|
switch_case: "case" ret_expr ":" [switch_case_body]
|
||||||
switch_default: "default" ":" [switch_case_body]
|
switch_default: "default" ":" [switch_case_body]
|
||||||
|
|
||||||
switch_case_body: ("{" switch_case_statements "}") | switch_case_statements
|
switch_case_body: (("{" switch_case_statements "}") | switch_case_statements) break_statement
|
||||||
|
|
||||||
switch_case_statements: switch_case_statement*
|
switch_case_statements: switch_case_statement*
|
||||||
switch_case_statement: statement
|
switch_case_statement: statement
|
||||||
| break
|
|
||||||
|
|
||||||
// --------------------------------------------------------------------------
|
// --------------------------------------------------------------------------
|
||||||
// Error Handling
|
// Error Handling
|
||||||
@ -397,7 +435,7 @@ try_catch: "try" try_catch_body "catch" "(" id ")" try_catch_
|
|||||||
|
|
||||||
try_catch_body: "{" statement* "}"
|
try_catch_body: "{" statement* "}"
|
||||||
|
|
||||||
throw: "throw" ret_expr
|
throw_statement: "throw" ret_expr
|
||||||
|
|
||||||
// --------------------------------------------------------------------------
|
// --------------------------------------------------------------------------
|
||||||
// interfaces
|
// interfaces
|
||||||
|
Loading…
Reference in New Issue
Block a user