#!/usr/bin/env --split-string=${JDK_HOME}/bin/java @Makeshift/java_arguments @Makeshift/java_javac_arguments import Breccia.parser.*; import Breccia.parser.plain.IllegalParseState; //import java.io.*; import java.io.IOException; import java.io.Reader; import java.nio.file.Path; import wayic.Waybrec.parser.WaybrecCursor; import static Breccia.parser.plain.Project.newSourceReader; import static java.lang.System.out; //import static java.nio.charset.StandardCharsets.UTF_8; //import static java.nio.file.Files.newInputStream; /** A shell command to smoke test the Waybrec Parser. * * @see * Usage instructions */ public final class SmokeTestCommand { // [AFN] private SmokeTestCommand() {} public static void main( final String[] arguments ) throws IOException { final Path sourceFile = Path.of( arguments[0] ); final WaybrecCursor in = new WaybrecCursor(); // try( final InputStream byteSource = newInputStream​( sourceFile ); // final InputStreamReader charSource = new BufferedReader( new InputStreamReader( // byteSource, UTF_8 ))) { // in.source( charSource ); try( final Reader sourceReader = newSourceReader​( sourceFile )) { in.source( sourceReader ); for( ;; ) { final ParseState state = in.state(); final Fractum f = in.asFractum(); if( f != null ) { // out.println( f ); // final CommandPoint p = in.asCommandPoint(); // if( p != null ) { // // out.println( p ); // out.println( p.tagName() ); // out.println( p.modifierSet() ); // ; } out.println( f.tagName() ); printComponentsOf( f, " " ); ; } else { out.print( " " ); out.println( state ); } if( state.isFinal() ) break; in.next(); }} catch( final ParseError x ) { out.print( sourceFile ); out.print( ':' ); out.print( x.lineNumber ); out.print( ": " ); out.println( x ); } catch( final IllegalParseState x ) { out.print( sourceFile ); out.print( ':' ); out.print( x.pointer.lineNumber ); out.print( ": " ); out.println( x ); }} private static void printComponentsOf( final Granum granum, final String indent ) throws ParseError { for( final Granum component: granum.components() ) { out.print( indent ); // out.println( component.tagName() ); out.println( component ); printComponentsOf( component, indent + " " ); }}} // NOTE // ──── // AFN Atypical file naming is allowed here. ‘The compiler does not enforce the optional restriction // defined at the end of JLS §7.6, that a type in a named package should exist in a file whose // name is composed from the type name followed by the .java extension.’ // // // // No longer, however, does this allowance extend to the package name. While in JDK releases // prior to 22 “the launcher's source-file mode was permissive about which package, if any, // was declared”, current releases enforce a correspondence between the declared package name // and the file path. Failing this, the launcher aborts with “end of path to source file // does not match its package name”.