Skip to content

Commit 2ca6ea5

Browse files
committed
build: switch to use Go tools rather than sed/awk
Signed-off-by: Leonardo Di Donato <[email protected]>
1 parent a7e28b3 commit 2ca6ea5

File tree

5 files changed

+15
-44
lines changed

5 files changed

+15
-44
lines changed

makefile

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
SHELL := /bin/bash
22
RAGEL := ragel -I common
3+
REMOVECOMMENTS := go run github.com/leodido/go-urn/tools/removecomments@master
4+
SNAKE2CAMEL := go run github.com/leodido/go-urn/tools/snake2camel@master
5+
GOFMT := go fmt
36

47
export GO_TEST=env GOTRACEBACK=all GO111MODULE=on go test $(GO_ARGS)
58

69
.PHONY: build
710
build: rfc5424/machine.go rfc5424/builder.go nontransparent/parser.go rfc3164/machine.go
8-
@gofmt -w -s ./rfc5424
9-
@gofmt -w -s ./rfc3164
10-
@gofmt -w -s ./octetcounting
11-
@gofmt -w -s ./nontransparent
1211

1312
rfc5424/machine.go: rfc5424/machine.go.rl common/common.rl
1413

@@ -20,26 +19,21 @@ nontransparent/parser.go: nontransparent/parser.go.rl
2019

2120
rfc5424/builder.go rfc5424/machine.go:
2221
$(RAGEL) -Z -G2 -e -o $@ $<
23-
@sed -i '/^\/\/line/d' $@
24-
$(MAKE) file=$@ snake2camel
22+
$(REMOVECOMMENTS) $@
23+
$(SNAKE2CAMEL) $@
24+
$(GOFMT) $@
2525

2626
rfc3164/machine.go:
2727
$(RAGEL) -Z -G2 -e -o $@ $<
28-
@sed -i '/^\/\/line/d' $@
29-
$(MAKE) file=$@ snake2camel
28+
$(REMOVECOMMENTS) $@
29+
$(SNAKE2CAMEL) $@
30+
$(GOFMT) $@
3031

3132
nontransparent/parser.go:
3233
$(RAGEL) -Z -G2 -e -o $@ $<
33-
@sed -i '/^\/\/line/d' $@
34-
$(MAKE) file=$@ snake2camel
35-
36-
.PHONY: snake2camel
37-
snake2camel:
38-
@awk -i inplace '{ \
39-
while ( match($$0, /(.*)([a-z]+[0-9]*)_([a-zA-Z0-9])(.*)/, cap) ) \
40-
$$0 = cap[1] cap[2] toupper(cap[3]) cap[4]; \
41-
print \
42-
}' $(file)
34+
$(REMOVECOMMENTS) $@
35+
$(SNAKE2CAMEL) $@
36+
$(GOFMT) $@
4337

