add C-style comment support

This commit is contained in:
GenZmeY 2020-11-03 11:20:24 +03:00
parent f083dcd3d8
commit 69be8312f8
27 changed files with 56 additions and 45 deletions

View File

@ -1,21 +1,30 @@
NAME=multini NAME = $(shell basename $(shell readlink -e .))
VERSION=0.2.3 VERSION = dev_$(shell date +%F_%T)
GOCMD=go GOCMD = go
LDFLAGS:="$(LDFLAGS) -X 'main.Version=$(VERSION)'" LDFLAGS := "$(LDFLAGS) -X 'main.Version=$(VERSION)'"
GOBUILD=$(GOCMD) build -ldflags=$(LDFLAGS) GOBUILD = $(GOCMD) build -ldflags=$(LDFLAGS)
SRCMAIN=. SRCMAIN = ./cmd/$(NAME)
BINDIR=bin SRCDOC = ./doc
BIN=$(BINDIR)/$(NAME) SRCTEST = ./test
README=README BINDIR = bin
LICENSE=LICENSE BIN = $(BINDIR)/$(NAME)
TEST=./run_test.sh README = $(SRCDOC)/README
PREFIX=/usr LICENSE = LICENSE
TEST = $(SRCTEST)/run_test.sh
PREFIX = /usr
.PHONY: all prep doc build check-build freebsd-386 darwin-386 linux-386 windows-386 freebsd-amd64 darwin-amd64 linux-amd64 windows-amd64 compile install check-install uninstall clean test
all: build all: build
prep: clean prep: clean
go mod init; go mod tidy
mkdir $(BINDIR) mkdir $(BINDIR)
doc: check-build
test -d $(SRCDOC) || mkdir $(SRCDOC)
$(BIN) --help > $(README)
build: prep build: prep
$(GOBUILD) -o $(BIN) $(SRCMAIN) $(GOBUILD) -o $(BIN) $(SRCMAIN)
@ -71,3 +80,4 @@ clean:
test: check-build test: check-build
$(TEST) $(BIN) $(TEST) $(BIN)

View File

