Skip to content

Commit

Permalink
[build] Fixes for antlr#3468 -- Dependabot PRs cause crashes. (antlr#…
Browse files Browse the repository at this point in the history
…3469)

* Fixes for antlr#3468

Remove all mention of tool version in workflows/main.yml, because the version is per-target. Instead install antlr4 tool.

* Fixes for antlr#3468.

Set versions for Java Antlr version and use antlr4 tool to build.

* Fix for antlr#3468. Cpp.

Remove all explicit checks for java and just use the antlr4-tools antlr4 tool.

* Fix for antlr#3468. Java and install of Python3 and Pip.

Fix the Java template, and install of Python3 and Pip regardless because we now use antlr4, and never install java explicitly.

* Fixes for antlr#3468. JavaScript.

Fix the JavaScript build scripts, including the package.json version for Antlr4 runtime.

* Fixes for $3468. TypeScript.

Fix the version number for Antlr4 tool and runtime, and grep the version from the package.json file and send that the the antlr4 tool.

* Fix antlr#3468. JavaScript, TypeScript, Dart.

Fixes to remove newlines from brain-damaged version number that contain newlines.

* Fixes for antlr#3468. Java.

Set version for Antlr. Set up correct location of jar file using Python script from antlr4 tool.

* Fixes for antlr#3468. Java and Powershell.

This is a change to the Powershell version of the build script, equivalent to the Bash version.

* Fixes for antlr#3468. Java and Powershell running.

This is a fix for the jar path for running the parser with java.

* Fixes for antlr#3468. Java and Powershell.

Variable references require curly braces around the name when colon follows the name.

* Fixes for antlr#3468. PHP and Bash.

Change reference to java and the antlr jar to the antlr4 tool and version.

* Fixes for antlr#3468. Python3, CSharp.

Updates to version number of antlr for CSharp, scripts for Python3.

* Fixes for antlr#3468. Go target.

These changes are to fix the problem of using the antlr4 tool and using the latest api for 4.13.0 for Go. It's all changed.

* Fixes for antlr#3468. Cpp and Pwsh

Updates to get Cpp target to work. Adjustments to pwsh scripts.

* Fixes for antlr#3468. Fix formatting of abb grammar, call all build of all targets.

This change is to the abb grammar, but the only thing that is done is to remove some triple spacing between some rules. The point is to force a rebuild of all targets, so the new build scripts can all be checked.

* Fixes for antlr#3468. Dart target still on 4.12.0.

Rollback the version of Antlr to 4.12.0 for Dart--the runtime has not been released yet. In addition, this is a fabulous test of the new per-target Antlr version testing.

* Fixes for antlr#3468. Dart.

An release of the Dart runtime for 4.13.0 has been made in the last day.

* Fixes for antlr#3468. Remove the .errors file mistakenly commited.
  • Loading branch information
kaby76 authored May 26, 2023
1 parent 4ee2f74 commit dfe17de
Show file tree
Hide file tree
Showing 27 changed files with 132 additions and 104 deletions.
42 changes: 18 additions & 24 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,21 @@ jobs:
run: |
go version
- name: Install Python
if: ${{ matrix.language == 'Python3' }}
uses: actions/[email protected]
with:
python-version: '3.10'
- name: Do not trust Python env
if: ${{ matrix.language == 'Python3' }}
run: |
python --version
- name: Upgrade Pip.
run: |
python -m ensurepip --upgrade
- name: Do not trust Pip.
run: |
pip --version
- name: Install Antlr tool
run: |
pip install antlr4-tools
- name: Install JavaScript
if: ${{ matrix.language == 'JavaScript' }}
uses: actions/[email protected]
Expand All @@ -78,16 +85,6 @@ jobs:
if: ${{ matrix.language == 'JavaScript' }}
run: |
node --version
- name: Download ANTLR
shell: pwsh
run: |
$antlrPath = _scripts/get-antlr.ps1 "4.13.0"
echo "$antlrPath" | Write-Host
echo "antlr_path=$antlrPath" >> $env:GITHUB_ENV
If(!(test-path -PathType container /tmp)) {
New-Item -Path '/tmp' -ItemType Directory
}
copy $antlrPath /tmp/antlr4-complete.jar
- name: Update paths
shell: pwsh
run: |
Expand Down Expand Up @@ -167,14 +164,21 @@ jobs:
run: |
go version
- name: Install Python
if: ${{ matrix.language == 'Python3' }}
uses: actions/[email protected]
with:
python-version: '3.10'
- name: Do not trust Python env
if: ${{ matrix.language == 'Python3' }}
run: |
python --version
- name: Upgrade Pip.
run: |
python -m ensurepip --upgrade
- name: Do not trust Pip.
run: |
pip --version
- name: Install Antlr tool
run: |
pip install antlr4-tools
- name: Install JavaScript
if: ${{ matrix.language == 'JavaScript' }}
uses: actions/[email protected]
Expand All @@ -184,16 +188,6 @@ jobs:
if: ${{ matrix.language == 'JavaScript' }}
run: |
node --version
- name: Download ANTLR
shell: pwsh
run: |
$antlrPath = _scripts/get-antlr.ps1 "4.13.0"
echo "$antlrPath" | Write-Host
echo "antlr_path=$antlrPath" >> $env:GITHUB_ENV
If(!(test-path -PathType container /tmp)) {
New-Item -Path '/tmp' -ItemType Directory
}
copy $antlrPath /tmp/antlr4-complete.jar
- name: Install trgen
shell: bash
run: |
Expand Down
4 changes: 1 addition & 3 deletions _scripts/templates/CSharp/Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@
\</PropertyGroup>
\<ItemGroup>
<tool_grammar_files:{x | \<Antlr4 Include="<x>">
<if(name_space)>\<Package><name_space>\</Package><endif>
\<!-- AntlrRuntime><antlr_tool_path>\</AntlrRuntime -->
\</Antlr4>
<if(name_space)>\<Package><name_space>\</Package><endif>\</Antlr4>
} > \</ItemGroup>
\<ItemGroup>
\<PackageReference Include="Antlr4.Runtime.Standard" Version ="4.13.0" />
Expand Down
2 changes: 0 additions & 2 deletions _scripts/templates/Cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ cmake_minimum_required (VERSION 3.14)
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)

set(CMAKE_CXX_STANDARD 17)
set(ANTLR_EXECUTABLE "<antlr_tool_path>")
set(Java_JAVA_EXECUTABLE "java")
set(ANTLR4_TAG 4.13.0)
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
Expand Down
1 change: 1 addition & 0 deletions _scripts/templates/Cpp/build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,5 @@ if($compile_exit_code -ne 0){
Write-Host "Failed second cmake call $compile_exit_code."
exit $compile_exit_code
}
Set-Location '..'
exit $compile_exit_code
19 changes: 3 additions & 16 deletions _scripts/templates/Cpp/cmake/FindANTLR.cmake
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
find_package(Java QUIET COMPONENTS Runtime)

if(NOT ANTLR_EXECUTABLE)
find_program(ANTLR_EXECUTABLE
NAMES antlr.jar antlr4.jar antlr-4.jar antlr-4.8-complete.jar)
endif()

