mirror of
https://github.com/apple/pkl.git
synced 2026-03-26 02:51:13 +01:00
Only allow shebangs in the beginning of a module (#1126)
This commit is contained in:
@@ -18,6 +18,7 @@ package org.pkl.parser;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
import java.util.function.Supplier;
|
||||
import org.pkl.parser.syntax.Annotation;
|
||||
@@ -112,6 +113,7 @@ public class Parser {
|
||||
if (lookahead == Token.EOF) {
|
||||
return new Module(Collections.singletonList(null), new Span(0, 0));
|
||||
}
|
||||
if (lookahead == Token.SHEBANG) next();
|
||||
var start = spanLookahead;
|
||||
Span end = null;
|
||||
ModuleDecl moduleDecl;
|
||||
@@ -1787,16 +1789,16 @@ public class Parser {
|
||||
private FullToken forceNext() {
|
||||
var tk = lexer.next();
|
||||
precededBySemicolon = false;
|
||||
while (tk == Token.LINE_COMMENT
|
||||
|| tk == Token.BLOCK_COMMENT
|
||||
|| tk == Token.SEMICOLON
|
||||
|| tk == Token.SHEBANG) {
|
||||
while (AFFIXES.contains(tk)) {
|
||||
precededBySemicolon = precededBySemicolon || tk == Token.SEMICOLON;
|
||||
tk = lexer.next();
|
||||
}
|
||||
return new FullToken(tk, lexer.span(), lexer.newLinesBetween);
|
||||
}
|
||||
|
||||
private static final EnumSet<Token> AFFIXES =
|
||||
EnumSet.of(Token.LINE_COMMENT, Token.BLOCK_COMMENT, Token.SEMICOLON);
|
||||
|
||||
// Like next, but don't ignore comments
|
||||
private FullToken nextComment() {
|
||||
prev = _lookahead;
|
||||
|
||||
@@ -95,3 +95,6 @@ danglingDocComment=\
|
||||
Dangling documentation comment.\n\
|
||||
\n\
|
||||
Documentation comments must be attached to modules, classes, typealiases, methods, or properties.
|
||||
|
||||
wrongShebangPosition=\
|
||||
Shebangs are only allowed at the very beginning of a file.
|
||||
|
||||
Reference in New Issue
Block a user