diff --git a/vim/templates/yacc/base-goyacc.y b/vim/templates/yacc/base-goyacc.y new file mode 100644 index 0000000..e6e4d14 --- /dev/null +++ b/vim/templates/yacc/base-goyacc.y @@ -0,0 +1,68 @@ +%{ +package main + +import "text/scanner" + +type Expression interface{} +type Token struct { + token int + literal string +} +type NumExpr struct { + literal string +} +type BinOpExpr struct { + left, right Expression + operator rune +} +%} + +%union{ + token Token + expr Expression +} + +%type program +%type expr +%token NUMBER + +%left '+' + +%% + +program + : expr + { + $$ = $1 + yylex.(*Lexer).result = $$ + } + +expr + : NUMBER + { + $$ = NumExpr{literal: $1.literal} + } + | expr '+' expr + { + $$ = BinOpExpr{left: $1, operator: '+', right: $3} + } + +%% + +type Lexer struct { + scanner.Scanner + result Expression +} + +func (l *Lexer) Lex(lval *yySymType) int { + token := int(l.Scan()) + if token == scanner.Int { + token = NUMBER + } + lval.token = Token{token: token, literal: l.TokenText()} + return token +} + +func (l *Lexer) Error(e string) { + panic(e) +} diff --git a/vim/templates/yacc/base-main.y b/vim/templates/yacc/base-main.y new file mode 100644 index 0000000..7fc9d57 --- /dev/null +++ b/vim/templates/yacc/base-main.y @@ -0,0 +1,35 @@ +%{ +// headers +%} + +%union{ + expr Expression + token Token +} + +%type program +%type expr +%token NUMBER + +%left '+' + +%% + +program + : expr + { + $$ = $1 + yylex.(*Lexer).Result = $$ + } + +expr + : NUMBER + { + } + | expr '+' expr + { + } + +%% + +// body diff --git a/vimrc b/vimrc index a97b0fb..e4b374a 100644 --- a/vimrc +++ b/vimrc @@ -10,8 +10,8 @@ " Sorry for writing some comments in Japanese, and I'll translate to English " later. " ====================== -set nocompatible " be iMproved +" use https://github.com/junegunn/vim-plug call plug#begin() "Plugin Installing @@ -48,9 +48,10 @@ Plug 'sumpygump/php-documentor-vim', {'autoload':{'filetypes':['php']}} Plug '2072/PHP-Indenting-for-VIm', {'autoload':{'filetypes':['php']}} Plug 'hynek/vim-python-pep8-indent', {'autoload':{'filetypes':['python']}} Plug 'MaxMEllon/vim-jsx-pretty' -Plug 'marijnh/tern_for_vim', {'do': 'npm install', 'for': 'javascript'} Plug 'othree/yajs.vim', {'autoload':{'filetypes':['javascript']}} Plug 'othree/javascript-libraries-syntax.vim' +Plug 'keith/swift.vim', {'autoload':{'filetypes':['swift']}} +Plug 'posva/vim-vue', {'autoload':{'filetypes':['vue']}} call plug#end() @@ -320,6 +321,13 @@ set tags=tags " ===================================================== let g:snips_author = 'Kenta Suzuki' +" ===================================================== +"" sonictemplate +" ===================================================== +let g:sonictemplate_vim_template_dir = [ +\ '$HOME/.vim/templates', +\] + " ===================================================== "" tagbar " =====================================================