Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. The Lounge
  3. "Every corpse on Mount Everest was once a highly motivated person"

"Every corpse on Mount Everest was once a highly motivated person"

Scheduled Pinned Locked Moved The Lounge
csharpvisual-studioregexhelpquestion
11 Posts 7 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • honey the codewitchH honey the codewitch

    I keep thinking of that as I work on my source generator for my Visual FA project. It's a lot of work and I have a long way to go before I can write an article or anything. Writing source generators for C# is difficult, especially in Visual Studio where your updated generation code doesn't always "take" until you exit and relaunch Visual Studio. I had to find that out the hard way, after hours of struggle. I've also got to learn to make NuGet packages, and probably something more than just a simple DLL or something. Here's what I have so far, and I'm quite happy with it. So far you can declare a regex matcher (one FARule) or lexer (multiple FARules, possibly with symbol names and ids):

    using VisualFA;
    partial class TestSource
    {
    // Declare a lexer. Here we specify the rules and the type of lexer
    // as indicated by FARule attributes and the return type
    // shared dependency code is automatically generated as needed.
    // It won't be generated if your code references VisualFA.
    [FARule(@"\/\*",Symbol="commentBlock",BlockEnd=@"\*\/")]
    [FARule(@"\/\/[^\n]*", Symbol = "lineComment")]
    [FARule(@"[ \t\r\n]+", Symbol = "whiteSpace")]
    [FARule(@"[A-Za-z_][A-Za-z0-9_]*",Symbol="identifier")]
    [FARule(@"(0|([1-9][0-9]*))((\.[0-9]+[Ee]\-?[1-9][0-9]*)?|\.[0-9]+)",Symbol="number")]
    [FARule(@"\+",Symbol = "plus")]
    [FARule(@"\-", Symbol = "minus")]
    [FARule(@"\*", Symbol = "multiply")]
    [FARule(@"\/", Symbol = "divide")]
    [FARule(@"%", Symbol = "modulo")]
    internal static partial FATextReaderRunner Calc(TextReader text);
    }

    That causes the C# compiler, with the help of my source generator to generate all the code necessary such that you can do this with it:

    var exp = "the 10 quick brown foxes jumped over 1.5 lazy dogs";
    foreach (var match in TestSource.Calc(new StringReader(exp)))
    {
    Console.WriteLine(match);
    }

    Which nets you this:

    [SymbolId: 3, Value: "the", Position: 0 (1, 1)]
    [SymbolId: 2, Value: " ", Position: 3 (1, 4)]
    [SymbolId: 4, Value: "10", Position: 4 (1, 5)]
    [SymbolId: 2, Value: " ", Position: 6 (1, 7)]
    [SymbolId: 3, Value: "quick", Position: 7 (1, 8)]
    [SymbolId: 2, Value: " ", Position: 12 (1, 13)]
    [SymbolId: 3, Value: "brown", Position: 13 (1, 14)]
    [SymbolId: 2, Value: " ", Position: 18 (1, 19)]
    [SymbolId: 3, Value: "foxes", Position: 19 (1, 20)]
    [SymbolId: 2, Value: " ", Position: 24 (1, 25)]
    [SymbolId: 3, Value: "jumped", Position: 25 (1, 26)]

    Richard DeemingR Offline
    Richard DeemingR Offline
    Richard Deeming
    wrote on last edited by
    #2

    honey the codewitch wrote:

    Writing source generators for C# is difficult, especially in Visual Studio where your updated generation code doesn't always "take" until you exit and relaunch Visual Studio. I had to find that out the hard way, after hours of struggle.

    I assume you've read Andrew Lock's 10-part series on writing source generators, particularly Testing an incremental generator with snapshot testing[^]? :)


    "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

    "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

    honey the codewitchH 1 Reply Last reply
    0
    • Richard DeemingR Richard Deeming

      honey the codewitch wrote:

      Writing source generators for C# is difficult, especially in Visual Studio where your updated generation code doesn't always "take" until you exit and relaunch Visual Studio. I had to find that out the hard way, after hours of struggle.

      I assume you've read Andrew Lock's 10-part series on writing source generators, particularly Testing an incremental generator with snapshot testing[^]? :)


      "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

      honey the codewitchH Offline
      honey the codewitchH Offline
      honey the codewitch
      wrote on last edited by
      #3

      Yep, and if he mentioned having to restart visual studio for your source generator code adjustments to take effect sometimes I missed it.

      Check out my IoT graphics library here: https://honeythecodewitch.com/gfx And my IoT UI/User Experience library here: https://honeythecodewitch.com/uix

      1 Reply Last reply
      0
      • honey the codewitchH honey the codewitch

        I keep thinking of that as I work on my source generator for my Visual FA project. It's a lot of work and I have a long way to go before I can write an article or anything. Writing source generators for C# is difficult, especially in Visual Studio where your updated generation code doesn't always "take" until you exit and relaunch Visual Studio. I had to find that out the hard way, after hours of struggle. I've also got to learn to make NuGet packages, and probably something more than just a simple DLL or something. Here's what I have so far, and I'm quite happy with it. So far you can declare a regex matcher (one FARule) or lexer (multiple FARules, possibly with symbol names and ids):

        using VisualFA;
        partial class TestSource
        {
        // Declare a lexer. Here we specify the rules and the type of lexer
        // as indicated by FARule attributes and the return type
        // shared dependency code is automatically generated as needed.
        // It won't be generated if your code references VisualFA.
        [FARule(@"\/\*",Symbol="commentBlock",BlockEnd=@"\*\/")]
        [FARule(@"\/\/[^\n]*", Symbol = "lineComment")]
        [FARule(@"[ \t\r\n]+", Symbol = "whiteSpace")]
        [FARule(@"[A-Za-z_][A-Za-z0-9_]*",Symbol="identifier")]
        [FARule(@"(0|([1-9][0-9]*))((\.[0-9]+[Ee]\-?[1-9][0-9]*)?|\.[0-9]+)",Symbol="number")]
        [FARule(@"\+",Symbol = "plus")]
        [FARule(@"\-", Symbol = "minus")]
        [FARule(@"\*", Symbol = "multiply")]
        [FARule(@"\/", Symbol = "divide")]
        [FARule(@"%", Symbol = "modulo")]
        internal static partial FATextReaderRunner Calc(TextReader text);
        }

        That causes the C# compiler, with the help of my source generator to generate all the code necessary such that you can do this with it:

        var exp = "the 10 quick brown foxes jumped over 1.5 lazy dogs";
        foreach (var match in TestSource.Calc(new StringReader(exp)))
        {
        Console.WriteLine(match);
        }

        Which nets you this:

        [SymbolId: 3, Value: "the", Position: 0 (1, 1)]
        [SymbolId: 2, Value: " ", Position: 3 (1, 4)]
        [SymbolId: 4, Value: "10", Position: 4 (1, 5)]
        [SymbolId: 2, Value: " ", Position: 6 (1, 7)]
        [SymbolId: 3, Value: "quick", Position: 7 (1, 8)]
        [SymbolId: 2, Value: " ", Position: 12 (1, 13)]
        [SymbolId: 3, Value: "brown", Position: 13 (1, 14)]
        [SymbolId: 2, Value: " ", Position: 18 (1, 19)]
        [SymbolId: 3, Value: "foxes", Position: 19 (1, 20)]
        [SymbolId: 2, Value: " ", Position: 24 (1, 25)]
        [SymbolId: 3, Value: "jumped", Position: 25 (1, 26)]

        A Offline
        A Offline
        Amarnath S
        wrote on last edited by
        #4

        honey the codewitch wrote:

        Every corpse on Mount Everest was once a highly motivated person

        Is this also highly likely - Every corpse was once a highly motivated person ... ... with a few dashed dreams.

        honey the codewitchH 1 Reply Last reply
        0
        • A Amarnath S

          honey the codewitch wrote:

          Every corpse on Mount Everest was once a highly motivated person

          Is this also highly likely - Every corpse was once a highly motivated person ... ... with a few dashed dreams.

          honey the codewitchH Offline
          honey the codewitchH Offline
          honey the codewitch
          wrote on last edited by
          #5

          I don't know. I've met some pretty lazy people - I imagine they'd make lazy corpses.

          Check out my IoT graphics library here: https://honeythecodewitch.com/gfx And my IoT UI/User Experience library here: https://honeythecodewitch.com/uix

          D 1 Reply Last reply
          0
          • honey the codewitchH honey the codewitch

            I don't know. I've met some pretty lazy people - I imagine they'd make lazy corpses.

            Check out my IoT graphics library here: https://honeythecodewitch.com/gfx And my IoT UI/User Experience library here: https://honeythecodewitch.com/uix

            D Offline
            D Offline
            Daniel Pfeffer
            wrote on last edited by
            #6

            honey the codewitch wrote:

            I imagine they'd make lazy corpses.

            There's another kind? :~

            Freedom is the freedom to say that two plus two make four. If that is granted, all else follows. -- 6079 Smith W.

            M D honey the codewitchH 3 Replies Last reply
            0
            • D Daniel Pfeffer

              honey the codewitch wrote:

              I imagine they'd make lazy corpses.

              There's another kind? :~

              Freedom is the freedom to say that two plus two make four. If that is granted, all else follows. -- 6079 Smith W.

              M Offline
              M Offline
              MarkTJohnson
              wrote on last edited by
              #7

              Zombies

              I’ve given up trying to be calm. However, I am open to feeling slightly less agitated. I’m begging you for the benefit of everyone, don’t be STUPID.

              1 Reply Last reply
              0
              • D Daniel Pfeffer

                honey the codewitch wrote:

                I imagine they'd make lazy corpses.

                There's another kind? :~

                Freedom is the freedom to say that two plus two make four. If that is granted, all else follows. -- 6079 Smith W.

                D Offline
                D Offline
                dandy72
                wrote on last edited by
                #8

                Yeah, the highly motivated kind. Just be grateful there's so few of them.

                1 Reply Last reply
                0
                • D Daniel Pfeffer

                  honey the codewitch wrote:

                  I imagine they'd make lazy corpses.

                  There's another kind? :~

                  Freedom is the freedom to say that two plus two make four. If that is granted, all else follows. -- 6079 Smith W.

                  honey the codewitchH Offline
                  honey the codewitchH Offline
                  honey the codewitch
                  wrote on last edited by
                  #9

                  Depends on how many George Romero movies you've watched, I suppose.

                  Check out my IoT graphics library here: https://honeythecodewitch.com/gfx And my IoT UI/User Experience library here: https://honeythecodewitch.com/uix

                  1 Reply Last reply
                  0
                  • honey the codewitchH honey the codewitch

                    I keep thinking of that as I work on my source generator for my Visual FA project. It's a lot of work and I have a long way to go before I can write an article or anything. Writing source generators for C# is difficult, especially in Visual Studio where your updated generation code doesn't always "take" until you exit and relaunch Visual Studio. I had to find that out the hard way, after hours of struggle. I've also got to learn to make NuGet packages, and probably something more than just a simple DLL or something. Here's what I have so far, and I'm quite happy with it. So far you can declare a regex matcher (one FARule) or lexer (multiple FARules, possibly with symbol names and ids):

                    using VisualFA;
                    partial class TestSource
                    {
                    // Declare a lexer. Here we specify the rules and the type of lexer
                    // as indicated by FARule attributes and the return type
                    // shared dependency code is automatically generated as needed.
                    // It won't be generated if your code references VisualFA.
                    [FARule(@"\/\*",Symbol="commentBlock",BlockEnd=@"\*\/")]
                    [FARule(@"\/\/[^\n]*", Symbol = "lineComment")]
                    [FARule(@"[ \t\r\n]+", Symbol = "whiteSpace")]
                    [FARule(@"[A-Za-z_][A-Za-z0-9_]*",Symbol="identifier")]
                    [FARule(@"(0|([1-9][0-9]*))((\.[0-9]+[Ee]\-?[1-9][0-9]*)?|\.[0-9]+)",Symbol="number")]
                    [FARule(@"\+",Symbol = "plus")]
                    [FARule(@"\-", Symbol = "minus")]
                    [FARule(@"\*", Symbol = "multiply")]
                    [FARule(@"\/", Symbol = "divide")]
                    [FARule(@"%", Symbol = "modulo")]
                    internal static partial FATextReaderRunner Calc(TextReader text);
                    }

                    That causes the C# compiler, with the help of my source generator to generate all the code necessary such that you can do this with it:

                    var exp = "the 10 quick brown foxes jumped over 1.5 lazy dogs";
                    foreach (var match in TestSource.Calc(new StringReader(exp)))
                    {
                    Console.WriteLine(match);
                    }

                    Which nets you this:

                    [SymbolId: 3, Value: "the", Position: 0 (1, 1)]
                    [SymbolId: 2, Value: " ", Position: 3 (1, 4)]
                    [SymbolId: 4, Value: "10", Position: 4 (1, 5)]
                    [SymbolId: 2, Value: " ", Position: 6 (1, 7)]
                    [SymbolId: 3, Value: "quick", Position: 7 (1, 8)]
                    [SymbolId: 2, Value: " ", Position: 12 (1, 13)]
                    [SymbolId: 3, Value: "brown", Position: 13 (1, 14)]
                    [SymbolId: 2, Value: " ", Position: 18 (1, 19)]
                    [SymbolId: 3, Value: "foxes", Position: 19 (1, 20)]
                    [SymbolId: 2, Value: " ", Position: 24 (1, 25)]
                    [SymbolId: 3, Value: "jumped", Position: 25 (1, 26)]

                    Richard Andrew x64R Offline
                    Richard Andrew x64R Offline
                    Richard Andrew x64
                    wrote on last edited by
                    #10

                    Did you get that subject line from the Demotivators[^] collection?

                    Quote:

                    When we started Despair, we had a dream. To crush other people's dreams. But we knew, given our goal, we'd be in for a fight. After all, the Motivation Industry has been crushing dreams for decades, selling the easy lie of success you can buy. That's why we decided to differentiate ourselves- by crushing dreams with hard truths!

                    The difficult we do right away... ...the impossible takes slightly longer.

                    honey the codewitchH 1 Reply Last reply
                    0
                    • Richard Andrew x64R Richard Andrew x64

                      Did you get that subject line from the Demotivators[^] collection?

                      Quote:

                      When we started Despair, we had a dream. To crush other people's dreams. But we knew, given our goal, we'd be in for a fight. After all, the Motivation Industry has been crushing dreams for decades, selling the easy lie of success you can buy. That's why we decided to differentiate ourselves- by crushing dreams with hard truths!

                      The difficult we do right away... ...the impossible takes slightly longer.

                      honey the codewitchH Offline
                      honey the codewitchH Offline
                      honey the codewitch
                      wrote on last edited by
                      #11

                      LOL, it may have come that way to me indirectly, as I read it on the Internet somewhere.

                      Check out my IoT graphics library here: https://honeythecodewitch.com/gfx And my IoT UI/User Experience library here: https://honeythecodewitch.com/uix

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups