Help: Problem with simple parsing and Parse::RecDescent 
Author Message
 Help: Problem with simple parsing and Parse::RecDescent

Can anyone help me with this. I think it is rather trivial, but I am
stuck. This is my first attempt of using Parse:RecDescent and I have
not done any major parsing jobb earlier either.

The file parses ok except one thing:

The following line parses ok:
      Directory:    "all-6"                      

But not the this line:
      Directory:    "all-6"                       Key: "test"

The parser is expecting type when it sees the 'Key:' string.

This is the rule that parses the line:
element:
  type nameAndVersion
  | type nameAndVersion label string
  | <error>

Why does it want a type rule?

I have included the grammar, the output and the input file below.

Thanks!

Henrik

# GRAMMAR
my $grammar = q {
 number: /[0-9]+/

 text: /\".*\"/

 eol: /\n*/

 string: /\"[A-Za-z].*\"/

 comment: /^\..*\n/

 startrule: header pathWithContents(s) checksums  | <error>

 header:
   'Company:' text eol
   'Document_title:' text eol
   'Document_number:' text eol    
   'Document_version:' text eol    
   'Document_status:' text eol    
   'Prepared_by:' text eol    
   'Date:' text eol    
   'Time:' text eol    
   'Specification_document_number:' text eol    
   'Specification_document_version:' text eol    
   'Product_name:' text eol    
   'Product_number:' text eol    
   'Product_version:' text eol    

 pathWithContents:  path '{' element(s) '}'
   | <error>

 path: 'Path:' text eol
   | <error>

element:
  type nameAndVersion
  {

  }
  | type nameAndVersion label string
  {

  }
  | <error>

type: 'Component:' | 'Resource:' | 'Replacement:' | 'Semiproduct:' |
'File:' | 'Directory:' | 'Subproduct:' | 'Subcomponent:'

nameAndVersion: /\".*-[A-Za-z0-9]*\"/

label: 'Key:' | 'Identity:' | 'Description:' | 'Platform:'

checksums: 'Checksum_A:' number(s) eol
           'Checksum_B:' number(s) eol

Quote:
};

# OUTPUT START
element File: "ConfigInfo.CI-8"
element Directory: "delivery-1"
element Directory: "distribution-5"
element Directory: "function-5"
element Directory: "implementation-5"
element Directory: "information-6"
element Directory: "interface-1"
element Directory: "miscellaneous-6"
element Directory: "process-1"
element Directory: "reference-10"
element Directory: "revision-7"
element Directory: "safety-4"
element Directory: "common-1"
element Directory: "safetyCertification-1"
element Directory: "all-6"

      ERROR (line 45): Invalid element: Was expecting type

      ERROR (line 45): Invalid pathWithContents: Was expecting '}' but
found
                       "Key: "test"" instead

      ERROR (line 43): Invalid startrule: Was expecting checksums but
found
                       "Path: "~/distribution/common"" instead
Bad text
# OUTPUT END

Here is the input file:

# FILE START
    Company:                                    "Adtranz Signal"
    Document_title:                             "Configuration
information"
    Document_number:                            "3NSS004227D0048"
    Document_version:                           "8"
    Document_status:                            "released"
    Prepared_by:                                "ebiconfig"
    Date:                                       "2001-09-28"
    Time:                                       "16:24:24"
    Specification_document_number:              "3NSS004091D0104"
    Specification_document_version:             "1.X"

    Product_name:                               "CBI950"
    Product_number:                             "3NSS004227-01"
    Product_version:                            "1.1"

    Path:  "~"
    {
      File:         "ConfigInfo.CI-8"          
      Directory:    "delivery-1"              
      Directory:    "distribution-5"            
      Directory:    "function-5"                
      Directory:    "implementation-5"          
      Directory:    "information-6"            
      Directory:    "interface-1"              
      Directory:    "miscellaneous-6"          
      Directory:    "process-1"                
      Directory:    "reference-10"              
      Directory:    "revision-7"                
      Directory:    "safety-4"                  
    }

    Path:  "~/distribution"
    {
      Directory:    "common-1"                  
      Directory:    "safetyCertification-1"    
    }

    Path:  "~/distribution/common"
    {
      Directory:    "all-6"                       Key: "test"
    }

Checksum_A: 58031     52599     47508     9295      
Checksum_B: 21051     58367     53330     65202    
# FILE END



Tue, 27 Jul 2004 15:52:35 GMT  
 
 [ 1 post ] 

 Relevant Pages 

1. HELP needed on a simple Parse::RecDescent program (problem: some rules are matched twice)

2. HELP needed on a simple Parse::RecDescent program (problem: some rules are matched twice)

3. Text Parsing - Parse::RecDescent or another method?

4. Parsing with Parse::RecDescent

5. Parse::RecDescent and parsing comments

6. Parsing with Parse::RecDescent

7. Parse::RecDescent stops parsing.

8. Parse::RecDescent: need help with actions and return values

9. Need help w/ Parse::RecDescent

10. Help with Parse:RecDescent

11. Help with Parse:RecDescent

12. Problem mit Parse::RecDescent

 

 
Powered by phpBB® Forum Software