Open this document in Emacs and type C-c C-c to execute the code examples!
(require 'reazon)
(require 'tree-edit)
(require 'tree-edit-java-grammar)
(setq-local java-grammar
(with-mode-local java-mode tree-edit-grammar))
(reazon-run 10 (q)
(reazon-set-equalo q '(1 2 3 4)))
(reazon-run 5 (tokens)
;; TOKENS is a list of tokens that parses as a 'try_statement'. (Ignore the '())
(tree-edit-parseo (alist-get 'try_statement java-grammar) tokens '()))
(reazon-run 5 (tokens)
;; TOKENS is a list of tokens that parses as a 'argument_list'.
(tree-edit-parseo (alist-get 'argument_list java-grammar) tokens '()))
Insert an expression after x
in func(x)
(reazon-run 1 (new-tokens)
(reazon-fresh (tokens)
;; A token of type 'expression' exists in the new tokens
(reazon-membero 'expression new-tokens)
;; NEW-TOKENS is preceeded by "(" and is followed by ")", where TOKENS is the entire list.
(tree-edit--prefixpostfixo '("(" expression) new-tokens '(")") tokens)
;; TOKENS is a list of tokens that parses as a 'argument_list'.
(tree-edit-parseo (alist-get 'argument_list java-grammar) tokens '())))
Insert an expression before x
in func(x)
(reazon-run 1 (new-tokens)
(reazon-fresh (tokens)
;; A token of type 'expression' exists in the new tokens
(reazon-membero 'expression new-tokens)
;; NEW-TOKENS is preceeded by "(" and is followed by ")", where TOKENS is the entire list.
(tree-edit--prefixpostfixo '("(") new-tokens '(expression ")") tokens)
;; TOKENS is a list of tokens that parses as a 'argument_list'.
(tree-edit-parseo (alist-get 'argument_list java-grammar) tokens '())))
Insert another expression after if (...) {...}
(reazon-run 1 (new-tokens)
(reazon-fresh (tokens)
;; TOKENS is a list of tokens that parses as a 'argument_list'.
(tree-edit-parseo (alist-get 'if_statement java-grammar) tokens '())
;; NEW-TOKENS is preceeded by "(" and is followed by ")", where TOKENS is the entire list.
(tree-edit--prefixpostfixo '("if" parenthesized_expression statement) new-tokens '() tokens)
;; A token of type 'expression' exists in the new tokens
(reazon-membero 'statement new-tokens)))