Skip to content

Commit

Permalink
user group file language
Browse files Browse the repository at this point in the history
  • Loading branch information
heyitsanthony committed Dec 18, 2017
1 parent 784d0bb commit eb5dc68
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
27 changes: 27 additions & 0 deletions group/group.peg
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Adapted from "Linux Programmer's Manual" group(5)
# group - user group file
package group

type Grammar Peg {}

group <- (entry '\n')* !.

# There is one entry per line, with the following format:
# group_name:password:GID:user_list
entry <- group_name ':' password ':' GID ':' user_list

# group_name the name of the group.
group_name <- (![:\n].)+

# password the (encrypted) group password. If this field is empty, no password is needed.
password <- _shadow &':' / _null / _encrypted_password
_encrypted_password <- (![:\n].)+
_null <- &':'
_shadow <- 'x'

# GID the numeric group ID.
GID <- [0-9]+

# user_list a list of the usernames that are members of this group, separated by commas.
user_list <- (_user (',' _user)*)?
_user <- [a-z0-9._\-]+
4 changes: 4 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//go:generate peg -strict crontab/crontab.peg
//go:generate peg -strict golang/golang.peg
//go:generate peg -strict group/group.peg
//go:generate peg -strict offside/offside.peg
//go:generate peg -strict passwd/passwd.peg
//go:generate peg -strict peg/peg.peg
Expand All @@ -19,6 +20,7 @@ import (

"github.com/heyitsanthony/grammars/crontab"
"github.com/heyitsanthony/grammars/golang"
"github.com/heyitsanthony/grammars/group"
"github.com/heyitsanthony/grammars/offside"
"github.com/heyitsanthony/grammars/passwd"
"github.com/heyitsanthony/grammars/peg"
Expand All @@ -42,6 +44,7 @@ type g interface {

func newCrontab(s string) g { return &crontab.Grammar{Buffer: s, Pretty: true} }
func newGo(s string) g { return &golang.Grammar{Buffer: s, Pretty: true} }
func newGroup(s string) g { return &group.Grammar{Buffer: s, Pretty: true} }
func newOffside(s string) g { return &offside.Grammar{Buffer: s, Pretty: true} }
func newPasswd(s string) g { return &passwd.Grammar{Buffer: s, Pretty: true} }
func newPeg(s string) g { return &peg.Grammar{Buffer: s, Pretty: true} }
Expand All @@ -54,6 +57,7 @@ func newShadow(s string) g { return &shadow.Grammar{Buffer: s, Pretty: true} }
var grammars = map[string](func(string) g){
"crontab": newCrontab,
"go": newGo,
"group": newGroup,
"offside": newOffside,
"passwd": newPasswd,
"peg": newPeg,
Expand Down

0 comments on commit eb5dc68

Please sign in to comment.