Prechádzať zdrojové kódy

The structured prototype of application was added

Dmitry Eliseev 12 rokov pred
rodič
commit
19c165f7c0

+ 18 - 0
structured/index.html

@@ -0,0 +1,18 @@
+<!DOCTYPE html>
+<html id="home" lang="ru">
+    <head>
+        <script src="http://yui.yahooapis.com/3.10.3/build/yui/yui-min.js"></script>
+        <script src="http://codemirror.net/lib/codemirror.js"></script>
+        <script src="js/YUI_config.js"></script>
+    </head>
+    <body class="yui3-skin-sam">
+        <div id="app"></div>
+        <script type="text/javascript">
+            YUI().use('ui-app-se', function (Y) {
+                var app = new Y.UI.App.Se({ container: '#app' });
+
+                app.render();
+            });
+        </script>
+    </body>
+</html>

+ 19 - 0
structured/js/YUI_config.js

@@ -0,0 +1,19 @@
+var YUI_config = {
+        groups: {
+            oc: {
+                base: 'js/oc/',
+                filter: 'raw',
+                patterns: { 'oc-': {} }
+            },
+            se: {
+                base: 'js/se/',
+                filter: 'raw',
+                patterns: { 'se-': {} }
+            },
+            ui: {
+                base: 'js/ui/',
+                filter: 'raw',
+                patterns: { 'ui-': {} }
+            }
+        }
+    };

+ 76 - 0
structured/js/oc/oc-aos-symbols/oc-aos-symbols.js

@@ -0,0 +1,76 @@
+YUI.add('oc-aos-symbols', function (Y) {
+
+    Y.namespace('OC.AOS').Symbols = {
+        NULL:       0,
+        TIMES:      1,
+        SLASH:      2,
+        DIV:        3,
+        MOD:        4,
+        AND:        5,
+        PLUS:       6,
+        MINUS:      7,
+        OR:         8,
+        EQL:        9,
+        NEQ:       10,
+        LSS:       11,
+        LEQ:       12,
+        GTR:       13,
+        GEQ:       14,
+        IN:        15,
+        IS:        16,
+        ARROW:     17,
+        PERIOD:    18,
+        COMMA:     19,
+        COLON:     20,
+        UPTO:      21,
+        RPAREN:    22,
+        RBRAK:     23,
+        RBRACE:    24,
+        OF:        25,
+        THEN:      26,
+        DO:        27,
+        TO:        28,
+        BY:        29,
+        LPAREN:    30,
+        LBRAK:     31,
+        LBRACE:    32,
+        NOT:       33,
+        BECOMES:   34,
+        NUMBER:    35,
+        NIL:       36,
+        TRUE:      37,
+        FALSE:     38,
+        STRING:    39,
+        IDENT:     40,
+        SEMICOLON: 41,
+        BAR:       42,
+        END:       43,
+        ELSE:      44,
+        ELSIF:     45,
+        UNTIL:     46,
+        IF:        47,
+        CASE:      48,
+        WHILE:     49,
+        REPEAT:    50,
+        FOR:       51,
+        LOOP:      52,
+        WITH:      53,
+        EXIT:      54,
+        RETURN:    55,
+        ARRAY:     56,
+        OBJECT:    57,
+        RECORD:    58,
+        POINTER:   59,
+        BEGIN:     60,
+        CODE:      61,
+        CONST:     62,
+        TYPE:      63,
+        VAR:       64,
+        PROCEDURE: 65,
+        IMPORT:    66,
+        MODULE:    67,
+        EOF:       68,
+        ERROR:     69
+    };
+
+}, '1.0', {});

+ 77 - 0
structured/js/oc/oc-o07-symbols/oc-o07-symbols.js

