PetitParser

所属分类:collect
开发工具:Smalltalk
文件大小:0KB
下载次数:0
上传日期:2021-06-08 12:31:15
上 传 者sh-1993
说明:  Petit Parser是一个用于构建解析器的框架。,
(Petit Parser is a framework for building parsers.,)

文件列表:
.project (27, 2019-06-21)
.smalltalk.ston (560, 2019-06-21)
.travis.yml (183, 2019-06-21)
CONTRIBUTING.md (811, 2019-06-21)
LICENSE (1057, 2019-06-21)
resources/ (0, 2019-06-21)
resources/HighlightedTextInspector.png (14945, 2019-06-21)
src/ (0, 2019-06-21)
src/.properties (21, 2019-06-21)
src/BaselineOfPetitParser/ (0, 2019-06-21)
src/BaselineOfPetitParser/BaselineOfPetitParser.class.st (6108, 2019-06-21)
src/BaselineOfPetitParser/package.st (43, 2019-06-21)
src/FactorialLanguage-Tests/ (0, 2019-06-21)
src/FactorialLanguage-Tests/FLFactorialExample.class.st (3159, 2019-06-21)
src/FactorialLanguage-Tests/package.st (47, 2019-06-21)
src/FactorialLanguage/ (0, 2019-06-21)
src/FactorialLanguage/FLFactorialCompiler.class.st (2223, 2019-06-21)
src/FactorialLanguage/FLFactorialGrammar.class.st (2236, 2019-06-21)
src/FactorialLanguage/FLFactorialPrinter.class.st (962, 2019-06-21)
src/FactorialLanguage/package.st (39, 2019-06-21)
src/PetitAnalyzer-Tests/ (0, 2019-06-21)
src/PetitAnalyzer-Tests/PPAnalyzerTest.class.st (19700, 2019-06-21)
src/PetitAnalyzer-Tests/PPRewriterTest.class.st (4739, 2019-06-21)
src/PetitAnalyzer-Tests/PPSearcherTest.class.st (15105, 2019-06-21)
src/PetitAnalyzer-Tests/package.st (43, 2019-06-21)
src/PetitAnalyzer/ (0, 2019-06-21)
src/PetitAnalyzer/PPActionParser.extension.st (258, 2019-06-21)
src/PetitAnalyzer/PPBlockReplaceRule.class.st (898, 2019-06-21)
src/PetitAnalyzer/PPDelegateParser.extension.st (236, 2019-06-21)
src/PetitAnalyzer/PPEndOfFileParser.extension.st (121, 2019-06-21)
src/PetitAnalyzer/PPEpsilonParser.extension.st (116, 2019-06-21)
src/PetitAnalyzer/PPFailingParser.extension.st (264, 2019-06-21)
src/PetitAnalyzer/PPLimitedRepeatingParser.extension.st (250, 2019-06-21)
src/PetitAnalyzer/PPListParser.extension.st (804, 2019-06-21)
src/PetitAnalyzer/PPListPattern.class.st (222, 2019-06-21)
src/PetitAnalyzer/PPLiteralParser.extension.st (304, 2019-06-21)
src/PetitAnalyzer/PPNotParser.extension.st (211, 2019-06-21)
src/PetitAnalyzer/PPOptionalParser.extension.st (118, 2019-06-21)
src/PetitAnalyzer/PPParser.extension.st (10422, 2019-06-21)
... ...

