forked from nikitabobko/AeroSpace
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1/3 Add Antlr dependency and write first draft of AeroShell grammar
- Loading branch information
1 parent
3636df4
commit cd13c0a
Showing
13 changed files
with
154 additions
and
2 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#!/usr/bin/env bash | ||
cd "$(dirname "$0")" | ||
source ./script/setup.sh | ||
|
||
test -e ./.deps/python-venv/bin/antlr4 || ./script/install-antlr.sh | ||
source ./.deps/python-venv/bin/activate | ||
antlr4 -no-listener -Dlanguage=Swift -o ./Sources/AeroShellParserGenerated ./grammar/AeroShellLexer.g4 ./grammar/AeroShellParser.g4 | ||
|
||
# Antlr generates weird *.interp and *.tokens files | ||
rm ./Sources/AeroShellParserGenerated/grammar/*.interp | ||
rm ./Sources/AeroShellParserGenerated/grammar/*.tokens |
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,31 @@ | ||
// AeroShell lexer grammar. Powered by https:/antlr/antlr4 | ||
// Use ./generate-aero-shell-parser.sh to regenerate grammar code | ||
lexer grammar AeroShellLexer; | ||
|
||
RESERVED : '"""' | '\'\'\'' ; | ||
|
||
SINGLE_QUOTED_STRING : '\'' SINGLE_QUOTED_STRING_CONTENT '\'' ; | ||
fragment SINGLE_QUOTED_STRING_CONTENT : .*? ; | ||
|
||
LDQUOTE : '"' -> pushMode(IN_DSTRING) ; | ||
LPAR : '(' -> pushMode(DEFAULT_MODE) ; | ||
INTERPOLATION_START : '$(' -> pushMode(DEFAULT_MODE) ; | ||
RPAR : ')' -> popMode ; | ||
|
||
WORD : ([a-zA-Z0-9] | '.' | '_' | '-' | '+' | '/' | '%' | '{' | '}' | '@' | ',' | '[' | ']' | '=' | '^')+ ; | ||
AND : '&&' ; | ||
PIPE : '|' ; | ||
OR : '||' ; | ||
NOT : '!' SPACES ; // require space to make it possible use bang in arguments (not used yet, and maybe it's worth to allow '!false') | ||
SEMICOLON : ';' ; | ||
NEWLINES : '\n' (SPACES | '\n')* ; | ||
|
||
ESCAPE_NEWLINE : '\\' SPACES? COMMENT? '\n' -> skip ; | ||
COMMENT : '#' ~('\n')* -> skip ; | ||
SPACES : [ \t]+ -> skip ; | ||
|
||
mode IN_DSTRING; | ||
TEXT : ~('\\' | '"' | '$')+ ; | ||
INTERPOLATION_START_IN_DSTRING : '$(' -> pushMode(DEFAULT_MODE) ; | ||
ESCAPE_SEQUENCE : '\\' . ; | ||
RDQUOTE : '"' -> popMode ; |
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,39 @@ | ||
// AeroShell parser grammar. Powered by https:/antlr/antlr4 | ||
// Use ./generate-aero-shell-parser.sh to regenerate grammar code | ||
parser grammar AeroShellParser; | ||
|
||
options { | ||
tokenVocab = './grammar/AeroShellLexer'; | ||
} | ||
|
||
root : program EOF | EOF ; // Consume ALL the input | ||
|
||
program | ||
: NOT program #Not | ||
|
||
| program NEWLINES PIPE program #Pipe | ||
| program PIPE program #Pipe | ||
|
||
| program NEWLINES AND program #And | ||
| program AND program #And | ||
|
||
| program NEWLINES OR program #Or | ||
| program OR program #Or | ||
|
||
| program (SEMICOLON | NEWLINES) (program)*? #Seq | ||
| LPAR program RPAR #Parens | ||
| arg+ #Args | ||
; | ||
|
||
arg | ||
: WORD #Word | ||
| LDQUOTE dStringFragment* RDQUOTE #DQuotedString | ||
| INTERPOLATION_START program RPAR #Substitution | ||
| SINGLE_QUOTED_STRING #SQuotedString | ||
; | ||
|
||
dStringFragment | ||
: TEXT | ||
| ESCAPE_SEQUENCE | ||
| INTERPOLATION_START_IN_DSTRING program RPAR | ||
; |
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,7 @@ | ||
#!/usr/bin/env bash | ||
cd "$(dirname "$0")/.." | ||
source ./script/setup.sh | ||
|
||
python3 -m venv .deps/python-venv | ||
source .deps/python-venv/bin/activate | ||
python3 -m pip install 'antlr4-tools==0.2.1' |
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,28 @@ | ||
Copyright (c) 2012-2022 The ANTLR Project. All rights reserved. | ||
|
||
Redistribution and use in source and binary forms, with or without | ||
modification, are permitted provided that the following conditions | ||
are met: | ||
|
||
1. Redistributions of source code must retain the above copyright | ||
notice, this list of conditions and the following disclaimer. | ||
|
||
2. Redistributions in binary form must reproduce the above copyright | ||
notice, this list of conditions and the following disclaimer in the | ||
documentation and/or other materials provided with the distribution. | ||
|
||
3. Neither name of copyright holders nor the names of its contributors | ||
may be used to endorse or promote products derived from this software | ||
without specific prior written permission. | ||
|
||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR | ||
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | ||
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | ||
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | ||
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | ||
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |