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

  • SEARCH
  • Home
  • 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 8910209
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T03:37:47+00:00 2026-06-15T03:37:47+00:00

I have the grammar file alexa_scrape.tt : grammar AlexaScrape rule document category_listing* end rule

  • 0

I have the grammar file alexa_scrape.tt:

grammar AlexaScrape
  rule document
    category_listing*
  end
  rule category_listing
    category_line url_line*
  end
  rule category_line
    category "\n"
  end
  rule category
    ("/" [^/]+)+
  end
  rule url_line
    [0-9]+ ". " url "\n"
  end
  rule url
    [^\n]*
  end
end

I have a ruby file which attempts to make use of it:

#!/usr/bin/env ruby -I .
require 'rubygems'
require 'polyglot'
require 'treetop'
require 'alexa_scrape.tt'

parser = AlexaScrapeParser.new
p( parser.parse("") || parser.failure_reason )
p( parser.parse("/x\n") || parser.failure_reason )

But I’m not getting the results I expected:

SyntaxNode offset=0, ""
"Expected one of /, \n at line 2, column 1 (byte 4) after /x\n"

It parses the empty string properly (as the trivial match for document, zero category_listings), but fails to parse "/x\n" (as the document containing a single category_listing that itself has zero url_lines).

What am I doing wrong?

  • 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-15T03:37:48+00:00Added an answer on June 15, 2026 at 3:37 am

    It looks like the regex in category is advancing through the white space needed to match category_line … do this:

      rule category
        ("/" [^/\s]+)+    # or perhaps ("/" [^/\n]+)+
      end
    

    (And, wow, a Treetop question. This is number 47 in the history of SO and its 4 million total questions. One in 87,000 SO questions are tagged Treetop).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to have a grammar rule like below in my yacc file: insert_statement:
I have lexer/parser (Generated from an ANTLR grammar file) which (for performance reasons) I
I have a file, each line of which can be described by this grammar:
I have an ANTLR grammar file as part of a C# project file and
friends. I have a 'make'-like style file needed to be parsed. The grammar is
I have the following grammar: grammar bxk; options { language=CSharp3; } // start rule
I have a text file which I'm trying to parse. The file looks like
I have the following context free grammar in a text file 'grammar.txt' S ::=
I have to define the grammar of a file like the one shown below.
I have a file with the following grammar: <whitespace_sequence><string><whitespace_sequence><--More--><whitespace_sequence><string_sequence><newline> Using Python (2.4), I would

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.