Skip to content

Commit

Permalink
update vimrc
Browse files Browse the repository at this point in the history
* add yacc and cmd/yacc templates
* remove set nocompatible
  • Loading branch information
suzuken committed Sep 20, 2016
1 parent 3bae8ac commit 396fa8c
Show file tree
Hide file tree
Showing 3 changed files with 113 additions and 2 deletions.
68 changes: 68 additions & 0 deletions 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<expr> program
%type<expr> expr
%token<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)
}
35 changes: 35 additions & 0 deletions vim/templates/yacc/base-main.y
@@ -0,0 +1,35 @@
%{
// headers
%}

%union{
expr Expression
token Token
}

%type<expr> program
%type<expr> expr
%token<token> NUMBER

%left '+'

%%

program
: expr
{
$$ = $1
yylex.(*Lexer).Result = $$
}

expr
: NUMBER
{
}
| expr '+' expr
{
}

%%

// body
12 changes: 10 additions & 2 deletions vimrc
Expand Up @@ -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
Expand Down Expand Up @@ -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()

Expand Down Expand Up @@ -320,6 +321,13 @@ set tags=tags
" =====================================================
let g:snips_author = 'Kenta Suzuki'

" =====================================================
"" sonictemplate
" =====================================================
let g:sonictemplate_vim_template_dir = [
\ '$HOME/.vim/templates',
\]

" =====================================================
"" tagbar
" =====================================================
Expand Down

0 comments on commit 396fa8c

Please sign in to comment.