项目作者: io7m

项目描述 :
S-expression parsing
高级语言: Java
项目地址: git://github.com/io7m/jsx.git
创建时间: 2015-08-23T10:34:19Z
项目社区:https://github.com/io7m/jsx

开源协议:ISC License

下载


jsx

Maven Central
Maven Central (snapshot)
Codecov
Java Version

com.io7m.jsx

JVM Platform Status
OpenJDK (Temurin) Current Linux Build (OpenJDK (Temurin) Current, Linux)
OpenJDK (Temurin) LTS Linux Build (OpenJDK (Temurin) LTS, Linux)
OpenJDK (Temurin) Current Windows Build (OpenJDK (Temurin) Current, Windows)
OpenJDK (Temurin) LTS Windows Build (OpenJDK (Temurin) LTS, Windows)

jsx

A general-purpose, configurable S-expression parser.

Features

  • Hand-coded lexer and parser with full support for tokens using characters outside of the Unicode BMP.
  • Optional square brackets [f (g [x y])].
  • Optional multi-line strings.
  • Configurable comment characters (#, %, or ;).
  • Configurable pretty printing of expressions.
  • High coverage test suite.
  • OSGi-ready
  • JPMS-ready
  • ISC license.

Documentation

See the user manual.

Usage

Parsing

Give the configuration for the lexer:

  1. var squareBrackets = true;
  2. var newlinesInQuotedStrings = true;
  3. var startAtLine = 1;
  4. final var lexConfiguration =
  5. new JSXLexerConfiguration(
  6. squareBrackets,
  7. newlinesInQuotedStrings,
  8. Optional.of(URI.create("file.txt")),
  9. EnumSet.noneOf(JSXLexerComment.class),
  10. startAtLine
  11. );

Instantiate a parser using a parser and lexer configuration:

  1. var preserveLexicalInfo = true;
  2. final var parserConfig =
  3. new JSXParserConfiguration(preserveLexicalInfo);
  4. final JSXParserSupplierType parsers =
  5. new JSXParserSupplier();
  6. final var parser =
  7. parsers.createFromStreamUTF8(
  8. parserConfig,
  9. lexConfiguration,
  10. lexers,
  11. System.in
  12. );

Parse expressions:

  1. final var exprOpt = parser.parseExpressionOrEOF();
  2. if (exprOpt.isPresent()) {
  3. final var e = exprOpt.get();
  4. System.out.println(e);
  5. }