简体   繁体   English

在Java中使用emacs解析器?

[英]Use emacs parser in java?

I found on internet a Parser for emacs here : http://www.emacswiki.org/emacs/rtrt-script.el for testRT script (an IBM tool for test). 我在Internet上找到了一个用于emacs的解析器: http ://www.emacswiki.org/emacs/rtrt-script.el for testRT脚本(一种用于测试的IBM工具)。

And I want to know if it's possible to use this Emacs Lips parser File in a Java Swing application. 我想知道是否有可能在Java Swing应用程序中使用此Emacs Lips解析器文件。 I just need the part who indent the code. 我只需要缩进代码的部分。 For example with a command line like : I give the file I need to indent with the rtrt-script.el and in return I have a file with indentation. 例如,使用类似命令行的命令:我给我需要使用rtrt-script.el缩进的文件,作为回报,我得到了一个带有缩进的文件。 there is any way to do that? 有什么办法吗? Thank's for your help. 谢谢你的帮助。

edit : The part I think I need is between: 编辑:我认为我需要的部分之间:

Indentation du code. 缩进代码。

(defun rtrt-script-indent-line ()
  "Indent current line as RTRT-SCRIPT code"
  (interactive)
  (save-excursion                ; si la ligne précedente est test ou 

    (beginning-of-line)
    (if (bobp)                          ; Check for rule 1
        (indent-line-to 0)
      (let ((not-indented t)      cur-indent)
        (if (looking-at "^[ \t]*--[ -=]*\n") ; indentation des commentaires
            (progn             
              (save-excursion    ; si la ligne précedente est test ou 
                (forward-line -1)       ; on indente au même niveau.
                (if (looking-at "^[ \t]*\\<\\(TEST\|SERVICE\\)\\>")
                    (setq cur-indent (current-indentation))
                  (while not-indented
                    (forward-line -1)

                    ;; on ignore les lignes blanches et les commentaires.
                    (while (looking-at "^[ \t]*\n")
                      (forward-line -1))
                    (if (looking-at "^[ \t]*\\<END\\>") ; Check for rule 3
                        (progn

                          (setq cur-indent (current-indentation))
                          (setq not-indented nil))
                    ; Check for rule 4
                      (if (looking-at 
                           "^[ \t]*\\<\\(ENVIRONMENT\\|ELEMENT\\|INITIALIZATION\\|DEFINE[ \t]+STUB\\|TERMINATION\\|TEST\\|SERVICE\\|NEXT_TEST\\)\\>")
                          (progn
                            (setq cur-indent (+ (current-indentation) rtrt-script-indent))
                            (setq not-indented nil))
                        (if (bobp)      ; Check for rule 5
                            (setq not-indented nil))    
                        ))))
                )
              )
          (if (looking-at "^[ \t]*\\<\\(END\\|NEXT_TEST\\)\\>") ; Check for rule 2
              (progn
                (save-excursion
                  (forward-line -1)

                  ;; on ignore les lignes blanches.
                  (while (looking-at "^[ \t]*\\(\n\\|--.*\n\\)")
                    (forward-line -1))

                  (setq cur-indent (- (current-indentation) rtrt-script-indent)))
                (if (< cur-indent 0)
                    (setq cur-indent 0)))
            (save-excursion 
              (while not-indented
                (forward-line -1)

                ;; on ignore les lignes blanches et les commentaires.
                (while (looking-at "^[ \t]*\\(\n\\|--.*\n\\)")
                  (forward-line -1))

                (if (looking-at "^[ \t]*\\<END\\>") ; Check for rule 3
                    (progn

                      (setq cur-indent (current-indentation))
                      (setq not-indented nil))
                    ; Check for rule 4
                  (if (looking-at 
                       "^[ \t]*\\<\\(ENVIRONMENT\\|ELEMENT\\|INITIALIZATION\\|DEFINE[ \t]+STUB\\|TERMINATION\\|TEST\\|SERVICE\\|NEXT_TEST\\)\\>")
                      (progn
                        (setq cur-indent (+ (current-indentation) rtrt-script-indent))
                        (setq not-indented nil))
                    (if (bobp)          ; Check for rule 5
                        (setq not-indented nil))    
                    ))))
            )
          )
        (if cur-indent
            (progn
              (save-excursion    ; si la ligne précedente est test ou 

                (message "cur_indent =>%d" cur-indent)
                (if (looking-at "^[ \t]*\n")
                    (indent-line-to 0)
                  (indent-line-to cur-indent)
                  ;; tant qu'a faire on retire aussi les tabulations.
                  (untabify (point-at-bol) (point-at-eol)))
                )
              )
          (indent-line-to 0)))
      )
    )
  ) ;; If we didn't see an indentation hint, then allow no indentation

Something like this should work: 这样的事情应该起作用:

emacs --batch -l /path/to/rtrt-script.el my-file.rtrt \
      -f rtrt-script-mode --eval '(indent-region (point-min) (point-max))' \
      -f save-buffer

Note that this will overwrite my-file.rtrt with the indented version. 请注意,这将使用缩进版本覆盖my-file.rtrt

You can tell emacs to run code upon startup. 您可以告诉emacs在启动时运行代码。 See options -f , -l and --eval (and maybe --batch , too) in man emacs . 请参阅man emacs选项-f-l--eval (也许还有--batch )。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM