Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
miyako committed May 24, 2022
1 parent d8b8046 commit b1af28d
Show file tree
Hide file tree
Showing 6 changed files with 74,551 additions and 74,970 deletions.
15 changes: 15 additions & 0 deletions corpus/14. break.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
==================
Break
==================

function factorial ( $n : Integer) : Integer

If ($n<1)
return 1
Else
return $n*factorial($n-1)
End if

---

(source (comment ) (comment ) (class_extends ) (constructor_block (constructor_name ) (local_variable ) (class )) (comment ) (comment ) (value (function (arguments (argument (value (variable (local_variable )))) (argument (value (variable (local_variable ))))))) (comment ) (comment ) (assignment (value (variable (process_variable ) (property ))) (value (string ))) (function_block (function_name )) (value (function (arguments (argument (value (variable (parameter ))))))) (assignment (value (variable (parameter ))) (value (formula (value (variable (process_variable ) (property ))) (value (variable (process_variable ) (property )))))))
Expand Down
2 changes: 1 addition & 1 deletion corpus/8. case_of.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ fin de cas

---

(source (case_block (case_of ) (case (arguments (argument (value (variable (local_variable ))))) (end_case ))) (case_block (case_of ) (case (arguments (argument (value (variable (local_variable ))))) (else_case_block (else ) (end_case )))) (case_block (case_of ) (case (arguments (argument (value (variable (local_variable ))))) (end_case ))) (case_block (case_of ) (case (arguments (argument (value (variable (local_variable ))))) (else_case_block (else ) (end_case )))))
(source (case_block (case_of ) (case_colon_block (arguments (argument (value (variable (local_variable )))))) (end_case )) (case_block (case_of ) (case_colon_block (arguments (argument (value (variable (local_variable )))))) (else_case_block (else ) (end_case ))) (case_block (case_of ) (case_colon_block (arguments (argument (value (variable (local_variable )))))) (end_case )) (case_block (case_of ) (case_colon_block (arguments (argument (value (variable (local_variable )))))) (else_case_block (else ) (end_case ))))
Expand Down
7 changes: 7 additions & 0 deletions examples/16. break.4dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
function factorial ( $n : Integer)

