lang, lang: types: Add automatic stringer generation

It's more useful if we know the string representation of Kind's.
This commit is contained in:
James Shubin
2019-04-27 16:14:10 -04:00
parent 310239e707
commit 2f7e202f40
7 changed files with 39 additions and 5 deletions

View File

@@ -23,8 +23,11 @@ OLDGOYACC := $(shell go version | grep -E 'go1.6|go1.7')
all: build
build: lexer.nn.go y.go
@# recursively run make in child dir named types
@$(MAKE) --quiet -C types
clean:
$(MAKE) --quiet -C types clean
@rm -f lexer.nn.go y.go y.output || true
lexer.nn.go: lexer.nex

View File

@@ -1 +1 @@
# err: err3: can't unify, invariant illogicality with equality: base kind does not match (2 != 3)
# err: err3: can't unify, invariant illogicality with equality: base kind does not match (Str != Int)

View File

@@ -1 +1 @@
# err: err3: can't unify, invariant illogicality with equals: base kind does not match (2 != 5)
# err: err3: can't unify, invariant illogicality with equals: base kind does not match (Str != List)

30
lang/types/Makefile Normal file
View File

@@ -0,0 +1,30 @@
# Mgmt
# Copyright (C) 2013-2019+ James Shubin and the project contributors
# Written by James Shubin <james@shubin.ca> and the project contributors
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
SHELL = /usr/bin/env bash
.PHONY: all build clean
all: build
build: kind_stringer.go
clean:
@rm -f kind_stringer.go || true
kind_stringer.go: type.go
@echo "Generating: type kind strings..."
go generate

View File

@@ -697,7 +697,7 @@ func TestUnification1(t *testing.T) {
name: "typed if expr",
ast: stmt,
fail: true,
experrstr: "can't unify, invariant illogicality with equality: base kind does not match (2 != 3)",
experrstr: "can't unify, invariant illogicality with equality: base kind does not match (Str != Int)",
})
}
{
@@ -750,7 +750,7 @@ func TestUnification1(t *testing.T) {
name: "typed var expr",
ast: stmt,
fail: true,
experrstr: "can't unify, invariant illogicality with equality: base kind does not match (2 != 1)",
experrstr: "can't unify, invariant illogicality with equality: base kind does not match (Str != Bool)",
})
}

View File

@@ -27,7 +27,7 @@ if [ "$COMMITS" != "" ] && [ "$COMMITS" -gt "1" ]; then
fi
# find all go files, exluding temporary directories and generated files
LINT=$(find * -maxdepth 9 -iname '*.go' -not -path 'old/*' -not -path 'tmp/*' -not -path 'bindata/*' -not -path 'lang/y.go' -not -path 'lang/lexer.nn.go' -not -path 'vendor/*' -exec golint {} \;) # current golint output
LINT=$(find * -maxdepth 9 -iname '*.go' -not -path 'old/*' -not -path 'tmp/*' -not -path 'bindata/*' -not -path 'lang/y.go' -not -path 'lang/lexer.nn.go' -not -path 'lang/types/kind_stringer.go' -not -path 'vendor/*' -exec golint {} \;) # current golint output
COUNT=`echo -e "$LINT" | wc -l` # number of golint problems in current branch
[ "$LINT" = "" ] && echo PASS && exit # everything is "perfect"

View File

@@ -48,6 +48,7 @@ gml="$gml --enable=misspell"
gml="$gml --exclude=lang/lexer.nn.go"
gml="$gml --exclude=lang/y.go"
gml="$gml --exclude=bindata/bindata.go"
gml="$gml --exclude=lang/types/kind_stringer.go"
gometalinter="$gml" # final
echo "Using: $gometalinter"