Skip to content

Generated files are empty #44

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
naphta opened this issue May 4, 2021 · 9 comments
Closed

Generated files are empty #44

naphta opened this issue May 4, 2021 · 9 comments

Comments

@naphta
Copy link

naphta commented May 4, 2021

My problem is that when I run ldetool the resulting generated go code is an empty file.

Very much in the early stages of playing around (so there may be some glaring mistake), I'm running go 1.16.3 and my lde file is as follows:

type time.Duration from "time";
type ip.IP from "net";

Combined =
  ?RemoteServer(IPAddress(ip.IP) ' - ')
  ?RemoteUser(Value(string))
  ^' [' Time(string) ']'
  ^' ' ?HTTPHost(Value(string))
  ^' "' ?HTTPLine(Value(string) '"')
  ^' ' ?TlsProtocol(Value(string) '/')
  ^' ' ?TlsCipher(Value(string) ' ')
  ^' ' ?HTTPCode(Value(uint16) ' ')
  ^' ' ?HTTPBodyBytesSent(Value(uint16) ' ')
  ^' ' ?HTTPResponseTime(DurationFromSeconds(time.Duration) ' ')
  ^' ' ?HTTPUpstreamResponseTime(DurationFromSeconds(time.Duration) ' ')
  ^' ' ?HTTPUpstreamCode(Value(uint16) ' ')
  ^' ' ?HTTPUpstreamHost(Host(string) ' ')
  ^' ' ?HTTPUpstreamCacheStatus(Value(string) ' ')
  ^' "' ?HTTPReferer(Value(string) '" ')
  ^' "' ?HTTPUserAgent(Value(string) '" ')
  ^'" ' ?HTTPForwardFor(Csv(string) '" ')
  ^'" ' ?HTTPAuthorization(Value(string) '"');

and the output from running ldetool is:

> ldetool --package main combined.lde
Rule `Combined`: processing
Named option RemoteServer
Take until ' - ' as IPAddress(ip.IP)
End of named option RemoteServer
Named option RemoteUser
Take the rest as Value(string)
End of named option RemoteUser
Check and pass character ' ['
Take until ']' as Time(string)
Check and pass character ' '
Named option HTTPHost
Take the rest as Value(string)
End of named option HTTPHost
Check and pass character ' "'
Named option HTTPLine
Take until '"' as Value(string)
End of named option HTTPLine
Check and pass character ' '
Named option TlsProtocol
Take until '/' as Value(string)
End of named option TlsProtocol
Check and pass character ' '
Named option TlsCipher
Take until ' ' as Value(string)
End of named option TlsCipher
Check and pass character ' '
Named option HTTPCode
Take until ' ' as Value(uint16)
End of named option HTTPCode
Check and pass character ' '
Named option HTTPBodyBytesSent
Take until ' ' as Value(uint16)
End of named option HTTPBodyBytesSent
Check and pass character ' '
Named option HTTPResponseTime
Take until ' ' as DurationFromSeconds(time.Duration)
End of named option HTTPResponseTime
Check and pass character ' '
Named option HTTPUpstreamResponseTime
Take until ' ' as DurationFromSeconds(time.Duration)
End of named option HTTPUpstreamResponseTime
Check and pass character ' '
Named option HTTPUpstreamCode
Take until ' ' as Value(uint16)
End of named option HTTPUpstreamCode
Check and pass character ' '
Named option HTTPUpstreamHost
Take until ' ' as Host(string)
End of named option HTTPUpstreamHost
Check and pass character ' '
Named option HTTPUpstreamCacheStatus
Take until ' ' as Value(string)
End of named option HTTPUpstreamCacheStatus
Check and pass character ' "'
Named option HTTPReferer
Take until '" ' as Value(string)
End of named option HTTPReferer
Check and pass character ' "'
Named option HTTPUserAgent
Take until '" ' as Value(string)
End of named option HTTPUserAgent
Check and pass character '" '
Named option HTTPForwardFor
Take until '" ' as Csv(string)
End of named option HTTPForwardFor
Check and pass character '" '
Named option HTTPAuthorization
Take until '"' as Value(string)
End of named option HTTPAuthorization
Rule `Combined`: done

@sirkon
Copy link
Owner

sirkon commented May 4, 2021

Thanks for the report, digging into it.

@naphta
Copy link
Author

naphta commented May 4, 2021

Thanks for the report, digging into it.

Had a further play and I can say that the generation breaks when:

  ^' [' Time(string) ']'
  ?RemoteServer(IPAddress(ip.IP) ' - ')
  ^' "' ?HTTPLine(Value(string) '"')
  ^' "' ?HTTPReferer(Value(string) '" ')
  ^' "' ?HTTPUserAgent(Value(string) '" ')
  ^'" ' ?HTTPForwardFor(Csv(string) '" ')
  ^'" ' ?HTTPAuthorization(Value(string) '"');

are included, if that helps at all! Seems to not like the time, IP, and anything with double quotes in. (or ", [, ], and -)

@sirkon
Copy link
Owner

sirkon commented May 4, 2021

The problem is ' - ' is not a correct rune literal. Change it into " - ". Also '" ' should be changed to "\" ", etc. These are not Python strings, they are Go's runes and strings.

A silenced execution is a bug of ldetool, where I missed return err in if err != nil. The problem though an error message is generated by the formatter (the one gofmt is built upon) and its error message is useless — no source code.

Need to fix it at lexer/grammar level, but this will take a bit of time.

@naphta
Copy link
Author

naphta commented May 4, 2021

Makes sense to me, cheers for looking into it so quickly. I'll leave this open just as something to work against for the aforementioned bug(/improvement).

@sirkon
Copy link
Owner

sirkon commented May 4, 2021

Need antlr/antlr4#2642 merged

@sirkon
Copy link
Owner

sirkon commented May 5, 2021

#45

@sirkon
Copy link
Owner

sirkon commented May 5, 2021

@naphta seems to be fixed. Not at the level I expected it to be, but I seriously don't want to rely on unmerged functionality.

@naphta
Copy link
Author

naphta commented May 5, 2021

Validations are fine from my pov, it's a shame they couldn't be better but certainly the error messages coming out of it would have led me to not raising this issue. Happy to close this off, or leave it open until that antlr PR, up to you.

@sirkon
Copy link
Owner

sirkon commented May 5, 2021

Closing it. I have a suspicious I will have a badge "my PR was accepted in ATNTLR in less than five years" LOL.

@sirkon sirkon closed this as completed May 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants