Parse::RecDescent and GrammarHow can I parse quoted CSV in Perl with a regex?Interpolating variables in a Parse::RecDescent regexIs Perl's Parse::RecDescent thread safe?Parse::RecDescent performance issueForcing gaps between words in a Marpa grammarHow do I make Marpa's sequence rules greedy?Parsing HTML-attributes like stringsCollecting data with Parse::RecDescentWhitespace-important parsing with Parse::RecDescent (eg. HAML, Python)Disable critic for an entire file - Parse::RecDescent precompiled parser & PerlCritic/Tidyall

A wiild aanimal, a cardinal direction, or a place by the water

What is a summary of basic Jewish metaphysics or theology?

Declaring a visitor to the UK as my "girlfriend" - effect on getting a Visitor visa?

Export economy of Mars

What is Albrecht Dürer's Perspective Machine drawing style?

Does proof-of-work contribute directly to prevent double-spending?

Unlocked Package Dependencies

Why do my fried eggs start browning very fast?

Lower bound for the number of lattice points on high dimensional spheres

Is law enforcement responsible for damages made by a search warrant?

Went to a big 4 but got fired for underperformance in a year recently - Now every one thinks I'm pro - How to balance expectations?

In a KP-K endgame, if the enemy king is in front of the pawn, is it always a draw?

Does a bard know when a character uses their Bardic Inspiration?

What does "autolyco-sentimental" mean?

How can I perform a deterministic physics simulation?

Speaker impedance: rewiring four 8 Ω speakers for use with 8 Ω amp output

Subverting the essence of fictional and/or religious entities; is it acceptable?

Why does the friction act on the inward direction when a car makes a turn on a level road?

Difference between "jail" and "prison" in German

Why adjustbox needs a tweak of raise=-0.3ex with enumitem?

Is it moral to remove/hide certain parts of a photo, as a photographer?

What is it exactly about flying a Flyboard across the English channel that made Zapata's thighs burn?

Why is the Vasa Museum in Stockholm so Popular?

Reasons for using monsters as bioweapons



Parse::RecDescent and Grammar


How can I parse quoted CSV in Perl with a regex?Interpolating variables in a Parse::RecDescent regexIs Perl's Parse::RecDescent thread safe?Parse::RecDescent performance issueForcing gaps between words in a Marpa grammarHow do I make Marpa's sequence rules greedy?Parsing HTML-attributes like stringsCollecting data with Parse::RecDescentWhitespace-important parsing with Parse::RecDescent (eg. HAML, Python)Disable critic for an entire file - Parse::RecDescent precompiled parser & PerlCritic/Tidyall






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








1















I defined the following grammar using Parse::RecDescent



my $grammar = q

top : operand equal value print $itemvalue

operand: /w+/

equal : /=/

value : my $value = extract_quotelike($text) ;$return =$value;

;


which i wants it to handle the following cases :



X = 2 -> should print 2



X = "2" -> should print 2



x = '2' -> should print 2



but the above grammar provide different results :



for x=2 it fail to parse it



for x="2" -> it print "2"



for x ='2' -> it pring '2'



any idea to change the above grammar to print 2 on all the the 3 above cases , i.e removing the quotes










