-
Notifications
You must be signed in to change notification settings - Fork 19
initial reason implementation #127
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
base: master
Are you sure you want to change the base?
Changes from all commits
c08c10e
ae0cf62
892fe7b
bddedf3
305cb37
be6aeb1
e343809
1a6ee61
0ebdaf0
0c6f983
efea624
4c66076
7248e4a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,3 +2,5 @@ node_modules | |
| .DS_Store | ||
| *.log | ||
| build | ||
| lib/bs/ | ||
| lib/js/src/ | ||
| 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. | ||
| ] | ||
| } |
| 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); |
| 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) { | ||
| | (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" | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can use the |
||
| | (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) | ||
| } | ||
| }; | ||
|
|
||
| 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; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function application 'binds more tightly' than operator application, so you can write |
||
| 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) | ||
| } | ||
| }; | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This file should be inside the
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
| } | ||
| ] | ||
| } | ||
| } | ||
There was a problem hiding this comment.
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 😊