Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions lib/linguist/heuristics.yml
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,15 @@ 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'
- language: Brainfuck
pattern: '(>\+>|>\+<)'
- language: Limbo
pattern: '(?:^\w+\s*:\s*module\s*\{)|(implement \w+;)'
- extensions: ['.bas']
rules:
- language: B4X
Expand Down
10 changes: 9 additions & 1 deletion lib/linguist/languages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -539,14 +539,22 @@ Awk:
tm_scope: source.awk
ace_mode: text
language_id: 28
B:
type: programming
color: "#da7666"
extensions:
- ".b"
tm_scope: source.c
ace_mode: text
language_id: 700792152
B (Formal Method):
type: programming
color: "#8aa8c5"
extensions:
- ".mch"
tm_scope: source.b
ace_mode: text
language_id: 700792152
language_id: 993355937
B4X:
type: programming
color: "#00e4ff"
Expand Down
65 changes: 65 additions & 0 deletions samples/B/brtb.b
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/* brtb.b - B run-time library */

char(s, n) {
if (n & 1) return(s[n/2] & 0777);
return((s[n/2]/512) & 0777);
}

lchar(s, n, c) {
if (n & 1) s[n/2] = (s[n/2] & 0777000) | c;
else s[n/2] = (s[n/2] & 0777) | (c*512);
return(c);
}

putnum(n, b) {
auto a, d;

d = 0;
if (n < 0) {
n = -n;
if (n < 0) {
n = n-1;
d = 1;
} else
putchar('-');
}
if (a = n/b)
putnum(a, b);
putchar(n%b + '0' + d);
}

printf(fmt,x1,x2,x3,x4,x5,x6,x7,x8,x9) {
auto adx, a, c, i, n;

i = 0;
adx = &x1;
loop:
while ((c = char(fmt, i)) != '%') {
if (c == '*e')
return;
putchar(c);
i = i+1;
}
i = i+1;
a = *adx;
c = char(fmt, i);
if (c=='d')
putnum(a, 10);
else if (c=='o')
putnum(a, 8);
else if (c=='c')
putchar(a);
else if (c=='s') {
n = 0;
while ((c = char(a, n)) != '*e') {
putchar(c);
n = n+1;
}
} else {
putchar('%');
goto loop;
}
i = i+1;
adx = adx+1;
goto loop;
}
40 changes: 40 additions & 0 deletions samples/B/cat.b
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
EOF 4294967295 /* -1 */;

from_stdin(){
extrn getchar, putchar;
auto c;
while((c = getchar()) != EOF){
putchar(c);
}
return(0);
}

from_args(argc, argv){
extrn perror, fopen, fclose, putchar, fgetc;
auto i, fp, c;
i = 1;
while(i < argc){
fp = fopen(argv[i], "r");
if(!fp){
perror("fopen");
return(1);
}

while((c = fgetc(fp)) != EOF){
putchar(c);
}

fclose(fp);

i++;
}
return(0);
}

main(argc, argv){
if(argc <= 1){
return(from_stdin());
} else {
return(from_args(argc, argv));
}
}
31 changes: 31 additions & 0 deletions samples/B/shell.b
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
cmd[512];

lchar(string, i, char){
*(string + i) = char & 255;
}

starts_with(s1, s2){
extrn memcmp, strlen;
if(strlen(s1) < strlen(s2)) return(0);
return(!memcmp(s1, s2, strlen(s2)));
}

main(){
extrn stdin, fflush, fgets, strlen, strcmp, memset, printf, chdir, system;

while(1){
printf("$ ");
fflush(stdin);

memset(cmd, 0, 512);
if(!fgets(cmd, 512, stdin)) goto quit;
lchar(cmd, strlen(cmd) - 1, 0); /* remove newline */

if(strcmp(cmd, "exit") == 0){
goto quit;
} else if(starts_with(cmd, "cd ")){
chdir(cmd + 3);
} else system(cmd);
}
quit:
}
8 changes: 8 additions & 0 deletions test/test_heuristics.rb
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,14 @@ def test_asy_by_heuristics
})
end

def test_b_by_heuristics
assert_heuristics({
"B" => all_fixtures("B", "*.b"),
"Limbo" => all_fixtures("Limbo", "*.b"),
"Brainfuck" => all_fixtures("Brainfuck", "*.b")
})
end

def test_bas_by_heuristics
assert_heuristics({
"B4X" => all_fixtures("B4X", "*.bas"),
Expand Down
1 change: 1 addition & 0 deletions vendor/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ This is a list of grammars that Linguist selects to provide syntax highlighting
- **AutoIt:** [AutoIt/SublimeAutoItScript](https://github.com/AutoIt/SublimeAutoItScript)
- **Avro IDL:** [Jason3S/avro.tmLanguage](https://github.com/Jason3S/avro.tmLanguage)
- **Awk:** [github-linguist/awk-sublime](https://github.com/github-linguist/awk-sublime)
- **B:** [mikomikotaishi/c.tmbundle](https://github.com/mikomikotaishi/c.tmbundle)
- **B (Formal Method):** [JJWRoeloffs/b-vscode](https://github.com/JJWRoeloffs/b-vscode)
- **B4X:** [serkonda7/vscode-vba](https://github.com/serkonda7/vscode-vba)
- **BAML:** [boundaryml/textMate-baml](https://github.com/boundaryml/textMate-baml)
Expand Down
Loading