# PetitParser [![Build Status](https://travis-ci.org/moosetechnology/PetitParser.svg?branch=development)](https://travis-ci.org/moosetechnology/PetitParser) Petit Parser is a framework for building parsers. The version of PetitParser on this repository is supported by Pharo 6.1 and Pharo 7. To use it with older Pharo version, please refer to the [Smalltalkhub repository](http://smalltalkhub.com/#!/~Moose/PetitParser). - [About Petit Parser](#about-petit-parser) * [Cool feature 1: Easily write an expression parser](#cool-feature-1-easily-write-an-expression-parser) * [Cool feature 2: Create a cheap highlighter from your grammar](#cool-feature-2-create-a-cheap-highlighter-from-your-grammar) - [Install](#install) * [Groups](#groups) - [Version management](#version-management) - [Grammars provided](#grammars-provided) - [Packages removed during/after migration](#packages-removed-duringafter-migration) ## About Petit Parser Petit Parser is a framework for building parsers. It was originally developed by Lukas Renggli. Basic information about PetitParser can be found here: - [Writing Parsers with PetitParser](http://www.lukas-renggli.ch/blog/petitparser-1) - [Composite Grammars with PetitParser](http://www.lukas-renggli.ch/blog/petitparser-2) - [Petit Parser in Deep into Pharo Book](http://pharobooks.gforge.inria.fr/PharoByExampleTwo-Eng/latest/PetitParser.pdf) This repository is a port from the [Smalltalkhub repository](http://smalltalkhub.com/#!/~Moose/PetitParser). However, further contributions to this project should take place on this Github repository. ### Cool feature 1: Easily write an expression parser > Note: this section is based on the comment of PPExpressionParser class. The following code initializes a parser for arithmetic expressions. First we instantiate an expression parser, a simple parser for expressions in parenthesis and a simple parser for integer numbers. ```Smalltalk expression := PPExpressionParser new. parens := $( asParser trim , expression , $) asParser trim ==> [ :nodes | nodes second ]. integer := #digit asParser plus trim ==> [ :token | Integer readFrom: token readStream ]. ``` Then we define on what term the expression grammar is built on: ```Smalltalk expression term: parens / integer. ``` Finally we define the operator-groups in descending precedence. Note, that the action blocks receive both, the terms and the parsed operator in the order they appear in the parsed input. ```Smalltalk expression group: [ :g | g prefix: $- asParser trim do: [ :op :a | a negated ] ]; group: [ :g | g postfix: '++' asParser trim do: [ :a :op | a + 1 ]. g postfix: '--' asParser trim do: [ :a :op | a - 1 ] ]; group: [ :g | g right: $^ asParser trim do: [ :a :op :b | a raisedTo: b ] ]; group: [ :g | g left: $* asParser trim do: [ :a :op :b | a * b ]. g left: $/ asParser trim do: [ :a :op :b | a / b ] ]; group: [ :g | g left: $+ asParser trim do: [ :a :op :b | a + b ]. g left: $- asParser trim do: [ :a :op :b | a - b ] ]. ``` After evaluating the above code the `expression` is an efficient parser that evaluates examples like: ```Smalltalk expression parse: '-8++'. expression parse: '1+2*3'. expression parse: '1*2+3'. expression parse: '(1+2)*3'. expression parse: '8/4/2'. expression parse: '8/(4/2)'. expression parse: '2^2^3'. expression parse: '(2^2)^3'. ``` ### Cool feature 2: Create a cheap highlighter from your grammar `PPTextHighlighter` allows you to create a cheap syntax highlighter from your grammar. Consider the following example from a JSON grammar. We want: - `null` to appear gray; - `true` to appear green; - `false` to appear red; and - any number to appear yellow. ``` jsonParser := PPJsonGrammar new. text := '{ "number" : 1, "true" : true, "false" : false, "null" : null }' asText. jsonParser parse: text asString. PPTextHighlighter new parser: jsonParser; addAttribute: TextColor gray for: #nullToken; "The symbol is the name of the method in which the rule is defined." addAttribute: TextColor green for: #trueToken; addAttribute: TextColor red for: #falseToken; addAttribute: TextColor yellow for: #number; highlight: text. "Here we tell the highlighter to higlight text. This modifies the Text object." text inspect ``` Result: ![Inspector on highlighted text](resources/HighlightedTextInspector.png) > Note: PPTextHighlighter is available in 'Highlighter' group of the baseline. ## Install ``` Metacello new baseline: 'PetitParser'; repository: 'github://moosetechnology/PetitParser/src'; load. ``` ### Groups It is possible to load subpart(s) of this project using groups: - `Minimal`: Kernel of the framework. - `Core`: Kernel of the framework and extensions to SUnit to make parsers testing easier. - `Tests`: Tests of PetitParser's core. - `Examples`: Simple examples of grammars. - `Islands`: Utilities to define island grammars. - `Analyzer`: Various tools to do code analysis / code rewriting. - `Indent`: Utilities to define grammar for language based on indentation (e.g. Python, YAML, etc.) - `Preprocessor`: Utilities to apply pre-processing on a parser input in a handy way. - `Extension`: Provides `PPExtendedCompositeParser` which allows one to define parsers for which rules do not rely on instance variables (allow to exceed the limit of 256 rules per parser) and `PPMultiStringParser` which allows to build efficient parsers for huge list of strings. - `TestsExtension`: Adds some useful methods to `PPCompositeParserTest`. - `Highlighter`: Utility to create cheap highlighter for Text object from a grammar. - `GT`: Extension to the inspector allowing to debug grammar more easily. - `SmalltalkCore`: Smalltalk parser. - `Smalltalk`: Smalltalk parser and its tests. - `RegexCore`: Regex parser. - `Regex`: Regex parser and its tests. - `YAMLCore`: YAML parser. - `YAML`: YAML parser and its tests. - `ParserCore`: A collection of various grammars. - `Parser`: A collection of various grammars and their tests. - `ParserIDE`: Graphical tools to develop and debug parsers. By default, if no group is specified, `Core`, `Tests`, `Examples`, `Islands`, `Analyzer`, `GT` and `Parser` groups are loaded. ## Version management This project use semantic versionning to define the releases. This mean that each stable release of the project will get associate a version number of the form `vX.Y.Z`. - **X** define the major version number - **Y** define the minor version number - **Z** define the patch version number When a release contains only bug fixes, the patch number increase. When the release contains new features backward compatibles, the minor version increase. When the release contains breaking changes, the major version increase. Thus, it should be safe to depend on a fixed major version and moving minor version of this project. The first release on this Github repository matches with the last release that happened on Smalltalkhub (v1.9.2). ## Grammars provided 11 grammars are provided by this project. One can load them all using `Parser` group. - Factorial-Language - PetitCSV - PetitIndent - PetitJson - PetitMSE - PetitManifestMf - PetitRegex - PetitSmalltalk - PetitXPath - PetitXml - PetitYAML ## Packages removed during/after migration Some package were not migrable, thus they stayed on smalltalkhub. If you find a way to migrate them, please propose a PR: - ConfigurationOfSqlEvaluator - GT-InspectorExtensions-Pillar - PetitBeta - PetitSQL - SQL-Evaluator - SQL-Evaluator-GemStone - SQL-Evaluator-Pharo Because its unit tests were all broken, the Java island grammar has been removed. The last time it was available in this repository is at commit [37074366fb6587dd8554cc4cd9a8621dfa5487bd](https://github.com/moosetechnology/PetitParser/commit/37074366fb6587dd8554cc4cd9a8621dfa5487bd). Feel free to load the version of this repository pointed by this commit to reanimate this island grammar if you want. In such case, a PPR is welcome.

近期下载者

相关文件


收藏者