Игнорирование нескольких блоков текста внутри выражения - PullRequest
0 голосов
/ 14 апреля 2020

У меня есть ситуация, когда я анализирую файл и пытаюсь перехватить определенные фрагменты кода. Хотя это не относится к конкретной проблеме, я на самом деле разбираю verilog и использую подмножество примера verilogParse.py (с дополнительными элементами, добавленными для поддержки V2001 и SV). Я только пытаюсь получить порты модуля и экземпляры модуля. Из-за этого код, который может меня волновать, выглядит примерно так:

module mymod (
  input  wire en,
  input  wire in,
  output wire out
);


wire somewire;
reg somereg;

someothermod u_someothermod(
  .myport(myconn)
);

assign somewire = 1'b0;

endmodule

Так что правило для захвата модуля будет выглядеть так:

module = Group(moduleHdr + /*INTERNALS*/ + "endmodule").setResultsName("module")

Проблема, с которой я сталкиваюсь, Я хочу захватить экземпляры модуля, и я нашел способ сделать это, имея следующее для module parserElement

module = Group(moduleHdr + Group(ZeroOrMore(SkipTo(moduleInstantiation) + moduleInstantiation)).setResultsName("stuff") + SkipTo("endmodule")("remainingStuff") + "endmodule").setResultsName("module")

Это работает, и я в порядке с этим решением, как могу проверьте наличие объекта, однако я вижу, что результаты stuff - это список всего, что находится за пределами moduleHdr и «endmodule». Я хочу, чтобы текст не входил в moduleInstantiation, но я не знал, есть ли способ обработать классификатор SkipTo +, чтобы такого поведения не было. В идеале я мог бы ссылаться на module.moduleInstantiation аналогично тому, как я могу сделать с moduleHdr. Или возможно SkipTo просто не правильный путь к go о том, что я пытаюсь сделать.

Вот вывод того, что я вижу (не -stuff [0] | [1 ] предметов):

[[[['module', 'mymod', '(', ['input', 'wire', 'en'], ['input', 'wire', 'in'], ['output', 'wire', 'out'], ')', ';'], ['\n\n\nwire somewire;\nreg somereg;', ['someothermod', [['u_someothermod'], ['(', ['.', 'myport', '(', 'myconn', ')'], ')']], ';']], "assign somewire = 1'b0;\n\n", 'endmodule']]]
[0]:
  [[['module', 'mymod', '(', ['input', 'wire', 'en'], ['input', 'wire', 'in'], ['output', 'wire', 'out'], ')', ';'], ['\n\n\nwire somewire;\nreg somereg;', ['someothermod', [['u_someothermod'], ['(', ['.', 'myport', '(', 'myconn', ')'], ')']], ';']], "assign somewire = 1'b0;\n\n", 'endmodule']]
  - module: [['module', 'mymod', '(', ['input', 'wire', 'en'], ['input', 'wire', 'in'], ['output', 'wire', 'out'], ')', ';'], ['\n\n\nwire somewire;\nreg somereg;', ['someothermod', [['u_someothermod'], ['(', ['.', 'myport', '(', 'myconn', ')'], ')']], ';']], "assign somewire = 1'b0;\n\n", 'endmodule']
    - moduleHdr: ['module', 'mymod', '(', ['input', 'wire', 'en'], ['input', 'wire', 'in'], ['output', 'wire', 'out'], ')', ';']
      - moduleName: ['mymod']
      - portDecl: ['output', 'wire', 'out']
        - netType: 'wire'
        - portDir: 'output'
        - portname: ['out']
      - ports: [['input', 'wire', 'en'], ['input', 'wire', 'in'], ['output', 'wire', 'out']]
        [0]:
          ['input', 'wire', 'en']
          - netType: 'wire'
          - portDir: 'input'
          - portname: ['en']
        [1]:
          ['input', 'wire', 'in']
          - netType: 'wire'
          - portDir: 'input'
          - portname: ['in']
        [2]:
          ['output', 'wire', 'out']
          - netType: 'wire'
          - portDir: 'output'
          - portname: ['out']
    - remainingStuff: "assign somewire = 1'b0;\n\n"
    - stuff: ['\n\n\nwire somewire;\nreg somereg;', ['someothermod', [['u_someothermod'], ['(', ['.', 'myport', '(', 'myconn', ')'], ')']], ';']]
      [0]:



wire somewire;
reg somereg;
      [1]:
        ['someothermod', [['u_someothermod'], ['(', ['.', 'myport', '(', 'myconn', ')'], ')']], ';']
        - baseModule: ['someothermod']
        - moduleInstance: [['u_someothermod'], ['(', ['.', 'myport', '(', 'myconn', ')'], ')']]
          - moduleInstNameRange: ['u_someothermod']
            - moduleInstanceName: ['u_someothermod']
          - moduleInstPorts: ['(', ['.', 'myport', '(', 'myconn', ')'], ')']
            - namedPortConnection: ['.', 'myport', '(', 'myconn', ')']
              - instancePortConnName: 'myconn'
              - instancePortName: ['myport']
            - ports: [[['.', 'myport', '(', 'myconn', ')']]]
              [0]:
                [['.', 'myport', '(', 'myconn', ')']]
                [0]:
                  ['.', 'myport', '(', 'myconn', ')']
                  - instancePortConnName: 'myconn'
                  - instancePortName: ['myport']

Спасибо!

...