If ($n<1)
return 0x1
Else
return $n*factorial($n-1)
End if
27 changes: 8 additions & 19 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,14 @@ module.exports = grammar({
$.sql_block,
$.case_block,
$.var_block,
$.break_statement,
$.continue_statement,
$.return_statement,
$.function_block,
$.class_extends,
$.declare_block,
$.constructor_block,
$.break_statement,
$.continue_statement,
$.return_statement
$.constructor_block

),

comment: $ => choice(
Expand Down Expand Up @@ -114,17 +115,6 @@ module.exports = grammar({
choice($.else_case_block, $.end_case)
),

/*
case_block: $ => prec.right(seq(
$.case_of,
repeat1($.case))
),
*/

//case: $ => seq(':', $.arguments, repeat($._token), choice($.case, $.else_case_block, $.end_case)),



_if_e: $ => /(i|I)(f|F)/,
_if_f: $ => /(s|S)(i|I)/,
if : $ => prec(PREC.key, choice($._if_e, $._if_f)),
Expand Down Expand Up @@ -196,16 +186,15 @@ module.exports = grammar({
_var: $ => /(v|V)(a|A)(r|R)/,
var : $ => prec(PREC.key, $._var),

__return: $ => /(r|R)(e|E)(t|T)(u|U)(r|R)(n|N)/,
_return : $ => prec(PREC.key, $.__return),

_break: $ => /(b|B)(r|R)(e|E)(a|A)(k|K)/,
break_statement : $ => prec(PREC.key, $._break),

_continue: $ => /(c|C)(o|O)(n|N)(t|T)(i|I)(n|N)(u|U)(e|E)/,
continue_statement : $ => prec(PREC.key, $._continue),

return_statement: $ => prec.right(choice($._return, seq($._return, $.value))),
_return: $ => /(r|R)(e|E)(t|T)(u|U)(r|R)(n|N)/,
_return_statement: $ => prec.left(seq($._return, optional(seq($._return, $.value)))),
return_statement : $ => prec(PREC.key, $._return_statement),

_class_function: $ => /((((l|L)(o|O)(c|C)(a|A)(l|L))|((e|E)(x|X)(p|P)(o|O)(s|S)(e|E)(d|D)))\s+)?((f|F)(u|U)(n|N)(c|C)(t|T)(i|I)(o|O)(n|N))(\s+(((g|G|s|S)(e|E)(t|T))|((o|O)(r|R)(d|D)(e|E)(r|R)(b|B)(y|Y))|((q|Q)(u|U)(e|E)(r|R)(y|Y))))?(\s+[A-Za-z_][A-Za-z_0-9]+)/,
class_extends: $ => /((c|C)(l|L)(a|A)(s|S)(s|S))(\s+(e|E)(x|X)(t|T)(e|E)(n|N)(d|D)(s|S))(\s+[A-Za-z_][A-Za-z_0-9]+)/,
Expand Down
62 changes: 35 additions & 27 deletions src/grammar.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,31 +61,31 @@
},
{
"type": "SYMBOL",
"name": "function_block"
"name": "break_statement"
},
{
"type": "SYMBOL",
"name": "class_extends"
"name": "continue_statement"
},
{
"type": "SYMBOL",
"name": "declare_block"
"name": "return_statement"
},
{
"type": "SYMBOL",
"name": "constructor_block"
"name": "function_block"
},
{
"type": "SYMBOL",
"name": "break_statement"
"name": "class_extends"
},
{
"type": "SYMBOL",
"name": "continue_statement"
"name": "declare_block"
},
{
"type": "SYMBOL",
"name": "return_statement"
"name": "constructor_block"
}
]
},
Expand Down Expand Up @@ -891,18 +891,6 @@
"name": "_var"
}
},
"__return": {
"type": "PATTERN",
"value": "(r|R)(e|E)(t|T)(u|U)(r|R)(n|N)"
},
"_return": {
"type": "PREC",
"value": -3,
"content": {
"type": "SYMBOL",
"name": "__return"
}
},
"_break": {
"type": "PATTERN",
"value": "(b|B)(r|R)(e|E)(a|A)(k|K)"
Expand All @@ -927,32 +915,52 @@
"name": "_continue"
}
},
"return_statement": {
"type": "PREC_RIGHT",
"_return": {
"type": "PATTERN",
"value": "(r|R)(e|E)(t|T)(u|U)(r|R)(n|N)"
},
"_return_statement": {
"type": "PREC_LEFT",
"value": 0,
"content": {
"type": "CHOICE",
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "_return"
},
{
"type": "SEQ",
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_return"
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "_return"
},
{
"type": "SYMBOL",
"name": "value"
}
]
},
{
"type": "SYMBOL",
"name": "value"
"type": "BLANK"
}
]
}
]
}
},
"return_statement": {
"type": "PREC",
"value": -3,
"content": {
"type": "SYMBOL",
"name": "_return_statement"
}
},
"_class_function": {
"type": "PATTERN",
"value": "((((l|L)(o|O)(c|C)(a|A)(l|L))|((e|E)(x|X)(p|P)(o|O)(s|S)(e|E)(d|D)))\\s+)?((f|F)(u|U)(n|N)(c|C)(t|T)(i|I)(o|O)(n|N))(\\s+(((g|G|s|S)(e|E)(t|T))|((o|O)(r|R)(d|D)(e|E)(r|R)(b|B)(y|Y))|((q|Q)(u|U)(e|E)(r|R)(y|Y))))?(\\s+[A-Za-z_][A-Za-z_0-9]+)"
Expand Down
Loading

0 comments on commit b1af28d

Please sign in to comment.