4438
.PHONY: bench
4539
bench: rfc5424/*_test.go rfc5424/machine.go octetcounting/performance_test.go

nontransparent/parser.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ type machine struct {
2828
func (m *machine) Exec(s *parser.State) (int, int) {
2929
// Retrieve previously stored parsing variables
3030
cs, p, pe, eof, data := s.Get()
31-
3231
{
3332
var _widec int16
3433
if p == pe {
@@ -162,7 +161,6 @@ func (m *machine) Exec(s *parser.State) (int, int) {
162161
{
163162
}
164163
}
165-
166164
// Update parsing variables
167165
s.Set(cs, p, pe, eof)
168166
return p, pe
@@ -218,7 +216,7 @@ func NewParser(options ...syslog.ParserOption) syslog.Parser {
218216
return m
219217
}
220218

221-
// WithMaxMessageLength does nothing for this parser
219+
// WithMaxMessageLength does nothing for this parser.
222220
func (m *machine) WithMaxMessageLength(length int) {}
223221

224222
// HasBestEffort tells whether the receiving parser has best effort mode on or off.

rfc3164/machine.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,9 @@ func (m *machine) Parse(input []byte) (syslog.Message, error) {
102102
m.eof = len(input)
103103
m.err = nil
104104
output := &syslogMessage{}
105-
106105
{
107106
m.cs = start
108107
}
109-
110108
{
111109
var _widec int16
112110
if (m.p) == (m.pe) {
@@ -967,7 +965,6 @@ func (m *machine) Parse(input []byte) (syslog.Message, error) {
967965

968966
output.priority = uint8(common.UnsafeUTF8DecimalCodePointsToInt(m.text()))
969967
output.prioritySet = true
970-
971968
if (m.data)[(m.p)] == 62 {
972969
goto st4
973970
}
@@ -5995,7 +5992,6 @@ func (m *machine) Parse(input []byte) (syslog.Message, error) {
59955992

59965993
output.priority = uint8(common.UnsafeUTF8DecimalCodePointsToInt(m.text()))
59975994
output.prioritySet = true
5998-
59995995
switch (m.data)[(m.p)] {
60005996
case 57:
60015997
goto st332
@@ -6019,7 +6015,6 @@ func (m *machine) Parse(input []byte) (syslog.Message, error) {
60196015

60206016
output.priority = uint8(common.UnsafeUTF8DecimalCodePointsToInt(m.text()))
60216017
output.prioritySet = true
6022-
60236018
if (m.data)[(m.p)] == 62 {
60246019
goto st4
60256020
}
@@ -6035,7 +6030,6 @@ func (m *machine) Parse(input []byte) (syslog.Message, error) {
60356030

60366031
output.priority = uint8(common.UnsafeUTF8DecimalCodePointsToInt(m.text()))
60376032
output.prioritySet = true
6038-
60396033
if (m.data)[(m.p)] == 62 {
60406034
goto st4
60416035
}
@@ -7242,7 +7236,6 @@ func (m *machine) Parse(input []byte) (syslog.Message, error) {
72427236
{
72437237
goto st373
72447238
}
7245-
72467239
}
72477240
}
72487241

rfc5424/builder.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
)
1010

1111
// todo(leodido) > support best effort for builder ?
12-
1312
const builderStart int = 52
1413

1514
const builderEnTimestamp int = 1
@@ -72,7 +71,6 @@ func (sm *SyslogMessage) set(from entrypoint, value string) *SyslogMessage {
7271
eof := len(data)
7372
cs := from.translate()
7473
backslashes := []int{}
75-
7674
{
7775
if p == pe {
7876
goto _testEof
@@ -9252,7 +9250,6 @@ func (sm *SyslogMessage) set(from entrypoint, value string) *SyslogMessage {
92529250
if s := string(data[pb:p]); s != "" {
92539251
sm.Message = &s
92549252
}
9255-
92569253
}
92579254
}
92589255

@@ -9380,7 +9377,7 @@ func (sm *SyslogMessage) String() (string, error) {
93809377
if sm.StructuredData != nil {
93819378
// Sort element identifiers
93829379
identifiers := make([]string, 0)
9383-
for k := range *sm.StructuredData {
9380+
for k, _ := range *sm.StructuredData {
93849381
identifiers = append(identifiers, k)
93859382
}
93869383
sort.Strings(identifiers)
@@ -9392,7 +9389,7 @@ func (sm *SyslogMessage) String() (string, error) {
93929389
// Sort parameter names
93939390
params := (*sm.StructuredData)[id]
93949391
names := make([]string, 0)
9395-
for n := range params {
9392+
for n, _ := range params {
93969393
names = append(names, n)
93979394
}
93989395
sort.Strings(names)

rfc5424/machine.go

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ const (
4848

4949
// RFC3339MICRO represents the timestamp format that RFC5424 mandates.
5050
const RFC3339MICRO = "2006-01-02T15:04:05.999999Z07:00"
51-
5251
const start int = 1
5352
const firstFinal int = 603
5453

@@ -120,11 +119,9 @@ func (m *machine) Parse(input []byte) (syslog.Message, error) {
120119
m.eof = len(input)
121120
m.err = nil
122121
output := &syslogMessage{}
123-
124122
{
125123
m.cs = start
126124
}
127-
128125
{
129126
if (m.p) == (m.pe) {
130127
goto _testEof
@@ -1729,7 +1726,6 @@ func (m *machine) Parse(input []byte) (syslog.Message, error) {
17291726

17301727
output.priority = uint8(common.UnsafeUTF8DecimalCodePointsToInt(m.text()))
17311728
output.prioritySet = true
1732-
17331729
if (m.data)[(m.p)] == 62 {
17341730
goto st4
17351731
}
@@ -1755,7 +1751,6 @@ func (m *machine) Parse(input []byte) (syslog.Message, error) {
17551751
stCase5:
17561752

17571753
output.version = uint16(common.UnsafeUTF8DecimalCodePointsToInt(m.text()))
1758-
17591754
if (m.data)[(m.p)] == 32 {
17601755
goto st6
17611756
}
@@ -9583,7 +9578,6 @@ func (m *machine) Parse(input []byte) (syslog.Message, error) {
95839578
stCase591:
95849579

95859580
output.version = uint16(common.UnsafeUTF8DecimalCodePointsToInt(m.text()))
9586-
95879581
if (m.data)[(m.p)] == 32 {
95889582
goto st6
95899583
}
@@ -9598,7 +9592,6 @@ func (m *machine) Parse(input []byte) (syslog.Message, error) {
95989592
stCase592:
95999593

96009594
output.version = uint16(common.UnsafeUTF8DecimalCodePointsToInt(m.text()))
9601-
96029595
if (m.data)[(m.p)] == 32 {
96039596
goto st6
96049597
}
@@ -9616,7 +9609,6 @@ func (m *machine) Parse(input []byte) (syslog.Message, error) {
96169609

96179610
output.priority = uint8(common.UnsafeUTF8DecimalCodePointsToInt(m.text()))
96189611
output.prioritySet = true
9619-
96209612
switch (m.data)[(m.p)] {
96219613
case 57:
96229614
goto st595
@@ -9640,7 +9632,6 @@ func (m *machine) Parse(input []byte) (syslog.Message, error) {
96409632

96419633
output.priority = uint8(common.UnsafeUTF8DecimalCodePointsToInt(m.text()))
96429634
output.prioritySet = true
9643-
96449635
if (m.data)[(m.p)] == 62 {
96459636
goto st4
96469637
}
@@ -9656,7 +9647,6 @@ func (m *machine) Parse(input []byte) (syslog.Message, error) {
96569647

96579648
output.priority = uint8(common.UnsafeUTF8DecimalCodePointsToInt(m.text()))
96589649
output.prioritySet = true
9659-
96609650
if (m.data)[(m.p)] == 62 {
96619651
goto st4
96629652
}
@@ -12025,7 +12015,6 @@ func (m *machine) Parse(input []byte) (syslog.Message, error) {
1202512015
{
1202612016
goto st614
1202712017
}
12028-
1202912018
}
1203012019
}
1203112020

0 commit comments

Comments
 (0)