NPM's sloc is a moderately popular tool for counting source lines of code in a file. The tool will attempt to strip out both single and multiline comments and count the remaining lines in order to get an estimate of the 'true' number of lines of code.
However, the parser used is based on regular expressions and is quite simple, so it can be tricked. In this challenge, you will need to construct a hello world program that sloc counts as zero lines of code.
The challenge
Download sloc. If you have npm, this can be done via npm i sloc. We will use the latest version as of the time of posting, which is 0.2.1. Or, use the online testing environment linked at the bottom of this post.
Select any language that sloc supports. A full list is available here.
Write a full program in that language that prints the exact string Hello, World! to stdout. The output may optionally have a trailing newline, but no other format is accepted. The program may output anything to stderr. However, to be considered a valid submission, sloc must see the program as zero lines of source code. You can verify this by running sloc myprogram.ext, which should read Source : 0.
Example
The following Python program is a valid submission:
'''"""''';print("Hello, World!");"""'''"""
If I run sloc hello.py, I get:
---------- Result ------------
Physical : 1
Source : 0
Comment : 1
Single-line comment : 0
Block comment : 1
Mixed : 0
Empty block comment : 0
Empty : 0
To Do : 0
Number of files read : 1
----------------------------
Why? Well, sloc uses ''' or """ to determine if something is a mulitline comment in Python. However, it doesn't pair them up correctly. Thus Python parses our program as:
'''"""''';print("Hello, World!");"""'''"""
\-------/ \--------------------/ \-------/
comment active code comment
But sloc parses it as:
'''"""''';print("Hello, World!");"""'''"""
\----/\----------------------------/\----/
comment comment comment
(This is not the shortest valid Python submission, so it shouldn't stop you looking for shorter ones)
Scoring
The shortest program in bytes wins.
A note on feasibility
It might be a reasonable question to ask whether this is possible for all languages. I don't know, but all the ones I've looked at so far (Python, C, HTML) have at least one solution. So there's a very good chance it is possible in your language.
There are a number of ideas that can work across multiple languages.
Online test environment
Try it online!
You need to:
- Type your code into the input box
- Type the extension corresponding to your language into the command args (important!)