tree-sitter-nim icon indicating copy to clipboard operation
tree-sitter-nim copied to clipboard

[New Feature] complex expressions

Open aMOPel opened this issue 2 years ago • 0 comments

official grammar:

expr = (blockExpr
      | ifExpr
      | whenExpr
      | caseStmt
      | forExpr
      | tryExpr)
      / simpleExpr

blockExpr = 'block' symbol? colcom stmt

condExpr = expr colcom expr optInd
        ('elif' expr colcom expr optInd)*
         'else' colcom expr
ifExpr = 'if' condExpr
whenExpr = 'when' condExpr

caseStmt = 'case' expr ':'? COMMENT?
            (IND{>} ofBranches DED
            | IND{=} ofBranches)

forExpr = forStmt

tryExpr = 'try' colcom stmt &(optInd 'except'|'finally')
           (optInd 'except' exprList colcom stmt)*
           (optInd 'finally' colcom stmt)?

examples:

see existing tests below

Some work has already been done:

https://github.com/aMOPel/tree-sitter-nim/blob/main/grammar.js#L707

existing tests:

(needs to be moved to test/corpus/expr.txt) https://github.com/aMOPel/tree-sitter-nim/blob/main/test/expr.txt

aMOPel avatar Aug 19 '22 18:08 aMOPel