@ -1,8 +1,8 @@
package main package main
import ( import (
"multini/output" "multini/internal/output"
"multini/types" "multini/internal/types"
) )
func chk() int { func chk() int {

View File

@ -4,8 +4,8 @@ import (
"errors" "errors"
"os" "os"
"multini/output" "multini/internal/output"
"multini/types" "multini/internal/types"
"github.com/juju/gnuflag" "github.com/juju/gnuflag"
) )

View File

@ -3,8 +3,8 @@ package main
import ( import (
"os" "os"
"multini/output" "multini/internal/output"
"multini/types" "multini/internal/types"
) )
const ( const (

View File

@ -7,8 +7,8 @@ import (
"regexp" "regexp"
"strings" "strings"
"multini/output" "multini/internal/output"
"multini/types" "multini/internal/types"
) )
var ( var (
@ -26,15 +26,15 @@ var (
RxBodyPrefix string = `(?P<` + NgPrefix + `>\s+)?` RxBodyPrefix string = `(?P<` + NgPrefix + `>\s+)?`
RxSectionName string = `\[(?P<` + NgSection + `>.+)\]` RxSectionName string = `\[(?P<` + NgSection + `>.+)\]`
RxKey string = `(?P<` + NgKey + `>(?:[^;#=]+[^\s=;#]|[^;#=]))?` RxKey string = `(?P<` + NgKey + `>(?:[^;#/=]+[^\s=;#/]|[^;#/=]))?`
RxKeyPostfix string = `(?P<` + NgKeyPostfix + `>\s+)?` RxKeyPostfix string = `(?P<` + NgKeyPostfix + `>\s+)?`
RxValuePrefix string = `(?P<` + NgValuePrefix + `>\s+)?` RxValuePrefix string = `(?P<` + NgValuePrefix + `>\s+)?`
RxValue string = `(?P<` + NgValue + `>(?:[^;#]+[^\s;#]|[^;#]))?` RxValue string = `(?P<` + NgValue + `>(?:[^;#/]+[^\s;#/]|[^;#/]))?`
RxValuePostfix string = `(?P<` + NgValuePostfix + `>\s+)?` RxValuePostfix string = `(?P<` + NgValuePostfix + `>\s+)?`
RxKeyVal string = RxKey + RxKeyPostfix + `=` + RxValuePrefix + RxValue + RxValuePostfix RxKeyVal string = RxKey + RxKeyPostfix + `=` + RxValuePrefix + RxValue + RxValuePostfix
RxBody string = `(?:` + RxSectionName + `|` + RxKeyVal + `)?` RxBody string = `(?:` + RxSectionName + `|` + RxKeyVal + `)?`
RxBodyPostfix string = `(?P<` + NgPostifx + `>\s+)?` RxBodyPostfix string = `(?P<` + NgPostifx + `>\s+)?`
RxCommentPrefix string = `(?P<` + NgCommentPrefix + `>[#;]\s*)` RxCommentPrefix string = `(?P<` + NgCommentPrefix + `>([#;]|//)\s*)`
RxCommentText string = `(?P<` + NgComment + `>.+)?` RxCommentText string = `(?P<` + NgComment + `>.+)?`
RxComment string = `(?:` + RxCommentPrefix + RxCommentText + `)?` RxComment string = `(?:` + RxCommentPrefix + RxCommentText + `)?`
Rx string = RxBodyPrefix + RxBody + RxBodyPostfix + RxComment Rx string = RxBodyPrefix + RxBody + RxBodyPostfix + RxComment

View File

@ -7,7 +7,7 @@ import (
"os" "os"
"path/filepath" "path/filepath"
"multini/types" "multini/internal/types"
) )
// Source: https://gist.github.com/var23rav/23ae5d0d4d830aff886c3c970b8f6c6b // Source: https://gist.github.com/var23rav/23ae5d0d4d830aff886c3c970b8f6c6b

View File

@ -10,7 +10,7 @@ DefKey3=NoSpaces!
Key2 = 2 Key2 = 2
Key3 = 3 Key3 = 3
[MultipleKeySection] [MultipleKeySection] // C style comment
Key = 1 Key = 1
Key = 2 Key = 2
Key = 3 Key = 3

View File

@ -9,7 +9,7 @@ DefKey3=NoSpaces!
Key1 = 1 Key1 = 1
Key2 = 2 Key2 = 2
[MultipleKeySection] [MultipleKeySection] // C style comment
Key = 1 Key = 1
Key = 2 Key = 2
Key = 3 Key = 3

View File

@ -9,7 +9,7 @@ DefKey3=NoSpaces!
Key1 = 1 Key1 = 1
Key2 = 2 Key2 = 2
[MultipleKeySection] [MultipleKeySection] // C style comment
Key = 1 Key = 1
Key = 2 Key = 2
Key = 3 Key = 3

View File

@ -8,7 +8,7 @@ DefKey3=NoSpaces!
[SimpleSection] # Comment For Section [SimpleSection] # Comment For Section
Key2 = 2 Key2 = 2
[MultipleKeySection] [MultipleKeySection] // C style comment
Key = 1 Key = 1
Key = 2 Key = 2
Key = 3 Key = 3

View File

@ -9,7 +9,7 @@ DefKey3=NoSpaces!
Key1 = 1 Key1 = 1
Key2 = 2 Key2 = 2
[MultipleKeySection] [MultipleKeySection] // C style comment
[SectionWithIndent] [SectionWithIndent]
Key=Value Key=Value

View File

@ -9,7 +9,7 @@ DefKey3=NoSpaces!
Key1 = 1 Key1 = 1
Key2 = 2 Key2 = 2
[MultipleKeySection] [MultipleKeySection] // C style comment
Key = 1 Key = 1
Key = 3 Key = 3

View File

@ -9,7 +9,7 @@ DefKey3=NoSpaces!
Key1 = 1 Key1 = 1
Key2 = 2 Key2 = 2
[MultipleKeySection] [MultipleKeySection] // C style comment
Key = 1 Key = 1
Key = 2 Key = 2
Key = 3 Key = 3

View File

@ -9,7 +9,7 @@ DefKey3=NoSpaces!
Key1 = 1 Key1 = 1
Key2 = 2 Key2 = 2
[MultipleKeySection] [MultipleKeySection] // C style comment
Key = onlyone Key = onlyone
[SectionWithIndent] [SectionWithIndent]

View File

@ -9,7 +9,7 @@ DefKey3=NoSpaces!
Key1 = 1 Key1 = 1
Key2 = 2 Key2 = 2
[MultipleKeySection] [MultipleKeySection] // C style comment
Key = 1 Key = 1
Key = 2 Key = 2
Key = 3 Key = 3

View File

@ -9,7 +9,7 @@ DefKey3=NoSpaces!
Key1 = 1 Key1 = 1
Key2 = 2 Key2 = 2
[MultipleKeySection] [MultipleKeySection] // C style comment
Key = 1 Key = 1
Key = 2 Key = 2
Key = 3 Key = 3

View File

@ -9,7 +9,7 @@ DefKey3=NoSpaces!
Key1 = 1 Key1 = 1
Key2 = 2 Key2 = 2
[MultipleKeySection] [MultipleKeySection] // C style comment
Key = 1 Key = 1
Key = 2 Key = 2
Key = 3 Key = 3

View File

@ -9,7 +9,7 @@ DefKey3=NoSpaces!
Key1 = 1 Key1 = 1
Key2 = 2 Key2 = 2
[MultipleKeySection] [MultipleKeySection] // C style comment
Key = 1 Key = 1
Key = 2 Key = 2
Key = 3 Key = 3

View File

@ -9,7 +9,7 @@ DefKey3=NoSpaces!
Key1 = 1 Key1 = 1
Key2 = 2 Key2 = 2
[MultipleKeySection] [MultipleKeySection] // C style comment
Key = 1 Key = 1
Key = 2 Key = 2
Key = 3 Key = 3

View File

@ -9,7 +9,7 @@ DefKey3=NoSpaces!
Key1 = 1 Key1 = 1
Key2 = 2 Key2 = 2
[MultipleKeySection] [MultipleKeySection] // C style comment
Key = 1 Key = 1
Key = 2 Key = 2
Key = 3 Key = 3

View File

@ -9,7 +9,7 @@ DefKey3=NoSpaces!
Key1 = 1 Key1 = 1
Key2 = 2 Key2 = 2
[MultipleKeySection] [MultipleKeySection] // C style comment
Key = 1 Key = 1
Key = 2 Key = 2
Key = 3 Key = 3

View File

@ -9,7 +9,7 @@ DefKey3=NoSpaces!
Key1 = 1 Key1 = 1
Key2 = 2 Key2 = 2
[MultipleKeySection] [MultipleKeySection] // C style comment
Key = 1 Key = 1
Key = 2 Key = 2
Key = 3 Key = 3

View File

@ -9,7 +9,7 @@ DefKey3=NoSpaces!
Key1 = 1 Key1 = 1
Key2 = 2 Key2 = 2
[MultipleKeySection] [MultipleKeySection] // C style comment
Key = 1 Key = 1
Key = 2 Key = 2
Key = 3 Key = 3

View File

@ -9,7 +9,7 @@ DefKey3=NoSpaces!
Key1 = 1 Key1 = 1
Key2 = 2 Key2 = 2
[MultipleKeySection] [MultipleKeySection] // C style comment
Key = 1 Key = 1
Key = 2 Key = 2
Key = 3 Key = 3

View File

@ -9,7 +9,7 @@ DefKey3=NoSpaces!
Key1 = 1 Key1 = 1
Key2 = 2 Key2 = 2
[MultipleKeySection] [MultipleKeySection] // C style comment
Key = 1 Key = 1
Key = 2 Key = 2
Key = 3 Key = 3

View File

@ -9,7 +9,7 @@ DefKey3=NoSpaces!
Key1 = 1 Key1 = 1
Key2 = 2 Key2 = 2
[MultipleKeySection] [MultipleKeySection] // C style comment
Key = 1 Key = 1
Key = 2 Key = 2
Key = 3 Key = 3

View File

@ -1,10 +1,11 @@
#!/bin/bash #!/bin/bash
DEF='\e[0m'; BLD='\e[1m'; RED='\e[31m'; GRN='\e[32m'; WHT='\e[97m' DEF='\e[0m'; BLD='\e[1m'; RED='\e[31m'; GRN='\e[32m'; WHT='\e[97m'
ScriptFullname=$(readlink -e "$0") ScriptFullname=$(readlink -e "$0")
ScriptName=$(echo "$ScriptFullname" | awk -F '/' '{print $NF;}') ScriptName=$(echo "$ScriptFullname" | awk -F '/' '{print $NF;}')
ScriptDir=$(dirname "$ScriptFullname") ScriptDir=$(dirname "$ScriptFullname")
TestDir="$ScriptDir/tests" TestDir="$ScriptDir/data"
Multini=$(readlink -e "$1") Multini=$(readlink -e "$1")
if [[ -z "$Multini" ]]; then if [[ -z "$Multini" ]]; then