@@ -0,0 +1,77 @@
+YUI.add('oc-o07-symbols', function (Y) {
+
+    Y.namespace('OC.O07').Symbols = {
+        NULL:       0,
+        TIMES:      1,
+        RDIV:       2,
+        DIV:        3,
+        MOD:        4,
+        END:        5,
+        PLUS:       6,
+        MINUS:      7,
+        OR:         8,
+        EQL:        9,
+        NEQ:       10,
+        LSS:       11,
+        LEQ:       12,
+        GTR:       13,
+        GEQ:       14,
+        IN:        15,
+        IS:        16,
+        ARROW:     17,
+        PERIOD:    18,
+        CHAR:      20,
+        INT:       21,
+        REAL:      22,
+        FALSE:     23,
+        TRUE:      24,
+        NIL:       25,
+        STRING:    26,
+        NOT:       27,
+        LPAREN:    28,
+        LBRAK:     29,
+        LBRACE:    30,
+        IDENT:     31,
+        IF:        32,
+        CASE:      33,
+        WHILE:     34,
+        REPEAT:    35,
+        FOR:       36,
+        WITH:      37,
+        ASSERT:    38,
+        COMMA:     40,
+        COLON:     41,
+        BECOMES:   42,
+        UPTO:      43,
+        RPAREN:    44,
+        RBRAK:     45,
+        RBRACE:    46,
+        THEN:      47,
+        OF:        48,
+        DO:        49,
+        TO:        50,
+        BY:        51,
+        SEMICOLON: 52,
+        END:       53,
+        BAR:       54,
+        ELSE:      55,
+        ELSIF:     56,
+        UNTIL:     57,
+        RETURN:    58,
+        ARRAY:     60,
+        RECORD:    61,
+        POINTER:   62,
+        CONST:     63,
+        TYPE:      64,
+        VAR:       65,
+        PROCEDURE: 66,
+        BEGIN:     67,
+        IMPORT:    68,
+        MODULE:    69,
+        EOF:       70,
+        LOOP:      71,
+        EXIT:      72,
+        ERROR:     99
+    };
+
+}, '1.0', {});

+ 7 - 0
structured/js/se/se-model-docs/lang/se-model-docs_ru.js

@@ -0,0 +1,7 @@
+YUI.add('lang/se-model-docs_ru', function (Y) {
+
+    Y.Intl.add('se-model-docs', 'ru', {
+        info: 'Среда программирования на языке Оберон'
+    });
+
+}, '1.0');

+ 34 - 0
structured/js/se/se-model-docs/se-model-docs.js

@@ -0,0 +1,34 @@
+YUI.add('se-model-docs', function (Y) {
+
+    Y.namespace('SE.Models').Docs = Y.Base.create('docsModelSE', Y.Model, [], {
+        getInfo: function () {
+            var strings = this.get('strings');
+
+            return strings.info;
+        }
+    }, {
+        ATTRS: {
+            title: {
+                value: null,
+                validator: Y.Lang.isString
+            },
+            description: {
+                value: null,
+                validator: Y.Lang.isString
+            },
+            strings: {
+                valueFn: function () {
+                    return Y.Intl.get('se-model-docs');
+                }
+            }
+        }
+    });
+
+}, '1.0', {
+    lang: [
+        'ru'
+    ],
+    requires: [
+        'model'
+    ]
+});

+ 88 - 0
structured/js/se/se-model-module/se-model-module.js

