- Notifications
You must be signed in to change notification settings - Fork120
The fast scanner generator for Java™ with full Unicode support
License
jflex-de/jflex
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
JFlex is a lexical analyzer generator (also known as scanner generator) for Java.
JFlex takes as input a specification with a set of regular expressions and corresponding actions.It generates Java source of a lexer that reads input, matches the input against the regularexpressions in the spec file, and runs the corresponding action if a regular expressionmatched. Lexers usually are the first front-end step in compilers, matching keywords, comments,operators, etc, and generating an input token stream for parsers.
JFlex lexers are based on deterministic finite automata (DFAs).They are fast, without expensive backtracking.
For documentation and more information see theJFlex documentationand thewiki.
You needMaven 3.5.2 or later, and JDK 8 or later.
Place grammar files in
src/main/flex/directory.Extend the projectPOM build section with the
maven-jflex-plugin<build> <plugins> <plugin> <groupId>de.jflex</groupId> <artifactId>jflex-maven-plugin</artifactId> <version>1.9.0</version> <executions> <execution> <goals> <goal>generate</goal> </goals> </execution> </executions> </plugin> </plugins> </build>
Voilà: Java code is produced in
target/generated-sources/during thegenerate-sourcesphase(which happens before thecompilephase) and included in the compilation scope.
You need ant, the binary JFlex jar and JDK 8 or later.
Define ant task
<taskdefclassname="jflex.anttask.JFlexTask"name="jflex"classpath="path-to-jflex.jar"/>
Use it
<jflexfile="src/grammar/parser.flex"destdir="build/generated/"/><javacsrcdir="build/generated/"destdir="build/classes/"/>
We provide ajflex rule
load("@jflex_rules//jflex:jflex.bzl","jflex")jflex(name="",# Choose a rule namesrcs= [],# Add input lex specificationsoutputs= [],# List expected generated files)
See the samplesimple BUILDfile.
You need the binary jflex jar and JDK 8 or later.
You can also use JFlex directly from the command line:
jflex/bin/jflex src/grammar/parser.flex
Or:
java -jar jflex-full-1.9.0.jar -d output src/grammar/parser.flex
Have a look at the sample project:simple and otherexamples.
JFlex is free software, contributions are welcome.See theContributing page for instructions.
The top level directory of the JFLex git repository contains:
- cup A copy of the CUP runtime
- cup-maven-plugin A simple Maven plugin to generate a parser with CUP.
- docs the Markdown sources for the user manual
- java Java sources [WIP, Bazel]
- javatests Java sources of test [WIP, Bazel]
- jflex JFlex, the scanner/lexer generator for Java
- jflex-maven-plugin the JFlex maven plugin, that helps to integrate JFlex in your project
- jflex-unicode-plugin the JFlex unicode maven plugin, used for compiling JFlex
- testsuite the regression test suite for JFlex,
- third_party third-party libraries used by examples of theBazel build system
JFlex can be built with Bazel.Migration to Bazel is still work in progress, concerning the test suite, for instance.
You needBazel.
bazel build //jflex:jflex_bin
This buildsbazel-bin/jflex/jflex_bin, that you can use
bazel-bin/jflex/jflex_bin --info
Or:
bazel run //jflex:jflex_bin -- --info
Build uberjar (aka fatjar aka deploy jar)
bazel build jflex/jflex_bin_deploy.jar
You need JDK 8 or later.
./mvnw install
This generatesjflex/target/jflex-full-1.9.1-SNAPSHOT.jar that you can use, e.g.
java -jar jflex-full-1.9.1-SNAPSHOT.jar --info
About
The fast scanner generator for Java™ with full Unicode support
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Uh oh!
There was an error while loading.Please reload this page.