kernel/src/main/java/org/kframework/parser/inner/ParseInModule.java
/**
     * Parse the given input. This function is private because the final disambiguation
     * in {@link AmbFilter} eliminates ambiguities that will be equivalent only after
     * calling {@link TreeNodesToKORE#apply(Term)}, but returns a result that is
     * somewhat arbitrary as an actual parser {@link Term}.
     * Fortunately all callers want the result as a K, and can use the public
     * version of this method.
     * @param input
     * @param startSymbol
     * @param source
     * @param startLine
     * @param startColumn
     * @return
     */
Parse the given input. This function is private because the final disambiguation
in  AmbFilter eliminates ambiguities that will be equivalent only after
calling  TreeNodesToKORE#apply(Term), but returns a result that is
somewhat arbitrary as an actual parser  Term.
Fortunately all callers want the result as a K, and can use the public
version of this method.
Parse the given input . This function is private because the final disambiguation in AmbFilter eliminates ambiguities that will be equivalent only after calling TreeNodesToKORE#apply ( Term ) but returns a result that is somewhat arbitrary as an actual parser Term . Fortunately all callers want the result as a K and can use the public version of this method .
private Tuple2<Either<Set<KEMException>, Term>, Set<KEMException>>
            parseStringTerm(String input, Sort startSymbol, Scanner scanner, Source source, int startLine, int startColumn, boolean inferSortChecks, boolean isAnywhere) {
        getParser(scanner, startSymbol);
        long start, endParse = 0, startTypeInf = 0, endTypeInf = 0;
        start = profileRules ? System.currentTimeMillis() : 0;
        try {
            Set<KEMException> warn = Sets.newHashSet();
            Term parsed;
            try {
                parsed = parser.parse(input, source, startLine, startColumn);
            } catch (KEMException e) {
                return Tuple2.apply(Left.apply(Collections.singleton(e)), Collections.emptySet());
            }
            endParse = profileRules ? System.currentTimeMillis() : 0;
            Term rez3 = new TreeCleanerVisitor().apply(parsed);
            Either<Set<KEMException>, Term> rez = new CollapseRecordProdsVisitor(rez3).apply(rez3);
            if (rez.isLeft())
                return new Tuple2<>(rez, warn);
            rez = new PriorityVisitor(disambModule.priorities(), disambModule.leftAssoc(), disambModule.rightAssoc()).apply(rez.right().get());
            if (rez.isLeft())
                return new Tuple2<>(rez, warn);
            rez = new KAppToTermConsVisitor(disambModule).apply(rez.right().get());
            if (rez.isLeft())
                return new Tuple2<>(rez, warn);
            rez3 = new PushAmbiguitiesDownAndPreferAvoid().apply(rez.right().get());
            rez3 = new PushTopAmbiguityUp().apply(rez3);
            startTypeInf = profileRules ? System.currentTimeMillis() : 0;
            TypeInferencer currentInferencer;
            if (isDebug(source, startLine)) {
                currentInferencer = new TypeInferencer(disambModule, true);
                inferencers.add(currentInferencer);
            } else {
                currentInferencer = inferencer.get();
                if (currentInferencer == null) {
                    currentInferencer = new TypeInferencer(disambModule, isDebug(source, startLine));
                    inferencer.set(currentInferencer);
                    inferencers.add(currentInferencer);
                }
            }
            rez = new TypeInferenceVisitor(currentInferencer, startSymbol, strict && inferSortChecks, true, isAnywhere).apply(rez3);
            if (rez.isLeft())
                return new Tuple2<>(rez, warn);
            endTypeInf = profileRules ? System.currentTimeMillis() : 0;
            rez = new ResolveOverloadedTerminators(disambModule.overloads()).apply(rez.right().get());
            if (rez.isLeft())
                return new Tuple2<>(rez, warn);
            rez3 = new PushAmbiguitiesDownAndPreferAvoid(disambModule.overloads()).apply(rez.right().get());
            rez = new AmbFilterError(strict && inferSortChecks).apply(rez3);
            if (rez.isLeft())
                return new Tuple2<>(rez, warn);
            Tuple2<Either<Set<KEMException>, Term>, Set<KEMException>> rez2 = new AddEmptyLists(disambModule, startSymbol).apply(rez.right().get());
            warn = Sets.union(rez2._2(), warn);
            if (rez2._1().isLeft())
                return rez2;
            rez3 = new RemoveBracketVisitor().apply(rez2._1().right().get());
            return new Tuple2<>(Right.apply(rez3), warn);
        } finally {
            if (profileRules) {
                try {
                    long stop = System.currentTimeMillis();
                    long totalTime = stop - start;
                    long parseTime = endParse - start;
                    long tiTime = endTypeInf - startTypeInf;
                    File f = File.createTempFile("timing", ".log", files.resolveTemp(""));
                    FileUtils.writeStringToFile(f, String.format("%s:%d\n%5d %s:%d   parse:%4d typeInf:%4d",
                            source.source(), startLine, totalTime, source.source(), startLine, parseTime, tiTime), StandardCharsets.UTF_8);
                } catch (IOException e) {
                  throw KEMException.internalError("Could not write to timing.log", e);
                }
            }
        }
    }
