From 48805286ef17e930fd28499c92667e1856f0a92c Mon Sep 17 00:00:00 2001 From: aceinetx Date: Sun, 5 Jul 2026 21:44:38 +0300 Subject: [PATCH 1/7] Add B to languages.yml --- lib/linguist/languages.yml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/linguist/languages.yml b/lib/linguist/languages.yml index 92b013df81..10a6dd6c7c 100644 --- a/lib/linguist/languages.yml +++ b/lib/linguist/languages.yml @@ -529,6 +529,13 @@ Awk: tm_scope: source.awk ace_mode: text language_id: 28 +B: + type: programming + color: "#da7666" + extensions: + - ".b" + tm_scope: source.b + ace_mode: text B (Formal Method): type: programming color: "#8aa8c5" From 4b1c4dc9e43b98797b5bc236cfa438ce11bff73c Mon Sep 17 00:00:00 2001 From: aceinetx Date: Sun, 5 Jul 2026 22:04:01 +0300 Subject: [PATCH 2/7] Set tm_scope to none for B --- lib/linguist/languages.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/linguist/languages.yml b/lib/linguist/languages.yml index 10a6dd6c7c..5f62b2148f 100644 --- a/lib/linguist/languages.yml +++ b/lib/linguist/languages.yml @@ -534,7 +534,7 @@ B: color: "#da7666" extensions: - ".b" - tm_scope: source.b + tm_scope: none ace_mode: text B (Formal Method): type: programming From 54781e051c0cd4985b444676b9e90623e8c25788 Mon Sep 17 00:00:00 2001 From: aceinetx Date: Sun, 5 Jul 2026 22:04:17 +0300 Subject: [PATCH 3/7] Add more samples for B --- samples/B/array.b | 20 +++++++++++++ samples/B/carrying_statement.b | 1 + samples/B/char.b | 7 +++++ samples/B/curses.b | 25 ++++++++++++++++ samples/B/duffs_device.b | 26 ++++++++++++++++ samples/B/lower.b | 11 +++++++ samples/B/printf.b | 55 ++++++++++++++++++++++++++++++++++ samples/B/printn.b | 14 +++++++++ 8 files changed, 159 insertions(+) create mode 100644 samples/B/array.b create mode 100644 samples/B/carrying_statement.b create mode 100644 samples/B/char.b create mode 100644 samples/B/curses.b create mode 100644 samples/B/duffs_device.b create mode 100644 samples/B/lower.b create mode 100644 samples/B/printf.b create mode 100644 samples/B/printn.b diff --git a/samples/B/array.b b/samples/B/array.b new file mode 100644 index 0000000000..1777f8c94f --- /dev/null +++ b/samples/B/array.b @@ -0,0 +1,20 @@ +array[5] 1, 2, 3, 4, 5; + +sum(array, size){ + auto sum 0; + auto i 0; while(i < 5){ + sum =+ array[i]; + i++; + } + return(sum); +} + +main(){ + extrn printf; + auto i 0; while(i < 5){ + printf("%d*n", array[i]); + i++; + } + printf("sum = %d*n", sum(array, 5)); + return(0); +} diff --git a/samples/B/carrying_statement.b b/samples/B/carrying_statement.b new file mode 100644 index 0000000000..6eaab6ca9b --- /dev/null +++ b/samples/B/carrying_statement.b @@ -0,0 +1 @@ +main() extrn printf; auto i 123; printf("%d*n", i); diff --git a/samples/B/char.b b/samples/B/char.b new file mode 100644 index 0000000000..42424472ae --- /dev/null +++ b/samples/B/char.b @@ -0,0 +1,7 @@ +char(string, i){ + return(*(string + i) & 255); +} + +lchar(string, i, char){ + *(string + i) = char & 255; +} diff --git a/samples/B/curses.b b/samples/B/curses.b new file mode 100644 index 0000000000..25591fc78e --- /dev/null +++ b/samples/B/curses.b @@ -0,0 +1,25 @@ +main(){ + extrn initscr, endwin, curs_set, clear, mvprintw, refresh, getch; + auto k, x 1, y 1; + + initscr(); + curs_set(0); + + while(1){ + clear(); + + mvprintw(0, 0, "Hello, from B!"); + mvprintw(y, x, "@"); + + refresh(); + + k = getch(); + if(k == 'q') break; + else if(k == 'w') y =- 1; + else if(k == 's') y =+ 1; + else if(k == 'a') x =- 1; + else if(k == 'd') x =+ 1; + } + + endwin(); +} diff --git a/samples/B/duffs_device.b b/samples/B/duffs_device.b new file mode 100644 index 0000000000..305c39ee5c --- /dev/null +++ b/samples/B/duffs_device.b @@ -0,0 +1,26 @@ +/* https://github.com/bext-lang/b/blob/main/examples/duffs_device.b */ +/* // https://en.wikipedia.org/wiki/Duff%27s_device */ +duffs_device(s) { + extrn strlen, putchar; + auto n, count; + count = strlen(s); + n = (count + 7) / 8; + switch count%8 { + case 0: while(1) { putchar(*s++); + case 7: putchar(*s++); + case 6: putchar(*s++); + case 5: putchar(*s++); + case 4: putchar(*s++); + case 3: putchar(*s++); + case 2: putchar(*s++); + case 1: putchar(*s++); + putchar('|'); + putchar(10); + if (--n <= 0) return(0); + } + } +} + +main() { + duffs_device("The quick brown fox jumps over the lazy dog."); +} diff --git a/samples/B/lower.b b/samples/B/lower.b new file mode 100644 index 0000000000..857aea4e33 --- /dev/null +++ b/samples/B/lower.b @@ -0,0 +1,11 @@ +/* https://www.nokia.com/bell-labs/about/dennis-m-ritchie/bref.html */ +/* This function replaces each upper case character in the input +string s by its lower case equivalent. It uses the fact that +the ascii alphabetic characters are contiguous. */ + +lower(s) { + auto c,i; + i = -1; + while( (c=char(s,++i)) != '*e' ) + if( c >= 'A' & c <= 'Z' ) lchar(s~i~c-'A'+'a'); +} diff --git a/samples/B/printf.b b/samples/B/printf.b new file mode 100644 index 0000000000..d4368e3337 --- /dev/null +++ b/samples/B/printf.b @@ -0,0 +1,55 @@ +/* https://www.nokia.com/bell-labs/about/dennis-m-ritchie/kbman.html */ +/* The following function is a general formatting, printing, and + conversion subroutine. The first argument is a format string. + Character sequences of the form `%x' are interpreted and cause + conversion of type 'x' of the next argument, other character + sequences are printed verbatim. Thus + + printf("delta is %d*n", delta); + + will convert the variable delta to decimal (%d) and print the + string with the converted form of delta in place of %d. The + conversions %d-decimal, %o-octal, *s-string and %c-character + are allowed. + + This program calls upon the function `printn'. (see section + 9.1) */ + +printf(fmt, x1,x2,x3,x4,x5,x6,x7,x8,x9) { + extrn printn, char, putchar; + auto adx, x, c, i, j; + + i= 0; /* fmt index */ + adx = &x1; /* argument pointer */ +loop : + while((c=char(fmt,i++) ) != `%') { + if(c == `*e') + return; + putchar(c); + } + x = *adx++; + switch c = char(fmt,i++) { + + case `d': /* decimal */ + case `o': /* octal */ + if(x < O) { + x = -x ; + putchar('-'); + } + printn(x, c=='o'?8:1O); + goto loop; + + case 'c' : /* char */ + putchar(x); + goto loop; + + case 's': /* string */ + while(c=char(x, j++)) != '*e') + putchar(c); + goto loop; + } + putchar('%') ; + i--; + adx--; + goto loop; +} diff --git a/samples/B/printn.b b/samples/B/printn.b new file mode 100644 index 0000000000..1e449d9e64 --- /dev/null +++ b/samples/B/printn.b @@ -0,0 +1,14 @@ +/* https://www.nokia.com/bell-labs/about/dennis-m-ritchie/kbman.html */ +/* The following function will print a non-negative number, n, to + the base b, where 2<=b<=10, This routine uses the fact that + in the ANSCII character set, the digits O to 9 have sequential + code values. */ + +printn(n,b) { + extrn putchar; + auto a; + + if(a=n/b) /* assignment, not test for equality */ + printn(a, b); /* recursive */ + putchar(n%b + '0'); +} From fe3d1e854ffd811724a523512422f15a1f88a283 Mon Sep 17 00:00:00 2001 From: aceinetx Date: Sun, 5 Jul 2026 22:23:00 +0300 Subject: [PATCH 4/7] Add heuristics for B --- lib/linguist/heuristics.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/linguist/heuristics.yml b/lib/linguist/heuristics.yml index c621d3ab4c..89b814a9cb 100644 --- a/lib/linguist/heuristics.yml +++ b/lib/linguist/heuristics.yml @@ -107,6 +107,11 @@ disambiguations: - language: LTspice Symbol pattern: '^SymbolType[ \t]' - language: Asymptote +- extensions: ['.b'] + rules: + - language: B + pattern: '^\s*(?:extrn|auto|goto)\b' + negative_pattern: '^\s*(?:implement|include|load|ref)\b' - extensions: ['.bas'] rules: - language: B4X From 276e3115f34aacfc7e2128eaf9e5f970ebbd903d Mon Sep 17 00:00:00 2001 From: aceinetx Date: Sun, 5 Jul 2026 22:48:05 +0300 Subject: [PATCH 5/7] Add language ID for B --- lib/linguist/languages.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/linguist/languages.yml b/lib/linguist/languages.yml index 5f62b2148f..d695840a56 100644 --- a/lib/linguist/languages.yml +++ b/lib/linguist/languages.yml @@ -536,6 +536,7 @@ B: - ".b" tm_scope: none ace_mode: text + language_id: 700792152 B (Formal Method): type: programming color: "#8aa8c5" From 6d4e06f18b6fcee542b969e372176b6b45b7b514 Mon Sep 17 00:00:00 2001 From: aceinetx Date: Fri, 17 Jul 2026 20:11:39 +0300 Subject: [PATCH 6/7] Use C's TextMate scope for B --- lib/linguist/languages.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/linguist/languages.yml b/lib/linguist/languages.yml index d695840a56..c17e2ff20a 100644 --- a/lib/linguist/languages.yml +++ b/lib/linguist/languages.yml @@ -534,7 +534,7 @@ B: color: "#da7666" extensions: - ".b" - tm_scope: none + tm_scope: source.c ace_mode: text language_id: 700792152 B (Formal Method): From 41f79a45ef9575c3be976f2dd6c0b6e9f660a19e Mon Sep 17 00:00:00 2001 From: aceinetx Date: Fri, 17 Jul 2026 20:15:09 +0300 Subject: [PATCH 7/7] Reuse Brainfuck and Limbo heuristics for .b file type --- lib/linguist/heuristics.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/linguist/heuristics.yml b/lib/linguist/heuristics.yml index 89b814a9cb..649505fe7a 100644 --- a/lib/linguist/heuristics.yml +++ b/lib/linguist/heuristics.yml @@ -112,6 +112,10 @@ disambiguations: - language: B pattern: '^\s*(?:extrn|auto|goto)\b' negative_pattern: '^\s*(?:implement|include|load|ref)\b' + - language: Brainfuck + pattern: '(>\+>|>\+<)' + - language: Limbo + pattern: '^\w+\s*:\s*module\s*\{' - extensions: ['.bas'] rules: - language: B4X