@@ -0,0 +1,88 @@
+YUI.add('se-model-module', function (Y) {
+
+    var ID = 'id',
+        AST = 'ast',
+        SYM = 'sym',
+        CODE = 'code',
+        NAME = 'name',
+        TEXT = 'text';
+
+    Y.namespace('SE.Models').Module = Y.Base.create('moduleModelSE', Y.Model, [], {
+        getId: function () {
+            return this.get(ID);
+        },
+
+        setId: function (id) {
+            return this.set(ID, id);
+        },
+
+        getName: function () {
+            return this.get(NAME);
+        },
+
+        setName: function (name) {
+            return this.set(NAME, name);
+        },
+
+        getAst: function () {
+            return this.get(AST);
+        },
+
+        setAst: function (ast) {
+            return this.set(AST, ast);
+        },
+
+        getSym: function () {
+            return this.get(SYM);
+        },
+
+        setSym: function (sym) {
+            return this.set(SYM, sym);
+        },
+
+        getCode: function () {
+            return this.get(CODE)
+        },
+
+        setCode: function (code) {
+            return this.set(CODE, code);
+        },
+
+        getText: function () {
+            return this.get(TEXT);
+        },
+
+        setText: function (text) {
+            return this.set(TEXT, text);
+        },
+
+        isReady: function () {
+            return !Y.Lang.isNull(this.get(CODE));
+        }
+    }, {
+        ATTRS: {
+            ast: {
+                value: null
+            },
+            sym: {
+                value: null
+            },
+            code: {
+                value: null
+            },
+            name: {
+                value: 'noname',
+                validator: Y.Lang.isString
+            },
+            text: {
+                value: 'MODULE noname; END noname.',
+                validator: Y.Lang.isString
+            }
+        }
+    });
+
+}, '1.0', {
+    requires: [
+        'model'
+    ]
+});

+ 116 - 0
structured/js/ui/ui-app-se/ui-app-se.js

@@ -0,0 +1,116 @@
+YUI.add('ui-app-se', function (Y) {
+
+    var MODULE = 'module';
+
+    Y.namespace('UI.App').Se = Y.Base.create('seAppUI', Y.App, [], {
+        views: {
+            // libs: {
+            //     type: Y.UI.Pages.Libs
+            // },
+            // lib: {
+            //     type: Y.UI.Pages.Lib,
+            //     parent: 'libs'
+            // },
+            // projects: {
+            //     type: Y.UI.Pages.Projects
+            // },
+            // project: {
+            //     type: Y.UI.Pages.Project,
+            //     parent: 'projects'
+            // },
+            module: {
+                type: Y.UI.Pages.Module,
+                // parent: 'project'
+            },
+            // runtime: {
+            //     type: Y.UI.Pages.Runtime
+            // },
+            // docs: {
+            //     type: Y.UI.Pages.Docs
+            // }
+        },
+
+        initializer: function () {
+            var self = this;
+
+            self.once('ready', function (event) {
+                if (self.hasRoute(self.getPath())) {
+                    self.dispatch();
+                } else {
+                    self.showModule();
+                }
+            });
+        },
+
+        // showLibs: function (req, res) {
+        //     this.showView('docs'); // libs;
+        // },
+        
+        // showLib: function (req, res) {
+        //     this.showView('docs'); // lib
+        // },
+        
+        // showProjects: function (req, res) {
+        //     this.showView('docs'); // projects
+        // },
+        
+        // showProject: function (req, res) {
+        //     this.showView('docs'); // project
+        // },
+
+        showModule: function (req, res) {
+            this.showView('module', { module: this.getModule() });
+        },
+        
+        // showRuntime: function (req, res) {
+        //     this.showView('docs'); // runtime
+        // },
+
+        // showDocs: function (req, res) {
+        //     this.showView('docs');
+        // },
+
+        getModule: function () {
+            return this.get(MODULE);
+        },
+
+        setModule: function (module) {
+            return this.set(MODULE, module);
+        }
+    }, {
+        ATTRS: {
+            routes: [
+                { path: '/',         callbacks: 'showModule' },
+                // { path: '/libs',     callbacks: 'showLibs' },
+                // { path: '/lib',      callbacks: 'showLib' },
+                // { path: '/projects', callbacks: 'showProjects' },
+                // { path: '/project',  callbacks: 'showProject' },
+                { path: '/module',   callbacks: 'showModule' },
+                // { path: '/runtime',  callbacks: 'showRuntime' },
+                // { path: '/docs',     callbacks: 'showDocs' }
+            ],
+            module: {
+                value: new Y.SE.Models.Module,
+                validator: function (mod) {
+                    return mod instanceof Y.SE.Models.Module;
+                }
+            },
+            user: {
+                value: null
+            }
+        }
+    });
+
+}, '1.0', {
+    requires: [
+        'app',
+        // 'ui-page-libs',
+        // 'ui-page-lib',
+        // 'ui-page-projects',
+        // 'ui-page-project',
+        'ui-page-module',
+        // 'ui-page-runtime',
+        // 'ui-page-docs'
+        'se-model-module'
+    ]
+});

