Categories:
Audio (13)
Biotech (29)
Bytecode (36)
Database (77)
Framework (7)
Game (7)
General (507)
Graphics (53)
I/O (35)
IDE (2)
JAR Tools (101)
JavaBeans (21)
JDBC (121)
JDK (426)
JSP (20)
Logging (108)
Mail (58)
Messaging (8)
Network (84)
PDF (97)
Report (7)
Scripting (84)
Security (32)
Server (121)
Servlet (26)
SOAP (24)
Testing (54)
Web (15)
XML (309)
Collections:
Other Resources:
ANTLR Tool Source Code
ANTLR is a powerful parser generator for multiple programming languages
including Java.
ANTLR contains 2 major modules:
ANTLR Tool Source Code files are provided in the distribution packge (antlr4-4.10.1.zip). You can download them at ANTLR Website.
You can also browse the source code below:
✍: FYIcenter
⏎ org/antlr/v4/misc/Utils.java
/* * Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. * Use of this file is governed by the BSD 3-clause license that * can be found in the LICENSE.txt file in the project root. */ package org.antlr.v4.misc; import org.antlr.v4.runtime.misc.IntegerList; import org.antlr.v4.tool.ast.GrammarAST; import java.io.IOException; import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Paths; import java.util.*; /** */ public class Utils { public static final int INTEGER_POOL_MAX_VALUE = 1000; public interface Filter<T> { boolean select(T t); } public interface Func0<TResult> { TResult exec(); } public interface Func1<T1, TResult> { TResult exec(T1 arg1); } static Integer[] ints = new Integer[INTEGER_POOL_MAX_VALUE+1]; public static String stripFileExtension(String name) { if ( name==null ) return null; int lastDot = name.lastIndexOf('.'); if ( lastDot<0 ) return name; return name.substring(0, lastDot); } public static String join(Object[] a, String separator) { StringBuilder buf = new StringBuilder(); for (int i=0; i<a.length; i++) { Object o = a[i]; buf.append(o.toString()); if ( (i+1)<a.length ) { buf.append(separator); } } return buf.toString(); } public static String sortLinesInString(String s) { String lines[] = s.split("\n"); Arrays.sort(lines); List<String> linesL = Arrays.asList(lines); StringBuilder buf = new StringBuilder(); for (String l : linesL) { buf.append(l); buf.append('\n'); } return buf.toString(); } public static <T extends GrammarAST> List<String> nodesToStrings(List<T> nodes) { if ( nodes == null ) return null; List<String> a = new ArrayList<String>(); for (T t : nodes) a.add(t.getText()); return a; } // public static <T> List<T> list(T... values) { // List<T> x = new ArrayList<T>(values.length); // for (T v : values) { // if ( v!=null ) x.add(v); // } // return x; // } public static void writeSerializedATNIntegerHistogram(String filename, IntegerList serializedATN) { HashMap<Integer, Integer> histo = new HashMap<>(); for (int i : serializedATN.toArray()) { if ( histo.containsKey(i) ) { histo.put(i, histo.get(i) + 1); } else { histo.put(i, 1); } } TreeMap<Integer,Integer> sorted = new TreeMap<>(histo); String output = ""; output += "value,count\n"; for (int key : sorted.keySet()) { output += key+","+sorted.get(key)+"\n"; } try { Files.write(Paths.get(filename), output.getBytes(StandardCharsets.UTF_8)); } catch (IOException ioe) { System.err.println(ioe); } } public static String capitalize(String s) { return Character.toUpperCase(s.charAt(0)) + s.substring(1); } public static String decapitalize(String s) { return Character.toLowerCase(s.charAt(0)) + s.substring(1); } /** apply methodName to list and return list of results. method has * no args. This pulls data out of a list essentially. */ public static <From,To> List<To> select(List<From> list, Func1<From, To> selector) { if ( list==null ) return null; List<To> b = new ArrayList<To>(); for (From f : list) { b.add(selector.exec(f)); } return b; } /** Find exact object type or subclass of cl in list */ public static <T> T find(List<?> ops, Class<T> cl) { for (Object o : ops) { if ( cl.isInstance(o) ) return cl.cast(o); // if ( o.getClass() == cl ) return o; } return null; } public static <T> int indexOf(List<? extends T> elems, Filter<T> filter) { for (int i=0; i<elems.size(); i++) { if ( filter.select(elems.get(i)) ) return i; } return -1; } public static <T> int lastIndexOf(List<? extends T> elems, Filter<T> filter) { for (int i=elems.size()-1; i>=0; i--) { if ( filter.select(elems.get(i)) ) return i; } return -1; } public static void setSize(List<?> list, int size) { if (size < list.size()) { list.subList(size, list.size()).clear(); } else { while (size > list.size()) { list.add(null); } } } }
⏎ org/antlr/v4/misc/Utils.java
Or download all of them as a single archive file:
File name: antlr-tool-4.10.1-sources.jar File size: 347718 bytes Release date: 2022-04-15 Download
2022-04-24, 38595👍, 0💬
Popular Posts:
The Jakarta-ORO Java classes are a set of text-processing Java classes that provide Perl5 compatible...
JDK 11 jdk.jfr.jmod is the JMOD file for JDK 11 JFR module. JDK 11 JFR module compiled class files a...
This package is the backport of java.util.concurrent API, introduced in Java 5.0 and further refined...
Apache Log4j SLF4J Binding allows applications coded to the SLF4J API to use Log4j 2 as the implemen...
Java Cryptography Extension 1.6 JAR File Size and Download Location: File name: jce.jar, jce-1.6.jar...