Skip to content

Commit

Permalink
Add comments and inline comments support
Browse files Browse the repository at this point in the history
This is a workaround. The ideal would be implement in the grammar

Signed-off-by: Ulysses Souza <[email protected]>
  • Loading branch information
ulyssessouza committed Mar 23, 2024
1 parent 02cbe99 commit 086bcae
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
9 changes: 4 additions & 5 deletions envlang_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,19 +249,18 @@ A = "aaa ${B} ccc "
func TestFull(t *testing.T) {
log.SetLevel(log.DebugLevel)
is := `
# my comment
A=aaa
B="bbb"
A=aaa # my inline comment on A
B="bbb" # my inline comment on B
C =ccc
D= ddd
E='eee'
E='eee' # my inline comment on E
F=
G
H="my_value"
I = bar baz
export EXPORTED_VAR = exported_value
Expand Down
11 changes: 11 additions & 0 deletions handlers/filehandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ func (l *EnvLangFileListener) ExitEntry(c *fileparser.EntryContext) {
// TODO: Implement the logic to handle the export keyword in the grammar file
id, _ = strings.CutPrefix(id, "export ")
id = strings.TrimSpace(id)
if strings.HasPrefix(id, "#") {
return
}

hasAssign := true
if c.ASSIGN() == nil || c.ASSIGN().GetText() == "" {
Expand All @@ -47,6 +50,7 @@ func (l *EnvLangFileListener) ExitEntry(c *fileparser.EntryContext) {
valuePtr = &v
}

toTrim := true
if c.Value() != nil {
v := strings.TrimSpace(c.Value().GetText())
switch c.Value().GetStr().GetTokenType() {
Expand All @@ -55,8 +59,15 @@ func (l *EnvLangFileListener) ExitEntry(c *fileparser.EntryContext) {
valuePtr = &v
case fileparser.EnvLangFileParserDQSTRING:
v = v[1 : len(v)-1] // Removing quotes
toTrim = false
fallthrough
case fileparser.EnvLangFileParserTEXT:
if strings.Index(v, "#") != 0 {
v = strings.SplitN(v, "#", pair)[0]
if toTrim {
v = strings.TrimSpace(v)
}
}
v = GetValue(l.d, v)
valuePtr = &v
default:
Expand Down

0 comments on commit 086bcae

Please sign in to comment.