-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Julian Thome
committed
Jun 23, 2017
1 parent
379c75a
commit cf2dccf
Showing
12 changed files
with
203 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
inmemantlr-api/src/main/java/org/snt/inmemantlr/exceptions/ParsingException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,29 @@ | ||
/** | ||
* org.snt.inmemantlr.tool.Inmemantlr - In memory compiler for Antlr 4 | ||
* | ||
* The MIT License (MIT) | ||
* | ||
* Copyright (c) 2016 Julian Thome <[email protected]> | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy of | ||
* this software and associated documentation files (the "Software"), to deal in | ||
* the Software without restriction, including without limitation the rights to | ||
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies | ||
* of the Software, and to permit persons to whom the Software is furnished to do | ||
* so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
**/ | ||
|
||
package org.snt.inmemantlr.exceptions; | ||
|
||
/** | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,29 @@ | ||
/** | ||
* org.snt.inmemantlr.tool.Inmemantlr - In memory compiler for Antlr 4 | ||
* | ||
* The MIT License (MIT) | ||
* | ||
* Copyright (c) 2016 Julian Thome <[email protected]> | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy of | ||
* this software and associated documentation files (the "Software"), to deal in | ||
* the Software without restriction, including without limitation the rights to | ||
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies | ||
* of the Software, and to permit persons to whom the Software is furnished to do | ||
* so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
**/ | ||
|
||
package org.snt.inmemantlr.tool; | ||
|
||
import org.antlr.v4.runtime.BaseErrorListener; | ||
|
@@ -6,6 +32,8 @@ | |
import org.antlr.v4.runtime.Recognizer; | ||
import org.antlr.v4.runtime.atn.ATNConfigSet; | ||
import org.antlr.v4.runtime.dfa.DFA; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.util.BitSet; | ||
import java.util.HashMap; | ||
|
@@ -17,12 +45,13 @@ | |
public class InmemantlrErrorListener extends BaseErrorListener { | ||
|
||
|
||
private static final Logger LOGGER = LoggerFactory.getLogger(BaseErrorListener.class); | ||
|
||
public enum Type { | ||
SYNTAX_ERROR, | ||
AMBIGUITY, | ||
FULL_CTX, | ||
CTX_SSTV | ||
|
||
} | ||
|
||
Map<Type,String> log = new HashMap<>(); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/** | ||
* Inmemantlr - In memory compiler for Antlr 4 | ||
* | ||
* The MIT License (MIT) | ||
* | ||
* Copyright (c) 2016 Julian Thome <[email protected]> | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy of | ||
* this software and associated documentation files (the "Software"), to deal in | ||
* the Software without restriction, including without limitation the rights to | ||
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies | ||
* of the Software, and to permit persons to whom the Software is furnished to do | ||
* so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
**/ | ||
|
||
import org.junit.Test; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.snt.inmemantlr.GenericParser; | ||
import org.snt.inmemantlr.exceptions.CompilationException; | ||
import org.snt.inmemantlr.listener.DefaultTreeListener; | ||
import org.snt.inmemantlr.utils.FileUtils; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
|
||
import static org.junit.Assert.assertFalse; | ||
|
||
public class TestBroken { | ||
|
||
private static final Logger LOGGER = LoggerFactory.getLogger(TestBroken.class); | ||
|
||
String sgrammarcontent = ""; | ||
|
||
@Test | ||
public void testBroken() throws IOException { | ||
|
||
try (InputStream sgrammar = getClass().getClassLoader() | ||
.getResourceAsStream("inmemantlr/Broken.g4")) { | ||
sgrammarcontent = FileUtils.getStringFromStream(sgrammar); | ||
} | ||
|
||
GenericParser gp = new GenericParser(sgrammarcontent); | ||
DefaultTreeListener t = new DefaultTreeListener(); | ||
|
||
gp.setListener(t); | ||
|
||
boolean compile; | ||
|
||
try { | ||
gp.compile(); | ||
compile = true; | ||
} catch (CompilationException e) { | ||
compile = false; | ||
} | ||
|
||
assertFalse(compile); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
ANTLR4 grammar taken from TypeScript Documentation: | ||
https://github.com/Microsoft/TypeScript/blob/master/doc/spec.md#12.1.2 | ||
https://www.typescriptlang.org/docs/tutorial.html | ||
https://basarat.gitbooks.io/typescript/content/ | ||
https://github.com/Microsoft/TypeScript/wiki/What's-new-in-TypeScript | ||
IntelliJ with antlr4 plugin used: http://plugins.jetbrains.com/plugin/7358?pr= | ||
to develop this grammar | ||
*/ | ||
|
||
|
||
grammar Fail; | ||
|
||
|
||
s : RULE | STRICT; | ||
|
||
RULE : '[a-z]'; | ||
|
||
DIGIT: '[0-9]'; | ||
|
||
STRICT: | ||
{!strictMode}? '0' DIGIT+ | ||
; | ||
|
||
|
||
// | ||
// Whitespace and comments | ||
// | ||
|
||
WS: [ \t\r\n\u000C]+ -> skip | ||
; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters