Пример #1
0
        static public void Apply(ExcessCompiler compiler)
        {
            var lexical   = compiler.Lexical();
            var semantics = compiler.Semantics();

            lexical
            .match()     //lambda
            .any('(', '=', ',')
            .token("function", named: "fn")
            .enclosed('(', ')')
            .token('{', named: "brace")
            .then(compiler.Lexical().transform()
                  .remove("fn")
                  .insert("=>", before: "brace"))
            .match()
            .token("function", named: "fn")         //declarations
            .identifier(named: "id")
            .enclosed('(', ')')
            .token('{')
            .then(lexical.transform()
                  .remove("fn")
                  .then(ProcessMemberFunction, referenceToken: "id"));
            semantics
            .error("CS0246", FunctionType);
        }
Пример #2
0
 static public void Apply(ExcessCompiler compiler)
 {
     compiler.Lexical()
     .match()
     .any(new[] { '(', '=', ',' }, named: "start", matchDocumentStart: true)
     .enclosed('[', ']', start: "open", end: "close")
     .then(compiler.Lexical().transform()
           .insert("new []", after: "start")
           .replace("open", "{")
           .replace("close", "}"));
 }
Пример #3
0
        static public void Apply(ExcessCompiler compiler)
        {
            var lexical = compiler.Lexical();
            var syntax  = compiler.Syntax();

            lexical
            //methods
            .match()
            .token("method", named: "keyword")
            .identifier(named: "id")
            .enclosed('(', ')')
            .token('{')
            .then(lexical.transform()
                  .remove("keyword")
                  .then(Method, referenceToken: "id"))

            //properties
            .match()
            .token("property")
            .identifier(named: "id")
            .token("=")
            .then(Property)

            .match()
            .token("property", named: "keyword")
            .identifier(named: "id")
            .then(lexical.transform()
                  .remove("keyword")
                  .then(Property, referenceToken: "id"));

            syntax
            //constructor
            .match <MethodDeclarationSyntax>(method => method.ReturnType.IsMissing && method.Identifier.ToString() == "constructor")
            .then(Constructor);
        }
Пример #4
0
        public static void Apply(ExcessCompiler compiler)
        {
            var lexical = compiler.Lexical();

            lexical.match()
            .token("match", named: "keyword")
            .enclosed('(', ')')
            .token('{')
            .then(lexical.transform()
                  .replace("keyword", "switch")
                  .then(ProcessMatch, referenceToken: "keyword"));
        }
Пример #5
0
        public static void Apply(ExcessCompiler compiler, Scope scope = null)
        {
            scope?.AddKeywords("sql");
            compiler.Lexical()
                .extension("sql", ExtensionKind.Code, ParseDapper);

            compiler.Environment()
                .dependency("Excess.Runtime")
                .dependency("Dapper")
                .dependency<IDbConnection>("System.Data")
                .dependency("System.Collections.Generic")
                .dependency("System.Linq");
        }
Пример #6
0
        static public void Apply(ExcessCompiler compiler)
        {
            var lexical   = compiler.Lexical();
            var semantics = compiler.Semantics();

            lexical
            .match()
            .token("typedef")
            .identifier(named: "id")
            .token("=")
            .until(';', named: "definition")
            .then(TypedefAssignment)
            .match()
            .token("typedef", named: "keyword")
            .until(';', named: "definition")
            .then(compiler.Lexical().transform()
                  .remove("keyword")
                  .then(Typedef));

            semantics
            .error("CS0246", FixMissingType);
        }
Пример #7
0
        public static void Apply(ExcessCompiler compiler, Scope scope = null)
        {
            scope?.AddKeywords("settings");

            compiler.Lexical()
            .indented <SettingsModel, SettingsRoot>("settings", ExtensionKind.Type, null)
            .match <SettingsRoot, HeaderModel>(ParseHeader,
                                               children: child => child
                                               .match <SettingsModel, HeaderModel, AssignmentExpressionSyntax>(
                                                   then: (header, assignment) => header.Values.Add(assignment)))

            .then()
            .transform <SettingsRoot>(LinkSettings);
        }
Пример #8
0
        static public void Apply(ExcessCompiler compiler)
        {
            var lexical = compiler.Lexical();

            lexical
            .match()
            .token("inject", named: "keyword")
            .enclosed('{', '}', end: "lastBrace")
            .then(lexical.transform()
                  .replace("keyword", "__injectFunction __inject = _ => ")
                  .insert(";", after: "lastBrace")
                  .then(ProcessInjection));

            compiler.Environment()
            .dependency <__Scope>("Excess.Runtime");
        }
Пример #9
0
        static public void Apply(ExcessCompiler compiler)
        {
            var lexical = compiler.Lexical();
            var syntax  = compiler.Syntax();

            lexical
            .match()
            .token("event", named: "ev")
            .identifier(named: "id")
            .enclosed('(', ')', contents: "args")
            .then(LexicalEventDeclaration);

            syntax
            .match <MethodDeclarationSyntax>(method => method.ReturnType.ToString() == "on")
            .then(EventHandler);
        }
Пример #10
0
        public static void Apply(ExcessCompiler compiler)
        {
            compiler.Environment()
            .dependency <JObject>("Newtonsoft.Json.Linq");

            compiler.Lexical()
            .grammar <JsonGrammar, ParserRuleContext>("json", ExtensionKind.Code)
            .transform <JSONParser.ExpressionContext>(AntlrExpression.Parse)
            .transform <JSONParser.JsonContext>(Main)
            .transform <JSONParser.ObjectContext>(JObject)
            .transform <JSONParser.ArrayContext>(JArray)
            .transform <JSONParser.PairContext>(JPair)
            .transform <JSONParser.ValueContext>(JValue)

            .then(Transform);
            ;
        }
Пример #11
0
        public static void Apply(ExcessCompiler compiler)
        {
            var lexical = compiler.Lexical();

            lexical
            .match()
            .token("concurrent", named: "keyword")
            .token("class", named: "ref")
            .then(lexical.transform()
                  .remove("keyword")
                  .then(Compile))
            .match()
            .token("concurrent", named: "keyword")
            .token("object", named: "ref")
            .then(lexical.transform()
                  .remove("keyword")
                  .replace("ref", "class")
                  .then(CompileObject));
        }
Пример #12
0
        public static void Apply(ExcessCompiler compiler, Scope scope)
        {
            var options = scope?.get <ServerExtensionOptions>()
                          ?? new ServerExtensionOptions();

            var keywords = scope?.get("keywords") as List <string>;

            keywords?.Add("service");

            compiler.Syntax()
            .extension("server", ExtensionKind.Type, CompileServer);

            var lexical = compiler.Lexical();

            lexical.match()
            .token("service", named: "keyword")
            .identifier(named: "ref")
            .then(lexical.transform()
                  .replace("keyword", "class ")
                  .then(CompileService));

            compiler.Environment()
            .dependency("Middleware");

            if (options.GenerateJsServices)
            {
                throw new NotImplementedException();
                //var compilation = compiler.Compilation();
                //if (compilation != null)
                //    compilation
                //        .match<ClassDeclarationSyntax>(isConcurrentClass)
                //            .then(jsConcurrentClass)
                //        .match<ClassDeclarationSyntax>(isConcurrentObject)
                //            .then(jsConcurrentObject);
            }
        }
Пример #13
0
        public static void Apply(ExcessCompiler compiler, Scope scope, CompilationAnalysis compilation = null)
        {
            var options = scope?.get <ServerExtensionOptions>()
                          ?? new ServerExtensionOptions();

            var keywords = scope?.get("keywords") as List <string>;

            keywords?.Add("service");

            //compiler.Syntax()
            //    .extension("server", ExtensionKind.Type, CompileServer);

            var lexical = compiler.Lexical();

            lexical.match()
            .token("service", named: "keyword")
            .identifier(named: "ref")
            .then(lexical.transform()
                  .replace("keyword", "class ")
                  .then(CompileService));

            compiler.Environment()
            .dependency("System.Configuration")
            .dependency("System.Security.Principal")
            .dependency("Microsoft.Owin")
            .dependency("Excess.Server.Middleware")
            ;

            compiler.Lexical()
            .indented <ServerModel, ServerInstance>("server", ExtensionKind.Type, InitApp)
            .match <ServerModel, ServerInstance, ServerLocation>(new[] {
                "@{Url}",
                "on port {Port}",
                "@{Url} port {Port}",
                "@{Url}, port {Port}"
            },
                                                                 then: SetServerLocation)

            .match <ServerModel, ServerInstance, ConfigModel>("using {Threads} threads", then: SetConfiguration)
            .match <ServerModel, ServerInstance, ConfigModel>("identity @{Identity}", then: SetConfiguration)

            .match <ServerModel, ServerInstance, HostingModel>("hosting {ClassName}",
                                                               then: (server, hosting) => server.HostedClasses.Add(hosting.ClassName))

            .match <ServerModel, ServerInstance, StaticFilesModel>(new[] {
                "static files @{Directory}",
                "static files {Directory}",
            },
                                                                   then: (server, staticFiles) => server.StaticFiles = staticFiles.Directory)

            .match <ServerModel, ServerInstance, ServerInstance>("new instance",
                                                                 then: AddInstance,
                                                                 children: child => child.match_parent())

            .match <ServerModel, ServerInstance, SQLLocation>(new[] {
                "sql @{ConnectionString}",
                "sql with {ConnectionInstantiator} @{ConnectionString}",
                "sql on connection {ConnectionId}",
                "sql with {ConnectionInstantiator} on connection {ConnectionId}",
            },
                                                              then: (server, sql) => server.SetSqlLocation(sql))

            .then()
            .transform <ServerInstance>(LinkServerInstance);
        }