Click here to Skip to main content
15,886,873 members

Welcome to the Lounge

   

For discussing anything related to a software developer's life but is not for programming questions. Got a programming question?

The Lounge is rated Safe For Work. If you're about to post something inappropriate for a shared office environment, then don't post it. No ads, no abuse, and no programming questions. Trolling, (political, climate, religious or whatever) will result in your account being removed.

 
GeneralRe: Never do this. Pin
OriginalGriff2-Feb-24 2:01
mveOriginalGriff2-Feb-24 2:01 
GeneralRe: Never do this. Pin
trønderen2-Feb-24 2:58
trønderen2-Feb-24 2:58 
GeneralRe: Never do this. Pin
jmaida2-Feb-24 15:56
jmaida2-Feb-24 15:56 
GeneralRe: Never do this. Pin
PIEBALDconsult2-Feb-24 4:23
mvePIEBALDconsult2-Feb-24 4:23 
GeneralRe: Never do this. Pin
CPallini2-Feb-24 5:18
mveCPallini2-Feb-24 5:18 
GeneralRe: Never do this. Pin
PIEBALDconsult2-Feb-24 5:25
mvePIEBALDconsult2-Feb-24 5:25 
GeneralRe: Never do this. Pin
Joan M2-Feb-24 5:01
professionalJoan M2-Feb-24 5:01 
General"Every corpse on Mount Everest was once a highly motivated person" Pin
honey the codewitch1-Feb-24 14:46
mvahoney the codewitch1-Feb-24 14:46 
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):

C#
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:

C#
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:

Terminal
[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)]
[SymbolId: 2, Value: " ", Position: 31 (1, 32)]
[SymbolId: 3, Value: "over", Position: 32 (1, 33)]
[SymbolId: 2, Value: " ", Position: 36 (1, 37)]
[SymbolId: 4, Value: "1.5", Position: 37 (1, 38)]
[SymbolId: 2, Value: " ", Position: 40 (1, 41)]
[SymbolId: 3, Value: "lazy", Position: 41 (1, 42)]
[SymbolId: 2, Value: " ", Position: 45 (1, 46)]
[SymbolId: 3, Value: "dogs", Position: 46 (1, 47)]

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

GeneralRe: "Every corpse on Mount Everest was once a highly motivated person" Pin
Richard Deeming1-Feb-24 21:56
mveRichard Deeming1-Feb-24 21:56 
GeneralRe: "Every corpse on Mount Everest was once a highly motivated person" Pin
honey the codewitch1-Feb-24 22:34
mvahoney the codewitch1-Feb-24 22:34 
GeneralRe: "Every corpse on Mount Everest was once a highly motivated person" Pin
Amarnath S1-Feb-24 22:58
professionalAmarnath S1-Feb-24 22:58 
GeneralRe: "Every corpse on Mount Everest was once a highly motivated person" Pin
honey the codewitch1-Feb-24 23:13
mvahoney the codewitch1-Feb-24 23:13 
GeneralRe: "Every corpse on Mount Everest was once a highly motivated person" Pin
Daniel Pfeffer2-Feb-24 2:15
professionalDaniel Pfeffer2-Feb-24 2:15 
GeneralRe: "Every corpse on Mount Everest was once a highly motivated person" Pin
MarkTJohnson2-Feb-24 3:04
professionalMarkTJohnson2-Feb-24 3:04 
GeneralRe: "Every corpse on Mount Everest was once a highly motivated person" Pin
dandy722-Feb-24 3:24
dandy722-Feb-24 3:24 
GeneralRe: "Every corpse on Mount Everest was once a highly motivated person" Pin
honey the codewitch2-Feb-24 3:46
mvahoney the codewitch2-Feb-24 3:46 
GeneralRe: "Every corpse on Mount Everest was once a highly motivated person" Pin
Richard Andrew x642-Feb-24 12:41
professionalRichard Andrew x642-Feb-24 12:41 
GeneralRe: "Every corpse on Mount Everest was once a highly motivated person" Pin
honey the codewitch2-Feb-24 15:08
mvahoney the codewitch2-Feb-24 15:08 
GeneralWordle 958 Pin
StarNamer@work1-Feb-24 14:22
professionalStarNamer@work1-Feb-24 14:22 
GeneralRe: Wordle 958 Pin
Amarnath S1-Feb-24 15:10
professionalAmarnath S1-Feb-24 15:10 
GeneralRe: Wordle 958 Pin
Sandeep Mewara1-Feb-24 16:13
mveSandeep Mewara1-Feb-24 16:13 
GeneralRe: Wordle 958 Pin
Shane01031-Feb-24 17:31
Shane01031-Feb-24 17:31 
GeneralRe: Wordle 958 Pin
GKP19921-Feb-24 18:58
professionalGKP19921-Feb-24 18:58 
GeneralRe: Wordle 958 Pin
OriginalGriff1-Feb-24 19:34
mveOriginalGriff1-Feb-24 19:34 
GeneralRe: Wordle 958 Pin
ChandraRam1-Feb-24 19:46
ChandraRam1-Feb-24 19:46 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.