From b10bf62963349828068f735771a87f0d4a5214d8 Mon Sep 17 00:00:00 2001 From: Grzegorz Adam Hankiewicz Date: Sat, 26 Jul 2014 11:57:26 +0200 Subject: Documents pretty command. --- doc/advopt.txt | 1 + doc/nimrodc.txt | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+) (limited to 'doc') diff --git a/doc/advopt.txt b/doc/advopt.txt index 08465e457..7a11e9041 100644 --- a/doc/advopt.txt +++ b/doc/advopt.txt @@ -12,6 +12,7 @@ Advanced commands: module dependency graph //dump dump all defined conditionals and search paths //check checks the project for syntax and semantic + //pretty homogenizes source code style //idetools compiler support for IDEs: possible options: --track:FILE,LINE,COL track a file/cursor position --trackDirty:DIRTY_FILE,ORIG_FILE,LINE,COL diff --git a/doc/nimrodc.txt b/doc/nimrodc.txt index 428c42f39..90fad7f9c 100644 --- a/doc/nimrodc.txt +++ b/doc/nimrodc.txt @@ -540,6 +540,58 @@ in C/C++). **Note**: This pragma will not exist for the LLVM backend. +Source code style +================= + +Nimrod allows you to `mix freely case and underscores as identifier separators +`_, so variables named ``MyPrecioussInt`` and +``my_preciouss_int`` are equivalent: + +.. code-block:: Nimrod + var MyPrecioussInt = 3 + # Following line compiles fine! + echo my_preciouss_int + +Since this can lead to many variants of the same source code (you can use +`nimgrep `_ instead of your typical ``grep`` to ignore style +problems) the compiler provides the command ``pretty`` to help unifying the +style of source code. Running ``nimrod pretty ugly_test.nim`` with this +example will generate a secondary file named ``ugly_test.pretty.nim`` with the +following content: + +.. code-block:: Nimrod + var MyPrecioussInt = 3 + # Following line compiles fine! + echo MyPrecioussInt + +During execution the ``pretty`` command will also run on Nimrod's standard +library, since it doesn't differentiate the standard library as something +special, and hence will warn of many *errors* which are out of your hand to +fix, creating respective ``.pretty.nim`` files all the way. You can ignore +these errors if they don't belong to your source and simply compare your +original version to the new pretty one. In fact, running ``pretty`` on our test +file will show the following:: + + Hint: ugly_test [Processing] + ugly_test.nim(1, 4) Error: name should be: myPrecioussInt + ugly_test.nim(1, 4) Error: name should be: myPrecioussInt + +At the moment ``pretty`` will homogenize the style of symbols but will leave +important changes for you to review. In this case the command is warning that a +variable name should not start with a capital letter, which is usually reserved +to `object types `_. To learn about the accepted `camel case +style `_ read `Coding Guidelines in +the Internals of Nimrod Compiler `_ or `Coding +Guidelines `_ and `NEP 1 +: Style Guide for Nimrod Code +`_ +from the Nimrod `GitHub wiki`_. + +This command is safe to run because it will never attempt to overwrite your +existing sources, but the respective ``.pretty.nim`` files **will** be +overwritten without notice. + + DynlibOverride ============== -- cgit 1.4.1-2-gfad0 From b87ec14579ac89b56be9d0b5788f3788f836245a Mon Sep 17 00:00:00 2001 From: Grzegorz Adam Hankiewicz Date: Sun, 27 Jul 2014 00:21:23 +0200 Subject: Factors common documentation in fragment to avoid repetition. --- doc/manual.txt | 32 +------------------------------- doc/sets_fragment.txt | 40 ++++++++++++++++++++++++++++++++++++++++ doc/tut1.txt | 41 +---------------------------------------- 3 files changed, 42 insertions(+), 71 deletions(-) create mode 100644 doc/sets_fragment.txt (limited to 'doc') diff --git a/doc/manual.txt b/doc/manual.txt index 54c1477e8..53700ae80 100644 --- a/doc/manual.txt +++ b/doc/manual.txt @@ -1221,38 +1221,8 @@ branch switch ``system.reset`` has to be used. Set type -------- -The set type models the mathematical notion of a set. The set's -basetype can only be an ordinal type. The reason is that sets are implemented -as high performance bit vectors. - -Sets can be constructed via the set constructor: ``{}`` is the empty set. The -empty set is type compatible with any special set type. The constructor -can also be used to include elements (and ranges of elements) in the set: - -.. code-block:: nimrod - - {'a'..'z', '0'..'9'} # This constructs a set that contains the - # letters from 'a' to 'z' and the digits - # from '0' to '9' - -These operations are supported by sets: - -================== ======================================================== -operation meaning -================== ======================================================== -``A + B`` union of two sets -``A * B`` intersection of two sets -``A - B`` difference of two sets (A without B's elements) -``A == B`` set equality -``A <= B`` subset relation (A is subset of B or equal to B) -``A < B`` strong subset relation (A is a real subset of B) -``e in A`` set membership (A contains element e) -``A -+- B`` symmetric set difference (= (A - B) + (B - A)) -``card(A)`` the cardinality of A (number of elements in A) -``incl(A, elem)`` same as A = A + {elem} -``excl(A, elem)`` same as A = A - {elem} -================== ======================================================== +.. include:: sets_fragment.txt Reference and pointer types --------------------------- diff --git a/doc/sets_fragment.txt b/doc/sets_fragment.txt new file mode 100644 index 000000000..fba355269 --- /dev/null +++ b/doc/sets_fragment.txt @@ -0,0 +1,40 @@ +The set type models the mathematical notion of a set. The set's +basetype can only be an ordinal type. The reason is that sets are implemented +as high performance bit vectors. + +Sets can be constructed via the set constructor: ``{}`` is the empty set. The +empty set is type compatible with any concrete set type. The constructor +can also be used to include elements (and ranges of elements): + +.. code-block:: nimrod + type + TCharSet = set[char] + var + x: TCharSet + x = {'a'..'z', '0'..'9'} # This constructs a set that contains the + # letters from 'a' to 'z' and the digits + # from '0' to '9' + +These operations are supported by sets: + +================== ======================================================== +operation meaning +================== ======================================================== +``A + B`` union of two sets +``A * B`` intersection of two sets +``A - B`` difference of two sets (A without B's elements) +``A == B`` set equality +``A <= B`` subset relation (A is subset of B or equal to B) +``A < B`` strong subset relation (A is a real subset of B) +``e in A`` set membership (A contains element e) +``e notin A`` A does not contain element e +``contains(A, e)`` A contains element e +``A -+- B`` symmetric set difference (= (A - B) + (B - A)) +``card(A)`` the cardinality of A (number of elements in A) +``incl(A, elem)`` same as ``A = A + {elem}`` +``excl(A, elem)`` same as ``A = A - {elem}`` +================== ======================================================== + +Sets are often used to define a type for the *flags* of a procedure. This is +a much cleaner (and type safe) solution than just defining integer +constants that should be ``or``'ed together. diff --git a/doc/tut1.txt b/doc/tut1.txt index a2aa835ee..55eb0ebd7 100644 --- a/doc/tut1.txt +++ b/doc/tut1.txt @@ -1117,47 +1117,8 @@ avoid this common programming error. Sets ---- -The set type models the mathematical notion of a set. The set's -basetype can only be an ordinal type. The reason is that sets are implemented -as high performance bit vectors. - -Sets can be constructed via the set constructor: ``{}`` is the empty set. The -empty set is type compatible with any concrete set type. The constructor -can also be used to include elements (and ranges of elements): - -.. code-block:: nimrod - type - TCharSet = set[char] - var - x: TCharSet - x = {'a'..'z', '0'..'9'} # This constructs a set that contains the - # letters from 'a' to 'z' and the digits - # from '0' to '9' - -These operations are supported by sets: - -================== ======================================================== -operation meaning -================== ======================================================== -``A + B`` union of two sets -``A * B`` intersection of two sets -``A - B`` difference of two sets (A without B's elements) -``A == B`` set equality -``A <= B`` subset relation (A is subset of B or equal to B) -``A < B`` strong subset relation (A is a real subset of B) -``e in A`` set membership (A contains element e) -``e notin A`` A does not contain element e -``contains(A, e)`` A contains element e -``A -+- B`` symmetric set difference (= (A - B) + (B - A)) -``card(A)`` the cardinality of A (number of elements in A) -``incl(A, elem)`` same as ``A = A + {elem}`` -``excl(A, elem)`` same as ``A = A - {elem}`` -================== ======================================================== - -Sets are often used to define a type for the *flags* of a procedure. This is -a much cleaner (and type safe) solution than just defining integer -constants that should be ``or``'ed together. +.. include:: sets_fragment.txt Arrays ------ -- cgit 1.4.1-2-gfad0 From bddfe007b6975687102e924cebab0497ea93584f Mon Sep 17 00:00:00 2001 From: Grzegorz Adam Hankiewicz Date: Sat, 2 Aug 2014 20:51:21 +0200 Subject: Adds placeholder text for js disabled browsers. Refs #1292. --- doc/lib.txt | 6 ++++-- web/babelpkglist.nim | 6 ++---- 2 files changed, 6 insertions(+), 6 deletions(-) (limited to 'doc') diff --git a/doc/lib.txt b/doc/lib.txt index 2da753007..5bacfcc4f 100644 --- a/doc/lib.txt +++ b/doc/lib.txt @@ -594,7 +594,8 @@ compiler. .. raw:: html -
+
If you are reading this you are missing + babelpkglist.js or have javascript disabled in your browser.
Unofficial packages ------------------- @@ -605,7 +606,8 @@ Nimrod programming language. .. raw:: html -
+
If you are reading this you are missing + babelpkglist.js or have javascript disabled in your browser.
diff --git a/web/babelpkglist.nim b/web/babelpkglist.nim index 8de6047ef..e8f9efc1b 100644 --- a/web/babelpkglist.nim +++ b/web/babelpkglist.nim @@ -50,19 +50,17 @@ proc processContent(content: string) = var officialPkgListDiv = document.getElementById("officialPkgList") - officialPkgListDiv.innerHTML.add( + officialPkgListDiv.innerHTML = p("There are currently " & $officialCount & " official packages in the Babel package repository.") & ul(officialList) - ) var unofficialPkgListDiv = document.getElementById("unofficialPkgList") - unofficialPkgListDiv.innerHTML.add( + unofficialPkgListDiv.innerHTML = p("There are currently " & $unofficialCount & " unofficial packages in the Babel package repository.") & ul(unofficialList) - ) proc gotPackageList(apiReply: TData) {.exportc.} = let decoded = decodeContent($apiReply.content) -- cgit 1.4.1-2-gfad0