Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow optional capital letters and numbers in code Beta #295

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
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
179 changes: 127 additions & 52 deletions docs/translations_report.md

Large diffs are not rendered by default.

22 changes: 20 additions & 2 deletions packages/keybr-code/lib/syntax.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { type Rules } from "./ast.ts";
import { generate } from "./generate.ts";
import { Output } from "./output.ts";
import lang_cpp from "./syntax/lang_cpp.ts";
import lang_go from "./syntax/lang_go.ts";
import lang_html_css from "./syntax/lang_html_css.ts";
import lang_javascript from "./syntax/lang_javascript.ts";
import lang_python from "./syntax/lang_python.ts";
Expand Down Expand Up @@ -66,6 +67,11 @@ export class Syntax implements EnumItem {
"Python",
lang_python,
);
static readonly GO = new Syntax(
"go", //
"Go",
lang_go,
);
static readonly ALL = new Enum<Syntax>(
Syntax.HTML,
Syntax.CSS,
Expand All @@ -88,14 +94,26 @@ export class Syntax implements EnumItem {
Object.freeze(this);
}

generate(rng?: RNG): string {
generate(
rng?: RNG,
includeCapitalization: boolean = false,
includeNumbers: boolean = false,
): string {
const output = new Output(200);
while (true) {
try {
if (output.length > 0) {
output.separate(" ");
}
generate(this.rules, this.start, { output, rng });
let startRule = this.start;
if (includeCapitalization && includeNumbers) {
startRule += "_capitalization_and_numbers";
} else if (includeCapitalization) {
startRule += "_capitalization";
} else if (includeNumbers) {
startRule += "_numbers";
}
generate(this.rules, startRule, { output, rng });
} catch (err) {
if (err === Output.Stop) {
break;
Expand Down
9 changes: 9 additions & 0 deletions packages/keybr-code/lib/syntax/lang_cpp.g
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
start -> c_func ;
start_capitalization -> c_func ;
start_numbers -> c_func ;
start_capitalization_and_numbers -> c_func ;

start_fproto -> c_func_proto ";" ;
start_fproto_capitalization -> c_func_proto ";" ;
start_fproto_numbers -> c_func_proto ";" ;
start_fproto_capitalization_and_numbers -> c_func_proto ";" ;

start_stmt -> c_stmt ;
start_stmt_capitalization -> c_stmt ;
start_stmt_numbers -> c_stmt ;
start_stmt_capitalization_and_numbers -> c_stmt ;

c_func -> c_func_proto _ c_func_body ;

Expand Down
42 changes: 42 additions & 0 deletions packages/keybr-code/lib/syntax/lang_cpp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,15 @@ export default {
start: {
ref: "c_func",
},
start_capitalization: {
ref: "c_func",
},
start_numbers: {
ref: "c_func",
},
start_capitalization_and_numbers: {
ref: "c_func",
},
start_fproto: {
seq: [
{
Expand All @@ -14,9 +23,42 @@ export default {
";",
],
},
start_fproto_capitalization: {
seq: [
{
ref: "c_func_proto",
},
";",
],
},
start_fproto_numbers: {
seq: [
{
ref: "c_func_proto",
},
";",
],
},
start_fproto_capitalization_and_numbers: {
seq: [
{
ref: "c_func_proto",
},
";",
],
},
start_stmt: {
ref: "c_stmt",
},
start_stmt_capitalization: {
ref: "c_stmt",
},
start_stmt_numbers: {
ref: "c_stmt",
},
start_stmt_capitalization_and_numbers: {
ref: "c_stmt",
},
c_func: {
seq: [
{
Expand Down
Loading