if(ANTLR_EXECUTABLE AND Java_JAVA_EXECUTABLE)
execute_process(
COMMAND ${Java_JAVA_EXECUTABLE} -jar ${ANTLR_EXECUTABLE}
COMMAND antlr4<if(os_win)>.exe<else><endif>
OUTPUT_VARIABLE ANTLR_COMMAND_OUTPUT
ERROR_VARIABLE ANTLR_COMMAND_ERROR
RESULT_VARIABLE ANTLR_COMMAND_RESULT
Expand All @@ -19,7 +13,7 @@ if(ANTLR_EXECUTABLE AND Java_JAVA_EXECUTABLE)
else()
message(
SEND_ERROR
"Command '${Java_JAVA_EXECUTABLE} -jar ${ANTLR_EXECUTABLE}' "
"Command antlr4<if(os_win)>.exe<else><endif> "
"failed with the output '${ANTLR_COMMAND_ERROR}'")
endif()

Expand Down Expand Up @@ -103,7 +97,7 @@ if(ANTLR_EXECUTABLE AND Java_JAVA_EXECUTABLE)

add_custom_command(
OUTPUT ${ANTLR_${Name}_OUTPUTS}
COMMAND ${Java_JAVA_EXECUTABLE} -jar ${ANTLR_EXECUTABLE}
COMMAND antlr4<if(os_win)>.exe<else><endif>
${InputFile}
-o ${ANTLR_${Name}_OUTPUT_DIR}
-no-listener
Expand All @@ -115,10 +109,3 @@ if(ANTLR_EXECUTABLE AND Java_JAVA_EXECUTABLE)
COMMENT "Building ${Name} with ANTLR ${ANTLR_VERSION}")
endmacro(ANTLR_TARGET)

endif(ANTLR_EXECUTABLE AND Java_JAVA_EXECUTABLE)

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(
ANTLR
REQUIRED_VARS ANTLR_EXECUTABLE Java_JAVA_EXECUTABLE
VERSION_VAR ANTLR_VERSION)
2 changes: 0 additions & 2 deletions _scripts/templates/Cpp/cmake/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ include_directories(${ANTLR4_INCLUDE_DIRS})
# set variable pointing to the antlr tool that supports C++
# this is not required if the jar file can be found under PATH environment
set(ANTLR_EXECUTABLE /home/user/antlr-4.8-complete.jar)
# add macros to generate ANTLR Cpp code from grammar
find_package(ANTLR REQUIRED)
Expand Down Expand Up @@ -60,7 +59,6 @@ The module defines the following variables:

```
ANTLR_FOUND - true is ANTLR jar executable is found
ANTLR_EXECUTABLE - the path to the ANTLR jar executable
ANTLR_VERSION - the version of ANTLR
```

Expand Down
10 changes: 1 addition & 9 deletions _scripts/templates/Cpp/cmake/antlr4-generator.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -124,14 +124,6 @@ function(antlr4_generate
set(Antlr4_LibOption "")
endif ()

if(NOT Java_FOUND)
message(FATAL_ERROR "Java is required to process grammar or lexer files! - Use 'FIND_PACKAGE(Java COMPONENTS Runtime REQUIRED)'")
endif()

if(NOT EXISTS "${ANTLR4_JAR_LOCATION}")
message(FATAL_ERROR "Unable to find antlr tool. ANTLR4_JAR_LOCATION:${ANTLR4_JAR_LOCATION}")
endif()

# The call to generate the files
add_custom_command(
OUTPUT ${Antlr4_GeneratedTargets}
Expand All @@ -143,7 +135,7 @@ function(antlr4_generate
${CMAKE_COMMAND} -E make_directory ${Antlr4_GeneratedSrcDir}
COMMAND
# Generate files
"${Java_JAVA_EXECUTABLE}" -jar "${ANTLR4_JAR_LOCATION}" -Werror -Dlanguage=Cpp ${Antlr4_BuildListenerOption} ${Antlr4_BuildVisitorOption} ${Antlr4_LibOption} ${ANTLR4_GENERATED_OPTIONS} -o "${Antlr4_GeneratedSrcDir}" ${Antlr4_NamespaceOption} "${Antlr4_InputFile}"
antlr4 -v $(ANTLR4_TAG) -Werror -Dlanguage=Cpp ${Antlr4_BuildListenerOption} ${Antlr4_BuildVisitorOption} ${Antlr4_LibOption} ${ANTLR4_GENERATED_OPTIONS} -o "${Antlr4_GeneratedSrcDir}" ${Antlr4_NamespaceOption} "${Antlr4_InputFile}"
WORKING_DIRECTORY "${CMAKE_BINARY_DIR}"
MAIN_DEPENDENCY "${Antlr4_InputFile}"
DEPENDS ${Antlr4_AdditionalDependencies}
Expand Down
8 changes: 7 additions & 1 deletion _scripts/templates/Dart/build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,14 @@ if (Test-Path -Path transformGrammar.py -PathType Leaf) {
$(& python3 transformGrammar.py ) 2>&1 | Write-Host
}

# Because there is no integrated build script for Dart targets, we need
# to manually look at the version in pubspec.yaml and extract the
# version number. We can then use this with antlr4 to generate the
# parser and lexer.
$version = Select-String -Path "pubspec.yaml" -Pattern "antlr4" | ForEach-Object {$_.Line.Split(" ")[3]}

<tool_grammar_files:{x |
$(& java -jar <antlr_tool_path> <x> -encoding <antlr_encoding> -Dlanguage=Dart <antlr_tool_args:{y | <y> } > ; $compile_exit_code = $LASTEXITCODE) | Write-Host
$(& antlr4 -v $version <x> -encoding <antlr_encoding> -Dlanguage=Dart <antlr_tool_args:{y | <y> } > ; $compile_exit_code = $LASTEXITCODE) | Write-Host
if($compile_exit_code -ne 0){
exit $compile_exit_code
\}
Expand Down
8 changes: 7 additions & 1 deletion _scripts/templates/Dart/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,14 @@ set -e

if [ -f transformGrammar.py ]; then python3 transformGrammar.py ; fi

# Because there is no integrated build script for Dart targets, we need
# to manually look at the version in pubspec.yaml and extract the
# version number. We can then use this with antlr4 to generate the
# parser and lexer.
version=`grep antlr4 pubspec.yaml | awk '{print $2}' | tr -d '\r' | tr -d '\n'`

<tool_grammar_tuples:{x |
java -jar "<antlr_tool_path>" -encoding <antlr_encoding> -Dlanguage=Dart <x.AntlrArgs> <antlr_tool_args:{y | <y> } > <x.GrammarFileName>
antlr4 -v $version -encoding <antlr_encoding> -Dlanguage=Dart <x.AntlrArgs> <antlr_tool_args:{y | <y> } > <x.GrammarFileName>
} >

dart pub get
Expand Down
8 changes: 4 additions & 4 deletions _scripts/templates/Go/Test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"time"
"strconv"
"bufio"
"github.com/antlr/antlr4/runtime/Go/antlr/v4"
"github.com/antlr4-go/antlr/v4"
"example.com/myparser/<package_name>"
)
type CustomErrorListener struct {
Expand Down Expand Up @@ -44,15 +44,15 @@ func (l *CustomErrorListener) SyntaxError(recognizer antlr.Recognizer, offending
}
}

func (l *CustomErrorListener) ReportAmbiguity(recognizer antlr.Parser, dfa *antlr.DFA, startIndex, stopIndex int, exact bool, ambigAlts *antlr.BitSet, configs antlr.ATNConfigSet) {
func (l *CustomErrorListener) ReportAmbiguity(recognizer antlr.Parser, dfa *antlr.DFA, startIndex, stopIndex int, exact bool, ambigAlts *antlr.BitSet, configs *antlr.ATNConfigSet) {
antlr.ConsoleErrorListenerINSTANCE.ReportAmbiguity(recognizer, dfa, startIndex, stopIndex, exact, ambigAlts, configs)
}

func (l *CustomErrorListener) ReportAttemptingFullContext(recognizer antlr.Parser, dfa *antlr.DFA, startIndex, stopIndex int, conflictingAlts *antlr.BitSet, configs antlr.ATNConfigSet) {
func (l *CustomErrorListener) ReportAttemptingFullContext(recognizer antlr.Parser, dfa *antlr.DFA, startIndex, stopIndex int, conflictingAlts *antlr.BitSet, configs *antlr.ATNConfigSet) {
antlr.ConsoleErrorListenerINSTANCE.ReportAttemptingFullContext(recognizer, dfa, startIndex, stopIndex, conflictingAlts, configs)
}

func (l *CustomErrorListener) ReportContextSensitivity(recognizer antlr.Parser, dfa *antlr.DFA, startIndex, stopIndex, prediction int, configs antlr.ATNConfigSet) {
func (l *CustomErrorListener) ReportContextSensitivity(recognizer antlr.Parser, dfa *antlr.DFA, startIndex, stopIndex, prediction int, configs *antlr.ATNConfigSet) {
antlr.ConsoleErrorListenerINSTANCE.ReportContextSensitivity(recognizer, dfa, startIndex, stopIndex, prediction, configs)
}

Expand Down
4 changes: 2 additions & 2 deletions _scripts/templates/Go/build.ps1
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Generated from trgen <version>
$env:GO111MODULE = "on"
For ($i=0; $i -le 5; $i++) {
$(& go get github.com/antlr4-go/antlr ; $compile_exit_code = $LASTEXITCODE) | Write-Host
$(& go get github.com/antlr4-go/antlr/v4 ; $compile_exit_code = $LASTEXITCODE) | Write-Host
if($compile_exit_code -eq 0){
Break
}
Expand All @@ -16,7 +16,7 @@ if (Test-Path -Path transformGrammar.py -PathType Leaf) {
}

<tool_grammar_tuples:{x |
$(& java -jar <antlr_tool_path> <x.GrammarFileName> -encoding <antlr_encoding> -Dlanguage=Go <x.AntlrArgs> <antlr_tool_args:{y | <y> } > ; $compile_exit_code = $LASTEXITCODE) | Write-Host
$(& antlr4 <x.GrammarFileName> -encoding <antlr_encoding> -Dlanguage=Go <x.AntlrArgs> <antlr_tool_args:{y | <y> } > ; $compile_exit_code = $LASTEXITCODE) | Write-Host
if($compile_exit_code -ne 0){
exit $compile_exit_code
\}
Expand Down
10 changes: 8 additions & 2 deletions _scripts/templates/Go/build.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
# Generated from trgen <version>
export GO111MODULE=on
for i in {1..5}; do go get github.com/antlr4-go/antlr; if [ "$?" = "0" ]; then break; fi; done; if [ "$?" != "0" ]; then exit 1; fi
for i in {1..5}; do go get github.com/antlr4-go/antlr/v4; if [ "$?" = "0" ]; then break; fi; done; if [ "$?" != "0" ]; then exit 1; fi

set -e

if [ -f transformGrammar.py ]; then python3 transformGrammar.py ; fi

# Because there is no integrated build script for Dart targets, we need
# to manually look at the version in pubspec.yaml and extract the
# version number. We can then use this with antlr4 to generate the
# parser and lexer.
# Go has no version, just the latest version.

<tool_grammar_tuples:{x |
java -jar "<antlr_tool_path>" -encoding <antlr_encoding> -Dlanguage=Go <x.AntlrArgs> <antlr_tool_args:{y | <y> } > <x.GrammarFileName>
antlr4 -encoding <antlr_encoding> -Dlanguage=Go <x.AntlrArgs> <antlr_tool_args:{y | <y> } > <x.GrammarFileName>
} >

go build Test.go
7 changes: 5 additions & 2 deletions _scripts/templates/Java/build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@
if (Test-Path -Path transformGrammar.py -PathType Leaf) {
$(& python3 transformGrammar.py ) 2>&1 | Write-Host
}
$version = "4.13.0"

<tool_grammar_tuples:{x |
$(& java -jar <antlr_tool_path> <x.GrammarFileName> -encoding <antlr_encoding> -Dlanguage=Java <x.AntlrArgs> <antlr_tool_args:{y | <y> } > ; $compile_exit_code = $LASTEXITCODE) | Write-Host
$(& antlr4 -v $version <x.GrammarFileName> -encoding <antlr_encoding> -Dlanguage=Java <x.AntlrArgs> <antlr_tool_args:{y | <y> } > ; $compile_exit_code = $LASTEXITCODE) | Write-Host
if($compile_exit_code -ne 0){
exit $compile_exit_code
\}
}>

$(& javac -cp "<antlr_tool_path><if(path_sep_semi)>;<else>:<endif>." <tool_grammar_tuples:{x|<x.GeneratedFileName> }> Test.java ErrorListener.java ; $compile_exit_code = $LASTEXITCODE) | Write-Host
$homePath = [System.Environment]::GetFolderPath("UserProfile")
$JAR = Join-Path -Path $homePath -ChildPath ".m2/repository/org/antlr/antlr4/$version/antlr4-$version-complete.jar"
$(& javac -cp "${JAR}<if(path_sep_semi)>;<else>:<endif>." <tool_grammar_tuples:{x|<x.GeneratedFileName> }> Test.java ErrorListener.java ; $compile_exit_code = $LASTEXITCODE) | Write-Host
exit $compile_exit_code
10 changes: 8 additions & 2 deletions _scripts/templates/Java/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,17 @@
set -e
if [ -f transformGrammar.py ]; then python3 transformGrammar.py ; fi

# Because there is no integrated build script for Dart targets, we need
# to manually look at the version in pubspec.yaml and extract the
# version number. We can then use this with antlr4 to generate the
# parser and lexer.
version=4.13.0

<tool_grammar_tuples:{x |
java -jar "<antlr_tool_path>" -encoding <antlr_encoding> -Dlanguage=Java <x.AntlrArgs> <antlr_tool_args:{y | <y> } > <x.GrammarFileName>
antlr4 -v $version -encoding <antlr_encoding> -Dlanguage=Java <x.AntlrArgs> <antlr_tool_args:{y | <y> } > <x.GrammarFileName>
}>

JAR=<antlr_tool_path>
JAR=`python -c "import os; from pathlib import Path; print(os.path.join(Path.home() , '.m2', 'repository', 'org', 'antlr', 'antlr4', '$version', 'antlr4-$version-complete.jar'))"`
CLASSPATH="$JAR<if(path_sep_semi)>\;<else>:<endif>."
javac -cp "$CLASSPATH" *.java

Expand Down
7 changes: 5 additions & 2 deletions _scripts/templates/Java/test.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,15 @@ if (-not(Test-Path -Path "tests.txt" -PathType Leaf)) {
}

# Parse all input files.
$version = "4.13.0"
$homePath = [System.Environment]::GetFolderPath("UserProfile")
$JAR = Join-Path -Path $homePath -ChildPath ".m2/repository/org/antlr/antlr4/$version/antlr4-$version-complete.jar"
<if(individual_parsing)>
# Individual parsing.
Get-Content "tests.txt" | ForEach-Object { trwdog java -cp "<antlr_tool_path><if(path_sep_semi)>;<else>:<endif>." Test -q -tee -tree *>> parse.txt }
Get-Content "tests.txt" | ForEach-Object { trwdog java -cp "$JAR<if(path_sep_semi)>;<else>:<endif>." Test -q -tee -tree *>> parse.txt }
<else>
# Group parsing.
get-content "tests.txt" | trwdog java -cp "<antlr_tool_path><if(path_sep_semi)>;<else>:<endif>." Test -q -x -tee -tree *> parse.txt
get-content "tests.txt" | trwdog java -cp "${JAR}<if(path_sep_semi)>;<else>:<endif>." Test -q -x -tee -tree *> parse.txt
$status = $LASTEXITCODE
<endif>

Expand Down
3 changes: 2 additions & 1 deletion _scripts/templates/Java/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ do
done

# Parse all input files.
JAR="<antlr_tool_path>"
version=4.13.0
JAR=`python -c "import os; from pathlib import Path; print(os.path.join(Path.home() , '.m2', 'repository', 'org', 'antlr', 'antlr4', '$version', 'antlr4-$version-complete.jar'))"`
CLASSPATH="$JAR<if(path_sep_semi)>\;<else>:<endif>."
<if(individual_parsing)>
# Individual parsing.
Expand Down
8 changes: 7 additions & 1 deletion _scripts/templates/JavaScript/build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,14 @@ if (Test-Path -Path transformGrammar.py -PathType Leaf) {
$(& python3 transformGrammar.py ) 2>&1 | Write-Host
}

# Because there is no integrated build script for Dart targets, we need
# to manually look at the version in package.json and extract the
# version number. We can then use this with antlr4 to generate the
# parser and lexer.
$version = (Select-String -Path "package.json" -Pattern "antlr4" | ForEach-Object {$_.Line.Split(" ")[5]}) -replace '"|,|\r|\n'

<tool_grammar_tuples:{x |
$(& java -jar <antlr_tool_path> <x.GrammarFileName> -encoding <antlr_encoding> -Dlanguage=JavaScript <x.AntlrArgs> <antlr_tool_args:{y | <y> } > ; $compile_exit_code = $LASTEXITCODE) | Write-Host
$(& antlr4 -v $version <x.GrammarFileName> -encoding <antlr_encoding> -Dlanguage=JavaScript <x.AntlrArgs> <antlr_tool_args:{y | <y> } > ; $compile_exit_code = $LASTEXITCODE) | Write-Host
if($compile_exit_code -ne 0){
exit $compile_exit_code
\}
Expand Down
8 changes: 7 additions & 1 deletion _scripts/templates/JavaScript/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,14 @@ set -e

if [ -f transformGrammar.py ]; then python3 transformGrammar.py ; fi

# Because there is no integrated build script for Dart targets, we need
# to manually look at the version in package.json and extract the
# version number. We can then use this with antlr4 to generate the
# parser and lexer.
version=`grep antlr4 package.json | awk '{print $2}' | tr -d '"' | tr -d ',' | tr -d '\r' | tr -d '\n'`

<tool_grammar_tuples:{x |
java -jar "<antlr_tool_path>" -encoding <antlr_encoding> -Dlanguage=JavaScript <x.AntlrArgs> <antlr_tool_args:{y | <y> } > <x.GrammarFileName>
antlr4 -v $version -encoding <antlr_encoding> -Dlanguage=JavaScript <x.AntlrArgs> <antlr_tool_args:{y | <y> } > <x.GrammarFileName>
} >

npm install
Expand Down
2 changes: 1 addition & 1 deletion _scripts/templates/JavaScript/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"author": "",
"license": "ISC",
"dependencies": {
"antlr4": "4.13",
"antlr4": "4.13.0",
"fs-extra": "^11.1.0",
"timer-node": "^5.0.6",
"typescript-string-operations": "^1.4.1"
Expand Down
Loading

0 comments on commit dfe17de

Please sign in to comment.