share|improve this question
































    1















    I defined the following grammar using Parse::RecDescent



    my $grammar = q

    top : operand equal value print $itemvalue

    operand: /w+/

    equal : /=/

    value : my $value = extract_quotelike($text) ;$return =$value;

    ;


    which i wants it to handle the following cases :



    X = 2 -> should print 2



    X = "2" -> should print 2



    x = '2' -> should print 2



    but the above grammar provide different results :



    for x=2 it fail to parse it



    for x="2" -> it print "2"



    for x ='2' -> it pring '2'



    any idea to change the above grammar to print 2 on all the the 3 above cases , i.e removing the quotes










    share|improve this question




























      1












      1








      1


      0






      I defined the following grammar using Parse::RecDescent



      my $grammar = q

      top : operand equal value print $itemvalue

      operand: /w+/

      equal : /=/

      value : my $value = extract_quotelike($text) ;$return =$value;

      ;


      which i wants it to handle the following cases :



      X = 2 -> should print 2



      X = "2" -> should print 2



      x = '2' -> should print 2



      but the above grammar provide different results :



      for x=2 it fail to parse it



      for x="2" -> it print "2"



      for x ='2' -> it pring '2'



      any idea to change the above grammar to print 2 on all the the 3 above cases , i.e removing the quotes










      share|improve this question
















      I defined the following grammar using Parse::RecDescent



      my $grammar = q

      top : operand equal value print $itemvalue

      operand: /w+/

      equal : /=/

      value : my $value = extract_quotelike($text) ;$return =$value;

      ;


      which i wants it to handle the following cases :



      X = 2 -> should print 2



      X = "2" -> should print 2



      x = '2' -> should print 2



      but the above grammar provide different results :



      for x=2 it fail to parse it



      for x="2" -> it print "2"



      for x ='2' -> it pring '2'



      any idea to change the above grammar to print 2 on all the the 3 above cases , i.e removing the quotes







      perl parse-recdescent






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 27 at 2:48









      ysth

      80k5 gold badges100 silver badges195 bronze badges




      80k5 gold badges100 silver badges195 bronze badges










      asked Mar 27 at 1:05









      jsorjsor

      3071 silver badge9 bronze badges




      3071 silver badge9 bronze badges

























          1 Answer
          1






          active

          oldest

          votes


















          2














          build_parser.pl:



          use strict;
          use warnings;

          use Parse::RecDescent qw( );

          Parse::RecDescent->Precompile(<<'__EOS__', "Parser");

          # The code in rules is also covered by these pragmas.
          use strict;
          use warnings;

          sub dequote substr($_[0], 1, -1) =~ s/\(.)/$1/srg


          start : assign /Z/ $item[1]

          assign : lvalue '=' expr [ 'assign', $item[1], $item[3] ]

          lvalue : IDENT

          expr : NUM_LIT [ 'num_const', $item[1] ]
          | STR_LIT [ 'str_const', $item[1] ]

          # TOKENS
          # ----------------------------------------

          IDENT : w+

          NUM_LIT : /[0-9]+/

          STR_LIT : /'(?:[^'\]++|\.)*+'/s dequote($item[1])
          | /"(?:[^"\]++|\.)*+"/s dequote($item[1])

          __EOS__


          Adjust the definition of string literals to your needs (but remember to adjust both the rule and dequote).



          Running build_parser.pl will generate Parser.pm, which can be used as follows:



          use strict;
          use warnings;

          use FindBin qw( $RealBin );
          use lib $RealBin;

          use Data::Dumper qw( Dumper );
          use Parser qw( );

          my $parser = Parser->new();
          print(Dumper( $parser->start('x = 2') ));





          share|improve this answer


























            Your Answer






            StackExchange.ifUsing("editor", function ()
            StackExchange.using("externalEditor", function ()
            StackExchange.using("snippets", function ()
            StackExchange.snippets.init();
            );
            );
            , "code-snippets");

            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "1"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader:
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            ,
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













            draft saved

            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55368327%2fparserecdescent-and-grammar%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            2














            build_parser.pl:



            use strict;
            use warnings;

            use Parse::RecDescent qw( );

            Parse::RecDescent->Precompile(<<'__EOS__', "Parser");

            # The code in rules is also covered by these pragmas.
            use strict;
            use warnings;

            sub dequote substr($_[0], 1, -1) =~ s/\(.)/$1/srg


            start : assign /Z/ $item[1]

            assign : lvalue '=' expr [ 'assign', $item[1], $item[3] ]

            lvalue : IDENT

            expr : NUM_LIT [ 'num_const', $item[1] ]
            | STR_LIT [ 'str_const', $item[1] ]

            # TOKENS
            # ----------------------------------------

            IDENT : w+

            NUM_LIT : /[0-9]+/

            STR_LIT : /'(?:[^'\]++|\.)*+'/s dequote($item[1])
            | /"(?:[^"\]++|\.)*+"/s dequote($item[1])

            __EOS__


            Adjust the definition of string literals to your needs (but remember to adjust both the rule and dequote).



            Running build_parser.pl will generate Parser.pm, which can be used as follows:



            use strict;
            use warnings;

            use FindBin qw( $RealBin );
            use lib $RealBin;

            use Data::Dumper qw( Dumper );
            use Parser qw( );

            my $parser = Parser->new();
            print(Dumper( $parser->start('x = 2') ));





            share|improve this answer































              2














              build_parser.pl:



              use strict;
              use warnings;

              use Parse::RecDescent qw( );

              Parse::RecDescent->Precompile(<<'__EOS__', "Parser");

              # The code in rules is also covered by these pragmas.
              use strict;
              use warnings;

              sub dequote substr($_[0], 1, -1) =~ s/\(.)/$1/srg


              start : assign /Z/ $item[1]

              assign : lvalue '=' expr [ 'assign', $item[1], $item[3] ]

              lvalue : IDENT

              expr : NUM_LIT [ 'num_const', $item[1] ]
              | STR_LIT [ 'str_const', $item[1] ]

              # TOKENS
              # ----------------------------------------

              IDENT : w+

              NUM_LIT : /[0-9]+/

              STR_LIT : /'(?:[^'\]++|\.)*+'/s dequote($item[1])
              | /"(?:[^"\]++|\.)*+"/s dequote($item[1])

              __EOS__


              Adjust the definition of string literals to your needs (but remember to adjust both the rule and dequote).



              Running build_parser.pl will generate Parser.pm, which can be used as follows:



              use strict;
              use warnings;

              use FindBin qw( $RealBin );
              use lib $RealBin;

              use Data::Dumper qw( Dumper );
              use Parser qw( );

              my $parser = Parser->new();
              print(Dumper( $parser->start('x = 2') ));





              share|improve this answer





























                2












                2








                2







                build_parser.pl:



                use strict;
                use warnings;

                use Parse::RecDescent qw( );

                Parse::RecDescent->Precompile(<<'__EOS__', "Parser");

                # The code in rules is also covered by these pragmas.
                use strict;
                use warnings;

                sub dequote substr($_[0], 1, -1) =~ s/\(.)/$1/srg


                start : assign /Z/ $item[1]

                assign : lvalue '=' expr [ 'assign', $item[1], $item[3] ]

                lvalue : IDENT

                expr : NUM_LIT [ 'num_const', $item[1] ]
                | STR_LIT [ 'str_const', $item[1] ]

                # TOKENS
                # ----------------------------------------

                IDENT : w+

                NUM_LIT : /[0-9]+/

                STR_LIT : /'(?:[^'\]++|\.)*+'/s dequote($item[1])
                | /"(?:[^"\]++|\.)*+"/s dequote($item[1])

                __EOS__


                Adjust the definition of string literals to your needs (but remember to adjust both the rule and dequote).



                Running build_parser.pl will generate Parser.pm, which can be used as follows:



                use strict;
                use warnings;

                use FindBin qw( $RealBin );
                use lib $RealBin;

                use Data::Dumper qw( Dumper );
                use Parser qw( );

                my $parser = Parser->new();
                print(Dumper( $parser->start('x = 2') ));





                share|improve this answer















                build_parser.pl:



                use strict;
                use warnings;

                use Parse::RecDescent qw( );

                Parse::RecDescent->Precompile(<<'__EOS__', "Parser");

                # The code in rules is also covered by these pragmas.
                use strict;
                use warnings;

                sub dequote substr($_[0], 1, -1) =~ s/\(.)/$1/srg


                start : assign /Z/ $item[1]

                assign : lvalue '=' expr [ 'assign', $item[1], $item[3] ]

                lvalue : IDENT

                expr : NUM_LIT [ 'num_const', $item[1] ]
                | STR_LIT [ 'str_const', $item[1] ]

                # TOKENS
                # ----------------------------------------

                IDENT : w+

                NUM_LIT : /[0-9]+/

                STR_LIT : /'(?:[^'\]++|\.)*+'/s dequote($item[1])
                | /"(?:[^"\]++|\.)*+"/s dequote($item[1])

                __EOS__


                Adjust the definition of string literals to your needs (but remember to adjust both the rule and dequote).



                Running build_parser.pl will generate Parser.pm, which can be used as follows:



                use strict;
                use warnings;

                use FindBin qw( $RealBin );
                use lib $RealBin;

                use Data::Dumper qw( Dumper );
                use Parser qw( );

                my $parser = Parser->new();
                print(Dumper( $parser->start('x = 2') ));






                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Mar 27 at 5:22

























                answered Mar 27 at 1:37









                ikegamiikegami

                276k11 gold badges195 silver badges419 bronze badges




                276k11 gold badges195 silver badges419 bronze badges





















                    Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.







                    Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.



















                    draft saved

                    draft discarded
















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid


                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.

                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55368327%2fparserecdescent-and-grammar%23new-answer', 'question_page');

                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

                    Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

                    Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript