Questions tagged [regexp-grammars]

Regexp::Grammars is module to add grammatical parsing features to Perl regexes.

Regexp::Grammars is module to add grammatical parsing features to Perl regexes.

It adds a small number of new regex constructs that can be used within Perl patterns to implement complete recursive-descent parsing.

25 questions
12
votes
1 answer

What does a character class with only a lone caret do?

In trying to answer the question Writing text into new line when a particular character is found, I have employed Regexp::Grammars. It has long interested me and finally I had reason to learn. I noticed that the description section the author has a…
Joel Berger
  • 20,180
  • 5
  • 49
  • 104
9
votes
1 answer

How can I use the perl6 regex metasyntax, ?

In perl6 grammars, as explained here (note, the design documents are not guaranteed to be up-to-date as the implementation is finished), if an opening angle bracket is followed by an identifier then the construct is a call to a subrule, method or…
Marty
  • 2,788
  • 11
  • 17
5
votes
3 answers

Case-insensitive hash-keys in Regexp::Grammars

In the perl module Regexp::Grammars, consider the following token: <%commands> This token is part of a complex grammar, parsing a wide variety of different sentences. This token matches any word in the hash %commands, which…
psgels
  • 737
  • 1
  • 6
  • 19
5
votes
5 answers

Perl: Regex to get all text between repeating patterns

I would like to create a regex for the following. I have some text like the following: field = "test string"; type = INT; funcCall(.., field, ...); ... text = "desc"; field = "test string 1"; type = FLOAT; funcCall(.., field, ...); ... text =…
Coco
  • 51
  • 3
5
votes
1 answer

Best way to reduce perl startup time

I have been working on a Perl parser on and off for a few years, though since it has always been in pre-alpha, I have never worried about speeding it up. However, I have started working on ways to optimize it, and was surprised at what I…
4
votes
2 answers

Perl6: Convert Match object to JSON-serializable Hash

I am currently gettin' my hands dirty on some Perl6. Specifically I am trying to write a Fortran parser based on grammars (the Fortran::Grammar module) For testing purposes, I would like to have the possiblity to convert a Match object into a…
NobodyInPerson
  • 115
  • 1
  • 11
4
votes
2 answers

Is there anything like perl's Regexp::Grammars or labeled subpatterns in .NET?

I really like perl's Regexp::Grammars module. Is there anything like this for .NET? I'd really like to use a recursive descent parser in a regex style way (eg searching for a matching pattern through a large document) in C#, and be able to express…
Matthew Lock
  • 13,144
  • 12
  • 92
  • 130
3
votes
1 answer

Should I use Parse::RecDescent or Regexp::Grammars to extract tables from documents?

I have lots of large plain text documents I wish to parse with perl. Each document has mostly English paragraphs in it, with a couple of plain text marked up tables in each document. I have created a grammar to describe the table structure, but am…
Matthew Lock
  • 13,144
  • 12
  • 92
  • 130
3
votes
1 answer

Perl: Regexp::Grammars

I tried Regexp::Grammars and I got 2 problems. Maybe someone can help me out. use strict; use warnings; use Regexp::Grammars; my $gr = qr { ^ $ …
ch ch
  • 51
  • 3
3
votes
1 answer

Parsing tags from a file with Regexp::Grammars

I'm trying to capture free tags from comments in a program using Perl and the Regexp::Grammars CPAN module. use strict; use v5.10; use YAML; my $s = q{ junk code; // here be tags #:tag1: junk code 2; // another one…
ojosilva
  • 1,984
  • 2
  • 15
  • 21
3
votes
1 answer

Using a "normal" regex after loading Regexp::Grammars

I'm trying to use Regexp::Grammars in an application, but it breaks a lot of other regular expressions. For example, the following code: $hello = 'hello'; print 'hello 1' if $hello =~ /hello/; #prints "hello 1" use Regexp::Grammars; print 'hello 2'…
Nate Glenn
  • 6,455
  • 8
  • 52
  • 95
3
votes
1 answer

How do I match a multiline pattern using Regexp::Grammars?

I'm new to Regexp::Grammars, and am having trouble matching a multi-line pattern. I have this input: my $text = <
Jeff French
  • 1,151
  • 1
  • 12
  • 19
2
votes
3 answers

Parse single quoted string using Marpa:r2 perl

How to parse single quoted string using Marpa:r2? In my below code, the single quoted strings appends '\' on parsing. Code: use strict; use Marpa::R2; use Data::Dumper; my $grammar = Marpa::R2::Scanless::G->new( { default_action =>…
zubug55
  • 729
  • 7
  • 27
2
votes
1 answer

Regexp::Grammars handling \n

I'm running the example from slide 15: qr{ <[text]>+ .+ }xm; When running against a multi-line text: line_1 line_2 I get: 'text' => [ 'line-1', ' line-2' ] and so far I've not…
Stefan_E
  • 117
  • 9
2
votes
0 answers

How to replace matches using Regexp::Grammars?

I am using Regexp::Grammars to search and extract information from a complex textual source, but ultimately I want to also make replacements on that source. Is there a way to accomplish this either directly or indirectly using Regexp::Grammars? For…
Coder Guy
  • 1,843
  • 1
  • 15
  • 21
1
2