codeout / junoser

PEG parser for JUNOS configuration.
MIT License
69 stars 11 forks source link

Rakefile generates syntax error in parser.rb #35

Closed Jypear closed 7 months ago

Jypear commented 7 months ago

Hi,

First of all thanks for the awesome project!

I seem to be encountering an issue when using an XSD file to generate new rules using the Rakefile. I have downloaded and tried different versions from the Juniper website both seem to have the same results.

I followed a git issue from earlier and tried older tags but still seem to be having this issue.

Option 1: specific_install

# RUN gem install specific_install
# RUN gem specific_install "${GITHUB_TARGET}" v0.5.4

Optional 2: regular install

RUN gem install junoser

Then I run the usual build to deploy the latest rules from the XML Schema

RUN bundle install
RUN mkdir tmp
RUN mv /build/junos-system-${JUNOS_VERSION}.xsd tmp/junos-system-${JUNOS_VERSION}.xsd
RUN mv /build/junos.xsd tmp/junos.xsd

RUN sed -i -e "s@tmp/junos-system-21.2.xsd@tmp/junos-system-"${JUNOS_VERSION}".xsd@g" Rakefile
RUN bundle exec rake build:config build:rule

The result is when I attempt to run junoser I get a syntax error inside parser.rb

root@476dd113a1f7:/usr/local/bundle/gems/junoser-0.5.5# junoser -v
<internal:/usr/local/lib/ruby/3.3.0/rubygems/core_ext/kernel_require.rb>:127:in `require': Search timed out SYNTAX_SUGGEST_TIMEOUT=1, run with SYNTAX_SUGGEST_DEBUG=1 for more info/usr/local/lib/ruby/3.3.0/timeout.rb:43:in `rescue in handle_timeout'
/usr/local/lib/ruby/3.3.0/timeout.rb:40:in `handle_timeout'
/usr/local/lib/ruby/3.3.0/timeout.rb:195:in `timeout'
/usr/local/bundle/gems/junoser-0.5.5/lib/junoser/parser.rb:115213: syntax error, unexpected ',', expecting `end' or dummy end (SyntaxError)
      ),

Going to line 115213 I can see the following:

            ).as(:oneline)
        )
      ),
                            str("teardown")
    end

    rule(:pcc_rule) do

For the full class which this relates too see below:

    rule(:pcc_flow) do
      b(arg.as(:arg),
        c(
            b(str("direction"),
              (str("downlink") | str("uplink") | str("both"))
            ),
            a(str("protocol"), arg),
            a(str("local-ports"), arg),
            b(str("local-port-range"),
                s(
                  a(str("low"), arg),
                  a(str("high"), arg)
                )
            ).as(:oneline),
            a(str("remote-ports"), arg),
            b(str("remote-port-range"),
                s(
                  a(str("low"), arg),
                  a(str("high"), arg)
                )
            ).as(:oneline),
            b(str("remote-address"),
                sc(
                    c(
                      b(str("ipv4-address"),
                        ipv4prefix
                      ),
                      b(str("ipv6-address"),
                        ipv6prefix
                      )
                    )
                )
            ).as(:oneline)
        )
      ),
                            str("teardown")
    end

I can fix this by just removing that statement from the rule:

                    )
                )
            ).as(:oneline)
        )
      )
    end

    rule(:pcc_rule) do

When run:

root@476dd113a1f7:/usr/local/bundle/gems/junoser-0.5.5/lib/junoser# junoser -v
0.5.5

The project still works fine with the built in rules/parsers. Just when I attempt to parse a new one. This was tried on xsd versions 20.4R3 and 22.3R0 - downloaded from Junipers site.

codeout commented 7 months ago

Hi, thank you for your reporting. I'll take a look into this. Is there any chance you could send me ( goodies@codeout.net ) the problematic .xsd, by the way?

Jypear commented 7 months ago

Hi, thanks for the reply.

I should have sent across the file. I'll remove it after a couple of days.

codeout commented 7 months ago

Hi, I have fixed an issue in the parser generator. With the latest origin/main you should be able to generate a correct ruby parser.

Please reopen this issue if you have any further problem.