Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7761905
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T14:15:19+00:00 2026-06-01T14:15:19+00:00

I am parsing a verilog file to extract the dependencies within it. I don’t

  • 0

I am parsing a verilog file to extract the dependencies within it. I don’t need to parse most of the module contents, but am only interested in include statements and module instantiations. I first am attempting to only extract the include statements. This is my code so far:

include_pragma = Group(Keyword("`include") + quotedString + lineEnd.suppress())
module_definition = ZeroOrMore(~Keyword("endmodule") + MatchFirst([include_pragma, restOfLine])) + Keyword("endmodule")

My point is that I will either match an include pragma, or a line of anything until I reach “endmodule”. If I try this grammer on the following string, pyparsing gets into some kind of infinite loop.

`include "InternalInclude.v"

localparam COMMA_WIDTH = 10;

localparam  UNKNOWN = 1'b0,
            KNOWN   = 1'b1;

reg     [DATA_WIDTH-1:0] TtiuPosQ2;
reg                      TtiuDetQ2;
reg     [           7:0] TtiuDetQ2Save;

assign DebugQO = {  DataQI,         // 65:34
                    TxTrainingEnQI, // 33
                    TtiuDetQ2,      // 32
                    TtiuPosQ2       // 31:0
                  };

always @(posedge Clk or posedge ResetI) begin
    if (ResetI) begin
        CommaPosQO <= {(DATA_WIDTH){1'b0}};
        CommaDetQO <= 0;
        CommaPosQ1 <= {(DATA_WIDTH){1'b0}};
        CommaPosQ2 <= {(DATA_WIDTH){1'b0}};
        CommaDetQ2 <= 0;
        StateQ <= 0;

        CommaPosSaveQ <= {(DATA_WIDTH){1'b0}};
        TtiuPosQ1 <= 0;
        TtiuPosQ2 <= 0;
        TtiuDetQ2 <= 0;
        TtiuDetQ2Save <= 8'h00;
    end
    else begin 
        CommaPosQO <= CommaPosC2;
        CommaDetQO <= CommaDetC2;
        CommaPosQ1 <= CommaPosC;
        CommaPosQ2 <= CommaPosQ1;
        CommaDetQ2 <= (| CommaPosQ1);
        StateQ <= StateC;
        CommaPosSaveQ <= CommaPosSaveC;
        TtiuPosQ1 <= TtiuPosC1;
        TtiuPosQ2 <= TtiuPosC2;
        TtiuDetQ2 <= TtiuDetC2;
        TtiuDetQ2Save <= TtiuDetQ2 ? 8'hFF : {1'b0, TtiuDetQ2Save[7:1]};
    end
end

endmodule

I am probably misunderstanding the ~ operator. Any suggestions?

update

After using the setDebug() method suggested, I found that the infinite loops prints this:

Match {Group:({"`include" quotedString using single or double quotes Suppress:(lineEnd)}) | Re:('.*')} at loc 0(1,1)
Matched {Group:({"`include" quotedString using single or double quotes Suppress:(lineEnd)}) | Re:('.*')} -> [['`include'
, '"InternalInclude.v"']]
Match {Group:({"`include" quotedString using single or double quotes Suppress:(lineEnd)}) | Re:('.*')} at loc 31(4,1)
Matched {Group:({"`include" quotedString using single or double quotes Suppress:(lineEnd)}) | Re:('.*')} -> ['']
Match {Group:({"`include" quotedString using single or double quotes Suppress:(lineEnd)}) | Re:('.*')} at loc 31(4,1)
Matched {Group:({"`include" quotedString using single or double quotes Suppress:(lineEnd)}) | Re:('.*')} -> ['']
Match {Group:({"`include" quotedString using single or double quotes Suppress:(lineEnd)}) | Re:('.*')} at loc 31(4,1)
Matched {Group:({"`include" quotedString using single or double quotes Suppress:(lineEnd)}) | Re:('.*')} -> ['']

Is something that I do causing the parse position not to move forward?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T14:15:20+00:00Added an answer on June 1, 2026 at 2:15 pm

    The problem was with using the restOfLine expression. It can match anything, including ”. So, the parser would proceed as follows:

    1. Matched include "InternalInclude.v"
    2. Match ” to restOfLine
    3. Match the same ” to restOfLine because it did not consume the \n AND there is still ” left before the \n, as there alwasy will be 😉

    To fix it, I changed restOfLine to (restOfLine + lineEnd). This forced the parser to consume the \n after matching the line. The new parser reads:

    include_pragma = Group(Keyword("`include") + quotedString + lineEnd.suppress())
    module_definition = ZeroOrMore(~Keyword("endmodule") + MatchFirst([include_pragma, (restOfLine + lineEnd)])) + Keyword("endmodule")
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Not parsing the parameters in the beginning but parse the input string read from
When parsing XML like below, does book.xml need to be a static file of
DOM parsing in php works only if the HTML is perfectly tagged. I need
I am parsing thorugh a 2000+ record excel file, and need ot be able
Most parsing can be done by looking only at the next symbol (character for
Parsing a text file in vb.net and need to locate the latitude and longitude
Im parsing an xml file and i keep getting a nullpointer exception. I don't
While parsing the contents of a page I want to just list images, but,
After parsing my file s contains AttributeGet:1,16,10106,10111 So I need to get all the
When parsing an xml file in android, I'm doing like this: try { InputStream

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.