GithubHelp home page GithubHelp logo

netduino / netmf Goto Github PK

View Code? Open in Web Editor NEW
28.0 14.0 16.0 47.73 MB

.NET Micro Framework for Netduino

License: Other

C++ 38.68% Objective-C 0.23% C 19.75% Assembly 0.99% C# 33.37% Shell 0.33% Makefile 1.73% Perl 4.36% eC 0.01% Emacs Lisp 0.01% Scheme 0.01% Perl 6 0.05% Prolog 0.05% Visual Basic 0.12% XSLT 0.04% Smalltalk 0.29%

netmf's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

netmf's Issues

Feature request: Named Captures in Regular Expressions

Please support named captures in regular expressions.

This expression:

const string CommandRegex = @"<(?<Address>(\w\d)),(?<Transaction>\d+),(?<Verb>[A-Za-z]\w+)(=((?<NumericPayload>\d+)|(?<TextPayload>.+)))?>";
const RegexOptions options = RegexOptions.Compiled | RegexOptions.CultureInvariant | RegexOptions.ExplicitCapture | RegexOptions.Singleline;
static readonly Regex Parser = new Regex(CommandRegex, options);

Should produce named captures named "Address", "Transaction", "Verb", "NumericPayload" and "TextPayload" with the last two being optional and mutually exclusive. This expression compiles correctly and works in "desktop" applications, but in .NET Micro Framework it throws

An unhandled exception of type 'System.Text.RegularExpressions.RegexpSyntaxException' occurred in System.Text.RegularExpressions.dll
Additional information: Syntax error: Missing operand to closure

This is a lamentable omission because Named Captures are one of the features that make regular expressions more bearable and lead to much cleaner code. Named captures also have great tooling support in products such as ReSharper.

The following test code should be able to match the example inputs shown in the comment block and retrieve the named captures (again this works correctly on "desktop" apps and even compiles in .netMF):

        /*
         * Commands are understood in one of three basic formats:
         * <F1,234,Nickname=Fred>   -- non-numeric payload
         * <F5,999,MoveTo=1000>     -- numeric payload
         * <F3,0,Center>            -- verb only (no payload)
         * If the RegEx match was successful, then we must have one of these three possibilities.
         * The address, transaction ID and command verb must always be present so we get those first.
         */
        var deviceAddress = matches.Groups["Address"].Value;
        var transaction = int.Parse(matches.Groups["Transaction"].Value);
        var verb = matches.Groups["Verb"].Value;

        // Now we must decide which of the three basic forms we are dealing with.
        // For the verb-only case, we simply set some defaults before checking for a payload.
        var position = Command.NoPosition;
        var data = string.Empty;

        if (matches.Groups["Position"].Success)
            {
            // We have a numeric payload
            position = int.Parse(matches.Groups["NumericPayload"].Value);
            }
        if (matches.Groups["Data"].Success)
            {
            // We have a non-numeric payload
            data = matches.Groups["TextPayload"].Value;
            }
        var source = matches.Value;
        /*
         * Commands are understood in one of three basic formats:
         * <F1,234,Nickname=Fred>   -- non-numeric payload
         * <F5,999,MoveTo=1000>     -- numeric payload
         * <F3,0,Center>            -- verb only (no payload)
         * If the RegEx match was successful, then we must have one of these three possibilities.
         * The address, transaction ID and command verb must always be present so we get those first.
         */
        var deviceAddress = matches.Groups["Address"].Value;
        var transaction = int.Parse(matches.Groups["Transaction"].Value);
        var verb = matches.Groups["Verb"].Value;

        // Now we must decide which of the three basic forms we are dealing with.
        // For the verb-only case, we simply set some defaults before checking for a payload.
        var position = Command.NoPosition;
        var data = string.Empty;

        if (matches.Groups["Position"].Success)
            {
            // We have a numeric payload
            position = int.Parse(matches.Groups["NumericPayload"].Value);
            }
        if (matches.Groups["Data"].Success)
            {
            // We have a non-numeric payload
            data = matches.Groups["TextPayload"].Value;
            }
        var source = matches.Value;

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.