Skip to content
This repository has been archived by the owner on Jul 9, 2024. It is now read-only.

Commit

Permalink
minor changes
Browse files Browse the repository at this point in the history
  • Loading branch information
sergioramos committed May 23, 2012
1 parent 597d479 commit 385f0e9
Show file tree
Hide file tree
Showing 9 changed files with 51 additions and 43 deletions.
2 changes: 1 addition & 1 deletion example.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ var tags = require('lib/jsctags/ctags').Tags,
tags = new tags();

fs.readFile('./example.js', 'utf-8', function (e, data) {
tags.scan(data, __dirname + '/example.js', {commonJS: false});
tags.scan(data, __dirname + '/example.js', {commonJS: true});
console.log(tags);
});
2 changes: 1 addition & 1 deletion lib/cfa2/jscfa.js
Original file line number Diff line number Diff line change
Expand Up @@ -1165,7 +1165,7 @@ function tagVarRefsId(classifyEvents) {
n.kind = HEAP;
n.addr = exports_object_av_addr;
var p = arguments[3]; // exported property name passed as extra arg
if (p.type === STRING)
if (p && p.type === STRING)
exports_object.lines[p.value.slice(0, -1)] = p.lineno;
return;
}
Expand Down
25 changes: 12 additions & 13 deletions lib/jsctags/ctags/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,22 +36,22 @@
* ***** END LICENSE BLOCK ***** */

var parse = require('../../../narcissus/lib/parser').parse;
var _ = require('underscore')._;
var _ = require('../underscore')._;
var Interpreter = require('./interp').Interpreter;
var TagReader = require('./reader').TagReader;
var TagWriter = require('./writer').TagWriter;
var Trait = require('../traits').Trait;