private Tuple2 < Either < Set < KEMException > , Term > , Set < KEMException > > parseStringTerm ( String input , Sort startSymbol , Scanner scanner , Source source , int startLine , int startColumn , boolean inferSortChecks , boolean isAnywhere ) { getParser ( scanner , startSymbol ) ; long start , endParse = 0 , startTypeInf = 0 , endTypeInf = 0 ; start = profileRules ? System . currentTimeMillis ( ) : 0 ; try { Set < KEMException > warn = Sets . newHashSet ( ) ; Term parsed ; try { parsed = parser . parse ( input , source , startLine , startColumn ) ; } catch ( KEMException e ) { return Tuple2 . apply ( Left . apply ( Collections . singleton ( e ) ) , Collections . emptySet ( ) ) ; } endParse = profileRules ? System . currentTimeMillis ( ) : 0 ; Term rez3 = new TreeCleanerVisitor ( ) . apply ( parsed ) ; Either < Set < KEMException > , Term > rez = new CollapseRecordProdsVisitor ( rez3 ) . apply ( rez3 ) ; if ( rez . isLeft ( ) ) return new Tuple2 < > ( rez , warn ) ; rez = new PriorityVisitor ( disambModule . priorities ( ) , disambModule . leftAssoc ( ) , disambModule . rightAssoc ( ) ) . apply ( rez . right ( ) . get ( ) ) ; if ( rez . isLeft ( ) ) return new Tuple2 < > ( rez , warn ) ; rez = new KAppToTermConsVisitor ( disambModule ) . apply ( rez . right ( ) . get ( ) ) ; if ( rez . isLeft ( ) ) return new Tuple2 < > ( rez , warn ) ; rez3 = new PushAmbiguitiesDownAndPreferAvoid ( ) . apply ( rez . right ( ) . get ( ) ) ; rez3 = new PushTopAmbiguityUp ( ) . apply ( rez3 ) ; startTypeInf = profileRules ? System . currentTimeMillis ( ) : 0 ; TypeInferencer currentInferencer ; if ( isDebug ( source , startLine ) ) { currentInferencer = new TypeInferencer ( disambModule , true ) ; inferencers . add ( currentInferencer ) ; } else { currentInferencer = inferencer . get ( ) ; if ( currentInferencer == null ) { currentInferencer = new TypeInferencer ( disambModule , isDebug ( source , startLine ) ) ; inferencer . set ( currentInferencer ) ; inferencers . add ( currentInferencer ) ; } } rez = new TypeInferenceVisitor ( currentInferencer , startSymbol , strict && inferSortChecks , true , isAnywhere ) . apply ( rez3 ) ; if ( rez . isLeft ( ) ) return new Tuple2 < > ( rez , warn ) ; endTypeInf = profileRules ? System . currentTimeMillis ( ) : 0 ; rez = new ResolveOverloadedTerminators ( disambModule . overloads ( ) ) . apply ( rez . right ( ) . get ( ) ) ; if ( rez . isLeft ( ) ) return new Tuple2 < > ( rez , warn ) ; rez3 = new PushAmbiguitiesDownAndPreferAvoid ( disambModule . overloads ( ) ) . apply ( rez . right ( ) . get ( ) ) ; rez = new AmbFilterError ( strict && inferSortChecks ) . apply ( rez3 ) ; if ( rez . isLeft ( ) ) return new Tuple2 < > ( rez , warn ) ; Tuple2 < Either < Set < KEMException > , Term > , Set < KEMException > > rez2 = new AddEmptyLists ( disambModule , startSymbol ) . apply ( rez . right ( ) . get ( ) ) ; warn = Sets . union ( rez2 . _2 ( ) , warn ) ; if ( rez2 . _1 ( ) . isLeft ( ) ) return rez2 ; rez3 = new RemoveBracketVisitor ( ) . apply ( rez2 . _1 ( ) . right ( ) . get ( ) ) ; return new Tuple2 < > ( Right . apply ( rez3 ) , warn ) ; } finally { if ( profileRules ) { try { long stop = System . currentTimeMillis ( ) ; long totalTime = stop - start ; long parseTime = endParse - start ; long tiTime = endTypeInf - startTypeInf ; File f = File . createTempFile ( "timing" , ".log" , files . resolveTemp ( "" ) ) ; FileUtils . writeStringToFile ( f , String . format ( "%s:%d\n%5d %s:%d   parse:%4d typeInf:%4d" , source . source ( ) , startLine , totalTime , source . source ( ) , startLine , parseTime , tiTime ) , StandardCharsets . UTF_8 ) ; } catch ( IOException e ) { throw KEMException . internalError ( "Could not write to timing.log" , e ) ; } } } }
Parse the given input.
Parse the given input .