Merge branch 'master' of github.com:antlr/antlr4 into master
This commit is contained in:
commit
fc640c944a
|
@ -120,7 +120,7 @@
|
|||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-plugin-plugin</artifactId>
|
||||
<version>3.3</version>
|
||||
<version>3.6.0</version>
|
||||
<configuration>
|
||||
<!-- see http://jira.codehaus.org/browse/MNG-5346 -->
|
||||
<skipErrorNoDescriptorsFound>true</skipErrorNoDescriptorsFound>
|
||||
|
|
|
@ -226,29 +226,37 @@ YYYY/MM/DD, github id, Full name, email
|
|||
2019/03/13, base698, Justin Thomas, justin.thomas1@gmail.com
|
||||
2019/03/18, carlodri, Carlo Dri, carlo.dri@gmail.com
|
||||
2019/05/02, askingalot, Andy Collins, askingalot@gmail.com
|
||||
2019/05/13, mapio, Massimo Santini, massimo.santini@gmail.com
|
||||
2019/07/11, olowo726, Olof Wolgast, olof@baah.se
|
||||
2019/07/16, abhijithneilabraham, Abhijith Neil Abraham, abhijithneilabrahampk@gmail.com
|
||||
2019/07/26, Braavos96, Eric Hettiaratchi, erichettiaratchi@gmail.com
|
||||
2019/08/02, thron7, Thomas Herchenroeder, thron7[at]users[dot]sourceforge[dot]net
|
||||
2019/08/12, easonlin404, Eason Lin, easonlin404@gmail.com
|
||||
2019/08/23, akaJes, Oleksandr Mamchyts, akaJes@gmail.com
|
||||
2019/08/27, wurzelpeter, Markus Franke, markus[hyphen]franke[at]web[dot]de
|
||||
2019/09/10, ImanHosseini, Iman Hosseini, hosseini.iman@yahoo.com
|
||||
2019/09/03, João Henrique, johnnyonflame@hotmail.com
|
||||
2019/09/10, neko1235, Ihar Mokharau, igor.mohorev@gmail.com
|
||||
2019/09/10, yar3333, Yaroslav Sivakov, yar3333@gmail.com
|
||||
2019/09/10, marcospassos, Marcos Passos, marcospassos.com@gmail.com
|
||||
2019/09/10, amorimjuliana, Juliana Amorim, juu.amorim@gmail.com
|
||||
2019/09/15, sullis, Sean Sullivan, github@seansullivan.com
|
||||
2019/09/17, kaz, Kazuki Sawada, kazuki@6715.jp
|
||||
2019/09/28, lmy269, Mingyang Liu, lmy040758@gmail.com
|
||||
2019/10/29, tehbone, Tabari Alexander, tehbone@gmail.com
|
||||
2019/10/31, a-square, Alexei Averchenko, lex.aver@gmail.com
|
||||
2019/11/05, listba, Ben List, ben.list89@gmail.com
|
||||
2019/11/11, foxeverl, Liu Xinfeng, liuxf1986[at]gmail[dot]com
|
||||
2019/11/17, felixn, Felix Nieuwenhuizhen, felix@tdlrali.com
|
||||
2019/11/18, mlilback, Mark Lilback, mark@lilback.com
|
||||
2020/01/19, lingyv-li, Lingyu Li, lingyv.li@gmail.com
|
||||
2020/02/02, carocad, Camilo Roca, carocad@unal.edu.co
|
||||
2020/02/10, julibert, Julián Bermúdez Ortega, julibert.dev@gmail.com
|
||||
2020/02/17, quantumsheep, Nathanael Demacon, nathanael.dmc@outlook.fr
|
||||
2020/02/21, StochasticTinkr, Daniel Pitts, github@coloraura.com
|
||||
2020/03/17, XsongyangX, Song Yang, songyang1218@gmail.com
|
||||
2020/04/07, deniskyashif, Denis Kyashif, denis.kyashif@gmail.com
|
||||
2020/04/08, lwehmeier, Leon Wehmeier, wehmeier@st.ovgu.de
|
||||
2020/04/10, agrabski, Adam Grabski, adam.gr@outlook.com
|
||||
2020/04/23, martinvw, Martin van Wingerden, martin@martinvw.nl
|
||||
2020/04/30, TristonianJones, Tristan Swadell, tswadell@google.com
|
||||
|
|
|
@ -84,7 +84,7 @@ Using a rule label looks like this:
|
|||
returnStat : 'return' e=expr {System.out.println("matched "+e.text);} ;
|
||||
```
|
||||
|
||||
You can also use `$ followed by the name of the attribute to access the value associated with the currently executing rule. For example, `$start` is the starting token of the current rule.
|
||||
You can also use `$` followed by the name of the attribute to access the value associated with the currently executing rule. For example, `$start` is the starting token of the current rule.
|
||||
|
||||
```
|
||||
returnStat : 'return' expr {System.out.println("first token "+$start.getText());} ;
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
# C++
|
||||
|
||||
The C++ target supports all platforms that can either run MS Visual Studio 2013 (or newer), XCode 7 (or newer) or CMake (C++11 required). All build tools can either create static or dynamic libraries, both as 64bit or 32bit arch. Additionally, XCode can create an iOS library. Also see [Antlr4 for C++ with CMake: A practical example](https://beyondtheloop.dev/Antlr-cpp-cmake/).
|
||||
The C++ target supports all platforms that can either run MS Visual Studio 2013 (or newer), XCode 7 (or newer) or CMake (C++11 required). All build tools can either create static or dynamic libraries, both as 64bit or 32bit arch. Additionally, XCode can create an iOS library. Also see [Antlr4 for C++ with CMake: A practical example](http://blorente.me/beyond-the-loop/Antlr-cpp-cmake/).
|
||||
|
||||
## How to create a C++ lexer or parser?
|
||||
This is pretty much the same as creating a Java lexer or parser, except you need to specify the language target, for example:
|
||||
|
|
|
@ -65,7 +65,7 @@ Another common option to the ANTLR tool is `-visitor`, which generates a parse t
|
|||
|
||||
We'll write a small main func to call the generated parser/lexer (assuming they are separate). This one writes out the encountered `ParseTreeContext`'s. Suppose the gen'ed parser code is in the `parser` directory relative to this code:
|
||||
|
||||
```
|
||||
```golang
|
||||
package main
|
||||
|
||||
import (
|
||||
|
|
|
@ -25,7 +25,7 @@ fragment DIGIT : [0-9] ; // not a token by itself
|
|||
|
||||
## Lexical Modes
|
||||
|
||||
Modes allow you to group lexical rules by context, such as inside and outside of XML tags. It’s like having multiple sublexers, one for context. The lexer can only return tokens matched by entering a rule in the current mode. Lexers start out in the so-called default mode. All rules are considered to be within the default mode unless you specify a mode command. Modes are not allowed within combined grammars, just lexer grammars. (See grammar `XMLLexer` from [Tokenizing XML](http://pragprog.com/book/tpantlr2/the-definitive-antlr-4-reference).)
|
||||
Modes allow you to group lexical rules by context, such as inside and outside of XML tags. It’s like having multiple sublexers, one for each context. The lexer can only return tokens matched by entering a rule in the current mode. Lexers start out in the so-called default mode. All rules are considered to be within the default mode unless you specify a mode command. Modes are not allowed within combined grammars, just lexer grammars. (See grammar `XMLLexer` from [Tokenizing XML](http://pragprog.com/book/tpantlr2/the-definitive-antlr-4-reference).)
|
||||
|
||||
```
|
||||
rules in default mode
|
||||
|
@ -125,7 +125,7 @@ ESC : '\\' . ; // match any escaped \x character
|
|||
|
||||
<tr>
|
||||
<td>{«action»}</td><td>
|
||||
Lexer actions can appear anywhere as of 4.2, not just at the end of the outermost alternative. The lexer executes the actions at the appropriate input position, according to the placement of the action within the rule. To execute a single action for a role that has multiple alternatives, you can enclose the alts in parentheses and put the action afterwards:
|
||||
Lexer actions can appear anywhere as of 4.2, not just at the end of the outermost alternative. The lexer executes the actions at the appropriate input position, according to the placement of the action within the rule. To execute a single action for a rule that has multiple alternatives, you can enclose the alts in parentheses and put the action afterwards:
|
||||
|
||||
<pre>
|
||||
END : ('endif'|'end') {System.out.println("found an end");} ;
|
||||
|
|
|
@ -26,8 +26,8 @@ The Javadoc comments are hidden from the parser and are ignored at the moment.
|
|||
Token names always start with a capital letter and so do lexer rules as defined by Java’s `Character.isUpperCase` method. Parser rule names always start with a lowercase letter (those that fail `Character.isUpperCase`). The initial character can be followed by uppercase and lowercase letters, digits, and underscores. Here are some sample names:
|
||||
|
||||
```
|
||||
ID, LPAREN, RIGHT_CURLY // token names/rules
|
||||
expr, simpleDeclarator, d2, header_file // rule names
|
||||
ID, LPAREN, RIGHT_CURLY // token names/lexer rules
|
||||
expr, simpleDeclarator, d2, header_file // parser rule names
|
||||
```
|
||||
|
||||
Like Java, ANTLR accepts Unicode characters in ANTLR names:
|
||||
|
|
|
@ -52,15 +52,6 @@ m.setDelimiters("<<", ">>", "$"); // $ is the escape character
|
|||
|
||||
This would allow pattern `<<ID>> = <<expr>> ;$<< ick $>>` to be interpreted as elements: `ID`, ` = `, `expr`, and ` ;<< ick >>`.
|
||||
|
||||
```java
|
||||
String xpath = "//blockStatement/*";
|
||||
String treePattern = "int <Identifier> = <expression>;";
|
||||
ParseTreePattern p =
|
||||
parser.compileParseTreePattern(treePattern,
|
||||
JavaParser.RULE_localVariableDeclarationStatement);
|
||||
List<ParseTreeMatch> matches = p.findAll(tree, xpath);
|
||||
```
|
||||
|
||||
### Pattern labels
|
||||
|
||||
The tree pattern matcher tracks the nodes in the tree at matches against the tags in a tree pattern. That way we can use the `get()` and `getAll()` methods to retrieve components of the matched subtree. For example, for pattern `<ID>`, `get("ID")` returns the node matched for that `ID`. If more than one node matched the specified token or rule tag, only the first match is returned. If there is no node associated with the label, this returns null.
|
||||
|
|
2
pom.xml
2
pom.xml
|
@ -151,7 +151,7 @@
|
|||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.6.0</version>
|
||||
<version>3.8.1</version>
|
||||
<configuration>
|
||||
<source>${maven.compiler.source}</source>
|
||||
<target>${maven.compiler.target}</target>
|
||||
|
|
|
@ -55,11 +55,11 @@ Either open the included XCode project and build that or use the cmake compilati
|
|||
Try run cmake -DCMAKE_ANDROID_NDK=/folder/of/android_ndkr17_and_above -DCMAKE_SYSTEM_NAME=Android -DCMAKE_ANDROID_API=14 -DCMAKE_ANDROID_ARCH_ABI=x86 -DCMAKE_ANDROID_STL_TYPE=c++_shared -DCMAKE_ANDROID_NDK_TOOLCHAIN_VERSION=clang -DCMAKE_BUILD_TYPE=Release /folder/antlr4_src_dir -G Ninja.
|
||||
|
||||
#### Compiling on Linux
|
||||
- cd <antlr4-dir>/runtime/Cpp (this is where this readme is located)
|
||||
- cd \<antlr4-dir\>/runtime/Cpp (this is where this readme is located)
|
||||
- mkdir build && mkdir run && cd build
|
||||
- cmake .. -DANTLR_JAR_LOCATION=full/path/to/antlr4-4.5.4-SNAPSHOT.jar -DWITH_DEMO=True
|
||||
- make
|
||||
- DESTDIR=<antlr4-dir>/runtime/Cpp/run make install
|
||||
- DESTDIR=\<antlr4-dir\>/runtime/Cpp/run make install
|
||||
|
||||
If you don't want to build the demo then simply run cmake without parameters.
|
||||
There is another cmake script available in the subfolder cmake/ for those who prefer the superbuild cmake pattern.
|
||||
|
|
Loading…
Reference in New Issue