exports.Tags = function(initialTags) {
exports.Tags = function (initialTags) {
this.tags = initialTags != null ? initialTags : [];
this.init();
};

exports.Tags.prototype = Object.create(Object.prototype, Trait.compose(Trait({
_search: function(id, pred) {
_search: function (id, pred) {
var shadowTag = { name: id };
var tags = this.tags;
var index = _(tags).sortedIndex(shadowTag, function(tag) {
var index = _(tags).sortedIndex(shadowTag, function (tag) {
return tag.name;
});

Expand All @@ -66,11 +66,11 @@ exports.Tags.prototype = Object.create(Object.prototype, Trait.compose(Trait({
return tags.slice(start + 1, end);
},

add: function(newTags) {
add: function (newTags) {
var tags = this.tags;
Array.prototype.push.apply(tags, newTags);

tags.sort(function(a, b) {
tags.sort(function (a, b) {
var nameA = a.name, nameB = b.name;
if (nameA < nameB) {
return -1;
Expand All @@ -83,16 +83,16 @@ exports.Tags.prototype = Object.create(Object.prototype, Trait.compose(Trait({
},

/** Returns all the tags that match the given identifier. */
get: function(id) {
return this._search(id, function(tag) { return tag.name === id; });
get: function (id) {
return this._search(id, function (tag) { return tag.name === id; });
},

/**
* Adds the tags from the supplied JavaScript file to the internal store of
* tags.
*/
//dimvar: string (file contents), path to file, options
scan: function(src, file, opts) {
scan: function (src, file, opts) {
if (opts === null || opts === undefined) {
opts = {};
}
Expand All @@ -106,11 +106,10 @@ exports.Tags.prototype = Object.create(Object.prototype, Trait.compose(Trait({
},

/** Returns all the tags that begin with the given prefix. */
stem: function(prefix) {
stem: function (prefix) {
var len = prefix.length;
return this._search(prefix, function(tag) {
return this._search(prefix, function (tag) {
return tag.name.substring(0, len) === prefix;
});
}
}), TagReader, TagWriter));

}), TagReader, TagWriter));
21 changes: 13 additions & 8 deletions lib/jsctags/ctags/reader.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@
*
* ***** END LICENSE BLOCK ***** */

var _ = require('underscore')._;
var Trait = require('traits').Trait;
var _ = require('../underscore')._;
var Trait = require('../traits').Trait;

exports.TagReader = Trait({
readLines: function(lines) {
readLines: function (lines) {
var tags = [];

_(lines).each(function(line) {
_(lines).each(function (line) {
var parts = line.split("\t");
if (parts.length < 3) {
return;
Expand All @@ -54,7 +54,11 @@ exports.TagReader = Trait({
}

// TODO: cope with tab characters in the addr
var tag = { name: name, tagfile: parts[1], addr: parts[2] };
var tag = {
name: name,
tagfile: parts[1],
addr: parts[2]
};

var fieldIndex;
if (parts.length > 3 && parts[3].indexOf(":") === -1) {
Expand All @@ -65,20 +69,21 @@ exports.TagReader = Trait({
}

var fields = {};
_(parts.slice(fieldIndex)).each(function(field) {
_(parts.slice(fieldIndex)).each(function (field) {
var match = /^([^:]+):(.*)/.exec(field);
fields[match[1]] = match[2];
});
tag.fields = fields;

tags.push(tag);
});

this.add(tags);
},

readString: function(str) {
readString: function (str) {
this.readLines(str.split("\n"));
str = str.split("\n");
}
});

4 changes: 2 additions & 2 deletions lib/jsctags/ctags/writer.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@
*
* ***** END LICENSE BLOCK ***** */

var Trait = require('traits').Trait;
var _ = require('underscore')._;
var Trait = require('../traits').Trait;
var _ = require('../underscore')._;

const ESCAPES = { "\\": "\\\\", "\n": "\\n", "\r": "\\r", "\t": "\\t" };

Expand Down
2 changes: 1 addition & 1 deletion lib/jsctags/traits.js
Original file line number Diff line number Diff line change
Expand Up @@ -661,4 +661,4 @@ var Trait = (function(){

if (typeof exports !== "undefined") { // CommonJS module support
exports.Trait = Trait;
}
}
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
"name": "ctags",
"description": "Intelligent code indexing for JavaScript",
"version": "0.1.0",
"keywords": [ "ctags", "tags" ],
"keywords": [
"ctags",
"tags"
],
"maintainers": [
{
"name": "Patrick Walton",
Expand Down
29 changes: 15 additions & 14 deletions test/readtags.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
#!/usr/bin/env node
//#!/usr/bin/env node
var tags = require('../lib/jsctags/ctags').Tags,
fs = require('fs'),
util = require('util'),
path = require('path'),
argv = process.argv;

var argv = process.argv;
var path = require('path');
require.paths.unshift(path.join(path.dirname(argv[1]), "..", "lib",
"jsctags"));

var ctags = require('ctags'), fs = require('fs'), util = require('util');

var tags = new ctags.Tags();
var str = fs.readFileSync(argv[2]);
tags.readString(str);

var result = (argv.length >= 4) ? tags.stem(argv[3]) : tags.tags;
util.puts(util.inspect(result));
tags = new tags();

fs.readFile(argv[2], 'utf-8', function (e, data) {
if (e) throw e;
//tags.readString(data);
tags.scan(data, argv[2]);

var result = (argv.length >= 4) ? tags.stem(argv[3]) : tags.tags;
util.puts(util.inspect(result));
});
4 changes: 2 additions & 2 deletions test/testcases/boot.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
// This module is set up to be dependency-less so that Narwhal
// will be able to run it right away.

bespin.useBespin = function(element, options) {
bespin.useBespin = function (element, options) {
var baseConfig = %s;
options = options || {};
for (var key in options) {
Expand All @@ -49,7 +49,7 @@ bespin.useBespin = function(element, options) {
return appconfig.launch(baseConfig);
};

document.addEventListener("DOMContentLoaded", function() {
document.addEventListener("DOMContentLoaded", function () {
var nodes = document.querySelectorAll(".bespin");
for (var i = 0; i < nodes.length; i++) {
var node = nodes[i];
Expand Down

0 comments on commit 385f0e9

Please sign in to comment.