Skip to content
This repository has been archived by the owner on Apr 22, 2020. It is now read-only.

Patch 1: makefile + fixes #467

Merged
merged 13 commits into from Jan 18, 2017
Merged

Conversation

amroamroamro
Copy link
Contributor

summary:

  • Makefile was given an update
  • added a variable HACK_TO_FIX_JS_INCLUDE_PL in js-modules/prettify.js as a hack so that the line include('defs.js') is correctly handled
  • reapplied some previous commits to the unprocessed file js-modules/prettify.js which were only modifying the generated src/prettify.js
  • added some new C/C++ keywords and types
  • some minor fixes
  • doc edits

I also ran make and committed the generated files (in preparation for a last release using makefile before we switch to grunt).

Instead of relying on timestamped dummy files to track dependencies,
we create a list of separate targets to build from their corresponding
sources. This is a better design because it allows recompiling only
the modified targets instead of all or nothing.

However the timestamp approach was kept for the lang-aliases rule
because the alias targets are not known in advance and have to be
extracted out of the language handler scripts.

The code to extract lang-alias was ported to a node.js script,
instead of the existing solution based on bash + perl + js-interpreter.

The compiled files are placed directly into the "loader" folder, and
and old cruft is dropped (no need for multiple archive formats
TAR/TGZ/BZ2), instead only one ZIP archive is generated in the
"distrib" folder.
C99: restrict
C++11: alignas, noexcept, noreturn
C_TYPES (STL containers): array, forward_*, reverse_*, unordered_*
include('defs.js') in prettify.js was inserted in the wrong place,
this is because of the way the perl script expects surrounding lines to
look like.
So we add a dummy variable declaration without preceding comment lines.
* Widely used with good cross-browser support. Powers https://code.google.com/
and http://stackoverflow.com/

[See an example][2].
Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for writing docs.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I actually lifted that features list from the old wiki pages :)
https://github.com/google/code-prettify/blob/wiki/ProjectHome.md

| callback=js_ident | | `window.exports["js_ident"]` will be called when prettyprinting finishes. If specified multiple times, all are called. |
| CGI parameter | default | meaning |
| --------------------- | ------- | ------------------------------ |
| autorun=(true, false) | true | run automatically on page load |
Copy link
Contributor

Choose a reason for hiding this comment

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

Good catch.

"internal,into,is,let,lock,null,object,out,override,orderby,params," +
"partial,readonly,ref,sbyte,sealed,stackalloc,string,select,uint,ulong," +
"unchecked,unsafe,ushort,var,virtual,where"];
"abstract,add,alias,as,ascending,async,await,base,bool,by,byte,checked,decimal,delegate,descending," +
Copy link
Contributor

Choose a reason for hiding this comment

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

I'll take your word for it. C#'s keyword list is approaching the union of all other language's keywords.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm actually re-applying previous patches here that were mistakenly undone later. I didn't add any new C# keywords myself: PR #384 and PR #418

@@ -1662,7 +1665,7 @@ var IN_GLOBAL_SCOPE = false;
'keywords': JSCRIPT_KEYWORDS,
'cStyleComments': true,
'regexLiterals': true
}), ['javascript', 'js']);
}), ['javascript', 'js', 'ts', 'typescript']);
Copy link
Contributor

Choose a reason for hiding this comment

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

Note to self: we can think about .jsx down the road.

(Apparently Facebook reinvented E4X and is calling it React JS.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

same thing, this is coming from an already merged PR #423, which modified the generated file src/prettify.js and not the actual source in js-modules/prettify.js.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

(JSX style of mixing JS/XML syntax would be a nice addition)

@@ -0,0 +1,87 @@
#!/usr/bin/env node
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yep. I should mention that I rewrote this script again, in a later patch, as a grunt plugin..


// for each unique alias, copy file if not already exist
langExtensions.filter(function (ext, pos) {
return langExtensions.indexOf(ext) == pos;
Copy link
Contributor

Choose a reason for hiding this comment

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

Note to self: equivalent of | uniq.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

correct, I think I borrowed it from here: http://stackoverflow.com/a/14438954/97160

We could shorten some of this stuff by using a library like underscore or lodash, but I wanted to avoid adding npm dependencies if possible

Copy link
Contributor

Choose a reason for hiding this comment

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

+1 on minimal dependencies

});

// collect extensions list
var langExtensions = sandbox.langExtensions;
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you sort the extensions here?

I should have in the original script to remove file-system child ordering as a source of non-determinism.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok, will add .sort()

@@ -49,7 +49,7 @@
* +------------------+---------------+------------------------------+--------+
*
* Exmaples
Copy link
Contributor

Choose a reason for hiding this comment

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

Not your fault but s/Exmaples/Examples/ please.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

will do

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
PR.registerLangHandler(PR.createSimpleLexer([["pln",/^[ \n\r\t\v\f\0]+/,null," \n\r\t\v\f\x00"],["str",/^"(?:[^"\\]|(?:\\.)|(?:\\\((?:[^"\\)]|\\.)*\)))*"/,null,'"']],[["lit",/^(?:(?:0x[\da-fA-F][\da-fA-F_]*\.[\da-fA-F][\da-fA-F_]*[pP]?)|(?:\d[\d_]*\.\d[\d_]*[eE]?))[+-]?\d[\d_]*/,null],["lit",/^-?(?:(?:0(?:(?:b[01][01_]*)|(?:o[0-7][0-7_]*)|(?:x[\da-fA-F][\da-fA-F_]*)))|(?:\d[\d_]*))/,null],["lit",/^(?:true|false|nil)\b/,null],["kwd",/^\b(?:__COLUMN__|__FILE__|__FUNCTION__|__LINE__|#available|#else|#elseif|#endif|#if|#line|arch|arm|arm64|associativity|as|break|case|catch|class|continue|convenience|default|defer|deinit|didSet|do|dynamic|dynamicType|else|enum|fallthrough|final|for|func|get|import|indirect|infix|init|inout|internal|i386|if|in|iOS|iOSApplicationExtension|is|lazy|left|let|mutating|none|nonmutating|operator|optional|OSX|OSXApplicationExtension|override|postfix|precedence|prefix|private|protocol|Protocol|public|required|rethrows|return|right|safe|self|set|static|struct|subscript|super|switch|throw|try|Type|typealias|unowned|unsafe|var|weak|watchOS|while|willSet|x86_64)\b/,
PR.registerLangHandler(PR.createSimpleLexer([["pln",/^[ \n\r\t\v\f\0]+/,null," \n\r\t\v\f\x00"],["str",/^"(?:[^"\\]|(?:\\.)|(?:\\\((?:[^"\\)]|\\.)*\)))*"/,null,'"']],[["lit",/^(?:(?:0x[\da-fA-F][\da-fA-F_]*\.[\da-fA-F][\da-fA-F_]*[pP]?)|(?:\d[\d_]*\.\d[\d_]*[eE]?))[+-]?\d[\d_]*/,null],["lit",/^-?(?:(?:0(?:(?:b[01][01_]*)|(?:o[0-7][0-7_]*)|(?:x[\da-fA-F][\da-fA-F_]*)))|(?:\d[\d_]*))/,null],["lit",/^(?:true|false|nil)\b/,null],["kwd",/^\b(?:__COLUMN__|__FILE__|__FUNCTION__|__LINE__|#available|#else|#elseif|#endif|#if|#line|arch|arm|arm64|associativity|as|break|case|catch|class|continue|convenience|default|defer|deinit|didSet|do|dynamic|dynamicType|else|enum|extension|fallthrough|final|for|func|get|guard|import|indirect|infix|init|inout|internal|i386|if|in|iOS|iOSApplicationExtension|is|lazy|left|let|mutating|none|nonmutating|operator|optional|OSX|OSXApplicationExtension|override|postfix|precedence|prefix|private|protocol|Protocol|public|required|rethrows|return|right|safe|self|set|static|struct|subscript|super|switch|throw|try|Type|typealias|unowned|unsafe|var|weak|watchOS|while|willSet|x86_64)\b/,
Copy link
Contributor

Choose a reason for hiding this comment

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

Note to self: adds "extension" and "guard"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, this is coming from PR #415

@@ -59,6 +59,8 @@

include("defs.js");

var HACK_TO_FIX_JS_INCLUDE_PL;
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this required by your port of jsinclude.pl? In another PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

no, I got rid of it later, along with the perl scripts and the entire makefile.

(some of these fixes were made before I started working on porting to a grunt solution)

Copy link
Contributor

Choose a reason for hiding this comment

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

Looks harmless and no need to create merge work for the patch PR.

@amroamroamro
Copy link
Contributor Author

amroamroamro commented Jan 13, 2017

The thing is files under loader/ and distrib/ directories, as well as src/(run_)prettify.js, are generated files and should not be manually edited. They are simply the result of running make.


oops, accidentally closed PR.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants