~mna/siberian

c518be4dbac0283a66ff15cb1045a4c3c46502e5 — Martin Angers 4 years ago
initial commit
5 files changed, 173 insertions(+), 0 deletions(-)

A .gitignore
A .golangci.toml
A doc/design.md
A ebnf.go
A ebnf_test.go
A  => .gitignore +8 -0
@@ 1,8 @@
# environment files
.env*

# output of various helper commands
*.out

# binaries
/bin/

A  => .golangci.toml +89 -0
@@ 1,89 @@
[linters]
  disable-all = true
  enable = [
    "deadcode",
    "errcheck",
    "gochecknoinits",
    "gochecknoglobals",
    "gofmt",
    "golint",
    "gosec",
    "gosimple",
    "govet",
    "ineffassign",
    "misspell",
    "nakedret",
    "prealloc",
    "staticcheck",
    "structcheck",
    "typecheck",
    "unconvert",
    "unparam",
    #"unused",
    "varcheck",
  ]

[issues]
  # regexps of issue texts to exclude
  # NOTE: using this instead of [[issues.exclude-rules]] as SpaceVim respects those
  # exclusions, but does not respect the specific exclude-rules.
  exclude = [
    # cmd/*: package-level vars for binaries, assigned with linker flags
    "`version` is a global variable",
    "`buildDate` is a global variable",
    "`shortUsage` is a global variable",
    "`longUsage` is a global variable",
    "`commands` is a global variable",

    # pkg/codegen
    "`basicIdentsToGo` is a global variable",
    "`goKeywords` is a global variable",
    "`tokenToGoToken` is a global variable",
    "`testUpdateCodegenTests` is a global variable",

    # pkg/internal/filetest
    "`testUpdateAllTests` is a global variable",

    # pkg/parser
    "`declStart` is a global variable",
    "`stmtStart` is a global variable",
    "`testUpdateParserTests` is a global variable",

    # pkg/scanner
    "`PrintError` is a global variable",
    "`testUpdateScannerTests` is a global variable",

    # pkg/semantic
    "`basicKindSizes` is a global variable",
    "`selectorTypeContext` is a global variable",

    # pkg/token
    "`NewFileSet` is a global variable",
    "`tokens` is a global variable",
    "`keywords` is a global variable",
    "`operators` is a global variable",

    # pkg/typecheck
    "`basicKindStrings` is a global variable",
    "`binaryOpsTable` is a global variable",
    "`boolsCompare` is a global variable",
    "`floatsCompare` is a global variable",
    "`floatsWidening` is a global variable",
    "`identToBasicKind` is a global variable",
    "`intsCompare` is a global variable",
    "`intsWidening` is a global variable",
    "`nodeType` is a global variable",
    "`objectType` is a global variable",
    "`stringsCompare` is a global variable",
    "`stringsWidening` is a global variable",
    "`testUpdateCheckTests` is a global variable",
    "`testUpdateScopesTests` is a global variable",
    "`testUpdateStaticTests` is a global variable",
    "`testUpdateTypesTests` is a global variable",
    "`typeContextStrings` is a global variable",
    "`typeContextValues` is a global variable",
    "`typeType` is a global variable",
    "`unaryOpsTable` is a global variable",
    "`universeIdents` is a global variable",
  ]


A  => doc/design.md +17 -0
@@ 1,17 @@
# design

Runtime-based parser-generator using declarative data structures.

The Scanner is defined using either rune range tables, regular expressions,
simple ASCII lookup table, exact (case-sensitive or -insensitive) match, or a
custom function.

A sequence of tokens are defined with how they must be scanned, and are
attempted in order. Special tokens are defined for ignored characters (e.g.
whitespace).

This scanner definition is recursive - that is, when a specific token is
scanned, it may enter a different scanner definition so that e.g. ignored
characters are different, etc. This is to support things like string literals
or escape characters, things like that. (is that required? or is the
sequence/choice/repeat operations enough?)

A  => ebnf.go +34 -0
@@ 1,34 @@
package siberian

// asciiTable encodes the allowed ASCII values on 128 bits.
type asciiTable [2]uint64

func (t *asciiTable) set(chars ...byte) {
}

func (t *asciiTable) unset(chars ...byte) {
}

func (t *asciiTable) String() string {
}

type Grammar struct{}

type Alt struct {
}

type Repeat struct {
	Min int
	Max int
}

type Seq struct {
}

type Group struct {
}

type Tok struct {
	// TODO: a token may be defined by a grammar (where e.g. the tokens
	// are single runes).
}

A  => ebnf_test.go +25 -0
@@ 1,25 @@
package siberian

import (
	"testing"
	"unicode"
	"unsafe"
)

func TestASCIITableSize(t *testing.T) {
	var b bool
	szBool := unsafe.Sizeof(b)
	t.Logf("sizeof(bool)=%d", szBool)

	var at [unicode.MaxASCII + 1]bool
	szArrayBool := unsafe.Sizeof(at)
	t.Logf("sizeof([128]bool)=%d", szArrayBool)

	var twoUints [2]uint64
	szArrayUint := unsafe.Sizeof(twoUints)
	t.Logf("sizeof([2]uint64)=%d", szArrayUint)

	if szArrayUint >= szArrayBool {
		t.Fatalf("size of [128]bool same or smaller than [2]uint64: %d vs %d", szArrayBool, szArrayUint)
	}
}