Skip to content
Open
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@ node_modules
.DS_Store
*.log
build
lib/bs/
lib/js/src/
13 changes: 13 additions & 0 deletions bsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// This is the configuration file used by BuckleScript's build system bsb. Its documentation lives here: http://bucklescript.github.io/bucklescript/docson/#build-schema.json
// BuckleScript comes with its own parser for bsconfig.json, which is normal JSON, with the extra support of comments and trailing commas.
{
"name": "my-first-app",
"version": "0.1.0",
"bsc-flags": ["-bs-super-errors"],
"sources": [
"src"
],
"bs-dependencies" : [
// add your dependencies here. You'd usually install them normally through `npm install my-dependency`. If my-dependency has a bsconfig.json too, then everything will work seamlessly.
]
}
8 changes: 8 additions & 0 deletions lib/js/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const z = require('./src/demo.js');

// result should look like {1verb: [...], 1adjective: [...]}
const result = z.conjugate('estudiar', { tense: 'present', subject: 'ella' });
const result2 = z.conjugate('comer', { tense: 'present', subject: 'tu' });

console.log('your result is: ', result);
console.log('your result is: ', result2);
10 changes: 8 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@
"start": "babel src/conjugator.js -o build/app.js -w",
"deploy": "babel src -d build && npm publish",
"eslint": "./node_modules/.bin/eslint src --ext .js",
"eslint:watch": "./node_modules/.bin/esw src -w --color --ext .js"
"eslint:watch": "./node_modules/.bin/esw src -w --color --ext .js",
"clean": "bsb -clean-world",
"build": "bsb -make-world",
"watch": "bsb -make-world -w"
},
"repository": {
"type": "git",
Expand All @@ -36,12 +39,15 @@
"babel-preset-env": "^1.2.2",
"babel-preset-es2015": "^6.24.0",
"babel-preset-es2016": "^6.22.0",
"bs-platform": "1.9.1",
"chai": "^3.5.0",
"eslint": "^3.19.0",
"eslint-config-airbnb-base": "^11.1.3",
"eslint-plugin-import": "^2.2.0",
"eslint-watch": "^3.1.0",
"mocha": "^3.2.0"
},
"files": ["build"]
"files": [
"build"
]
}
73 changes: 73 additions & 0 deletions src/demo.re
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*
Goal:
conjugate('estudiar', { tense: 'present', subject: 'ella' });
should return estudia
*/

module Subject = {
/*
The type name becomes just `t` to avoid repetition when
accessed from outside the module
*/

type t =
| Yo
| Tu
| Ella
| Nosotras
| Vosotras
| Ellas;
let ofString =
fun
| "yo" => Yo
| "tu" => Tu
| "ella" => Ella
| "nosotras" => Nosotras
| "vosotras" => Vosotras
| _ => Ellas
};

module Ending = {
type t =
| Ar
| Er
| Ir;
let ofString =
fun
| "ar" => Ar
| "er" => Er
| _ => Ir
};

let genPresentEnding ending subject => {
switch (subject:Subject.t, ending:Ending.t) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't really need the type annotations, Reason will infer them 😊

| (Yo, _) => "o"
| (Tu, Ar) => "as"
| (Tu, _) => "es"
| (Ella, Ar) => "a"
| (Ella, _) => "e"
| (Nosotras, _) => "amos"
| (Vosotras, _) => "\195\161s"
| (Ellas, _) => "an"
}
};

let genFutureEnding ending subject => {
switch (subject:Subject.t, ending:Ending.t) {
| (Yo, _) => "\130"
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use the {js| ... |js} technique here as well for Unicode.

| (Tu, _) => "\160s"
| ()
}
};

let conjugate word info => {
let start = ( String.length word ) - 2;
let endingType = Ending.ofString (String.sub word start 2);
let stem = (String.sub word 0 start);
let subjectType = Subject.ofString info##subject;
switch info##tense {
| "present" => stem ^ (genPresentEnding endingType subjectType)
//| "future" => word ^ (genFutureEnding endingType subjectType)
}
};

