LaravelTest
353 строки · 8.9 Кб
1// CodeMirror, copyright (c) by Marijn Haverbeke and others
2// Distributed under an MIT license: https://codemirror.net/LICENSE
3
4(function(mod) {5if (typeof exports == "object" && typeof module == "object") // CommonJS6mod(require("../../lib/codemirror"));7else if (typeof define == "function" && define.amd) // AMD8define(["../../lib/codemirror"], mod);9else // Plain browser env10mod(CodeMirror);11})(function(CodeMirror) {12"use strict";13
14CodeMirror.defineMode("gas", function(_config, parserConfig) {15'use strict';16
17// If an architecture is specified, its initialization function may18// populate this array with custom parsing functions which will be19// tried in the event that the standard functions do not find a match.20var custom = [];21
22// The symbol used to start a line comment changes based on the target23// architecture.24// If no architecture is pased in "parserConfig" then only multiline25// comments will have syntax support.26var lineCommentStartSymbol = "";27
28// These directives are architecture independent.29// Machine specific directives should go in their respective30// architecture initialization function.31// Reference:32// http://sourceware.org/binutils/docs/as/Pseudo-Ops.html#Pseudo-Ops33var directives = {34".abort" : "builtin",35".align" : "builtin",36".altmacro" : "builtin",37".ascii" : "builtin",38".asciz" : "builtin",39".balign" : "builtin",40".balignw" : "builtin",41".balignl" : "builtin",42".bundle_align_mode" : "builtin",43".bundle_lock" : "builtin",44".bundle_unlock" : "builtin",45".byte" : "builtin",46".cfi_startproc" : "builtin",47".comm" : "builtin",48".data" : "builtin",49".def" : "builtin",50".desc" : "builtin",51".dim" : "builtin",52".double" : "builtin",53".eject" : "builtin",54".else" : "builtin",55".elseif" : "builtin",56".end" : "builtin",57".endef" : "builtin",58".endfunc" : "builtin",59".endif" : "builtin",60".equ" : "builtin",61".equiv" : "builtin",62".eqv" : "builtin",63".err" : "builtin",64".error" : "builtin",65".exitm" : "builtin",66".extern" : "builtin",67".fail" : "builtin",68".file" : "builtin",69".fill" : "builtin",70".float" : "builtin",71".func" : "builtin",72".global" : "builtin",73".gnu_attribute" : "builtin",74".hidden" : "builtin",75".hword" : "builtin",76".ident" : "builtin",77".if" : "builtin",78".incbin" : "builtin",79".include" : "builtin",80".int" : "builtin",81".internal" : "builtin",82".irp" : "builtin",83".irpc" : "builtin",84".lcomm" : "builtin",85".lflags" : "builtin",86".line" : "builtin",87".linkonce" : "builtin",88".list" : "builtin",89".ln" : "builtin",90".loc" : "builtin",91".loc_mark_labels" : "builtin",92".local" : "builtin",93".long" : "builtin",94".macro" : "builtin",95".mri" : "builtin",96".noaltmacro" : "builtin",97".nolist" : "builtin",98".octa" : "builtin",99".offset" : "builtin",100".org" : "builtin",101".p2align" : "builtin",102".popsection" : "builtin",103".previous" : "builtin",104".print" : "builtin",105".protected" : "builtin",106".psize" : "builtin",107".purgem" : "builtin",108".pushsection" : "builtin",109".quad" : "builtin",110".reloc" : "builtin",111".rept" : "builtin",112".sbttl" : "builtin",113".scl" : "builtin",114".section" : "builtin",115".set" : "builtin",116".short" : "builtin",117".single" : "builtin",118".size" : "builtin",119".skip" : "builtin",120".sleb128" : "builtin",121".space" : "builtin",122".stab" : "builtin",123".string" : "builtin",124".struct" : "builtin",125".subsection" : "builtin",126".symver" : "builtin",127".tag" : "builtin",128".text" : "builtin",129".title" : "builtin",130".type" : "builtin",131".uleb128" : "builtin",132".val" : "builtin",133".version" : "builtin",134".vtable_entry" : "builtin",135".vtable_inherit" : "builtin",136".warning" : "builtin",137".weak" : "builtin",138".weakref" : "builtin",139".word" : "builtin"140};141
142var registers = {};143
144function x86(_parserConfig) {145lineCommentStartSymbol = "#";146
147registers.al = "variable";148registers.ah = "variable";149registers.ax = "variable";150registers.eax = "variable-2";151registers.rax = "variable-3";152
153registers.bl = "variable";154registers.bh = "variable";155registers.bx = "variable";156registers.ebx = "variable-2";157registers.rbx = "variable-3";158
159registers.cl = "variable";160registers.ch = "variable";161registers.cx = "variable";162registers.ecx = "variable-2";163registers.rcx = "variable-3";164
165registers.dl = "variable";166registers.dh = "variable";167registers.dx = "variable";168registers.edx = "variable-2";169registers.rdx = "variable-3";170
171registers.si = "variable";172registers.esi = "variable-2";173registers.rsi = "variable-3";174
175registers.di = "variable";176registers.edi = "variable-2";177registers.rdi = "variable-3";178
179registers.sp = "variable";180registers.esp = "variable-2";181registers.rsp = "variable-3";182
183registers.bp = "variable";184registers.ebp = "variable-2";185registers.rbp = "variable-3";186
187registers.ip = "variable";188registers.eip = "variable-2";189registers.rip = "variable-3";190
191registers.cs = "keyword";192registers.ds = "keyword";193registers.ss = "keyword";194registers.es = "keyword";195registers.fs = "keyword";196registers.gs = "keyword";197}198
199function armv6(_parserConfig) {200// Reference:201// http://infocenter.arm.com/help/topic/com.arm.doc.qrc0001l/QRC0001_UAL.pdf202// http://infocenter.arm.com/help/topic/com.arm.doc.ddi0301h/DDI0301H_arm1176jzfs_r0p7_trm.pdf203lineCommentStartSymbol = "@";204directives.syntax = "builtin";205
206registers.r0 = "variable";207registers.r1 = "variable";208registers.r2 = "variable";209registers.r3 = "variable";210registers.r4 = "variable";211registers.r5 = "variable";212registers.r6 = "variable";213registers.r7 = "variable";214registers.r8 = "variable";215registers.r9 = "variable";216registers.r10 = "variable";217registers.r11 = "variable";218registers.r12 = "variable";219
220registers.sp = "variable-2";221registers.lr = "variable-2";222registers.pc = "variable-2";223registers.r13 = registers.sp;224registers.r14 = registers.lr;225registers.r15 = registers.pc;226
227custom.push(function(ch, stream) {228if (ch === '#') {229stream.eatWhile(/\w/);230return "number";231}232});233}234
235var arch = (parserConfig.architecture || "x86").toLowerCase();236if (arch === "x86") {237x86(parserConfig);238} else if (arch === "arm" || arch === "armv6") {239armv6(parserConfig);240}241
242function nextUntilUnescaped(stream, end) {243var escaped = false, next;244while ((next = stream.next()) != null) {245if (next === end && !escaped) {246return false;247}248escaped = !escaped && next === "\\";249}250return escaped;251}252
253function clikeComment(stream, state) {254var maybeEnd = false, ch;255while ((ch = stream.next()) != null) {256if (ch === "/" && maybeEnd) {257state.tokenize = null;258break;259}260maybeEnd = (ch === "*");261}262return "comment";263}264
265return {266startState: function() {267return {268tokenize: null269};270},271
272token: function(stream, state) {273if (state.tokenize) {274return state.tokenize(stream, state);275}276
277if (stream.eatSpace()) {278return null;279}280
281var style, cur, ch = stream.next();282
283if (ch === "/") {284if (stream.eat("*")) {285state.tokenize = clikeComment;286return clikeComment(stream, state);287}288}289
290if (ch === lineCommentStartSymbol) {291stream.skipToEnd();292return "comment";293}294
295if (ch === '"') {296nextUntilUnescaped(stream, '"');297return "string";298}299
300if (ch === '.') {301stream.eatWhile(/\w/);302cur = stream.current().toLowerCase();303style = directives[cur];304return style || null;305}306
307if (ch === '=') {308stream.eatWhile(/\w/);309return "tag";310}311
312if (ch === '{') {313return "bracket";314}315
316if (ch === '}') {317return "bracket";318}319
320if (/\d/.test(ch)) {321if (ch === "0" && stream.eat("x")) {322stream.eatWhile(/[0-9a-fA-F]/);323return "number";324}325stream.eatWhile(/\d/);326return "number";327}328
329if (/\w/.test(ch)) {330stream.eatWhile(/\w/);331if (stream.eat(":")) {332return 'tag';333}334cur = stream.current().toLowerCase();335style = registers[cur];336return style || null;337}338
339for (var i = 0; i < custom.length; i++) {340style = custom[i](ch, stream, state);341if (style) {342return style;343}344}345},346
347lineComment: lineCommentStartSymbol,348blockCommentStart: "/*",349blockCommentEnd: "*/"350};351});352
353});354