Bracket matching

61 views
Skip to first unread message

Axel Kittenberger

unread,
Oct 27, 2011, 9:24:52 AM10/27/11
to nodejs
Does anybody know of a utility that does bracket matching of a js file? The V8 Compiler (as well Mozillas one) has the tendency to just point at the end of file and say "unexpected end of file" or "unexpected token" (last token) and not which bracket was unmatched. On fairly large js-files this can be a little pain to find out. When I had no idea what just changed, I tend to cut away half of the file, try again, cut away half, etc. until I find the offending lines. But it shouldn't be too difficult for a js tokenizer to say which bracket was left open when EOF is reached. Sometimes I just add a ) or } at EOF and use vim's bracket matching, but it doesn't always work. Especially if () and {} are intermangled. In one case I had (  {  ... ) } somewhere in the middle of the file which looked properly closed to the editors simple bracket matching, and took me an hour to find. So anybody know a fallback preprocessor like utility to use, when this happens?

Mark Hahn

unread,
Oct 27, 2011, 1:40:38 PM10/27/11
to nod...@googlegroups.com
Shouldn't that be an editor feature?

On Thu, Oct 27, 2011 at 6:24 AM, Axel Kittenberger <axk...@gmail.com> wrote:
Does anybody know of a utility that does bracket matching of a js file? The V8 Compiler (as well Mozillas one) has the tendency to just point at the end of file and say "unexpected end of file" or "unexpected token" (last token) and not which bracket was unmatched. On fairly large js-files this can be a little pain to find out. When I had no idea what just changed, I tend to cut away half of the file, try again, cut away half, etc. until I find the offending lines. But it shouldn't be too difficult for a js tokenizer to say which bracket was left open when EOF is reached. Sometimes I just add a ) or } at EOF and use vim's bracket matching, but it doesn't always work. Especially if () and {} are intermangled. In one case I had (  {  ... ) } somewhere in the middle of the file which looked properly closed to the editors simple bracket matching, and took me an hour to find. So anybody know a fallback preprocessor like utility to use, when this happens?

--
Job Board: http://jobs.nodejs.org/
Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to nod...@googlegroups.com
To unsubscribe from this group, send email to
nodejs+un...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en

Dominic Tarr

unread,
Oct 27, 2011, 9:44:47 PM10/27/11
to nod...@googlegroups.com
this might help you, but you will need to hack on it a bit to get what you are looking for. http://search.npmjs.org/#/bracket-matcher

Dominic Tarr

unread,
Oct 27, 2011, 9:56:52 PM10/27/11
to nod...@googlegroups.com
another thing, why do you have long js files? 

it's only my opinion, but if a file gets longer that 200 lines, it's time to refactor.

Axel Kittenberger

unread,
Oct 28, 2011, 3:22:05 AM10/28/11
to nod...@googlegroups.com
> On Fri, Oct 28, 2011 at 4:40 AM, Mark Hahn <ma...@hahnca.com> wrote:
> Shouldn't that be an editor feature?

It is up to a certain degree. I think I explained it in the original post. 

> On Fri, Oct 28, 2011 at 3:56 AM, Dominic Tarr <domini...@gmail.com> wrote:
> another thing, why do you have long js files? 
> it's only my opinion, but if a file gets longer that 200 lines, it's time to refactor.

My  personal opinion is, structure is not necessarily gained through  splitting. A ton of files is not naturally better factored than one good js file. The one exception was the concern of this thread :-)

 > On Fri, Oct 28, 2011 at 12:44 PM, Dominic Tarr <domini...@gmail.com> wrote:
 > this might help you, but you will need to hack on it a bit to get what you are looking for. 

Thank you.

Floby

unread,
Oct 28, 2011, 5:20:38 AM10/28/11
to nodejs
What dominic said. My limit is 200-300 lines.
also in vim I use an autoclose plugin which most the time prevent this
kind of issue. Also I use semicolons =)

On Oct 28, 9:22 am, Axel Kittenberger <axk...@gmail.com> wrote:
> > On Fri, Oct 28, 2011 at 4:40 AM, Mark Hahn <m...@hahnca.com> wrote:
> > Shouldn't that be an editor feature?
>
> It is up to a certain degree. I think I explained it in the original post.
>
> > On Fri, Oct 28, 2011 at 3:56 AM, Dominic Tarr <dominic.t...@gmail.com>wrote:
> > another thing, why do you have long js files?
>
> > it's only my opinion, but if a file gets longer that 200 lines, it's time
>
> to refactor.
>
> My  personal opinion is, structure is not necessarily gained through
>  splitting. A ton of files is not naturally better factored than one good js
> file. The one exception was the concern of this thread :-)
>

Justin

unread,
Nov 2, 2011, 7:28:57 PM11/2/11
to nodejs
coffeescript and vim plugin...but this doesn't prevent the odd
whitespace issue :)

Floby

unread,
Nov 3, 2011, 6:13:57 AM11/3/11
to nodejs
losing coffeescript gets rid of the odd whitespace issue =)

Justin

unread,
Nov 4, 2011, 1:28:51 AM11/4/11
to nodejs
losing coffeescript means losing my sanity :)

Paul Armstrong

unread,
Nov 5, 2011, 12:19:38 AM11/5/11
to nodejs
Why not use JSLint or nodelint?

`npm install nodelint` or clone directly from https://github.com/tav/nodelint
Reply all
Reply to author
Forward
0 new messages