80 changes: 80 additions & 0 deletions src/spanish.re
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/*
Goal:
conjugate('estudiar', { tense: 'present', subject: 'ella' });
should return estudia
*/

module Subject = {
/*
The type name becomes just `t` to avoid repetition when
accessed from outside the module
*/

type t =
| Yo
| Tu
| Ella
| Nosotras
| Vosotras
| Ellas;
let ofString =
fun
| "yo" => Yo
| "tu" => Tu
| "ella" => Ella
| "nosotras" => Nosotras
| "vosotras" => Vosotras
| _ => Ellas
};

module Ending = {
type t =
| Ar
| Er
| Ir;
let ofString =
fun
| "ar" => Ar
| "er" => Er
| _ => Ir
};

let genPresentEnding ending subject => {
switch (subject:Subject.t, ending:Ending.t) {
| (Yo, _) => "o"
| (Tu, Ar) => "as"
| (Tu, _) => "es"
| (Ella, Ar) => "a"
| (Ella, _) => "e"
| (Nosotras, Ar) => "amos"
| (Nosotras, Er) => "emos"
| (Nosotras, _) => "imos"
| (Vosotras, Ar) => {js|áis|js}
| (Vosotras, Er) => {js|éis|js}
| (Vosotras, _) => {js|ís|js}
| (Ellas, _) => "an"
}
};
let genFutureEnding ending subject => {
switch (subject:Subject.t, ending:Ending.t) {
| (Yo, _) => {js|é|js}
| (Tu, _) => {js|é|js}
| (Ella, _) => {js||js}
| (Nosotras, _) => "emos"
| (Vosotras, _) => {js|á|js}
| (Ellas, _) => {js|án|js}
}
};

let conjugate word info => {
let start = ( String.length word ) - 2;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function application 'binds more tightly' than operator application, so you can write String.length word - 2

let endingType = Ending.ofString (String.sub word start 2);
let stem = (String.sub word 0 start);
let subjectType = Subject.ofString info##subject;
switch info##tense {
| "present" => stem ^ (genPresentEnding endingType subjectType)
| "future" => word ^ (genFutureEnding endingType subjectType)
}
};


38 changes: 38 additions & 0 deletions tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file should be inside the .vscode directory

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not using visual studio (pure vim), so therefore do not have .vscode directory. Any better folder to place this in, or should I have not committed this file?

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, if you're not using Visual Studio Code, you don't need this. This is like a per-project .vimrc but for VSCode.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh wow. thanks!

"version": "0.1.0",
"command": "npm",
"options": {
"cwd": "${workspaceRoot}"
},
"isShellCommand": true,
"args": [
"run",
"watch"
],
"showOutput": "always",
"isBackground": true,
"problemMatcher": {
"fileLocation": "absolute",
"owner": "ocaml",
"watching": {
"activeOnStart": false,
"beginsPattern": ">>>> Start compiling",
"endsPattern": ">>>> Finish compiling"
},
"pattern": [
{
"regexp": "^File \"(.*)\", line (\\d+)(?:, characters (\\d+)-(\\d+))?:$",
"file": 1,
"line": 2,
"column": 3,
"endColumn": 4
},
{
"regexp": "^(?:(?:Parse\\s+)?(Warning|[Ee]rror)(?:\\s+\\d+)?:)?\\s+(.*)$",
"severity": 1,
"message": 2,
"loop": true
}
]
}
}
4 changes: 1 addition & 3 deletions test/spanish_tests.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
/* global describe, it */

import { Spanish } from '../src/spanish';
import spanish from '../lib/js/src/spanish';

const expect = require('chai').expect;

describe('Spanish', () => {
let conjugatedWord;
const spanish = new Spanish();

describe('Present Tense', () => {
it('should conjugate present tense correctly: hablar should be hablo for yo', () => {
conjugatedWord = spanish.conjugate('hablar', { tense: 'present', subject: 'yo' });
Expand Down