antlr4 - What is the grammar to have parentheses take place of linebreaks? -


For example, I'm trying to write a grammar to parse the DNS zone files. Resource records are usually separated by Newline. However, using a bracket, a record can be broken into several rows. For example:

record1 part1 part2 part3 part4

or

record 1 part 1 (part 2 part3 part4 )

How do I allow brackets to exist in any place within the record.

How about (not well tested).

Grammar:

  grammar DNS; File: (record | NL) + EOF; Record: record name recordpart + (nl | eof); Record Name: Some; RecordParty: '(' RecordPartyoneNewline ')' | something ; RecordPartyoneNew Line: NL | Recordpart; Some: [a-zA-Z0-9 :.] +; // be adjusted! WS: [\ t] + - - Skip; NL: ('\ r'? '\ N') | '\ r'; Comment : ';' ~ [\ R \ n] * - & gt; Skip;   

Test case (from Wikipedia):

  example.com. SOA ns1.example.com in 1800 Mailbox.example.com. (100; chennaiemar 300; refresh time 100; retire time 6000; expiration time 600; negative caching jit) example.com. 1800s NS NS1 Export Ns1.example.com. AAAA 2001: DB8 :: F: A www.example.com, in 1800, a 172.27.182.17 ns1.example.com 1800. In 1800 a 1902.06.1.2 www.example.com. AAAA 2001: DB8 :: 1: 2   

Result (Large Image) in 1800:

 parse tree

Comments

Popular posts from this blog

Verilog Error: output or inout port "Q" must be connected to a structural net expression -

jasper reports - How to center align barcode using jasperreports and barcode4j -

c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -