Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

primitive FRISC mode for ACE syntax highlighter

  • Loading branch information...
commit a89fcc3def6837a2fe50846e95eb777190b74261 1 parent f6b96e7
@izuzak authored
Showing with 125 additions and 1 deletion.
  1. +25 −0 ace-mode-frisc.css
  2. +95 −0 ace-mode-frisc.js
  3. +5 −1 main.html
View
25 ace-mode-frisc.css
@@ -0,0 +1,25 @@
+.ace_line {
+ font-weight: bold;
+}
+
+.ace_frisc_numeric {
+ color: #268bd2;
+}
+
+.ace_frisc_comment {
+ color: #666;
+ font-style: italic;
+ font-weight: normal;
+}
+
+.ace_frisc_register {
+ color: #859900;
+}
+
+.ace_frisc_instruction {
+ color: black;
+}
+
+.ace_frisc_label {
+ color: #dc322f
+}
View
95 ace-mode-frisc.js
@@ -0,0 +1,95 @@
+define('ace/mode/frisc', function(require, exports, module) {
+
+ var oop = require("ace/lib/oop");
+ var TextMode = require("ace/mode/text").Mode;
+ var Tokenizer = require("ace/tokenizer").Tokenizer;
+ var FriscHighlightRules = require("ace/mode/frisc_highlight_rules").FriscHighlightRules;
+
+ var Mode = function() {
+ this.$tokenizer = new Tokenizer(new FriscHighlightRules().getRules());
+ };
+ oop.inherits(Mode, TextMode);
+
+ (function() {
+ // Extra logic goes here.
+ }).call(Mode.prototype);
+
+ exports.Mode = Mode;
+ });
+
+ define('ace/mode/frisc_highlight_rules', function(require, exports, module) {
+
+ var oop = require("ace/lib/oop");
+ var TextHighlightRules = require("ace/mode/text_highlight_rules").TextHighlightRules;
+
+ var FriscHighlightRules = function() {
+ var keywords_all = ("add|move|or|and|xor|adc|sub|sbc|rotl|rotr|shl|shr|ashr|cmp|ret|reti|retn|halt|jp|call|jr|" +
+ "load|store|loadb|storeb|loadh|storeh|pop|push|`org|`dw|`equ|`ds|`end|`base|dw|dh|db").split("|");
+
+ var keywords_withCond = ("ret|reti|retn|halt|jp|call|jr").split("|");
+
+ var conditions = ("_m|_nn|_nv|_nz|_ne|_nc|_n|_p|_c|_ult|_uge|_v|_z|_eq|_ule|_ugt|_slt|_sle|_sge|_sgt").split("|");
+
+ var kw_all = {};
+ for (var i=0; i<keywords_all.length; i++) {
+ kw_all[keywords_all[i]] = null;
+ }
+
+ var kw_withCond = {};
+ for (var i=0; i<keywords_withCond.length; i++) {
+ kw_withCond[keywords_withCond[i]] = null;
+ }
+
+ var conds = {};
+ for (var i=0; i<conditions.length; i++) {
+ conds[conditions[i]] = null;
+ }
+
+ this.$rules = {
+ start : [
+ {
+ token : "frisc_comment",
+ regex : ";.*$"
+ }, {
+ token : "frisc_label",
+ regex : "^[a-zA-Z][0-9a-zA-Z]*"
+ }, {
+ token : "frisc_register",
+ regex : "\\b[Rr][0-7]\\b"
+ }, {
+ token : "frisc_register",
+ regex : "\\b[Ss][Rr]\\b"
+ }, {
+ token : "frisc_lparen",
+ regex : "[(]"
+ }, {
+ token : "frisc_rparen",
+ regex : "[)]"
+ }, {
+ token : "frisc_numeric",
+ regex : "\\b[0-9][0-9a-fA-F]*\\b"
+ }, {
+ token : function(v0, v1, v2) {
+ if (kw_withCond.hasOwnProperty(v1.toLowerCase()) && (typeof v2 !== "undefined") && conds.hasOwnProperty(v2.toLowerCase())) {
+ return ["frisc_random", "frisc_instruction", "frisc_instruction"];
+ } else if (kw_all.hasOwnProperty(v1.toLowerCase()) && (typeof v2 === "undefined")) {
+ return ["frisc_random", "frisc_instruction"];
+ } else if (typeof v2 !== "undefined") {
+ return ["frisc_random", "frisc_random", "frisc_random"];
+ } else {
+ return ["frisc_random", "frisc_random"];
+ }
+ },
+ regex : "(\\s)([`]?[a-zA-z][a-zA-Z]*)(_[a-zA-Z]*)?\\b"
+ }, {
+ token : "frisc_operator",
+ regex : "[,\+\-]"
+ }
+ ]
+ };
+ }
+
+ oop.inherits(FriscHighlightRules, TextHighlightRules);
+
+ exports.FriscHighlightRules = FriscHighlightRules;
+});
View
6 main.html
@@ -7,11 +7,13 @@
<title> FRISCjs - FRISC processor simulator in JavaScript</title>
<link rel="stylesheet" href="http://twitter.github.com/bootstrap/1.4.0/bootstrap.min.css" />
+ <link rel="stylesheet" href="ace-mode-frisc.css" />
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript" src="friscasm.js"></script>
<script type="text/javascript" src="friscjs.js"></script>
- <script type="text/javascript" src="https://raw.github.com/ajaxorg/ace/master/build/src/ace.js" charset="utf-8"></script>
+ <script type="text/javascript" src="https://raw.github.com/ajaxorg/ace/master/build/src/ace.js"></script>
<script type="text/javascript" src="https://raw.github.com/twitter/bootstrap/master/js/bootstrap-tabs.js"></script>
+ <script type="text/javascript" src="ace-mode-frisc.js"></script>
</head>
<body>
<div class="container" style="width: 1140px">
@@ -97,6 +99,8 @@
window.onload = function() {
$(function() { $("li").css("color", "#404040"); });
editor = ace.edit("frisc-inputdiv");
+ var FriscMode = require("ace/mode/frisc").Mode;
+ editor.getSession().setMode(new FriscMode());
document.getElementById('frisc-inputdiv').style.fontSize='10pt';
document.getElementById('frisc-inputdiv').style.fontFamily='courier new';
$(".ace_gutter").width("40px");
Please sign in to comment.
Something went wrong with that request. Please try again.