Permalink
Browse files

WIP: documentation.

  • Loading branch information...
1 parent cddc403 commit 58de7f89843d67b1afd468423202e74a3b916241 @ilyash committed Jan 7, 2017
Showing with 24 additions and 181 deletions.
  1. +0 −2 .gitignore
  2. +3 −0 c/todo.txt
  3. +12 −1 c/vm.c
  4. +2 −0 doc/.gitignore
  5. +5 −9 doc/Makefile
  6. +0 −2 doc/make_methods.ngs
  7. +0 −165 doc/make_methods_markdown.ngs
  8. +2 −2 doc/ngs.1.md
View
@@ -2,8 +2,6 @@
\#*
.#*
*~
-*.html
-*.1
node_modules
small-poc/ssl
TAGS
View
@@ -4,6 +4,9 @@ Note that this started as internal document so things here are unformed, not fin
Unsorted and undecided things go here. The important sections is [roadmap] and it's just below this section.
+ * C_PCRE_* - move to C_PCRE namespace
+ * Look for other sets of constants to move to namespaces
+
[roadmap]
* Phase 1 - the language (will be v0.1.0) [in progress]
View
@@ -1973,9 +1973,15 @@ void vm_init(VM *vm, int argc, char **argv) {
_doc(vm, "%RET", "The string <RegExp>");
register_global_func(vm, 1, ".", &native_attr_regexp, 2, "regexp", vm->RegExp, "attr", vm->Str);
- _doc(vm, "", "Get attributes of a RegExp. Throws AttrNotFound if attr is not one of the allowed values.");
+ _doc(vm, "", "Get attributes of a RegExp. Throws AttrNotFound if attr is not one of the allowed values. You should not use this directly. Use \"~\" and \"~~\" operators.");
_doc(vm, "attr", "\"options\" or \"names\"");
_doc(vm, "%RET", "Int for \"options\". Hash of names/indexes of named groups for \"names\".");
+ _doc_arr(vm, "%EX",
+ "/abc/i.options # 1 - case insensitive (C_PCRE_CASELESS)",
+ "/(?P<name1>abc)/i.names # Name to index Hash: {name1=1}",
+ NULL
+ );
+
// special
register_global_func(vm, 1, "args", &native_args, 0);
@@ -2180,6 +2186,11 @@ void vm_init(VM *vm, int argc, char **argv) {
_doc(vm, "", "Get BasicType (Int, Arr, Hash, ...) attribute. Throws AttrNotFound.");
_doc(vm, "attr", "Attribute to get. Currently only \"name\" and \"constructors\" are supported.");
_doc(vm, "%RET", "Str for \"name\" and Arr for \"constructors\".");
+ _doc_arr(vm, "%EX",
+ "Hash.name # String: Hash",
+ "Hash.constructors # [<Native method Hash>,<Closure Hash at ...>,...]",
+ NULL
+ );
// NormalType
register_global_func(vm, 1, ".", &native_get_attr_nt_str, 2, "obj", vm->NormalType, "attr", vm->Str);
View
@@ -1,2 +1,4 @@
+*.html
+*.1
ngsmet.1.md
ngstyp.1.md
View
@@ -1,12 +1,9 @@
-all: ngsmet.1.md ngstyp.1.md html man
+all: html man methods.html
-ngsmet.1.md: ../c/vm.c ../c/bootstrap.ngs ../c/stdlib.ngs ../c/autoload/* ngsmet.header make_methods_markdown.ngs
- (cat ngsmet.header ; ./make_methods_markdown.ngs methods) >$@
+methods.html: ../c/vm.c ../c/bootstrap.ngs ../c/stdlib.ngs ../c/autoload/* make_methods.ngs
+ ./make_methods.ngs >$@
-ngstyp.1.md: ../c/vm.c ../c/bootstrap.ngs ../c/stdlib.ngs ../c/autoload/* ngstyp.header make_methods_markdown.ngs
- (cat ngstyp.header ; ./make_methods_markdown.ngs types) >$@
-
-html: $(patsubst %.1.md,%.1.html,$(wildcard *.1.md)) ngsmet.1.md ngstyp.1.md
+html: $(patsubst %.1.md,%.1.html,$(wildcard *.1.md))
man: $(patsubst %.1.md,%.1,$(wildcard *.1.md))
%.1.html: %.1.md pandoc.css
@@ -18,5 +15,4 @@ man: $(patsubst %.1.md,%.1,$(wildcard *.1.md))
clean:
-rm *.1
-rm *.1.html
- -rm ngsmet.1.md
- -rm ngstyp.1.md
+ -rm methods.html
@@ -1,8 +1,6 @@
#!/usr/bin/env ngs
{
- # WORK IN PROGRESS! DO NOT USE YET!
-
# Autoload
AWS
ArgvMatcher
@@ -1,165 +0,0 @@
-#!/usr/bin/env ngs
-{
- # Autoload
- AWS
- ArgvMatcher
- Counter
- Iter
- KV
- Lock
- Res
- ResDef
- Stats
- Table
- Thread
-
- # Use anonymous function to exclude methods in this file
- # The inner functions are local
- F(){
-
- # http://pandoc.org/MANUAL.html#pandocs-markdown
- characters_to_escape = '\\`*_{}[]()>#+-.!'
-
-
- # TODO: consider introducing Param type
- # TODO: improve escaping
- F escape_markdown(s:Str) s.map({ if A in characters_to_escape "\\$A" else A }).join('')
- F escape_markdown(s:Str) {
- guard s == '``'
- '```` `` ````'
- }
- F escape_markdown(s:Str) {
- guard s == '````'
- '```````` ```` ````````'
- }
-
- F param_to_str(p:Hash) {
- ret = "${p.name}:${p.type.name}"
- if 'splat' in p
- ret = "${p.splat}${ret}"
- if 'dflt' in p
- ret = "${ret}=${p.dflt}"
- ret
- }
-
- F print_doc_val(v:Str, pfx:Str) {
- echo("${pfx}${v}")
- }
-
- F doc_has_key(doc:Hash, k:Str) k in doc
-
- F doc_has_key(doc:Null, k:Str) false
-
- F print_doc_key(doc:Hash, pfx:Str, k:Str) {
- econd {
- k not in doc
- null
- doc[k] is Arr
- doc[k].each(print_doc_val, pfx)
- doc[k] is Str
- print_doc_val(doc[k], pfx)
- }
- }
-
- F print_doc_key(doc:Null, pfx:Str, k:Str) null
-
- F print_method_doc(name:Str, value) {
- guard value is Arr
- guard value.all((is), Fun)
- not(value) returns null
- if ARGV[0] == 'methods' {
- echo("* **${name.escape_markdown()}**")
- }
- if ARGV[0] == 'types' {
- echo("")
- echo(" *Constructors*")
- echo("")
- }
- value.each(F(method_implementation) {
- local doc = method_implementation.attrs().doc
- params_strings = method_implementation.params().map(param_to_str)
- header_name = escape_markdown("${name}(${params_strings.join(', ')})")
- echo(" * $header_name")
- if doc_has_key(doc, "") {
- echo("")
- echo(" *Description*")
- echo("")
- print_doc_key(doc, " ", "")
- echo("")
- }
- # if method_implementation.params().any(F(param) {doc_has_key(doc, param.name)}) {
- # echo("### Parameters")
- # }
- method_implementation.params().each(F(param) {
- param_string = param_to_str(param)
- if doc_has_key(doc, param.name) {
- echo("")
- echo(" *Parameter* **${param_string}**")
- echo("")
- print_doc_key(doc, " ", param.name)
- }
- })
- if doc_has_key(doc, '%RET') {
- echo("")
- echo(" *Returns*")
- echo("")
- print_doc_key(doc, " ", '%RET')
- }
- if doc_has_key(doc, '%EX') {
- echo("")
- echo(" *Example*")
- echo("")
- print_doc_key(doc, " ", '%EX')
- }
- echo("")
- })
- }
-
- F print_type_doc(name:Str, value) {
- echo("* **${name.escape_markdown()}**")
- local doc = try value.attrs().doc
- not(doc) returns null
- if doc_has_key(doc, "") {
- echo("")
- echo(" *Description*")
- echo(" ")
- print_doc_key(doc, " ", "")
- echo("")
- }
- if doc is Hash {
- doc.keys().each(F(k) {
- if k != "" {
- echo("")
- echo(" *Field* **${k.escape_markdown()}**")
- echo("")
- print_doc_key(doc, " ", k)
- }
- })
- }
- echo("")
- }
-
- F is_private_name(name:Str) name ~ Pfx('_')
- F is_public_name(name:Str) not(is_private_name(name))
-
- g = globals()
- g.keys().filter(is_public_name).sort(lte).each(F(name) {
- value = g[name]
- cond {
- (ARGV[0] == 'methods') and (value is Arr) and value.all(is, Fun)
- print_method_doc(name, value)
- (ARGV[0] == 'types') and (value is Type) {
- print_type_doc(name, value)
- c = value.constructors
- if value is NormalType {
- # NormalType has special constructor which we can't handle for now
- # so skipping that one
- c = c[1..null]
- }
- print_method_doc(name, c)
- }
- }
- })
-
- }()
-}
View
@@ -81,8 +81,8 @@ Located in `NGS_DIR`. Standard library. Defines many methods and autoloading beh
|-|-|
|[ngslang(1)](ngslang.1.html)| NGS language tutorial |
|[ngssyn(1)](ngssyn.1.html)| NGS language syntax|
-|[ngstyp(1)](ngstyp.1.html)| NGS language pre-defined types|
-|[ngsmet(1)](ngsmet.1.html)| NGS language pre-defined methods|
+|[ngstyp(1)](ngstyp.1.html)| NGS language pre-defined types (not ready yet)|
+|[methods.html](methods.html)| NGS language pre-defined methods|
# THANKS

0 comments on commit 58de7f8

Please sign in to comment.