+ 136 - 0
structured/js/ui/ui-code-editor/ui-code-editor.js

@@ -0,0 +1,136 @@
+YUI.add('ui-code-editor', function (Y) {
+
+    CodeMirror.defineMode("oberon07", function () {
+        function words(str) {
+            var obj = {}, words = str.split(" ");
+        
+            for (var i = 0; i < words.length; ++i) obj[words[i]] = true;
+            return obj;
+        }
+      
+        var keywords = words("ARRAY IMPORT THEN BEGIN IN TO BY IS TRUE CASE MOD TYPE " +
+                           "CONST MODULE UNTIL DIV NIL VAR DO OF WHILE ELSE OR " +
+                           "ELSIF POINTER END PROCEDURE FALSE RECORD FOR REPEAT IF RETURN");
+                                                 
+        var atoms = {'null': true};
+
+        var isOperatorChar = /[+\-*&%=<>^~#!?\|\/]/;
+
+        function tokenBase(stream, state) {
+            var ch = stream.next();
+        
+            if (ch == "#" && state.startOfLine) {
+                stream.skipToEnd();
+                return "meta";
+            }
+        
+            if (ch == '"' || ch == "'") {
+                state.tokenize = tokenString(ch);
+                return state.tokenize(stream, state);
+            }
+        
+            if (ch == "(" && stream.eat("*")) {
+                state.tokenize = tokenComment;
+                return tokenComment(stream, state);
+            }
+        
+            if (/[\[\]{}\(\),;\:\.]/.test(ch)) {
+                return null;
+            }
+        
+            if (/\d/.test(ch)) {
+                stream.eatWhile(/[\w\.]/);
+                return "number";
+            }
+        
+            if (ch == "/") {
+                if (stream.eat("/")) {
+                    stream.skipToEnd();
+                    return "comment";
+                }
+            }
+        
+            if (isOperatorChar.test(ch)) {
+                stream.eatWhile(isOperatorChar);
+                return "operator";
+            }
+
+            stream.eatWhile(/[\w\$_]/);
+            
+            var cur = stream.current();
+        
+            if (keywords.propertyIsEnumerable(cur)) return "keyword";
+            if (atoms.propertyIsEnumerable(cur)) return "atom";
+            return "variable";
+        }
+
+        function tokenString(quote) {
+            return function(stream, state) {
+                var escaped = false, next, end = false;
+                
+                while ((next = stream.next()) != null) {
+                    if (next == quote && !escaped) {end = true; break;}
+                    escaped = !escaped && next == "\\";
+                }
+                
+                if (end || !escaped) state.tokenize = null;
+                return "string";
+            };
+        }
+
+        function tokenComment(stream, state) {
+            var maybeEnd = false, ch;
+            
+            while (ch = stream.next()) {
+                if (ch == ")" && maybeEnd) {
+                    state.tokenize = null;
+                    break;
+                }
+                maybeEnd = (ch == "*");
+            }
+            return "comment";
+        }
+
+      // Interface
+
+        return {
+            startState: function() {
+                return {tokenize: null};
+            },
+
+            token: function(stream, state) {
+                if (stream.eatSpace()) return null;
+                
+                var style = (state.tokenize || tokenBase)(stream, state);
+                
+                if (style == "comment" || style == "meta") return style;
+                
+                return style;
+            },
+
+            electricChars: "{}"
+        };
+    });
+
+    CodeMirror.defineMIME("text/x-oberon07", "oberon07");
+
+    /** Wrapper for CodeMirror Editor */
+    Y.namespace('UI.Code').Editor = Y.Base.create('editorCodeUI', Y.View, {
+        render: function (srcNode) {
+            var editor,
+                node = srcNode instanceof Y.Node ? srcNode : Y.one(srcNode);
+
+            if (node) {
+                editor = CodeMirror.fromTextArea(node._node, {
+                    lineNumbers: true,
+                    mode: 'text/x-oberon07'
+                });
+            }
+        }
+    }, {});
+
+}, '1.0', {
+    requires: [
+        'view'
+    ]
+});

+ 33 - 0
structured/js/ui/ui-page-docs/ui-page-docs.js

@@ -0,0 +1,33 @@
+YUI.add('ui-page-docs', function (Y) {
+
+    Y.namespace('UI.Pages').Docs = Y.Base.create('docsPageUI', Y.View, {
+        template: '<h3>{{title}}</h3>' +
+                '<p>{{description}}</p>',
+
+        render: function () {
+            var self = this,
+                doc = self.get('doc'),
+                container = self.get('container'),
+                content = Y.Handlebars.compile(self.template);
+
+            container.setHTML(content(doc.toJSON()));
+        }
+
+    }, {
+        ATTRS: {
+            doc: {
+                value: null,
+                validator: function (doc) {
+                    return doc instanceof Y.SE.Models.Docs;
+                }
+            }
+        }
+    });
+
+}, '1,0', {
+    requires: [
+        'view',
+        'handlebars',
+        'se-model-docs'
+    ]
+});

+ 1 - 0
structured/js/ui/ui-page-lib/ui-page-lib.js

@@ -0,0 +1 @@
+YUI.add('ui-page-lib', function (Y) {}, '1.0', {});

+ 1 - 0
structured/js/ui/ui-page-libs/ui-page-libs.js

@@ -0,0 +1 @@
+YUI.add('ui-page-libs', function (Y) {}, '1.0', {});

+ 50 - 0
structured/js/ui/ui-page-module/ui-page-module.js

@@ -0,0 +1,50 @@
+YUI.add('ui-page-module', function (Y) {
+
+    var MODULE = 'module',
+        STRINGS = 'strings',
+        CONTAINER = 'container';
+
+    Y.namespace('UI.Pages').Module = Y.Base.create('modulePageUI', Y.View, [], {
+        template: '<h3>{{module_name}}: <i>{{name}}</i></h3><div><textarea id="code">{{text}}</textarea></div>',
+
+        render: function () {
+            var editor = new Y.UI.Code.Editor(),
+                module = this.get(MODULE),
+                strings = this.get(STRINGS),
+                content = Y.Handlebars.compile(this.template);
+                container = this.get(CONTAINER);
+
+            container.setHTML(content({
+                module_name: strings.module.name,
+                name: module.getName(),
+                text: module.getText()
+            }));
+
+            editor.render(container.one('textarea'));
+
+            return this;
+        }
+    }, {
+        ATTRS: {
+            module: {
+                value: null,
+                validator: function (mod) {
+                    return mod instanceof Y.SE.Models.Module;
+                }
+            },
+            strings: {
+                value: {
+                    module: { name: 'Имя модуля' }
+                }
+            }
+        }
+    });
+
+}, '1.0', {
+    requires: [
+        'view',
+        'handlebars',
+        'se-model-module',
+        'ui-code-editor'
+    ]
+});

+ 1 - 0
structured/js/ui/ui-page-project/ui-page-project.js

@@ -0,0 +1 @@
+YUI.add('ui-page-project', function (Y) {}, '1.0', {});

+ 1 - 0
structured/js/ui/ui-page-projects/ui-page-projects.js

@@ -0,0 +1 @@
+YUI.add('ui-page-projects', function (Y) {}, '1.0', {});

+ 1 - 0
structured/js/ui/ui-page-runtime/ui-page-runtime.js

@@ -0,0 +1 @@
+YUI.add('ui-page-runtime', function (Y) {}, '1.0', {});