Add current C++ target runtime from antlr4cpp (Dan McLaughlin).
This commit is contained in:
parent
1cec262cee
commit
72d6e3b400
|
@ -0,0 +1,24 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>CFBundleDevelopmentRegion</key>
|
||||
<string>en</string>
|
||||
<key>CFBundleExecutable</key>
|
||||
<string>$(EXECUTABLE_NAME)</string>
|
||||
<key>CFBundleIdentifier</key>
|
||||
<string>com.antlr.$(PRODUCT_NAME:rfc1034identifier)</string>
|
||||
<key>CFBundleInfoDictionaryVersion</key>
|
||||
<string>6.0</string>
|
||||
<key>CFBundleName</key>
|
||||
<string>$(PRODUCT_NAME)</string>
|
||||
<key>CFBundlePackageType</key>
|
||||
<string>BNDL</string>
|
||||
<key>CFBundleShortVersionString</key>
|
||||
<string>1.0</string>
|
||||
<key>CFBundleSignature</key>
|
||||
<string>????</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>1</string>
|
||||
</dict>
|
||||
</plist>
|
|
@ -0,0 +1,73 @@
|
|||
/*
|
||||
* [The "BSD license"]
|
||||
* Copyright (c) 2015 Dan McLaughlin
|
||||
* 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. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
||||
*/
|
||||
|
||||
#import <Cocoa/Cocoa.h>
|
||||
#import <XCTest/XCTest.h>
|
||||
#include "ParserATNSimulator.h"
|
||||
#include "DFA.h"
|
||||
|
||||
#include <vector>
|
||||
|
||||
@interface antlrcpp_Tests : XCTestCase
|
||||
|
||||
@end
|
||||
|
||||
@implementation antlrcpp_Tests
|
||||
|
||||
- (void)setUp {
|
||||
[super setUp];
|
||||
// Put setup code here. This method is called before the invocation of each test method in the class.
|
||||
}
|
||||
|
||||
- (void)tearDown {
|
||||
// Put teardown code here. This method is called after the invocation of each test method in the class.
|
||||
[super tearDown];
|
||||
}
|
||||
|
||||
- (void)testExample {
|
||||
try {
|
||||
std::vector<org::antlr::v4::runtime::dfa::DFA> decisionToDFA;
|
||||
|
||||
org::antlr::v4::runtime::atn::ParserATNSimulator foo(nullptr, decisionToDFA, nullptr);
|
||||
}
|
||||
catch (std::exception e) {
|
||||
|
||||
XCTAssert(NO, @"Fail");
|
||||
}
|
||||
XCTAssert(YES, @"Pass");
|
||||
}
|
||||
|
||||
- (void)testPerformanceExample {
|
||||
// This is an example of a performance test case.
|
||||
[self measureBlock:^{
|
||||
// Put the code you want to measure the time of here.
|
||||
}];
|
||||
}
|
||||
|
||||
@end
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,43 @@
|
|||
#!/bin/sh
|
||||
# [The "BSD license"]
|
||||
# Copyright (c) 2013 Terence Parr
|
||||
# Copyright (c) 2013 Dan McLaughlin
|
||||
# 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. The name of the author may not be used to endorse or promote products
|
||||
# derived from this software without specific prior written permission.
|
||||
|
||||
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
||||
|
||||
|
||||
CURRENT_DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
|
||||
ANTLRCPP_XCODEPROJ="${CURRENT_DIR}/antlrcpp.xcodeproj"
|
||||
|
||||
# OS X
|
||||
xcrun xcodebuild -project ${ANTLRCPP_XCODEPROJ} -target antlrcpp -configuration Release $@
|
||||
xcrun xcodebuild -project ${ANTLRCPP_XCODEPROJ} -target antlrcpp -configuration Debug $@
|
||||
|
||||
# iOS
|
||||
#xcrun xcodebuild -project ${ANTLRCPP_XCODEPROJ} -target antlrcpp_iphone -configuration Release -sdk iphoneos $@
|
||||
#xcrun xcodebuild -project ${ANTLRCPP_XCODEPROJ} -target antlrcpp_iphone -configuration Debug -sdk iphoneos $@
|
||||
#xcrun xcodebuild -project ${ANTLRCPP_XCODEPROJ} -target antlrcpp_iphone_sim -configuration Release -sdk iphonesimulator $@
|
||||
#xcrun xcodebuild -project ${ANTLRCPP_XCODEPROJ} -target antlrcpp_iphone_sim -configuration Debug -sdk iphonesimulator $@
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
[The "BSD license"]
|
||||
Copyright (c) 2013 Terence Parr
|
||||
Copyright (c) 2013 Dan McLaughlin
|
||||
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. The name of the author may not be used to endorse or promote products
|
||||
derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
|
@ -0,0 +1,141 @@
|
|||
# [The "BSD license"]
|
||||
# Copyright (c) 2015 Dan McLaughlin
|
||||
# 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. The name of the author may not be used to endorse or promote products
|
||||
# derived from this software without specific prior written permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
||||
|
||||
LINUXROT:= `pwd` # doh
|
||||
RUNTIME := ../org/antlr/v4/runtime
|
||||
OBJDIR := obj
|
||||
|
||||
# Stop on any error or warning, comment out if you want to blast through
|
||||
NUMERRORS := -Werror
|
||||
|
||||
# Another possibility
|
||||
# NUMERRORS := -fmax-errors=5
|
||||
|
||||
CC := ./g++
|
||||
CFLAGS := -fPIC -shared -g -O3 -Wall -std=c++11 $(NUMERRORS)
|
||||
LDFLAGS :=
|
||||
IFLAGS :=-I../antlrcpp -I. -I $(RUNTIME) -I $(RUNTIME)/atn -I $(RUNTIME)/dfa \
|
||||
-I $(RUNTIME)/misc -I $(RUNTIME)/tree -I $(RUNTIME)/tree/pattern \
|
||||
-I $(RUNTIME)/tree/xpath
|
||||
NAME := ANTLR4
|
||||
MAJOR := 0
|
||||
MINOR := 1
|
||||
VERSION := $(MAJOR).$(MINOR)
|
||||
|
||||
DFA := $(RUNTIME)/dfa
|
||||
MISC := $(RUNTIME)/misc
|
||||
TREE := $(RUNTIME)/tree
|
||||
TREEPAT := $(TREE)/pattern
|
||||
XPATH := $(TREE)/xpath
|
||||
|
||||
RUNTIMESRC := $(wildcard $(RUNTIME)/*.cpp)
|
||||
RUNTIMEOBJ := $(patsubst %.cpp,%.o,$(RUNTIMESRC))
|
||||
DFASRC := $(wildcard $(DFA)/*.cpp)
|
||||
DFAOBJ := $(patsubst %.cpp,%.o,$(DFASRC))
|
||||
MISCSRC := $(wildcard $(MISC)/*.cpp)
|
||||
MISCOBJ := $(patsubst %.cpp,%.o,$(MISCSRC))
|
||||
TREESRC := $(wildcard $(TREE)/*.cpp)
|
||||
TREEOBJ := $(patsubst %.cpp,%.o,$(TREESRC))
|
||||
TREEPATSRC := $(wildcard $(TREEPAT)/*.cpp)
|
||||
TREEPATOBJ := $(patsubst %.cpp,%.o,$(TREEPATSRC))
|
||||
XPATHSRC := $(wildcard $(XPATH)/*.cpp)
|
||||
XPATHOBJ := $(patsubst %.cpp,%.o,$(XPATHSRC))
|
||||
|
||||
OBJS := $(notdir $(RUNTIMEOBJ) $(DFAOBJ) $(MISCOBJ) $(TREEOBJ) \
|
||||
$(TREEPATOBJ) $(XPATHOBJ) )
|
||||
|
||||
OBJECTS := $(addprefix $(OBJDIR)/,$(OBJS))
|
||||
|
||||
SOURCES := $(RUNTIMESRC) $(DFASRC) $(MISCSRC) $(TREESRC) $(TREEPATSRC) $(XPATHSRC)
|
||||
|
||||
LIB := lib$(NAME).so.$(VERSION)
|
||||
|
||||
all: $(LIB)
|
||||
|
||||
$(LIB): $(OBJECTS)
|
||||
$(CC) -shared -Wl,-soname,lib$(NAME).so.$(MAJOR) $^ -o $@
|
||||
|
||||
# pull in dependency info for *existing* .o files
|
||||
-include $(OBJECTS:.o=.d)
|
||||
|
||||
# TODO: Is there a way to collapse all these into one line? It doesn't
|
||||
# work if I do so
|
||||
$(OBJDIR)/%.o : $(RUNTIME)/%.cpp
|
||||
@set -e; rm -f $@; \
|
||||
$(CC) $(IFLAGS) $(CFLAGS) -o $@ -c $<
|
||||
$(CC) $(IFLAGS) $(CFLAGS) -o $(subst .o,.d,$@) -MM $<
|
||||
sed -i '1s/^/obj\//' $(subst .o,.d,$@)
|
||||
# This is the GNU makefile canonical way of adding the dependency file generation
|
||||
# to include regenerating when any of the dependencies change. However in our
|
||||
# solution the dependency is always generated whenever a compilation occurs (as it should)
|
||||
# so this is un-necessary
|
||||
# sed -i 's,\($*\)\.o[ :]*,\1.o $(subst .o,.d,$@) : ,g' $(subst .o,.d,$@)
|
||||
|
||||
$(OBJDIR)/%.o : $(DFA)/%.cpp
|
||||
@set -e; rm -f $@; \
|
||||
$(CC) $(IFLAGS) $(CFLAGS) -o $@ -c $<
|
||||
$(CC) $(IFLAGS) $(CFLAGS) -o $(subst .o,.d,$@) -MM $<
|
||||
sed -i '1s/^/obj\//' $(subst .o,.d,$@)
|
||||
# sed -i 's,\($*\)\.o[ :]*,\1.o $(subst .o,.d,$@) : ,g' $(subst .o,.d,$@)
|
||||
|
||||
$(OBJDIR)/%.o : $(MISC)/%.cpp
|
||||
@set -e; rm -f $@; \
|
||||
$(CC) $(IFLAGS) $(CFLAGS) -o $@ -c $<
|
||||
$(CC) $(IFLAGS) $(CFLAGS) -o $(subst .o,.d,$@) -MM $<
|
||||
sed -i '1s/^/obj\//' $(subst .o,.d,$@)
|
||||
# sed -i 's,\($*\)\.o[ :]*,\1.o $(subst .o,.d,$@) : ,g' $(subst .o,.d,$@)
|
||||
|
||||
$(OBJDIR)/%.o : $(TREE)/%.cpp
|
||||
@set -e; rm -f $@; \
|
||||
$(CC) $(IFLAGS) $(CFLAGS) -o $@ -c $<
|
||||
$(CC) $(IFLAGS) $(CFLAGS) -o $(subst .o,.d,$@) -MM $<
|
||||
sed -i '1s/^/obj\//' $(subst .o,.d,$@)
|
||||
# sed -i 's,\($*\)\.o[ :]*,\1.o $(subst .o,.d,$@) : ,g' $(subst .o,.d,$@)
|
||||
|
||||
$(OBJDIR)/%.o : $(TREEPAT)/%.cpp
|
||||
@set -e; rm -f $@; \
|
||||
$(CC) $(IFLAGS) $(CFLAGS) -o $@ -c $<
|
||||
$(CC) $(IFLAGS) $(CFLAGS) -o $(subst .o,.d,$@) -MM $<
|
||||
sed -i '1s/^/obj\//' $(subst .o,.d,$@)
|
||||
# sed -i 's,\($*\)\.o[ :]*,\1.o $(subst .o,.d,$@) : ,g' $(subst .o,.d,$@)
|
||||
|
||||
$(OBJDIR)/%.o : $(XPATH)/%.cpp
|
||||
@set -e; rm -f $@; \
|
||||
$(CC) $(IFLAGS) $(CFLAGS) -o $@ -c $<
|
||||
$(CC) $(IFLAGS) $(CFLAGS) -o $(subst .o,.d,$@) -MM $<
|
||||
sed -i '1s/^/obj\//' $(subst .o,.d,$@)
|
||||
# sed -i 's,\($*\)\.o[ :]*,\1.o $(subst .o,.d,$@) : ,g' $(subst .o,.d,$@)
|
||||
|
||||
$(OBJECTS): | $(OBJDIR)/
|
||||
|
||||
$(OBJDIR): FORCE
|
||||
mkdir -p $(OBJDIR)
|
||||
|
||||
FORCE:
|
||||
|
||||
clean:
|
||||
$(RM) $(NAME)_test *.so* -fr obj
|
|
@ -0,0 +1,2 @@
|
|||
#include <bits/codecvt.h>
|
||||
#include <locale.h>
|
|
@ -0,0 +1,254 @@
|
|||
#! /usr/bin/perl -w
|
||||
|
||||
#
|
||||
# colorgcc
|
||||
#
|
||||
# Version: 1.3.2
|
||||
#
|
||||
# $Id: colorgcc,v 1.10 1999/04/29 17:15:52 jamoyers Exp $
|
||||
#
|
||||
# A wrapper to colorize the output from compilers whose messages
|
||||
# match the "gcc" format.
|
||||
#
|
||||
# Requires the ANSIColor module from CPAN.
|
||||
#
|
||||
# Usage:
|
||||
#
|
||||
# In a directory that occurs in your PATH _before_ the directory
|
||||
# where the compiler lives, create a softlink to colorgcc for
|
||||
# each compiler you want to colorize:
|
||||
#
|
||||
# g++ -> colorgcc
|
||||
# gcc -> colorgcc
|
||||
# cc -> colorgcc
|
||||
# etc.
|
||||
#
|
||||
# That's it. When "g++" is invoked, colorgcc is run instead.
|
||||
# colorgcc looks at the program name to figure out which compiler to run.
|
||||
#
|
||||
# The default settings can be overridden with ~/.colorgccrc.
|
||||
# See the comments in the sample .colorgccrc for more information.
|
||||
#
|
||||
# Note:
|
||||
#
|
||||
# colorgcc will only emit color codes if:
|
||||
#
|
||||
# (1) Its STDOUT is a tty and
|
||||
# (2) the value of $TERM is not listed in the "nocolor" option.
|
||||
#
|
||||
# If colorgcc colorizes the output, the compiler's STDERR will be
|
||||
# combined with STDOUT. Otherwise, colorgcc just passes the output from
|
||||
# the compiler through without modification.
|
||||
#
|
||||
# Author: Jamie Moyers <jmoyers@geeks.com>
|
||||
# Started: April 20, 1999
|
||||
# Licence: GNU Public License
|
||||
#
|
||||
# Credits:
|
||||
#
|
||||
# I got the idea for this from a script called "color_cvs":
|
||||
# color_cvs .03 Adrian Likins <adrian@gimp.org> <adrian@redhat.com>
|
||||
#
|
||||
# <seh4@ix.netcom.com> (Scott Harrington)
|
||||
# Much improved handling of compiler command line arguments.
|
||||
# exec compiler when not colorizing to preserve STDOUT, STDERR.
|
||||
# Fixed my STDIN kludge.
|
||||
#
|
||||
# <ecarotti@athena.polito.it> (Elias S. G. Carotti)
|
||||
# Corrected handling of text like -DPACKAGE=\"Package\"
|
||||
# Spotted return code bug.
|
||||
#
|
||||
# <erwin@erwin.andreasen.org> (Erwin S. Andreasen)
|
||||
# <schurchi@ucsd.edu> (Steve Churchill)
|
||||
# Return code bug fixes.
|
||||
#
|
||||
# <rik@kde.org> (Rik Hemsley)
|
||||
# Found STDIN bug.
|
||||
#
|
||||
# Changes:
|
||||
#
|
||||
# 1.3.2 Better handling of command line arguments to compiler.
|
||||
#
|
||||
# If we aren't colorizing output, we just exec the compiler which
|
||||
# preserves the original STDOUT and STDERR.
|
||||
#
|
||||
# Removed STDIN kludge. STDIN being passed correctly now.
|
||||
#
|
||||
# 1.3.1 Added kludge to copy STDIN to the compiler's STDIN.
|
||||
#
|
||||
# 1.3.0 Now correctly returns (I hope) the return code of the compiler
|
||||
# process as its own.
|
||||
#
|
||||
# 1.2.1 Applied patch to handle text similar to -DPACKAGE=\"Package\".
|
||||
#
|
||||
# 1.2.0 Added tty check. If STDOUT is not a tty, don't do color.
|
||||
#
|
||||
# 1.1.0 Added the "nocolor" option to turn off the color if the terminal type
|
||||
# ($TERM) is listed.
|
||||
#
|
||||
# 1.0.0 Initial Version
|
||||
|
||||
use Term::ANSIColor;
|
||||
use IPC::Open3;
|
||||
|
||||
sub initDefaults
|
||||
{
|
||||
$compilerPaths{"gcc"} = "/usr/bin/gcc";
|
||||
$compilerPaths{"g++"} = "/usr/bin/g++";
|
||||
$compilerPaths{"cc"} = "/usr/bin/cc";
|
||||
$compilerPaths{"c++"} = "/usr/bin/c++";
|
||||
|
||||
$nocolor{"dumb"} = "true";
|
||||
|
||||
$colors{"srcColor"} = color("cyan");
|
||||
$colors{"introColor"} = color("blue");
|
||||
|
||||
$colors{"warningFileNameColor"} = color("yellow");
|
||||
$colors{"warningNumberColor"} = color("yellow");
|
||||
$colors{"warningMessageColor"} = color("yellow");
|
||||
|
||||
$colors{"errorFileNameColor"} = color("bold red");
|
||||
$colors{"errorNumberColor"} = color("bold red");
|
||||
$colors{"errorMessageColor"} = color("bold red");
|
||||
}
|
||||
|
||||
sub loadPreferences
|
||||
{
|
||||
# Usage: loadPreferences("filename");
|
||||
|
||||
my($filename) = @_;
|
||||
|
||||
open(PREFS, "<$filename") || return;
|
||||
|
||||
while(<PREFS>)
|
||||
{
|
||||
next if (m/^\#.*/); # It's a comment.
|
||||
next if (!m/(.*):\s*(.*)/); # It's not of the form "foo: bar".
|
||||
|
||||
$option = $1;
|
||||
$value = $2;
|
||||
|
||||
if ($option =~ m/cc|c\+\+|gcc|g\+\+/)
|
||||
{
|
||||
$compilerPaths{$option} = $value;
|
||||
}
|
||||
elsif ($option eq "nocolor")
|
||||
{
|
||||
# The nocolor option lists terminal types, separated by
|
||||
# spaces, not to do color on.
|
||||
foreach $termtype (split(/\s+/, $value))
|
||||
{
|
||||
$nocolor{$termtype} = "true";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$colors{$option} = color($value);
|
||||
}
|
||||
}
|
||||
close(PREFS);
|
||||
}
|
||||
|
||||
sub srcscan
|
||||
{
|
||||
# Usage: srcscan($text, $normalColor)
|
||||
# $text -- the text to colorize
|
||||
# $normalColor -- The escape sequence to use for non-source text.
|
||||
|
||||
# Looks for text between ` and ', and colors it srcColor.
|
||||
|
||||
my($line, $normalColor) = @_;
|
||||
|
||||
my($srcon) = color("reset") . $colors{"srcColor"};
|
||||
my($srcoff) = color("reset") . $normalColor;
|
||||
|
||||
$line = $normalColor . $line;
|
||||
|
||||
# This substitute replaces `foo' with `AfooB' where A is the escape
|
||||
# sequence that turns on the the desired source color, and B is the
|
||||
# escape sequence that returns to $normalColor.
|
||||
$line =~ s/\`(.*?)\'/\`$srcon$1$srcoff\'/g;
|
||||
|
||||
print($line, color("reset"));
|
||||
}
|
||||
|
||||
#
|
||||
# Main program
|
||||
#
|
||||
|
||||
# Set up default values for colors and compilers.
|
||||
initDefaults();
|
||||
|
||||
# Read the configuration file, if there is one.
|
||||
$configFile = $ENV{"HOME"} . "/.colorgccrc";
|
||||
if (-f $configFile)
|
||||
{
|
||||
loadPreferences($configFile);
|
||||
}
|
||||
|
||||
# Figure out which compiler to invoke based on our program name.
|
||||
$0 =~ m%.*/(.*)$%;
|
||||
$progName = $1 || $0;
|
||||
|
||||
$compiler = $compilerPaths{$progName} || $compilerPaths{"gcc"};
|
||||
|
||||
# Get the terminal type.
|
||||
$terminal = $ENV{"TERM"} || "dumb";
|
||||
|
||||
# If it's in the list of terminal types not to color, or if
|
||||
# we're writing to something that's not a tty, don't do color.
|
||||
if (! -t STDOUT || $nocolor{$terminal})
|
||||
{
|
||||
exec $compiler, @ARGV
|
||||
or die("Couldn't exec");
|
||||
}
|
||||
|
||||
# Keep the pid of the compiler process so we can get its return
|
||||
# code and use that as our return code.
|
||||
$compiler_pid = open3('<&STDIN', \*GCCOUT, '', $compiler, @ARGV);
|
||||
|
||||
# Colorize the output from the compiler.
|
||||
while(<GCCOUT>)
|
||||
{
|
||||
if (m/^(.*?):([0-9]+):(.*)$/) # filename:lineno:message
|
||||
{
|
||||
$field1 = $1 || "";
|
||||
$field2 = $2 || "";
|
||||
$field3 = $3 || "";
|
||||
|
||||
if ($field3 =~ m/\s+warning:.*/)
|
||||
{
|
||||
# Warning
|
||||
print($colors{"warningFileNameColor"}, "$field1:", color("reset"));
|
||||
print($colors{"warningNumberColor"}, "$field2:", color("reset"));
|
||||
srcscan($field3, $colors{"warningMessageColor"});
|
||||
}
|
||||
else
|
||||
{
|
||||
# Error
|
||||
print($colors{"errorFileNameColor"}, "$field1:", color("reset"));
|
||||
print($colors{"errorNumberColor"}, "$field2:", color("reset"));
|
||||
srcscan($field3, $colors{"errorMessageColor"});
|
||||
}
|
||||
print("\n");
|
||||
}
|
||||
elsif (m/^(.*?):(.+):$/) # filename:message:
|
||||
{
|
||||
# No line number, treat as an "introductory" line of text.
|
||||
srcscan($_, $colors{"introColor"});
|
||||
}
|
||||
else # Anything else.
|
||||
{
|
||||
# Doesn't seem to be a warning or an error. Print normally.
|
||||
print(color("reset"), $_);
|
||||
}
|
||||
}
|
||||
|
||||
# Get the return code of the compiler and exit with that.
|
||||
waitpid($compiler_pid, 0);
|
||||
exit ($? >> 8);
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
@ -0,0 +1 @@
|
|||
color-gcc.pl
|
|
@ -0,0 +1,34 @@
|
|||
# C++ target for ANTLR 4
|
||||
|
||||
This fork provides C++ runtime support for C++. See [the canonical antlr4 repository](https://github.com/antlr/antlr4) for in depth detail about how to use Antlr4.
|
||||
|
||||
## Authors and major contributors
|
||||
|
||||
ANTLR 4 is the result of substantial effort of the following people:
|
||||
|
||||
* [Terence Parr](http://www.cs.usfca.edu/~parrt/), parrt@cs.usfca.edu
|
||||
ANTLR project lead and supreme dictator for life
|
||||
[University of San Francisco](http://www.usfca.edu/)
|
||||
|
||||
* [Sam Harwell] (http://tunnelvisionlabs.com/)
|
||||
Tool co-author, Java and C# target)
|
||||
|
||||
The C++ target has been the work of the following people:
|
||||
|
||||
* Dan McLaughlin, dan.mclaughlin@gmail.com
|
||||
C++ Target project leader
|
||||
|
||||
* David Sisson, dsisson@google.com
|
||||
|
||||
|
||||
Project Status
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
o Building on OS X, Windows, and Linux (Ubuntu)
|
||||
o No errors and warnings
|
||||
o Library linking
|
||||
o Simple running (e.g. heap objects initialize properly)
|
||||
o Simple testing (creating significiant objects)
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
|
||||
Microsoft Visual Studio Solution File, Format Version 11.00
|
||||
# Visual Studio 2010
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "antlr4cpp", "antlr4cpp.vcxproj", "{A9762991-1B57-4DCE-90C0-EE42B96947BE}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Win32 = Debug|Win32
|
||||
Release|Win32 = Release|Win32
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{A9762991-1B57-4DCE-90C0-EE42B96947BE}.Debug|Win32.ActiveCfg = Debug|Win32
|
||||
{A9762991-1B57-4DCE-90C0-EE42B96947BE}.Debug|Win32.Build.0 = Debug|Win32
|
||||
{A9762991-1B57-4DCE-90C0-EE42B96947BE}.Release|Win32.ActiveCfg = Release|Win32
|
||||
{A9762991-1B57-4DCE-90C0-EE42B96947BE}.Release|Win32.Build.0 = Release|Win32
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
EndGlobal
|
Binary file not shown.
|
@ -0,0 +1,374 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup Label="ProjectConfigurations">
|
||||
<ProjectConfiguration Include="Debug|Win32">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|Win32">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<ProjectGuid>{A9762991-1B57-4DCE-90C0-EE42B96947BE}</ProjectGuid>
|
||||
<Keyword>Win32Proj</Keyword>
|
||||
<RootNamespace>antlr4cpp</RootNamespace>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||
<ConfigurationType>DynamicLibrary</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
<PlatformToolset>v120</PlatformToolset>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||
<ConfigurationType>DynamicLibrary</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
<PlatformToolset>v120</PlatformToolset>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Label="ExtensionSettings">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<LinkIncremental>true</LinkIncremental>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<LinkIncremental>false</LinkIncremental>
|
||||
</PropertyGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<ClCompile>
|
||||
<PrecompiledHeader>
|
||||
</PrecompiledHeader>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;_USRDLL;ANTLR4CPP_EXPORTS;%(PreprocessorDefinitions);WINDOWS</PreprocessorDefinitions>
|
||||
<AdditionalIncludeDirectories>$(ProjectDir)\..\antlrcpp;$(ProjectDir)\..\org\antlr\v4\runtime;$(ProjectDir)\..\org\antlr\v4\runtime\atn;$(ProjectDir)\..\org\antlr\v4\runtime\dfa;$(ProjectDir)\..\org\antlr\v4\runtime\misc;$(ProjectDir)\..\org\antlr\v4\runtime\tree;$(ProjectDir)\..\org\antlr\v4\runtime\tree\xpath;$(ProjectDir)\..\org\antlr\v4\runtime\tree\pattern;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<MultiProcessorCompilation>false</MultiProcessorCompilation>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Windows</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<PrecompiledHeader>
|
||||
</PrecompiledHeader>
|
||||
<Optimization>MaxSpeed</Optimization>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;_USRDLL;ANTLR4CPP_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Windows</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="..\antlrcpp\Arrays.cpp" />
|
||||
<ClCompile Include="..\antlrcpp\CPPUtils.cpp" />
|
||||
<ClCompile Include="..\antlrcpp\StringBuilder.cpp" />
|
||||
<ClCompile Include="..\antlrcpp\Strings.cpp" />
|
||||
<ClCompile Include="..\antlrcpp\UUID.cpp" />
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\ANTLRErrorListener.cpp" />
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\ANTLRErrorStrategy.cpp" />
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\ANTLRFileStream.cpp" />
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\ANTLRInputStream.cpp" />
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\atn\AbstractPredicateTransition.cpp" />
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\atn\ActionTransition.cpp" />
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\atn\ArrayPredictionContext.cpp" />
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\atn\ATN.cpp" />
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\atn\ATNConfig.cpp" />
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\atn\ATNConfigSet.cpp" />
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\atn\ATNDeserializationOptions.cpp" />
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\atn\ATNDeserializer.cpp" />
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\atn\ATNSerializer.cpp" />
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\atn\ATNSimulator.cpp" />
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\atn\ATNState.cpp" />
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\atn\ATNType.cpp" />
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\atn\AtomTransition.cpp" />
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\atn\BasicBlockStartState.cpp" />
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\atn\BasicState.cpp" />
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\atn\BlockEndState.cpp" />
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\atn\BlockStartState.cpp" />
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\atn\DecisionState.cpp" />
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\atn\EmptyPredictionContext.cpp" />
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\atn\EpsilonTransition.cpp" />
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\atn\LexerATNConfig.cpp" />
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\atn\LexerATNSimulator.cpp" />
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\atn\LL1Analyzer.cpp" />
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\atn\LoopEndState.cpp" />
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\atn\NotSetTransition.cpp" />
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\atn\OrderedATNConfigSet.cpp" />
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\atn\ParserATNSimulator.cpp" />
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\atn\PlusBlockStartState.cpp" />
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\atn\PlusLoopbackState.cpp" />
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\atn\PrecedencePredicateTransition.cpp" />
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\atn\PredicateTransition.cpp" />
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\atn\PredictionContext.cpp" />
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\atn\PredictionContextCache.cpp" />
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\atn\PredictionMode.cpp" />
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\atn\RangeTransition.cpp" />
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\atn\RuleStartState.cpp" />
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\atn\RuleStopState.cpp" />
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\atn\RuleTransition.cpp" />
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\atn\SemanticContext.cpp" />
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\atn\SetTransition.cpp" />
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\atn\SingletonPredictionContext.cpp" />
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\atn\StarBlockStartState.cpp" />
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\atn\StarLoopbackState.cpp" />
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\atn\StarLoopEntryState.cpp" />
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\atn\TokensStartState.cpp" />
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\atn\Transition.cpp" />
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\atn\WildcardTransition.cpp" />
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\BailErrorStrategy.cpp" />
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\BaseErrorListener.cpp" />
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\BufferedTokenStream.cpp" />
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\CharStream.cpp" />
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\CommonToken.cpp" />
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\CommonTokenFactory.cpp" />
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\CommonTokenStream.cpp" />
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\ConsoleErrorListener.cpp" />
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\DefaultErrorStrategy.cpp" />
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\dfa\DFA.cpp" />
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\dfa\DFASerializer.cpp" />
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\dfa\DFAState.cpp" />
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\dfa\LexerDFASerializer.cpp" />
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\DiagnosticErrorListener.cpp" />
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\Exceptions.cpp" />
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\FailedPredicateException.cpp" />
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\InputMismatchException.cpp" />
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\InterpreterRuleContext.cpp" />
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\IntStream.cpp" />
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\Lexer.cpp" />
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\LexerInterpreter.cpp" />
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\LexerNoViableAltException.cpp" />
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\ListTokenSource.cpp" />
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\misc\AbstractEqualityComparator.cpp" />
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\misc\EqualityComparator.cpp" />
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\misc\GraphicsSupport.cpp" />
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\misc\Interval.cpp" />
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\misc\IntervalSet.cpp" />
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\misc\IntSet.cpp" />
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\misc\LogManager.cpp" />
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\misc\MultiMap.cpp" />
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\misc\MurmurHash.cpp" />
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\misc\NotNull.cpp" />
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\misc\ObjectEqualityComparator.cpp" />
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\misc\OrderedHashSet.cpp" />
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\misc\ParseCancellationException.cpp" />
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\misc\TestRig.cpp" />
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\misc\Utils.cpp" />
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\NoViableAltException.cpp" />
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\Parser.cpp" />
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\ParserInterpreter.cpp" />
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\ParserRuleContext.cpp" />
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\ProxyErrorListener.cpp" />
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\RecognitionException.cpp" />
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\RuleContext.cpp" />
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\Token.cpp" />
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\TokenFactory.cpp" />
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\TokenSource.cpp" />
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\TokenStream.cpp" />
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\TokenStreamRewriter.cpp" />
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\tree\AbstractParseTreeVisitor.cpp" />
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\tree\ErrorNode.cpp" />
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\tree\ErrorNodeImpl.cpp" />
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\tree\ParseTree.cpp" />
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\tree\ParseTreeListener.cpp" />
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\tree\ParseTreeProperty.cpp" />
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\tree\ParseTreeVisitor.cpp" />
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\tree\ParseTreeWalker.cpp" />
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\tree\pattern\Chunk.cpp" />
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\tree\pattern\ParseTreeMatch.cpp" />
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\tree\pattern\ParseTreePattern.cpp" />
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\tree\pattern\ParseTreePatternMatcher.cpp" />
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\tree\pattern\RuleTagToken.cpp" />
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\tree\pattern\TagChunk.cpp" />
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\tree\pattern\TextChunk.cpp" />
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\tree\pattern\TokenTagToken.cpp" />
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\tree\RuleNode.cpp" />
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\tree\SyntaxTree.cpp" />
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\tree\TerminalNode.cpp" />
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\tree\TerminalNodeImpl.cpp" />
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\tree\Tree.cpp" />
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\tree\Trees.cpp" />
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\tree\xpath\XPath.cpp" />
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\tree\xpath\XPathElement.cpp" />
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\tree\xpath\XPathLexer.cpp" />
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\tree\xpath\XPathLexerErrorListener.cpp" />
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\tree\xpath\XPathRuleAnywhereElement.cpp" />
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\tree\xpath\XPathRuleElement.cpp" />
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\tree\xpath\XPathTokenAnywhereElement.cpp" />
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\tree\xpath\XPathTokenElement.cpp" />
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\tree\xpath\XPathWildcardAnywhereElement.cpp" />
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\tree\xpath\XPathWildcardElement.cpp" />
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\UnbufferedCharStream.cpp" />
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\WritableToken.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="..\antlrcpp\Arrays.h" />
|
||||
<ClInclude Include="..\antlrcpp\CPPUtils.h" />
|
||||
<ClInclude Include="..\antlrcpp\StringBuilder.h" />
|
||||
<ClInclude Include="..\antlrcpp\Strings.h" />
|
||||
<ClInclude Include="..\antlrcpp\UUID.h" />
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\ANTLRErrorListener.h" />
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\ANTLRErrorStrategy.h" />
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\ANTLRFileStream.h" />
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\ANTLRInputStream.h" />
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\atn\AbstractPredicateTransition.h" />
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\atn\ActionTransition.h" />
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\atn\ArrayPredictionContext.h" />
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\atn\ATN.h" />
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\atn\ATNConfig.h" />
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\atn\ATNConfigSet.h" />
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\atn\ATNDeserializationOptions.h" />
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\atn\ATNDeserializer.h" />
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\atn\ATNSerializer.h" />
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\atn\ATNSimulator.h" />
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\atn\ATNState.h" />
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\atn\ATNType.h" />
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\atn\AtomTransition.h" />
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\atn\BasicBlockStartState.h" />
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\atn\BasicState.h" />
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\atn\BlockEndState.h" />
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\atn\BlockStartState.h" />
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\atn\DecisionState.h" />
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\atn\EmptyPredictionContext.h" />
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\atn\EpsilonTransition.h" />
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\atn\LexerATNConfig.h" />
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\atn\LexerATNSimulator.h" />
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\atn\LL1Analyzer.h" />
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\atn\LoopEndState.h" />
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\atn\NotSetTransition.h" />
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\atn\OrderedATNConfigSet.h" />
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\atn\ParserATNSimulator.h" />
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\atn\PlusBlockStartState.h" />
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\atn\PlusLoopbackState.h" />
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\atn\PrecedencePredicateTransition.h" />
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\atn\PredicateTransition.h" />
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\atn\PredictionContext.h" />
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\atn\PredictionContextCache.h" />
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\atn\PredictionMode.h" />
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\atn\RangeTransition.h" />
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\atn\RuleStartState.h" />
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\atn\RuleStopState.h" />
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\atn\RuleTransition.h" />
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\atn\SemanticContext.h" />
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\atn\SetTransition.h" />
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\atn\SingletonPredictionContext.h" />
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\atn\StarBlockStartState.h" />
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\atn\StarLoopbackState.h" />
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\atn\StarLoopEntryState.h" />
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\atn\TokensStartState.h" />
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\atn\Transition.h" />
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\atn\WildcardTransition.h" />
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\BailErrorStrategy.h" />
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\BaseErrorListener.h" />
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\BufferedTokenStream.h" />
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\CharStream.h" />
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\CommonToken.h" />
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\CommonTokenFactory.h" />
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\CommonTokenStream.h" />
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\ConsoleErrorListener.h" />
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\DefaultErrorStrategy.h" />
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\dfa\DFA.h" />
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\dfa\DFASerializer.h" />
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\dfa\DFAState.h" />
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\dfa\LexerDFASerializer.h" />
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\DiagnosticErrorListener.h" />
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\Exceptions.h" />
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\FailedPredicateException.h" />
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\InputMismatchException.h" />
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\InterpreterRuleContext.h" />
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\IntStream.h" />
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\Lexer.h" />
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\LexerInterpreter.h" />
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\LexerNoViableAltException.h" />
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\ListTokenSource.h" />
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\misc\AbstractEqualityComparator.h" />
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\misc\Array2DHashSet.h" />
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\misc\DoubleKeyMap.h" />
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\misc\EqualityComparator.h" />
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\misc\GraphicsSupport.h" />
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\misc\Interval.h" />
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\misc\IntervalSet.h" />
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\misc\IntSet.h" />
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\misc\LogManager.h" />
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\misc\MultiMap.h" />
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\misc\MurmurHash.h" />
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\misc\NotNull.h" />
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\misc\ObjectEqualityComparator.h" />
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\misc\OrderedHashSet.h" />
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\misc\ParseCancellationException.h" />
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\misc\TestRig.h" />
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\misc\Utils.h" />
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\NoViableAltException.h" />
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\Parser.h" />
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\ParserInterpreter.h" />
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\ParserRuleContext.h" />
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\ProxyErrorListener.h" />
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\RecognitionException.h" />
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\Recognizer.h" />
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\RuleContext.h" />
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\Token.h" />
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\TokenFactory.h" />
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\TokenSource.h" />
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\TokenStream.h" />
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\TokenStreamRewriter.h" />
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\tree\AbstractParseTreeVisitor.h" />
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\tree\ErrorNode.h" />
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\tree\ErrorNodeImpl.h" />
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\tree\ParseTree.h" />
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\tree\ParseTreeListener.h" />
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\tree\ParseTreeProperty.h" />
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\tree\ParseTreeVisitor.h" />
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\tree\ParseTreeWalker.h" />
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\tree\pattern\Chunk.h" />
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\tree\pattern\ParseTreeMatch.h" />
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\tree\pattern\ParseTreePattern.h" />
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\tree\pattern\ParseTreePatternMatcher.h" />
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\tree\pattern\RuleTagToken.h" />
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\tree\pattern\TagChunk.h" />
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\tree\pattern\TextChunk.h" />
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\tree\pattern\TokenTagToken.h" />
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\tree\RuleNode.h" />
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\tree\SyntaxTree.h" />
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\tree\TerminalNode.h" />
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\tree\TerminalNodeImpl.h" />
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\tree\Tree.h" />
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\tree\Trees.h" />
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\tree\xpath\XPath.h" />
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\tree\xpath\XPathElement.h" />
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\tree\xpath\XPathLexer.h" />
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\tree\xpath\XPathLexerErrorListener.h" />
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\tree\xpath\XPathRuleAnywhereElement.h" />
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\tree\xpath\XPathRuleElement.h" />
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\tree\xpath\XPathTokenAnywhereElement.h" />
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\tree\xpath\XPathTokenElement.h" />
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\tree\xpath\XPathWildcardAnywhereElement.h" />
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\tree\xpath\XPathWildcardElement.h" />
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\UnbufferedCharStream.h" />
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\UnbufferedTokenStream.h" />
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\WritableToken.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="..\org\antlr\v4\runtime\atn\Makefile" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
</Project>
|
|
@ -0,0 +1,876 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup>
|
||||
<Filter Include="Source Files">
|
||||
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
|
||||
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="Header Files">
|
||||
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
|
||||
<Extensions>h;hpp;hxx;hm;inl;inc;xsd</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="Resource Files">
|
||||
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
|
||||
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\ANTLRErrorListener.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\ANTLRErrorStrategy.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\ANTLRFileStream.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\ANTLRInputStream.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\BailErrorStrategy.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\BaseErrorListener.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\BufferedTokenStream.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\CharStream.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\CommonToken.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\CommonTokenFactory.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\CommonTokenStream.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\ConsoleErrorListener.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\DefaultErrorStrategy.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\DiagnosticErrorListener.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\Exceptions.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\FailedPredicateException.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\InputMismatchException.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\InterpreterRuleContext.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\IntStream.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\Lexer.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\LexerInterpreter.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\LexerNoViableAltException.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\ListTokenSource.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\NoViableAltException.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\Parser.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\ParserInterpreter.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\ParserRuleContext.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\ProxyErrorListener.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\RecognitionException.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\RuleContext.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\Token.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\TokenFactory.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\TokenSource.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\TokenStream.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\TokenStreamRewriter.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\UnbufferedCharStream.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\WritableToken.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\atn\AbstractPredicateTransition.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\atn\ActionTransition.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\atn\ArrayPredictionContext.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\atn\ATN.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\atn\ATNConfig.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\atn\ATNConfigSet.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\atn\ATNDeserializationOptions.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\atn\ATNDeserializer.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\atn\ATNSerializer.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\atn\ATNSimulator.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\atn\ATNState.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\atn\ATNType.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\atn\AtomTransition.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\atn\BasicBlockStartState.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\atn\BasicState.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\atn\BlockEndState.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\atn\BlockStartState.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\atn\DecisionState.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\atn\EmptyPredictionContext.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\atn\EpsilonTransition.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\atn\LexerATNConfig.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\atn\LexerATNSimulator.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\atn\LL1Analyzer.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\atn\LoopEndState.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\atn\NotSetTransition.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\atn\OrderedATNConfigSet.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\atn\ParserATNSimulator.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\atn\PlusBlockStartState.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\atn\PlusLoopbackState.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\atn\PrecedencePredicateTransition.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\atn\PredicateTransition.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\atn\PredictionContext.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\atn\PredictionContextCache.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\atn\PredictionMode.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\atn\RangeTransition.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\atn\RuleStartState.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\atn\RuleStopState.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\atn\RuleTransition.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\atn\SemanticContext.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\atn\SetTransition.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\atn\SingletonPredictionContext.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\atn\StarBlockStartState.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\atn\StarLoopbackState.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\atn\StarLoopEntryState.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\atn\TokensStartState.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\atn\Transition.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\atn\WildcardTransition.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\dfa\DFA.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\dfa\DFASerializer.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\dfa\DFAState.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\dfa\LexerDFASerializer.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\misc\AbstractEqualityComparator.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\misc\EqualityComparator.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\misc\GraphicsSupport.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\misc\Interval.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\misc\IntervalSet.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\misc\IntSet.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\misc\LogManager.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\misc\MultiMap.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\misc\MurmurHash.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\misc\NotNull.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\misc\ObjectEqualityComparator.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\misc\OrderedHashSet.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\misc\ParseCancellationException.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\misc\TestRig.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\misc\Utils.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\tree\AbstractParseTreeVisitor.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\tree\ErrorNode.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\tree\ErrorNodeImpl.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\tree\ParseTree.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\tree\ParseTreeListener.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\tree\ParseTreeProperty.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\tree\ParseTreeVisitor.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\tree\ParseTreeWalker.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\tree\RuleNode.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\tree\SyntaxTree.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\tree\TerminalNode.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\tree\TerminalNodeImpl.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\tree\Tree.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\tree\Trees.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\tree\pattern\Chunk.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\tree\pattern\ParseTreeMatch.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\tree\pattern\ParseTreePattern.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\tree\pattern\ParseTreePatternMatcher.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\tree\pattern\RuleTagToken.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\tree\pattern\TagChunk.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\tree\pattern\TextChunk.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\tree\pattern\TokenTagToken.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\tree\xpath\XPath.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\tree\xpath\XPathElement.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\tree\xpath\XPathLexer.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\tree\xpath\XPathLexerErrorListener.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\tree\xpath\XPathRuleAnywhereElement.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\tree\xpath\XPathRuleElement.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\tree\xpath\XPathTokenAnywhereElement.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\tree\xpath\XPathTokenElement.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\tree\xpath\XPathWildcardAnywhereElement.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\org\antlr\v4\runtime\tree\xpath\XPathWildcardElement.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\antlrcpp\CPPUtils.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\antlrcpp\UUID.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\antlrcpp\Strings.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\antlrcpp\StringBuilder.cpp">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\antlrcpp\Arrays.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\ANTLRErrorListener.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\ANTLRErrorStrategy.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\ANTLRFileStream.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\ANTLRInputStream.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\BailErrorStrategy.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\BaseErrorListener.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\BufferedTokenStream.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\CharStream.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\CommonToken.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\CommonTokenFactory.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\CommonTokenStream.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\ConsoleErrorListener.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\DefaultErrorStrategy.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\DiagnosticErrorListener.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\Exceptions.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\FailedPredicateException.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\InputMismatchException.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\InterpreterRuleContext.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\IntStream.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\Lexer.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\LexerInterpreter.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\LexerNoViableAltException.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\ListTokenSource.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\NoViableAltException.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\Parser.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\ParserInterpreter.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\ParserRuleContext.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\ProxyErrorListener.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\RecognitionException.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\Recognizer.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\RuleContext.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\Token.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\TokenFactory.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\TokenSource.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\TokenStream.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\TokenStreamRewriter.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\UnbufferedCharStream.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\UnbufferedTokenStream.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\WritableToken.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\atn\AbstractPredicateTransition.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\atn\ActionTransition.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\atn\ArrayPredictionContext.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\atn\ATN.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\atn\ATNConfig.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\atn\ATNConfigSet.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\atn\ATNDeserializationOptions.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\atn\ATNDeserializer.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\atn\ATNSerializer.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\atn\ATNSimulator.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\atn\ATNState.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\atn\ATNType.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\atn\AtomTransition.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\atn\BasicBlockStartState.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\atn\BasicState.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\atn\BlockEndState.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\atn\BlockStartState.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\atn\DecisionState.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\atn\EmptyPredictionContext.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\atn\EpsilonTransition.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\atn\LexerATNConfig.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\atn\LexerATNSimulator.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\atn\LL1Analyzer.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\atn\LoopEndState.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\atn\NotSetTransition.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\atn\OrderedATNConfigSet.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\atn\ParserATNSimulator.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\atn\PlusBlockStartState.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\atn\PlusLoopbackState.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\atn\PrecedencePredicateTransition.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\atn\PredicateTransition.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\atn\PredictionContext.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\atn\PredictionContextCache.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\atn\PredictionMode.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\atn\RangeTransition.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\atn\RuleStartState.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\atn\RuleStopState.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\atn\RuleTransition.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\atn\SemanticContext.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\atn\SetTransition.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\atn\SingletonPredictionContext.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\atn\StarBlockStartState.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\atn\StarLoopbackState.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\atn\StarLoopEntryState.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\atn\TokensStartState.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\atn\Transition.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\atn\WildcardTransition.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\dfa\DFA.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\dfa\DFASerializer.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\dfa\DFAState.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\dfa\LexerDFASerializer.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\misc\AbstractEqualityComparator.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\misc\Array2DHashSet.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\misc\DoubleKeyMap.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\misc\EqualityComparator.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\misc\GraphicsSupport.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\misc\Interval.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\misc\IntervalSet.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\misc\IntSet.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\misc\LogManager.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\misc\MultiMap.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\misc\MurmurHash.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\misc\NotNull.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\misc\ObjectEqualityComparator.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\misc\OrderedHashSet.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\misc\ParseCancellationException.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\misc\TestRig.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\misc\Utils.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\tree\AbstractParseTreeVisitor.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\tree\ErrorNode.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\tree\ErrorNodeImpl.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\tree\ParseTree.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\tree\ParseTreeListener.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\tree\ParseTreeProperty.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\tree\ParseTreeVisitor.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\tree\ParseTreeWalker.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\tree\RuleNode.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\tree\SyntaxTree.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\tree\TerminalNode.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\tree\TerminalNodeImpl.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\tree\Tree.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\tree\Trees.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\tree\pattern\Chunk.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\tree\pattern\ParseTreeMatch.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\tree\pattern\ParseTreePattern.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\tree\pattern\ParseTreePatternMatcher.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\tree\pattern\RuleTagToken.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\tree\pattern\TagChunk.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\tree\pattern\TextChunk.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\tree\pattern\TokenTagToken.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\tree\xpath\XPath.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\tree\xpath\XPathElement.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\tree\xpath\XPathLexer.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\tree\xpath\XPathLexerErrorListener.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\tree\xpath\XPathRuleAnywhereElement.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\tree\xpath\XPathRuleElement.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\tree\xpath\XPathTokenAnywhereElement.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\tree\xpath\XPathTokenElement.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\tree\xpath\XPathWildcardAnywhereElement.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\org\antlr\v4\runtime\tree\xpath\XPathWildcardElement.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\antlrcpp\CPPUtils.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\antlrcpp\UUID.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\antlrcpp\Strings.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\antlrcpp\StringBuilder.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\antlrcpp\Arrays.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="..\org\antlr\v4\runtime\atn\Makefile" />
|
||||
</ItemGroup>
|
||||
</Project>
|
|
@ -0,0 +1,6 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<ShowAllFiles>false</ShowAllFiles>
|
||||
</PropertyGroup>
|
||||
</Project>
|
|
@ -0,0 +1,122 @@
|
|||
#include "Arrays.h"
|
||||
#include "Exceptions.h"
|
||||
|
||||
/*
|
||||
* [The "BSD license"]
|
||||
* Copyright (c) 2013 Dan McLaughlin
|
||||
* 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. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
||||
*/
|
||||
|
||||
std::wstring antlrcpp::Arrays::ListToString(std::vector<std::wstring> list,std::wstring separator)
|
||||
{
|
||||
|
||||
StringBuilder *sb = new StringBuilder();
|
||||
for (size_t i = 0; i < list.size(); i++)//(std::wstring s in list)
|
||||
{
|
||||
sb->append(list[i]);
|
||||
if (i + 1 < list.size()) sb->append(separator);
|
||||
}
|
||||
|
||||
return sb->toString();
|
||||
}
|
||||
|
||||
std::vector<char> antlrcpp::Arrays::asList(const std::wstring *items)
|
||||
{
|
||||
std::vector<char> returnAnswer(items->begin(), items->end());
|
||||
|
||||
return returnAnswer;
|
||||
}
|
||||
|
||||
std::vector<std::wstring> antlrcpp::Arrays::asList(int nArgs, ...)
|
||||
{
|
||||
|
||||
std::vector<std::wstring> returnAnswer;
|
||||
va_list ap;
|
||||
va_start(ap, nArgs);
|
||||
|
||||
for (int i = 0; i < nArgs; i++) {
|
||||
wchar_t * tmp = va_arg(ap, wchar_t*);
|
||||
returnAnswer.insert(returnAnswer.end(), tmp);
|
||||
}
|
||||
|
||||
return returnAnswer;
|
||||
}
|
||||
|
||||
bool antlrcpp::Arrays::equals(std::vector<int> a, std::vector<int> b)
|
||||
{
|
||||
|
||||
if (a.size() != b.size()) return false;
|
||||
|
||||
for (auto var: a) {
|
||||
if (a[var] != b[var]) return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool antlrcpp::Arrays::equals(void *a, void* b)
|
||||
{
|
||||
throw new org::antlr::v4::runtime::TODOException(L"antlrcpp::Arrays::equals");
|
||||
return false;
|
||||
}
|
||||
|
||||
std::list<std::wstring> antlrcpp::Arrays::copyOf(void * obj, int num)
|
||||
{
|
||||
std::list<std::wstring> returnAnswer;
|
||||
// What ?
|
||||
throw new org::antlr::v4::runtime::TODOException(L"antlrcpp::Arrays::copyOf(void*,int)");
|
||||
|
||||
return returnAnswer;
|
||||
}
|
||||
|
||||
std::wstring antlrcpp::Arrays::copyOf(std::wstring obj, int num)
|
||||
{
|
||||
std::wstring foo;
|
||||
throw new org::antlr::v4::runtime::TODOException(L"antlrcpp::Arrays::copyOf(wstring, int)");
|
||||
return foo;
|
||||
}
|
||||
|
||||
void antlrcpp::Arrays::arraycopy(void * arrayA, void * arrayB, int num)
|
||||
{
|
||||
throw new org::antlr::v4::runtime::TODOException(L"antlrcpp::Arrays::arraycopy");
|
||||
}
|
||||
|
||||
std::list<std::wstring> antlrcpp::Arrays::StringToStringList(std::wstring items, char separator)
|
||||
{
|
||||
/*
|
||||
std::list<std::wstring> *list = new std::list<std::wstring>();
|
||||
std::wstring listItmes[] = items.Split(separator);
|
||||
for (std::wstring item : listItmes)
|
||||
{
|
||||
list.Add(item);
|
||||
}
|
||||
if (list.Count > 0) {
|
||||
return list;
|
||||
} else {
|
||||
return null;
|
||||
}*/
|
||||
throw new org::antlr::v4::runtime::TODOException(L"antlrcpp::Arrays::StringToStringList");
|
||||
}
|
|
@ -0,0 +1,87 @@
|
|||
#pragma once
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <list>
|
||||
#include <stdarg.h>
|
||||
|
||||
#include "Declarations.h"
|
||||
#include "StringBuilder.h"
|
||||
|
||||
/*
|
||||
* [The "BSD license"]
|
||||
* Copyright (c) 2013 Dan McLaughlin
|
||||
* 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. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
||||
*/
|
||||
|
||||
|
||||
namespace antlrcpp {
|
||||
/// <summary>
|
||||
/// Converts List to string with given separator.
|
||||
/// </summary>
|
||||
/// <param name="list">The list.</param>
|
||||
/// <param name="separator">The separator.</param>
|
||||
/// <returns></returns>
|
||||
class Arrays {
|
||||
public:
|
||||
|
||||
static std::wstring ListToString(std::vector<std::wstring> list,std::wstring separator);
|
||||
|
||||
/// <summary>
|
||||
/// Strings to string list.
|
||||
/// </summary>
|
||||
/// <param name="items">The items.</param>
|
||||
/// <param name="separator">The separator.</param>
|
||||
/// <returns></returns>
|
||||
static std::list<std::wstring> StringToStringList(std::wstring items, char separator);
|
||||
|
||||
|
||||
static std::vector<char> asList(const std::wstring *items);
|
||||
|
||||
// Arguments must be of type wchar_t!
|
||||
static std::vector<std::wstring> asList(int nArgs, ...);
|
||||
|
||||
static bool equals(std::vector<int> a, std::vector<int> b);
|
||||
|
||||
|
||||
static bool equals(void *a, void* b);
|
||||
|
||||
/// <summary>
|
||||
/// Strings to string list.
|
||||
/// </summary>
|
||||
/// <param name="items">The items.</param>
|
||||
/// <param name="separator">The separator.</param>
|
||||
/// <returns></returns>
|
||||
|
||||
static std::list<std::wstring> copyOf(void * obj, int num);
|
||||
|
||||
static std::wstring copyOf(std::wstring obj, int num);
|
||||
|
||||
static void arraycopy(void * arrayA, void * arrayB, int num);
|
||||
};
|
||||
|
||||
}
|
|
@ -0,0 +1,131 @@
|
|||
#pragma once
|
||||
|
||||
#include <bitset>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <vector>
|
||||
|
||||
/*
|
||||
* [The "BSD license"]
|
||||
* Copyright (c) 2015 Ana Maria Rodriguez Reyes
|
||||
* 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. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
||||
*/
|
||||
|
||||
namespace antlrcpp {
|
||||
|
||||
class BitSet {
|
||||
|
||||
public:
|
||||
BitSet() {}
|
||||
|
||||
BitSet(const BitSet &other) {
|
||||
data = other.data;
|
||||
}
|
||||
|
||||
static const int BITSET_SIZE = 1024;
|
||||
std::bitset<BITSET_SIZE> data;
|
||||
|
||||
void assign(size_t count, const BitSet & value ) {
|
||||
|
||||
}
|
||||
|
||||
int nextSetBit(const int & pos) {
|
||||
for (size_t i = pos; i < data.size(); i++){
|
||||
if (data.test(i)) return (int)i;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
void set(size_t pos){
|
||||
data.set(pos);
|
||||
}
|
||||
|
||||
void set(){
|
||||
data.set();
|
||||
}
|
||||
|
||||
size_t count(){
|
||||
return data.count();
|
||||
}
|
||||
|
||||
size_t size(){
|
||||
return data.size();
|
||||
}
|
||||
|
||||
// Prints a list of every index for which the bitset contains a bit in true.
|
||||
friend std::wostream& operator<<(std::wostream& os, const BitSet& obj)
|
||||
{
|
||||
|
||||
os << L"{";
|
||||
size_t total = obj.data.count();
|
||||
for (size_t i = 0; i < obj.data.size(); i++){
|
||||
if (obj.data.test(i)){
|
||||
os << i;
|
||||
--total;
|
||||
if (total > 1){
|
||||
os << L", ";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
os << L"}";
|
||||
return os;
|
||||
}
|
||||
|
||||
static std::wstring subStringRepresentation(const std::vector<BitSet>::iterator &begin,
|
||||
const std::vector<BitSet>::iterator &end) {
|
||||
std::wstring result;
|
||||
std::vector<BitSet>::iterator vectorIterator;
|
||||
|
||||
for (vectorIterator = begin; vectorIterator != end; vectorIterator++) {
|
||||
result += vectorIterator->toString();
|
||||
}
|
||||
// Grab the end
|
||||
result += end->toString();
|
||||
|
||||
return result;
|
||||
}
|
||||
std::wstring toString(){
|
||||
std::wstringstream stream;
|
||||
stream << L"{";
|
||||
size_t total = data.count();
|
||||
for (size_t i = 0; i < data.size(); i++){
|
||||
if (data.test(i)){
|
||||
stream << i;
|
||||
--total;
|
||||
if (total > 1){
|
||||
stream << L", ";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
stream << L"}";
|
||||
return stream.str();
|
||||
}
|
||||
|
||||
};
|
||||
}
|
|
@ -0,0 +1,99 @@
|
|||
#include "CPPUtils.h"
|
||||
#include <stdarg.h> // for va_start, etc
|
||||
#include <memory> // for std::unique_ptr
|
||||
#include <stdlib.h>
|
||||
#include <vector>
|
||||
|
||||
/*
|
||||
* [The "BSD license"]
|
||||
* Copyright (c) 2014 Dan McLaughlin
|
||||
* 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. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
||||
*/
|
||||
|
||||
|
||||
namespace antlrcpp {
|
||||
std::wstring join(std::vector<std::wstring> strings, const std::wstring &separator) {
|
||||
std::wstring str;
|
||||
bool firstItem = true;
|
||||
for (std::wstring s : strings) {
|
||||
if (!firstItem) {
|
||||
str.append(separator);
|
||||
} else {
|
||||
firstItem = false;
|
||||
}
|
||||
str.append(s);
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
std::map<std::wstring, int>* toMap(const std::vector<std::wstring> &keys) {
|
||||
std::map<std::wstring, int>* m = new std::map<std::wstring, int>();
|
||||
for (int i = 0; i < (int)keys.size(); ++i) {
|
||||
m->insert(std::pair<std::wstring, int>(keys[i], i));
|
||||
}
|
||||
return m;
|
||||
}
|
||||
|
||||
std::wstring escapeWhitespace(std::wstring str, bool TODO) {
|
||||
// TODO - David, what is this boolean for, and what did you want to esacpe
|
||||
// whitespace with?
|
||||
std::wstring returnAnswer = str.replace(str.begin(), str.end(), L' ', L'\\');
|
||||
return returnAnswer;
|
||||
}
|
||||
|
||||
std::wstring stringFormat(const std::wstring fmt_str, ...)
|
||||
{
|
||||
// Not sure this is needed, just use swprintf (into a wchar_t array).
|
||||
// TODO(dsisson): Remove this function in a future change.
|
||||
std::wstring blank;
|
||||
return blank;
|
||||
}
|
||||
|
||||
wchar_t* toCharArray(const std::vector<size_t> *data){
|
||||
if (data == nullptr) return nullptr;
|
||||
wchar_t* cdata = new wchar_t[data->size()];
|
||||
|
||||
for (int i = 0; i < (int)data->size(); i++){
|
||||
cdata[i] = (char)data->at(i);
|
||||
}
|
||||
|
||||
return cdata;
|
||||
}
|
||||
|
||||
std::wstring toHexString(const int t){
|
||||
std::wstringstream stream;
|
||||
stream << std::uppercase << std::hex << t;
|
||||
return stream.str();
|
||||
}
|
||||
|
||||
std::wstring arrayToString(const std::vector<std::wstring> &data) {
|
||||
std::wstring answer;
|
||||
for (auto sub: data) {
|
||||
answer += sub;
|
||||
}
|
||||
return answer;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,63 @@
|
|||
#pragma once
|
||||
|
||||
#include <iostream>
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <cwchar>
|
||||
#include <iomanip>
|
||||
#include <sstream>
|
||||
|
||||
/*
|
||||
* [The "BSD license"]
|
||||
* Copyright (c) 2014 Dan McLaughlin
|
||||
* 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. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
||||
*/
|
||||
|
||||
|
||||
namespace antlrcpp {
|
||||
template<typename T1>
|
||||
class CopyOnWriteArrayList {
|
||||
public:
|
||||
CopyOnWriteArrayList(){};
|
||||
|
||||
};
|
||||
|
||||
std::wstring join(std::vector<std::wstring> strings, const std::wstring &separator);
|
||||
|
||||
std::map<std::wstring, int>* toMap(const std::vector<std::wstring> &keys);
|
||||
|
||||
std::wstring escapeWhitespace(std::wstring str, bool TODO);
|
||||
|
||||
std::wstring stringFormat(const wchar_t* fmt, ...);
|
||||
|
||||
wchar_t* toCharArray(const std::vector<size_t> *data);
|
||||
|
||||
std::wstring toHexString(const int t);
|
||||
|
||||
std::wstring arrayToString(const std::vector<std::wstring> &data);
|
||||
|
||||
}
|
|
@ -0,0 +1,214 @@
|
|||
#pragma once
|
||||
|
||||
/*
|
||||
* [The "BSD license"]
|
||||
* Copyright (c) 2013 Dan McLaughlin
|
||||
* 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. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
||||
*/
|
||||
|
||||
// This can be regenerated from the command line by using
|
||||
// ls *.h | sed "s/\.h\*/;/" | sed 's/^/class /'
|
||||
|
||||
// Autogenerated
|
||||
class XPathLexer;
|
||||
class XPathParser;
|
||||
|
||||
namespace org {
|
||||
namespace antlr {
|
||||
namespace v4 {
|
||||
namespace runtime {
|
||||
class IllegalStateException;
|
||||
class IllegalArgumentException;
|
||||
class NoSuchElementException;
|
||||
class NullPointerException;
|
||||
class InputMismatchException;
|
||||
class ParseCancellationException;
|
||||
class InputMismatchException;
|
||||
class EmptyStackException;
|
||||
class LexerNoViableAltException;
|
||||
|
||||
class ANTLRErrorListener;
|
||||
class ANTLRErrorStrategy;
|
||||
class ANTLRFileStream;
|
||||
class ANTLRInputStream;
|
||||
class BailErrorStrategy;
|
||||
class BaseErrorListener;
|
||||
class BufferedTokenStream;
|
||||
class CharStream;
|
||||
class CommonToken;
|
||||
class CommonTokenFactory;
|
||||
class CommonTokenStream;
|
||||
class ConsoleErrorListener;
|
||||
class DefaultErrorStrategy;
|
||||
class DiagnosticErrorListener;
|
||||
class FailedPredicateException;
|
||||
class InputMismatchException;
|
||||
class IntStream;
|
||||
class InterpreterRuleContext;
|
||||
class IErrorListener;
|
||||
template<typename Symbol, typename ATNInterpreter> class IRecognizer;
|
||||
class Lexer;
|
||||
class LexerInterpreter;
|
||||
class LexerNoViableAltException;
|
||||
class ListTokenSource;
|
||||
class NoViableAltException;
|
||||
class Parser;
|
||||
class ParserInterpreter;
|
||||
class ParserRuleContext;
|
||||
class ProxyErrorListener;
|
||||
class RecognitionException;
|
||||
template<typename T1, typename T2> class Recognizer;
|
||||
class RuleContext;
|
||||
class Token;
|
||||
template<typename Symbol> class TokenFactory;
|
||||
class TokenSource;
|
||||
class TokenStream;
|
||||
class TokenStreamRewriter;
|
||||
class UnbufferedCharStream;
|
||||
template<typename T> class UnbufferedTokenStream;
|
||||
class WritableToken;
|
||||
|
||||
namespace misc {
|
||||
template<typename T> class AbstractEqualityComparator;
|
||||
template<typename T> class Array2DHashSet;
|
||||
template<typename Key1, typename Key2, typename Value> class DoubleKeyMap;
|
||||
template<typename T> class EqualityComparator;
|
||||
|
||||
class GraphicsSupport;
|
||||
class IntSet;
|
||||
class Interval;
|
||||
class IntervalSet;
|
||||
class JFileChooserConfirmOverwrite;
|
||||
class LogManager;
|
||||
template<typename K, typename V> class MultiMap;
|
||||
class MurmurHash;
|
||||
class NotNull;
|
||||
class ObjectEqualityComparator;
|
||||
template<typename T> class OrderedHashSet;
|
||||
class ParseCancellationException;
|
||||
class TestRig;
|
||||
class Utils;
|
||||
}
|
||||
namespace atn {
|
||||
class ATN;
|
||||
class ATNConfig;
|
||||
class ATNConfigSet;
|
||||
class ATNDeserializationOptions;
|
||||
class ATNDeserializer;
|
||||
class ATNSerializer;
|
||||
class ATNSimulator;
|
||||
class ATNState;
|
||||
enum class ATNType;
|
||||
class AbstractPredicateTransition;
|
||||
class ActionTransition;
|
||||
class ArrayPredictionContext;
|
||||
class AtomTransition;
|
||||
class BasicBlockStartState;
|
||||
class BasicState;
|
||||
class BlockEndState;
|
||||
class BlockStartState;
|
||||
class DecisionState;
|
||||
class EmptyPredictionContext;
|
||||
class EpsilonTransition;
|
||||
class LL1Analyzer;
|
||||
class LexerATNConfig;
|
||||
class LexerATNSimulator;
|
||||
class LoopEndState;
|
||||
class NotSetTransition;
|
||||
class OrderedATNConfigSet;
|
||||
class ParserATNSimulator;
|
||||
class PlusBlockStartState;
|
||||
class PlusLoopbackState;
|
||||
class PrecedencePredicateTransition;
|
||||
class PredicateTransition;
|
||||
class PredictionContext;
|
||||
class PredictionContextCache;
|
||||
enum class PredictionMode;
|
||||
class PredictionModeClass;
|
||||
class RangeTransition;
|
||||
class RuleStartState;
|
||||
class RuleStopState;
|
||||
class RuleTransition;
|
||||
class SemanticContext;
|
||||
class SetTransition;
|
||||
class SingletonPredictionContext;
|
||||
class StarBlockStartState;
|
||||
class StarLoopEntryState;
|
||||
class StarLoopbackState;
|
||||
class TokensStartState;
|
||||
class Transition;
|
||||
class WildcardTransition;
|
||||
}
|
||||
namespace dfa {
|
||||
class DFA;
|
||||
class DFASerializer;
|
||||
class DFAState;
|
||||
class LexerDFASerializer;
|
||||
}
|
||||
namespace tree {
|
||||
template <typename t> class AbstractParseTreeVisitor;
|
||||
class ErrorNode;
|
||||
class ErrorNodeImpl;
|
||||
class ParseTree;
|
||||
class ParseTreeListener;
|
||||
template<typename T> class ParseTreeProperty;
|
||||
template<typename T> class ParseTreeVisitor;
|
||||
class ParseTreeWalker;
|
||||
class RuleNode;
|
||||
class SyntaxTree;
|
||||
class TerminalNode;
|
||||
class TerminalNodeImpl;
|
||||
class Tree;
|
||||
class Trees;
|
||||
|
||||
namespace pattern {
|
||||
class Chunk;
|
||||
class ParseTreeMatch;
|
||||
class ParseTreePattern;
|
||||
class ParseTreePatternMatcher;
|
||||
class RuleTagToken;
|
||||
class TagChunk;
|
||||
class TextChunk;
|
||||
class TokenTagToken;
|
||||
}
|
||||
|
||||
namespace xpath {
|
||||
class XPath;
|
||||
class XPathElement;
|
||||
class XPathLexerErrorListener;
|
||||
class XPathRuleAnywhereElement;
|
||||
class XPathRuleElement;
|
||||
class XPathTokenAnywhereElement;
|
||||
class XPathTokenElement;
|
||||
class XPathWildcardAnywhereElement;
|
||||
class XPathWildcardElement;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,149 @@
|
|||
#include <iostream>
|
||||
#include <memory>
|
||||
#include <cstdarg>
|
||||
|
||||
#include "StringBuilder.h"
|
||||
#include "ATNState.h"
|
||||
#include "SemanticContext.h"
|
||||
#include "Strings.h"
|
||||
|
||||
/*
|
||||
* [The "BSD license"]
|
||||
* Copyright (c) 2013 Dan McLaughlin
|
||||
* 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. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
||||
*/
|
||||
|
||||
|
||||
namespace antlrcpp {
|
||||
StringBuilder & StringBuilder::append(const std::wstring & str) {
|
||||
scratch.append(str);
|
||||
if (scratch.size() > ScratchSize) {
|
||||
main.append(scratch);
|
||||
scratch.resize(0);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
StringBuilder & StringBuilder::append(const org::antlr::v4::runtime::atn::ATNState* const state) {
|
||||
main = main + state->toString();
|
||||
return *this;
|
||||
}
|
||||
|
||||
StringBuilder & StringBuilder::append(const org::antlr::v4::runtime::atn::SemanticContext* const state) {
|
||||
main = main + state->toString();
|
||||
return *this;
|
||||
}
|
||||
|
||||
StringBuilder & StringBuilder::append(const wchar_t & str) {
|
||||
scratch.append(wchar2wstring(str));
|
||||
if (scratch.size() > ScratchSize) {
|
||||
main.append(scratch);
|
||||
scratch.resize(0);
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
const std::wstring & StringBuilder::str() {
|
||||
if (scratch.size() > 0) {
|
||||
main.append(scratch);
|
||||
scratch.resize(0);
|
||||
}
|
||||
return main;
|
||||
}
|
||||
|
||||
std::wstring StringBuilder::format(const std::string fmt_str, ...) {
|
||||
int final_n, n = (int)fmt_str.size() * 2; // reserve 2 times as much as the length of the fmt_str
|
||||
std::string str;
|
||||
std::unique_ptr<char[]> formatted;
|
||||
va_list ap;
|
||||
while(1) {
|
||||
formatted.reset(new char[n]); // wrap the plain char array into the unique_ptr
|
||||
strcpy(&formatted[0], fmt_str.c_str());
|
||||
va_start(ap, fmt_str);
|
||||
final_n = vsnprintf(&formatted[0], n, fmt_str.c_str(), ap);
|
||||
va_end(ap);
|
||||
if (final_n < 0 || final_n >= n)
|
||||
n += abs(final_n - n + 1);
|
||||
else
|
||||
break;
|
||||
}
|
||||
|
||||
return std::wstring(s2ws(formatted.get()));
|
||||
}
|
||||
|
||||
const std::wstring & StringBuilder::toString() {
|
||||
return str();
|
||||
}
|
||||
|
||||
std::wstring::size_type StringBuilder::length() {
|
||||
return str().size();
|
||||
}
|
||||
|
||||
std::wstring StringBuilder::stringToWstring( std::string str )
|
||||
{
|
||||
std::wstring wStr( str.length(), L' ' );
|
||||
std::copy( str.begin(), str.end(), wStr.begin() );
|
||||
return wStr;
|
||||
}
|
||||
|
||||
std::string StringBuilder::WstringTostring( std::wstring wStr )
|
||||
{
|
||||
std::string str( wStr.length(), ' ' );
|
||||
std::copy( wStr.begin(), wStr.end(), str.begin() );
|
||||
return str;
|
||||
}
|
||||
|
||||
std::string StringBuilder::string_replace(std::string src, std::string const& target, std::string const& repl)
|
||||
{
|
||||
// handle error situations/trivial cases
|
||||
|
||||
if (target.length() == 0) {
|
||||
// searching for a match to the empty string will result in
|
||||
// an infinite loop
|
||||
// it might make sense to throw an exception for this case
|
||||
return src;
|
||||
}
|
||||
|
||||
if (src.length() == 0) {
|
||||
return src; // nothing to match against
|
||||
}
|
||||
|
||||
size_t idx = 0;
|
||||
|
||||
for (;;) {
|
||||
idx = src.find( target, idx);
|
||||
if (idx == std::string::npos) break;
|
||||
|
||||
src.replace( idx, target.length(), repl);
|
||||
idx += repl.length();
|
||||
}
|
||||
|
||||
return src;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,72 @@
|
|||
#pragma once
|
||||
|
||||
#include "Declarations.h"
|
||||
|
||||
/*
|
||||
* [The "BSD license"]
|
||||
* Copyright (c) 2013 Dan McLaughlin
|
||||
* 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. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
||||
*/
|
||||
|
||||
namespace antlrcpp {
|
||||
|
||||
class StringBuilder {
|
||||
private:
|
||||
std::wstring main;
|
||||
std::wstring scratch;
|
||||
|
||||
const std::wstring::size_type ScratchSize = 1024; // or some other arbitrary number
|
||||
|
||||
public:
|
||||
StringBuilder & append(const std::wstring & str);
|
||||
|
||||
StringBuilder & append(const org::antlr::v4::runtime::atn::ATNState* const state);
|
||||
|
||||
StringBuilder & append(const org::antlr::v4::runtime::atn::SemanticContext* const state);
|
||||
|
||||
StringBuilder & append(const wchar_t & str);
|
||||
|
||||
const std::wstring & str();
|
||||
|
||||
const std::wstring & toString();
|
||||
|
||||
std::wstring::size_type length();
|
||||
|
||||
// Utility function to provide "format" capability
|
||||
|
||||
static std::wstring format(const std::string fmt_str, ...);
|
||||
|
||||
static std::wstring stringToWstring( std::string str );
|
||||
|
||||
static std::string WstringTostring( std::wstring wStr );
|
||||
|
||||
static std::string string_replace(std::string src,
|
||||
std::string const& target,
|
||||
std::string const& repl);
|
||||
};
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,68 @@
|
|||
#include <codecvt>
|
||||
#include <locale>
|
||||
#include <string>
|
||||
|
||||
#include "Strings.h"
|
||||
|
||||
/*
|
||||
* [The "BSD license"]
|
||||
* Copyright (c) 2014 Dan McLaughlin
|
||||
* 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. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
||||
*/
|
||||
|
||||
namespace antlrcpp {
|
||||
std::string ws2s(const std::wstring& wstr) {
|
||||
std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> converter;
|
||||
std::string narrow = converter.to_bytes(wstr);
|
||||
return narrow;
|
||||
}
|
||||
|
||||
std::wstring s2ws(const std::string& str) {
|
||||
std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> converter;
|
||||
std::wstring wide = converter.from_bytes(str);
|
||||
return wide;
|
||||
}
|
||||
|
||||
void replaceAll(std::wstring& str, const std::wstring& from, const std::wstring& to)
|
||||
{
|
||||
if(from.empty()) {
|
||||
return;
|
||||
}
|
||||
size_t start_pos = 0;
|
||||
while((start_pos = str.find(from, start_pos)) != std::string::npos) {
|
||||
str.replace(start_pos, from.length(), to);
|
||||
start_pos += to.length(); // In case 'to' contains 'from', like replacing 'x' with 'yx'
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
std::wstring wchar2wstring(const wchar_t & str) {
|
||||
std::wstring returnAnswer(&str);
|
||||
|
||||
return returnAnswer;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,43 @@
|
|||
#pragma once
|
||||
|
||||
/*
|
||||
* [The "BSD license"]
|
||||
* Copyright (c) 2014 Dan McLaughlin
|
||||
* 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. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
||||
*/
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace antlrcpp {
|
||||
void replaceAll(std::wstring& str, const std::wstring& from, const std::wstring& to);
|
||||
|
||||
std::string ws2s(const std::wstring& wstr);
|
||||
|
||||
std::wstring s2ws(const std::string & str);
|
||||
|
||||
std::wstring wchar2wstring(const wchar_t & str);
|
||||
|
||||
}
|
|
@ -0,0 +1,83 @@
|
|||
/*
|
||||
* [The "BSD license"]
|
||||
* Copyright (c) 2015 Dan McLaughlin
|
||||
* 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. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
||||
*/
|
||||
|
||||
#include "UUID.h"
|
||||
|
||||
// Terence thinks this is for some version control stuff or something
|
||||
// or other - probably not important. So be nice in this function, be quiet and
|
||||
// hope nobody complains
|
||||
|
||||
namespace antlrcpp {
|
||||
UUID::UUID(long long mostSigBits, long long leastSigBits) {
|
||||
// throw new std::exception();
|
||||
}
|
||||
UUID::UUID(const UUID &other) {
|
||||
// throw new std::exception();
|
||||
};
|
||||
|
||||
UUID::~UUID() {
|
||||
// throw new std::exception();
|
||||
};
|
||||
|
||||
const UUID &UUID::operator=(const UUID &rhs) {
|
||||
// throw new std::exception();
|
||||
return rhs;
|
||||
};
|
||||
bool UUID::operator==(const UUID &rhs) const {
|
||||
// throw new std::exception();
|
||||
return true;
|
||||
};
|
||||
bool UUID::equals(const UUID &rhs) const {
|
||||
// throw new std::exception();
|
||||
return true;
|
||||
};
|
||||
bool UUID::equals(const UUID *rhs) const {
|
||||
// throw new std::exception();
|
||||
return true;
|
||||
};
|
||||
|
||||
UUID *UUID::fromString(const std::wstring &name) {
|
||||
// throw new std::exception();
|
||||
return new UUID(0,0);
|
||||
};
|
||||
|
||||
std::wstring UUID::toString() const {
|
||||
// throw new std::exception();
|
||||
return L"UUID_UNIMPLEMENTED";
|
||||
};
|
||||
|
||||
long UUID::getLeastSignificantBits() const {
|
||||
// throw new std::exception();
|
||||
return 0;
|
||||
};
|
||||
long UUID::getMostSignificantBits() const {
|
||||
// throw new std::exception();
|
||||
return 0;
|
||||
};
|
||||
}
|
|
@ -0,0 +1,54 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
/*
|
||||
* [The "BSD license"]
|
||||
* Copyright (c) 2015 Dan McLaughlin
|
||||
* 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. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
||||
*/
|
||||
|
||||
namespace antlrcpp {
|
||||
class UUID {
|
||||
public:
|
||||
UUID(long long mostSigBits, long long leastSigBits);
|
||||
UUID(const UUID &other);
|
||||
~UUID();
|
||||
|
||||
const UUID &operator=(const UUID &rhs);
|
||||
bool operator==(const UUID &rhs) const;
|
||||
bool equals(const UUID &rhs) const;
|
||||
bool equals(const UUID *rhs) const;
|
||||
|
||||
static UUID *fromString(const std::wstring &name);
|
||||
std::wstring toString() const;
|
||||
|
||||
long getLeastSignificantBits() const;
|
||||
long getMostSignificantBits() const;
|
||||
};
|
||||
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
//
|
||||
// Prefix header
|
||||
//
|
||||
// The contents of this file are implicitly included at the beginning of every source file.
|
||||
//
|
||||
|
||||
#include <iostream>
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
/*
|
||||
* antlrcpp.cp
|
||||
* antlrcpp
|
||||
*
|
||||
* Created by Dan McLaughlin on 12/22/13.
|
||||
* Copyright (c) 2013 Dan McLaughlin. All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
#include "antlrcpp.h"
|
||||
#include "antlrcppPriv.h"
|
||||
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
/*
|
||||
* antlrcpp.h
|
||||
* antlrcpp
|
||||
*
|
||||
* Created by Dan McLaughlin on 12/22/13.
|
||||
* Copyright (c) 2013 Dan McLaughlin. All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef antlrcpp_
|
||||
#define antlrcpp_
|
||||
|
||||
/* The classes below are exported */
|
||||
#pragma GCC visibility push(default)
|
||||
|
||||
|
||||
|
||||
#pragma GCC visibility pop
|
||||
#endif
|
|
@ -0,0 +1,19 @@
|
|||
/*
|
||||
* antlrcppPriv.h
|
||||
* antlrcpp
|
||||
*
|
||||
* Created by Dan McLaughlin on 12/22/13.
|
||||
* Copyright (c) 2013 Dan McLaughlin. All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
/* The classes below are not exported */
|
||||
#pragma GCC visibility push(hidden)
|
||||
|
||||
class antlrcppPriv
|
||||
{
|
||||
public:
|
||||
void HelloWorldPriv(const char *);
|
||||
};
|
||||
|
||||
#pragma GCC visibility pop
|
|
@ -0,0 +1,4 @@
|
|||
GCC_WARN_ABOUT_RETURN_TYPE = YES;
|
||||
GCC_WARN_UNUSED_VARIABLE = YES;
|
||||
GCC_INCREASE_PRECOMPILED_HEADER_SHARING = YES;
|
||||
GCC_GENERATE_DEBUGGING_SYMBOLS = YES;
|
|
@ -0,0 +1,10 @@
|
|||
PRODUCT_NAME = libantlrcpp;
|
||||
MACH_O_TYPE = mh_dylib;
|
||||
DYLIB_COMPATIBILITY_VERSION = 1;
|
||||
DYLIB_CURRENT_VERSION = 1;
|
||||
GCC_PRECOMPILE_PREFIX_HEADER = YES;
|
||||
GCC_PREFIX_HEADER = antlrcpp/antlrcpp-Prefix.pch;
|
||||
GCC_ENABLE_CPP_EXCEPTIONS = YES;
|
||||
GCC_ENABLE_CPP_RTTI = YES;
|
||||
GCC_SYMBOLS_PRIVATE_EXTERN = YES;
|
||||
|
|
@ -0,0 +1,34 @@
|
|||
#pragma once
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
// Copyright © 2007 - 2013 Tangible Software Solutions Inc.
|
||||
// This class can be used by anyone provided that the copyright notice remains intact.
|
||||
//
|
||||
// This class is used to replace some conversions to or from strings.
|
||||
//----------------------------------------------------------------------------------------
|
||||
#include <sstream>
|
||||
|
||||
namespace antlrcpp {
|
||||
|
||||
class StringConverterHelper
|
||||
{
|
||||
public:
|
||||
template<typename T>
|
||||
static std::wstring toString(const T &subject)
|
||||
{
|
||||
std::wostringstream ss;
|
||||
ss << subject;
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
static T fromString(const std::wstring &subject)
|
||||
{
|
||||
std::wistringstream ss(subject);
|
||||
T target;
|
||||
ss >> target;
|
||||
return target;
|
||||
}
|
||||
};
|
||||
|
||||
}
|
|
@ -0,0 +1,31 @@
|
|||
#pragma once
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
// Copyright © 2007 - 2013 Tangible Software Solutions Inc.
|
||||
// This class can be used by anyone provided that the copyright notice remains intact.
|
||||
//
|
||||
// This class is used to simulate list constructor calls which reserve the list size.
|
||||
//----------------------------------------------------------------------------------------
|
||||
#include <vector>
|
||||
namespace antlrcpp {
|
||||
|
||||
class VectorHelper
|
||||
{
|
||||
public:
|
||||
template<typename T>
|
||||
static std::vector<T> VectorWithReservedSize(int size)
|
||||
{
|
||||
std::vector<T> vector;
|
||||
vector.reserve(size);
|
||||
return vector;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
static std::vector<T> VectorSublist(const std::vector<T>& vec, int start, int end)
|
||||
{
|
||||
std::vector<T> vector(vec.begin() + start, vec.begin() + end);
|
||||
return vector;
|
||||
}
|
||||
};
|
||||
|
||||
}
|
|
@ -0,0 +1,40 @@
|
|||
#include "ANTLRErrorListener.h"
|
||||
|
||||
/*
|
||||
* [The "BSD license"]
|
||||
* Copyright (c) 2013 Terence Parr
|
||||
* Copyright (c) 2013 Dan McLaughlin
|
||||
* 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. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
||||
*/
|
||||
|
||||
namespace org {
|
||||
namespace antlr {
|
||||
namespace v4 {
|
||||
namespace runtime {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,167 @@
|
|||
#pragma once
|
||||
|
||||
#include "IRecognizer.h"
|
||||
#include "Declarations.h"
|
||||
#include "BitSet.h"
|
||||
|
||||
/*
|
||||
* [The "BSD license"]
|
||||
* Copyright (c) 2013 Terence Parr
|
||||
* Copyright (c) 2013 Dan McLaughlin
|
||||
* 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. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
||||
*/
|
||||
|
||||
namespace org {
|
||||
namespace antlr {
|
||||
namespace v4 {
|
||||
namespace runtime {
|
||||
/// <summary>
|
||||
/// How to emit recognition errors. </summary>
|
||||
class ANTLRErrorListener {
|
||||
|
||||
/// <summary>
|
||||
/// Upon syntax error, notify any interested parties. This is not how to
|
||||
/// recover from errors or compute error messages. <seealso cref="ANTLRErrorStrategy"/>
|
||||
/// specifies how to recover from syntax errors and how to compute error
|
||||
/// messages. This listener's job is simply to emit a computed message,
|
||||
/// though it has enough information to create its own message in many cases.
|
||||
/// <p/>
|
||||
/// The <seealso cref="RecognitionException"/> is non-null for all syntax errors except
|
||||
/// when we discover mismatched token errors that we can recover from
|
||||
/// in-line, without returning from the surrounding rule (via the single
|
||||
/// token insertion and deletion mechanism).
|
||||
/// </summary>
|
||||
/// <param name="recognizer">
|
||||
/// What parser got the error. From this
|
||||
/// object, you can access the context as well
|
||||
/// as the input stream. </param>
|
||||
/// <param name="offendingSymbol">
|
||||
/// The offending token in the input token
|
||||
/// stream, unless recognizer is a lexer (then it's null). If
|
||||
/// no viable alternative error, {@code e} has token at which we
|
||||
/// started production for the decision. </param>
|
||||
/// <param name="line">
|
||||
/// The line number in the input where the error occurred. </param>
|
||||
/// <param name="charPositionInLine">
|
||||
/// The character position within that line where the error occurred. </param>
|
||||
/// <param name="msg">
|
||||
/// The message to emit. </param>
|
||||
/// <param name="e">
|
||||
/// The exception generated by the parser that led to
|
||||
/// the reporting of an error. It is null in the case where
|
||||
/// the parser was able to recover in line without exiting the
|
||||
/// surrounding rule. </param>
|
||||
public:
|
||||
template<typename T1, typename T2>
|
||||
void syntaxError(IRecognizer<T1, T2> *recognizer, void *offendingSymbol,
|
||||
int line, int charPositionInLine, const std::wstring &msg,
|
||||
RecognitionException *e) {}
|
||||
|
||||
/// <summary>
|
||||
/// This method is called by the parser when a full-context prediction
|
||||
/// results in an ambiguity.
|
||||
/// <p/>
|
||||
/// When {@code exact} is {@code true}, <em>all</em> of the alternatives in
|
||||
/// {@code ambigAlts} are viable, i.e. this is reporting an exact ambiguity.
|
||||
/// When {@code exact} is {@code false}, <em>at least two</em> of the
|
||||
/// alternatives in {@code ambigAlts} are viable for the current input, but
|
||||
/// the prediction algorithm terminated as soon as it determined that at
|
||||
/// least the <em>minimum</em> alternative in {@code ambigAlts} is viable.
|
||||
/// <p/>
|
||||
/// When the <seealso cref="PredictionMode#LL_EXACT_AMBIG_DETECTION"/> prediction mode
|
||||
/// is used, the parser is required to identify exact ambiguities so
|
||||
/// {@code exact} will always be {@code true}.
|
||||
/// <p/>
|
||||
/// This method is not used by lexers.
|
||||
/// </summary>
|
||||
/// <param name="recognizer"> the parser instance </param>
|
||||
/// <param name="dfa"> the DFA for the current decision </param>
|
||||
/// <param name="startIndex"> the input index where the decision started </param>
|
||||
/// <param name="stopIndex"> the input input where the ambiguity is reported </param>
|
||||
/// <param name="exact"> {@code true} if the ambiguity is exactly known, otherwise
|
||||
/// {@code false}. This is always {@code true} when
|
||||
/// <seealso cref="PredictionMode#LL_EXACT_AMBIG_DETECTION"/> is used. </param>
|
||||
/// <param name="ambigAlts"> the potentially ambiguous alternatives </param>
|
||||
/// <param name="configs"> the ATN configuration set where the ambiguity was
|
||||
/// determined </param>
|
||||
virtual void reportAmbiguity(Parser *recognizer, dfa::DFA *dfa, int startIndex, int stopIndex, bool exact, antlrcpp::BitSet *ambigAlts, atn::ATNConfigSet *configs) = 0;
|
||||
|
||||
/// <summary>
|
||||
/// This method is called when an SLL conflict occurs and the parser is about
|
||||
/// to use the full context information to make an LL decision.
|
||||
/// <p/>
|
||||
/// If one or more configurations in {@code configs} contains a semantic
|
||||
/// predicate, the predicates are evaluated before this method is called. The
|
||||
/// subset of alternatives which are still viable after predicates are
|
||||
/// evaluated is reported in {@code conflictingAlts}.
|
||||
/// <p/>
|
||||
/// This method is not used by lexers.
|
||||
/// </summary>
|
||||
/// <param name="recognizer"> the parser instance </param>
|
||||
/// <param name="dfa"> the DFA for the current decision </param>
|
||||
/// <param name="startIndex"> the input index where the decision started </param>
|
||||
/// <param name="stopIndex"> the input index where the SLL conflict occurred </param>
|
||||
/// <param name="conflictingAlts"> The specific conflicting alternatives. If this is
|
||||
/// {@code null}, the conflicting alternatives are all alternatives
|
||||
/// represented in {@code configs}. </param>
|
||||
/// <param name="configs"> the ATN configuration set where the SLL conflict was
|
||||
/// detected </param>
|
||||
virtual void reportAttemptingFullContext(Parser *recognizer, dfa::DFA *dfa, int startIndex, int stopIndex, antlrcpp::BitSet *conflictingAlts, atn::ATNConfigSet *configs) = 0;
|
||||
|
||||
/// <summary>
|
||||
/// This method is called by the parser when a full-context prediction has a
|
||||
/// unique result.
|
||||
/// <p/>
|
||||
/// For prediction implementations that only evaluate full-context
|
||||
/// predictions when an SLL conflict is found (including the default
|
||||
/// <seealso cref="ParserATNSimulator"/> implementation), this method reports cases
|
||||
/// where SLL conflicts were resolved to unique full-context predictions,
|
||||
/// i.e. the decision was context-sensitive. This report does not necessarily
|
||||
/// indicate a problem, and it may appear even in completely unambiguous
|
||||
/// grammars.
|
||||
/// <p/>
|
||||
/// {@code configs} may have more than one represented alternative if the
|
||||
/// full-context prediction algorithm does not evaluate predicates before
|
||||
/// beginning the full-context prediction. In all cases, the final prediction
|
||||
/// is passed as the {@code prediction} argument.
|
||||
/// <p/>
|
||||
/// This method is not used by lexers.
|
||||
/// </summary>
|
||||
/// <param name="recognizer"> the parser instance </param>
|
||||
/// <param name="dfa"> the DFA for the current decision </param>
|
||||
/// <param name="startIndex"> the input index where the decision started </param>
|
||||
/// <param name="stopIndex"> the input index where the context sensitivity was
|
||||
/// finally determined </param>
|
||||
/// <param name="prediction"> the unambiguous result of the full-context prediction </param>
|
||||
/// <param name="configs"> the ATN configuration set where the unambiguous prediction
|
||||
/// was determined </param>
|
||||
virtual void reportContextSensitivity(Parser *recognizer, dfa::DFA *dfa, int startIndex, int stopIndex, int prediction, atn::ATNConfigSet *configs) = 0;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,40 @@
|
|||
#include "ANTLRErrorStrategy.h"
|
||||
/*
|
||||
* [The "BSD license"]
|
||||
* Copyright (c) 2013 Terence Parr
|
||||
* Copyright (c) 2013 Dan McLaughlin
|
||||
* 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. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
||||
*/
|
||||
|
||||
namespace org {
|
||||
namespace antlr {
|
||||
namespace v4 {
|
||||
namespace runtime {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,144 @@
|
|||
#pragma once
|
||||
|
||||
#include "Declarations.h"
|
||||
|
||||
/*
|
||||
* [The "BSD license"]
|
||||
* Copyright (c) 2013 Terence Parr
|
||||
* Copyright (c) 2013 Dan McLaughlin
|
||||
* 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. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
||||
*/
|
||||
|
||||
namespace org {
|
||||
namespace antlr {
|
||||
namespace v4 {
|
||||
namespace runtime {
|
||||
|
||||
/// <summary>
|
||||
/// The interface for defining strategies to deal with syntax errors encountered
|
||||
/// during a parse by ANTLR-generated parsers. We distinguish between three
|
||||
/// different kinds of errors:
|
||||
///
|
||||
/// <ul>
|
||||
/// <li>The parser could not figure out which path to take in the ATN (none of
|
||||
/// the available alternatives could possibly match)</li>
|
||||
/// <li>The current input does not match what we were looking for</li>
|
||||
/// <li>A predicate evaluated to false</li>
|
||||
/// </ul>
|
||||
///
|
||||
/// Implementations of this interface report syntax errors by calling
|
||||
/// <seealso cref="Parser#notifyErrorListeners"/>.
|
||||
/// <p/>
|
||||
/// TODO: what to do about lexers
|
||||
/// </summary>
|
||||
class ANTLRErrorStrategy {
|
||||
/// <summary>
|
||||
/// Reset the error handler state for the specified {@code recognizer}. </summary>
|
||||
/// <param name="recognizer"> the parser instance </param>
|
||||
public:
|
||||
virtual void reset(Parser *recognizer) = 0;
|
||||
|
||||
/// <summary>
|
||||
/// This method is called when an unexpected symbol is encountered during an
|
||||
/// inline match operation, such as <seealso cref="Parser#match"/>. If the error
|
||||
/// strategy successfully recovers from the match failure, this method
|
||||
/// returns the <seealso cref="Token"/> instance which should be treated as the
|
||||
/// successful result of the match.
|
||||
/// <p/>
|
||||
/// Note that the calling code will not report an error if this method
|
||||
/// returns successfully. The error strategy implementation is responsible
|
||||
/// for calling <seealso cref="Parser#notifyErrorListeners"/> as appropriate.
|
||||
/// </summary>
|
||||
/// <param name="recognizer"> the parser instance </param>
|
||||
/// <exception cref="RecognitionException"> if the error strategy was not able to
|
||||
/// recover from the unexpected input symbol </exception>
|
||||
virtual Token *recoverInline(Parser *recognizer) = 0;
|
||||
|
||||
/// <summary>
|
||||
/// This method is called to recover from exception {@code e}. This method is
|
||||
/// called after <seealso cref="#reportError"/> by the default exception handler
|
||||
/// generated for a rule method.
|
||||
/// </summary>
|
||||
/// <seealso cref= #reportError
|
||||
/// </seealso>
|
||||
/// <param name="recognizer"> the parser instance </param>
|
||||
/// <param name="e"> the recognition exception to recover from </param>
|
||||
/// <exception cref="RecognitionException"> if the error strategy could not recover from
|
||||
/// the recognition exception </exception>
|
||||
virtual void recover(Parser *recognizer, RecognitionException *e) = 0;
|
||||
|
||||
/// <summary>
|
||||
/// This method provides the error handler with an opportunity to handle
|
||||
/// syntactic or semantic errors in the input stream before they result in a
|
||||
/// <seealso cref="RecognitionException"/>.
|
||||
/// <p/>
|
||||
/// The generated code currently contains calls to <seealso cref="#sync"/> after
|
||||
/// entering the decision state of a closure block ({@code (...)*} or
|
||||
/// {@code (...)+}).
|
||||
/// <p/>
|
||||
/// For an implementation based on Jim Idle's "magic sync" mechanism, see
|
||||
/// <seealso cref="DefaultErrorStrategy#sync"/>.
|
||||
/// </summary>
|
||||
/// <seealso cref= DefaultErrorStrategy#sync
|
||||
/// </seealso>
|
||||
/// <param name="recognizer"> the parser instance </param>
|
||||
/// <exception cref="RecognitionException"> if an error is detected by the error
|
||||
/// strategy but cannot be automatically recovered at the current state in
|
||||
/// the parsing process </exception>
|
||||
virtual void sync(Parser *recognizer) = 0;
|
||||
|
||||
/// <summary>
|
||||
/// Tests whether or not {@code recognizer} is in the process of recovering
|
||||
/// from an error. In error recovery mode, <seealso cref="Parser#consume"/> adds
|
||||
/// symbols to the parse tree by calling
|
||||
/// <seealso cref="ParserRuleContext#addErrorNode(Token)"/> instead of
|
||||
/// <seealso cref="ParserRuleContext#addChild(Token)"/>.
|
||||
/// </summary>
|
||||
/// <param name="recognizer"> the parser instance </param>
|
||||
/// <returns> {@code true} if the parser is currently recovering from a parse
|
||||
/// error, otherwise {@code false} </returns>
|
||||
virtual bool inErrorRecoveryMode(Parser *recognizer) = 0;
|
||||
|
||||
/// <summary>
|
||||
/// This method is called by when the parser successfully matches an input
|
||||
/// symbol.
|
||||
/// </summary>
|
||||
/// <param name="recognizer"> the parser instance </param>
|
||||
virtual void reportMatch(Parser *recognizer) = 0;
|
||||
|
||||
/// <summary>
|
||||
/// Report any kind of <seealso cref="RecognitionException"/>. This method is called by
|
||||
/// the default exception handler generated for a rule method.
|
||||
/// </summary>
|
||||
/// <param name="recognizer"> the parser instance </param>
|
||||
/// <param name="e"> the recognition exception to report </param>
|
||||
virtual void reportError(Parser *recognizer, RecognitionException *e) = 0;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,88 @@
|
|||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
#include <cstring>
|
||||
|
||||
#include "ANTLRFileStream.h"
|
||||
#include "Exceptions.h"
|
||||
|
||||
/*
|
||||
* [The "BSD license"]
|
||||
* Copyright (c) 2013 Terence Parr
|
||||
* Copyright (c) 2013 Dan McLaughlin
|
||||
* 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. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
||||
*/
|
||||
|
||||
namespace org {
|
||||
namespace antlr {
|
||||
namespace v4 {
|
||||
namespace runtime {
|
||||
ANTLRFileStream::ANTLRFileStream(const std::string &fileName) {
|
||||
}
|
||||
|
||||
ANTLRFileStream::ANTLRFileStream(const std::string &fileName, const std::string &encoding) {
|
||||
this->fileName = fileName;
|
||||
load(fileName, encoding);
|
||||
}
|
||||
|
||||
/*
|
||||
Issue: is seems that file name in C++ are considered to be not
|
||||
wide for the reason that not all systems support wchar file
|
||||
names. Win32 is good about this but not all others.
|
||||
TODO: this could be a place to have platform specific build
|
||||
flags
|
||||
*/
|
||||
void ANTLRFileStream::load(const std::string &fileName, const std::string &encoding) {
|
||||
if (fileName == "") {
|
||||
return;
|
||||
}
|
||||
|
||||
std::stringstream ss;
|
||||
std::wifstream f;
|
||||
|
||||
// Open as a byte stream
|
||||
f.open(fileName, std::ios::binary);
|
||||
ss<<f.rdbuf();
|
||||
|
||||
std::string const &s = ss.str();
|
||||
if (s.size() % sizeof(wchar_t) != 0)
|
||||
{
|
||||
throw new IOException(L"file not the right size");
|
||||
}
|
||||
|
||||
std::wstring ws;
|
||||
ws.resize(s.size()/sizeof(wchar_t));
|
||||
std::memcpy(&ws[0],s.c_str(),s.size()); // copy data into wstring
|
||||
data=ws;
|
||||
}
|
||||
|
||||
std::string ANTLRFileStream::getSourceName() {
|
||||
return fileName;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,63 @@
|
|||
#pragma once
|
||||
|
||||
#include "ANTLRInputStream.h"
|
||||
#include <string>
|
||||
|
||||
/*
|
||||
* [The "BSD license"]
|
||||
* Copyright (c) 2013 Terence Parr
|
||||
* Copyright (c) 2013 Dan McLaughlin
|
||||
* 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. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
||||
*/
|
||||
|
||||
namespace org {
|
||||
namespace antlr {
|
||||
namespace v4 {
|
||||
namespace runtime {
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// This is an <seealso cref="ANTLRInputStream"/> that is loaded from a file all at once
|
||||
/// when you construct the object.
|
||||
/// </summary>
|
||||
class ANTLRFileStream : public ANTLRInputStream {
|
||||
protected:
|
||||
std::string fileName;
|
||||
|
||||
public:
|
||||
ANTLRFileStream(const std::string &fileName); //this(fileName, nullptr);
|
||||
|
||||
ANTLRFileStream(const std::string &fileName, const std::string &encoding);
|
||||
|
||||
virtual void load(const std::string &fileName, const std::string &encoding);
|
||||
|
||||
virtual std::string getSourceName() override;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,209 @@
|
|||
#include "ANTLRInputStream.h"
|
||||
#include "Exceptions.h"
|
||||
#include "Interval.h"
|
||||
#include "assert.h"
|
||||
#include "Arrays.h"
|
||||
|
||||
/*
|
||||
* [The "BSD license"]
|
||||
* Copyright (c) 2013 Terence Parr
|
||||
* Copyright (c) 2013 Dan McLaughlin
|
||||
* 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. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
||||
*/
|
||||
|
||||
namespace org {
|
||||
namespace antlr {
|
||||
namespace v4 {
|
||||
namespace runtime {
|
||||
using misc::Interval;
|
||||
|
||||
ANTLRInputStream::ANTLRInputStream() {
|
||||
InitializeInstanceFields();
|
||||
}
|
||||
|
||||
ANTLRInputStream::ANTLRInputStream(const std::wstring &input) {
|
||||
InitializeInstanceFields();
|
||||
this->data = input;
|
||||
this->n = (int)input.length();
|
||||
}
|
||||
|
||||
ANTLRInputStream::ANTLRInputStream(wchar_t data[], int numberOfActualCharsInArray) {
|
||||
InitializeInstanceFields();
|
||||
this->data = data;
|
||||
this->n = numberOfActualCharsInArray;
|
||||
}
|
||||
|
||||
|
||||
ANTLRInputStream::ANTLRInputStream(std::wifstream *r) {
|
||||
}
|
||||
|
||||
|
||||
ANTLRInputStream::ANTLRInputStream(std::wifstream *r, int initialSize) {
|
||||
}
|
||||
|
||||
ANTLRInputStream::ANTLRInputStream(std::wifstream *r, int initialSize, int readChunkSize) {
|
||||
InitializeInstanceFields();
|
||||
load(r, initialSize, readChunkSize);
|
||||
}
|
||||
|
||||
|
||||
void ANTLRInputStream::load(std::wifstream *r, int size, int readChunkSize) {
|
||||
if (r == nullptr) {
|
||||
return;
|
||||
}
|
||||
if (size <= 0) {
|
||||
size = INITIAL_BUFFER_SIZE;
|
||||
}
|
||||
if (readChunkSize <= 0) {
|
||||
readChunkSize = READ_BUFFER_SIZE;
|
||||
}
|
||||
// System.out.println("load "+size+" in chunks of "+readChunkSize);
|
||||
try {
|
||||
// alloc initial buffer size.
|
||||
data = new wchar_t[size];
|
||||
// read all the data in chunks of readChunkSize
|
||||
int numRead = 0;
|
||||
int p = 0;
|
||||
do {
|
||||
if (p + readChunkSize > (int)data.length()) { // overflow?
|
||||
// System.out.println("### overflow p="+p+", data.length="+data.length);
|
||||
data = antlrcpp::Arrays::copyOf(data, (int)data.length() * 2);
|
||||
}
|
||||
r->read(new wchar_t[100], p);
|
||||
|
||||
// System.out.println("read "+numRead+" chars; p was "+p+" is now "+(p+numRead));
|
||||
p += numRead;
|
||||
} while (numRead != -1); // while not EOF
|
||||
// set the actual size of the data available;
|
||||
// EOF subtracted one above in p+=numRead; add one back
|
||||
n = p + 1;
|
||||
//System.out.println("n="+n);
|
||||
}
|
||||
catch (void *){
|
||||
r->close();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void ANTLRInputStream::reset() {
|
||||
p = 0;
|
||||
}
|
||||
|
||||
void ANTLRInputStream::consume() {
|
||||
if (p >= n) {
|
||||
assert(LA(1) == IntStream::_EOF);
|
||||
throw IllegalStateException(L"cannot consume EOF");
|
||||
}
|
||||
|
||||
//System.out.println("prev p="+p+", c="+(char)data[p]);
|
||||
if (p < n) {
|
||||
p++;
|
||||
//System.out.println("p moves to "+p+" (c='"+(char)data[p]+"')");
|
||||
}
|
||||
}
|
||||
|
||||
int ANTLRInputStream::LA(int i) {
|
||||
if (i == 0) {
|
||||
return 0; // undefined
|
||||
}
|
||||
if (i < 0) {
|
||||
i++; // e.g., translate LA(-1) to use offset i=0; then data[p+0-1]
|
||||
if ((p + i - 1) < 0) {
|
||||
return IntStream::_EOF; // invalid; no char before first char
|
||||
}
|
||||
}
|
||||
|
||||
if ((p + i - 1) >= n) {
|
||||
//System.out.println("char LA("+i+")=EOF; p="+p);
|
||||
return IntStream::_EOF;
|
||||
}
|
||||
//System.out.println("char LA("+i+")="+(char)data[p+i-1]+"; p="+p);
|
||||
//System.out.println("LA("+i+"); p="+p+" n="+n+" data.length="+data.length);
|
||||
return data[p + i - 1];
|
||||
}
|
||||
|
||||
int ANTLRInputStream::LT(int i) {
|
||||
return LA(i);
|
||||
}
|
||||
|
||||
int ANTLRInputStream::index() {
|
||||
return p;
|
||||
}
|
||||
|
||||
size_t ANTLRInputStream::size() {
|
||||
return n;
|
||||
}
|
||||
|
||||
int ANTLRInputStream::mark() {
|
||||
return -1;
|
||||
}
|
||||
|
||||
void ANTLRInputStream::release(int marker) {
|
||||
}
|
||||
|
||||
void ANTLRInputStream::seek(int index) {
|
||||
if (index <= p) {
|
||||
p = index; // just jump; don't update stream state (line, ...)
|
||||
return;
|
||||
}
|
||||
// seek forward, consume until p hits index
|
||||
while (p < index && index < n) {
|
||||
consume();
|
||||
}
|
||||
}
|
||||
|
||||
std::wstring ANTLRInputStream::getText(Interval *interval) {
|
||||
int start = interval->a;
|
||||
int stop = interval->b;
|
||||
if (stop >= n) {
|
||||
stop = n - 1;
|
||||
}
|
||||
int count = stop - start + 1;
|
||||
if (start >= n) {
|
||||
return L"";
|
||||
}
|
||||
// System.err.println("data: "+Arrays.toString(data)+", n="+n+
|
||||
// ", start="+start+
|
||||
// ", stop="+stop);
|
||||
return std::wstring(data, start, count);
|
||||
}
|
||||
|
||||
std::string ANTLRInputStream::getSourceName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
std::wstring ANTLRInputStream::toString() {
|
||||
return std::wstring(data);
|
||||
}
|
||||
|
||||
void ANTLRInputStream::InitializeInstanceFields() {
|
||||
n = 0;
|
||||
p = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,145 @@
|
|||
#pragma once
|
||||
|
||||
|
||||
#include <string>
|
||||
#include <fstream>
|
||||
#include "CharStream.h"
|
||||
#include "Declarations.h"
|
||||
|
||||
/*
|
||||
* [The "BSD license"]
|
||||
* Copyright (c) 2013 Terence Parr
|
||||
* Copyright (c) 2013 Dan McLaughlin
|
||||
* 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. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
||||
*/
|
||||
namespace org {
|
||||
namespace antlr {
|
||||
namespace v4 {
|
||||
namespace runtime {
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Vacuum all input from a <seealso cref="Reader"/>/<seealso cref="InputStream"/> and then treat it
|
||||
/// like a {@code char[]} buffer. Can also pass in a <seealso cref="String"/> or
|
||||
/// {@code char[]} to use.
|
||||
/// <p/>
|
||||
/// If you need encoding, pass in stream/reader with correct encoding.
|
||||
/// </summary>
|
||||
class ANTLRInputStream : public CharStream {
|
||||
public:
|
||||
static const int READ_BUFFER_SIZE = 1024;
|
||||
static const int INITIAL_BUFFER_SIZE = 1024;
|
||||
|
||||
/// <summary>
|
||||
/// The data being scanned </summary>
|
||||
protected:
|
||||
std::wstring data;
|
||||
|
||||
/// <summary>
|
||||
/// How many characters are actually in the buffer </summary>
|
||||
int n;
|
||||
|
||||
/// <summary>
|
||||
/// 0..n-1 index into string of next char </summary>
|
||||
int p;
|
||||
|
||||
/// <summary>
|
||||
/// What is name or source of this char stream? </summary>
|
||||
public:
|
||||
std::string name;
|
||||
|
||||
ANTLRInputStream();
|
||||
|
||||
/// <summary>
|
||||
/// Copy data in string to a local char array </summary>
|
||||
ANTLRInputStream(const std::wstring &input);
|
||||
|
||||
/// <summary>
|
||||
/// This is the preferred constructor for strings as no data is copied </summary>
|
||||
ANTLRInputStream(wchar_t data[], int numberOfActualCharsInArray);
|
||||
|
||||
ANTLRInputStream(std::wifstream *r) ; //this(r, INITIAL_BUFFER_SIZE, READ_BUFFER_SIZE);
|
||||
|
||||
ANTLRInputStream(std::wifstream *r, int initialSize) ; //this(r, initialSize, READ_BUFFER_SIZE);
|
||||
|
||||
ANTLRInputStream(std::wifstream *r, int initialSize, int readChunkSize);
|
||||
|
||||
ANTLRInputStream(std::wiostream *input) ; //this(new InputStreamReader(input), INITIAL_BUFFER_SIZE);
|
||||
|
||||
ANTLRInputStream(std::wiostream *input, int initialSize); //this(new InputStreamReader(input), initialSize);
|
||||
|
||||
ANTLRInputStream(std::wiostream *input, int initialSize, int readChunkSize); //this(new InputStreamReader(input), initialSize, readChunkSize);
|
||||
|
||||
virtual void load(std::wifstream *r, int size, int readChunkSize);
|
||||
|
||||
/// <summary>
|
||||
/// Reset the stream so that it's in the same state it was
|
||||
/// when the object was created *except* the data array is not
|
||||
/// touched.
|
||||
/// </summary>
|
||||
virtual void reset();
|
||||
|
||||
virtual void consume() override;
|
||||
|
||||
virtual int LA(int i) override;
|
||||
|
||||
virtual int LT(int i);
|
||||
|
||||
/// <summary>
|
||||
/// Return the current input symbol index 0..n where n indicates the
|
||||
/// last symbol has been read. The index is the index of char to
|
||||
/// be returned from LA(1).
|
||||
/// </summary>
|
||||
virtual int index() override;
|
||||
|
||||
virtual size_t size() override;
|
||||
|
||||
/// <summary>
|
||||
/// mark/release do nothing; we have entire buffer </summary>
|
||||
virtual int mark() override;
|
||||
|
||||
virtual void release(int marker) override;
|
||||
|
||||
/// <summary>
|
||||
/// consume() ahead until p==index; can't just set p=index as we must
|
||||
/// update line and charPositionInLine. If we seek backwards, just set p
|
||||
/// </summary>
|
||||
virtual void seek(int index) override;
|
||||
|
||||
virtual std::wstring getText(misc::Interval *interval) override;
|
||||
|
||||
virtual std::string getSourceName() override;
|
||||
|
||||
virtual std::wstring toString();
|
||||
|
||||
private:
|
||||
void InitializeInstanceFields();
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,70 @@
|
|||
#include "BailErrorStrategy.h"
|
||||
#include "Exceptions.h"
|
||||
#include "ParserRuleContext.h"
|
||||
#include "Parser.h"
|
||||
#include "ParseCancellationException.h"
|
||||
#include "InputMismatchException.h"
|
||||
|
||||
/*
|
||||
* [The "BSD license"]
|
||||
* Copyright (c) 2013 Terence Parr
|
||||
* Copyright (c) 2013 Dan McLaughlin
|
||||
* 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. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
||||
*/
|
||||
|
||||
|
||||
namespace org {
|
||||
namespace antlr {
|
||||
namespace v4 {
|
||||
namespace runtime {
|
||||
|
||||
void BailErrorStrategy::recover(Parser *recognizer, RecognitionException *e) {
|
||||
for (ParserRuleContext *context = recognizer->getContext(); context != nullptr; context = context->getParent()) {
|
||||
context->exception = e;
|
||||
}
|
||||
|
||||
throw new ParseCancellationException(e);
|
||||
}
|
||||
|
||||
runtime::Token *BailErrorStrategy::recoverInline(Parser *recognizer) {
|
||||
|
||||
InputMismatchException *e = new InputMismatchException(recognizer);
|
||||
for (ParserRuleContext *context = recognizer->getContext();
|
||||
context != nullptr;
|
||||
context = context->getParent()) {
|
||||
context->exception = e;
|
||||
}
|
||||
|
||||
throw new ParseCancellationException(e);
|
||||
|
||||
}
|
||||
|
||||
void BailErrorStrategy::sync(Parser *recognizer) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,70 @@
|
|||
#pragma once
|
||||
|
||||
#include "DefaultErrorStrategy.h"
|
||||
#include "Declarations.h"
|
||||
|
||||
/*
|
||||
* [The "BSD license"]
|
||||
* Copyright (c) 2013 Terence Parr
|
||||
* Copyright (c) 2013 Dan McLaughlin
|
||||
* 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. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
||||
*/
|
||||
|
||||
namespace org {
|
||||
namespace antlr {
|
||||
namespace v4 {
|
||||
namespace runtime {
|
||||
|
||||
/// <summary>
|
||||
/// Bail out of parser at first syntax error. Do this to use it:
|
||||
/// <p/>
|
||||
/// {@code myparser.setErrorHandler(new BailErrorStrategy());}
|
||||
/// </summary>
|
||||
class BailErrorStrategy : public DefaultErrorStrategy {
|
||||
/// <summary>
|
||||
/// Instead of recovering from exception {@code e}, re-throw it wrapped
|
||||
/// in a <seealso cref="ParseCancellationException"/> so it is not caught by the
|
||||
/// rule function catches. Use <seealso cref="Exception#getCause()"/> to get the
|
||||
/// original <seealso cref="RecognitionException"/>.
|
||||
/// </summary>
|
||||
public:
|
||||
virtual void recover(Parser *recognizer, RecognitionException *e) override;
|
||||
|
||||
/// <summary>
|
||||
/// Make sure we don't attempt to recover inline; if the parser
|
||||
/// successfully recovers, it won't throw an exception.
|
||||
/// </summary>
|
||||
virtual Token *recoverInline(Parser *recognizer) override;
|
||||
|
||||
/// <summary>
|
||||
/// Make sure we don't attempt to recover from problems in subrules. </summary>
|
||||
virtual void sync(Parser *recognizer) override;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,49 @@
|
|||
#include "BaseErrorListener.h"
|
||||
|
||||
/*
|
||||
* [The "BSD license"]
|
||||
* Copyright (c) 2013 Terence Parr
|
||||
* Copyright (c) 2013 Dan McLaughlin
|
||||
* 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. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
||||
*/
|
||||
|
||||
namespace org {
|
||||
namespace antlr {
|
||||
namespace v4 {
|
||||
namespace runtime {
|
||||
|
||||
void BaseErrorListener::reportAmbiguity(Parser *recognizer, dfa::DFA *dfa, int startIndex, int stopIndex, bool exact, antlrcpp::BitSet *ambigAlts, atn::ATNConfigSet *configs) {
|
||||
}
|
||||
|
||||
void BaseErrorListener::reportAttemptingFullContext(Parser *recognizer, dfa::DFA *dfa, int startIndex, int stopIndex, antlrcpp::BitSet *conflictingAlts, atn::ATNConfigSet *configs) {
|
||||
}
|
||||
|
||||
void BaseErrorListener::reportContextSensitivity(Parser *recognizer, dfa::DFA *dfa, int startIndex, int stopIndex, int prediction, atn::ATNConfigSet *configs) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,60 @@
|
|||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "ANTLRErrorListener.h"
|
||||
#include "IRecognizer.h"
|
||||
|
||||
/*
|
||||
* [The "BSD license"]
|
||||
* Copyright (c) 2013 Terence Parr
|
||||
* Copyright (c) 2013 Dan McLaughlin
|
||||
* 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. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
||||
*/
|
||||
|
||||
namespace org {
|
||||
namespace antlr {
|
||||
namespace v4 {
|
||||
namespace runtime {
|
||||
/// <summary>
|
||||
/// @author Sam Harwell
|
||||
/// </summary>
|
||||
class BaseErrorListener : public ANTLRErrorListener {
|
||||
|
||||
template<typename T1, typename T2>
|
||||
void syntaxError(IRecognizer<T1, T2> *recognizer, void *offendingSymbol, int line, int charPositionInLine, const std::wstring &msg, RecognitionException *e) { }
|
||||
|
||||
virtual void reportAmbiguity(Parser *recognizer, dfa::DFA *dfa, int startIndex, int stopIndex, bool exact, antlrcpp::BitSet *ambigAlts, atn::ATNConfigSet *configs) override;
|
||||
|
||||
virtual void reportAttemptingFullContext(Parser *recognizer, dfa::DFA *dfa, int startIndex, int stopIndex, antlrcpp::BitSet *conflictingAlts, atn::ATNConfigSet *configs);
|
||||
|
||||
virtual void reportContextSensitivity(Parser *recognizer, dfa::DFA *dfa, int startIndex, int stopIndex, int prediction, atn::ATNConfigSet *configs);
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,410 @@
|
|||
#include <assert.h>
|
||||
#include <algorithm>
|
||||
|
||||
#include "BufferedTokenStream.h"
|
||||
#include "WritableToken.h"
|
||||
#include "Lexer.h"
|
||||
#include "Exceptions.h"
|
||||
#include "StringBuilder.h"
|
||||
|
||||
/*
|
||||
* [The "BSD license"]
|
||||
* Copyright (c) 2013 Terence Parr
|
||||
* Copyright (c) 2013 Dan McLaughlin
|
||||
* 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. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
||||
*/
|
||||
|
||||
namespace org {
|
||||
namespace antlr {
|
||||
namespace v4 {
|
||||
namespace runtime {
|
||||
|
||||
BufferedTokenStream::BufferedTokenStream(TokenSource *tokenSource) {
|
||||
InitializeInstanceFields();
|
||||
if (tokenSource == nullptr) {
|
||||
throw new NullPointerException(L"tokenSource cannot be null");
|
||||
}
|
||||
this->tokenSource = tokenSource;
|
||||
}
|
||||
|
||||
TokenSource *BufferedTokenStream::getTokenSource() {
|
||||
return tokenSource;
|
||||
}
|
||||
|
||||
int BufferedTokenStream::index() {
|
||||
return p;
|
||||
}
|
||||
|
||||
int BufferedTokenStream::mark() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
void BufferedTokenStream::release(int marker) {
|
||||
// no resources to release
|
||||
}
|
||||
|
||||
void BufferedTokenStream::reset() {
|
||||
seek(0);
|
||||
}
|
||||
|
||||
void BufferedTokenStream::seek(int index) {
|
||||
lazyInit();
|
||||
p = adjustSeekIndex(index);
|
||||
}
|
||||
|
||||
size_t BufferedTokenStream::size() {
|
||||
return tokens.size();
|
||||
}
|
||||
|
||||
void BufferedTokenStream::consume() {
|
||||
if (LA(1) == _EOF) {
|
||||
throw new IllegalStateException(L"cannot consume EOF");
|
||||
}
|
||||
|
||||
if (sync(p + 1)) {
|
||||
p = adjustSeekIndex(p + 1);
|
||||
}
|
||||
}
|
||||
|
||||
bool BufferedTokenStream::sync(int i) {
|
||||
assert(i >= 0);
|
||||
size_t n = i - tokens.size() + 1; // how many more elements we need?
|
||||
//System.out.println("sync("+i+") needs "+n);
|
||||
if (n > 0) {
|
||||
size_t fetched = fetch((int)n);
|
||||
return fetched >= n;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
int BufferedTokenStream::fetch(int n) {
|
||||
if (fetchedEOF) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
for (int i = 0; i < n; i++) {
|
||||
Token *t = tokenSource->nextToken();
|
||||
if (dynamic_cast<WritableToken*>(t) != nullptr) {
|
||||
(static_cast<WritableToken*>(t))->setTokenIndex((int)tokens.size());
|
||||
}
|
||||
tokens.push_back(t);
|
||||
if (t->getType() == Token::_EOF) {
|
||||
fetchedEOF = true;
|
||||
return i + 1;
|
||||
}
|
||||
}
|
||||
|
||||
return n;
|
||||
}
|
||||
|
||||
Token *BufferedTokenStream::get(int i) {
|
||||
if (i < 0 || i >= (int)tokens.size()) {
|
||||
throw IndexOutOfBoundsException(std::wstring(L"token index ") +
|
||||
std::to_wstring(i) +
|
||||
std::wstring(L" out of range 0..") +
|
||||
std::to_wstring(tokens.size() - 1));
|
||||
}
|
||||
return tokens[i];
|
||||
}
|
||||
|
||||
std::vector<Token*> BufferedTokenStream::get(int start, int stop) {
|
||||
if (start < 0 || stop < 0) {
|
||||
return std::vector<Token*>();
|
||||
}
|
||||
lazyInit();
|
||||
std::vector<Token*> subset = std::vector<Token*>();
|
||||
if (stop >= (int)tokens.size()) {
|
||||
stop = (int)tokens.size() - 1;
|
||||
}
|
||||
for (int i = start; i <= stop; i++) {
|
||||
Token *t = tokens[i];
|
||||
if (t->getType() == Token::_EOF) {
|
||||
break;
|
||||
}
|
||||
subset.push_back(t);
|
||||
}
|
||||
return subset;
|
||||
}
|
||||
|
||||
int BufferedTokenStream::LA(int i) {
|
||||
return LT(i)->getType();
|
||||
}
|
||||
|
||||
Token *BufferedTokenStream::LB(int k) {
|
||||
if ((p - k) < 0) {
|
||||
return nullptr;
|
||||
}
|
||||
return tokens[p - k];
|
||||
}
|
||||
|
||||
Token *BufferedTokenStream::LT(int k) {
|
||||
lazyInit();
|
||||
if (k == 0) {
|
||||
return nullptr;
|
||||
}
|
||||
if (k < 0) {
|
||||
return LB(-k);
|
||||
}
|
||||
|
||||
int i = p + k - 1;
|
||||
sync(i);
|
||||
if (i >= (int)tokens.size()) { // return EOF token
|
||||
// EOF must be last token
|
||||
return tokens[tokens.size() - 1];
|
||||
}
|
||||
// if ( i>range ) range = i;
|
||||
return tokens[i];
|
||||
}
|
||||
|
||||
int BufferedTokenStream::adjustSeekIndex(int i) {
|
||||
return i;
|
||||
}
|
||||
|
||||
void BufferedTokenStream::lazyInit() {
|
||||
if (p == -1) {
|
||||
setup();
|
||||
}
|
||||
}
|
||||
|
||||
void BufferedTokenStream::setup() {
|
||||
sync(0);
|
||||
p = adjustSeekIndex(0);
|
||||
}
|
||||
|
||||
void BufferedTokenStream::setTokenSource(TokenSource *tokenSource) {
|
||||
this->tokenSource = tokenSource;
|
||||
tokens.clear();
|
||||
p = -1;
|
||||
}
|
||||
|
||||
std::vector<Token*> BufferedTokenStream::getTokens() {
|
||||
return tokens;
|
||||
}
|
||||
|
||||
std::vector<Token*> BufferedTokenStream::getTokens(int start, int stop) {
|
||||
return getTokens(start, stop, nullptr);
|
||||
}
|
||||
|
||||
std::vector<Token*> BufferedTokenStream::getTokens(int start, int stop, std::vector<int> *types) {
|
||||
lazyInit();
|
||||
if (start < 0 || stop >= (int)tokens.size() || stop < 0 || (int)start >= (int)tokens.size()) {
|
||||
throw new IndexOutOfBoundsException(std::wstring(L"start ") +
|
||||
std::to_wstring(start) +
|
||||
std::wstring(L" or stop ") +
|
||||
std::to_wstring(stop) +
|
||||
std::wstring(L" not in 0..") +
|
||||
std::to_wstring(tokens.size() - 1));
|
||||
}
|
||||
if (start > stop) {
|
||||
return std::vector<Token*>();
|
||||
}
|
||||
|
||||
// list = tokens[start:stop]:{T t, t.getType() in types}
|
||||
std::vector<Token*> filteredTokens = std::vector<Token*>();
|
||||
for (int i = start; i <= stop; i++) {
|
||||
Token *tok = tokens[i];
|
||||
|
||||
if (types == nullptr) {
|
||||
filteredTokens.push_back(tok);
|
||||
} else {
|
||||
if (types == nullptr || std::find(types->begin(), types->end(), tok->getType()) != types->end()) {
|
||||
filteredTokens.push_back(tok);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (filteredTokens.empty()) {
|
||||
filteredTokens.clear();
|
||||
}
|
||||
return filteredTokens;
|
||||
}
|
||||
|
||||
std::vector<Token*> BufferedTokenStream::getTokens(int start, int stop, int ttype) {
|
||||
std::vector<int> *s = new std::vector<int>();
|
||||
s->insert(s->begin(), ttype);
|
||||
return getTokens(start,stop, s);
|
||||
}
|
||||
|
||||
int BufferedTokenStream::nextTokenOnChannel(int i, int channel) {
|
||||
sync(i);
|
||||
Token *token = tokens[i];
|
||||
if (i >= (int)size()) {
|
||||
return -1;
|
||||
}
|
||||
while (token->getChannel() != channel) {
|
||||
if (token->getType() == Token::_EOF) {
|
||||
return -1;
|
||||
}
|
||||
i++;
|
||||
sync(i);
|
||||
token = tokens[i];
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
int BufferedTokenStream::previousTokenOnChannel(int i, int channel) {
|
||||
while (i >= 0 && tokens[i]->getChannel() != channel) {
|
||||
i--;
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
std::vector<Token*> BufferedTokenStream::getHiddenTokensToRight(int tokenIndex, int channel) {
|
||||
lazyInit();
|
||||
if (tokenIndex < 0 || tokenIndex >= (int)tokens.size()) {
|
||||
throw new IndexOutOfBoundsException(std::to_wstring(tokenIndex) +
|
||||
std::wstring(L" not in 0..") +
|
||||
std::to_wstring(tokens.size() - 1));
|
||||
}
|
||||
|
||||
int nextOnChannel = nextTokenOnChannel(tokenIndex + 1, Lexer::DEFAULT_TOKEN_CHANNEL);
|
||||
int to;
|
||||
int from = tokenIndex + 1;
|
||||
// if none onchannel to right, nextOnChannel=-1 so set to = last token
|
||||
if (nextOnChannel == -1) {
|
||||
to = (int)size() - 1;
|
||||
} else {
|
||||
to = nextOnChannel;
|
||||
}
|
||||
|
||||
return filterForChannel(from, to, channel);
|
||||
}
|
||||
|
||||
std::vector<Token*> BufferedTokenStream::getHiddenTokensToRight(int tokenIndex) {
|
||||
return getHiddenTokensToRight(tokenIndex, -1);
|
||||
}
|
||||
|
||||
std::vector<Token*> BufferedTokenStream::getHiddenTokensToLeft(int tokenIndex, int channel) {
|
||||
lazyInit();
|
||||
if (tokenIndex < 0 || tokenIndex >= (int)tokens.size()) {
|
||||
throw new IndexOutOfBoundsException(std::to_wstring(tokenIndex) +
|
||||
std::wstring(L" not in 0..") +
|
||||
std::to_wstring(tokens.size() - 1));
|
||||
}
|
||||
|
||||
int prevOnChannel = previousTokenOnChannel(tokenIndex - 1, Lexer::DEFAULT_TOKEN_CHANNEL);
|
||||
if (prevOnChannel == tokenIndex - 1) {
|
||||
return std::vector<Token*>();
|
||||
}
|
||||
// if none onchannel to left, prevOnChannel=-1 then from=0
|
||||
int from = prevOnChannel + 1;
|
||||
int to = tokenIndex - 1;
|
||||
|
||||
return filterForChannel(from, to, channel);
|
||||
}
|
||||
|
||||
std::vector<Token*> BufferedTokenStream::getHiddenTokensToLeft(int tokenIndex) {
|
||||
return getHiddenTokensToLeft(tokenIndex, -1);
|
||||
}
|
||||
|
||||
std::vector<Token*> BufferedTokenStream::filterForChannel(int from, int to, int channel) {
|
||||
std::vector<Token*> hidden = std::vector<Token*>();
|
||||
for (int i = from; i <= to; i++) {
|
||||
Token *t = tokens[i];
|
||||
if (channel == -1) {
|
||||
if (t->getChannel() != Lexer::DEFAULT_TOKEN_CHANNEL) {
|
||||
hidden.push_back(t);
|
||||
}
|
||||
} else {
|
||||
if (t->getChannel() == channel) {
|
||||
hidden.push_back(t);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (hidden.empty()) {
|
||||
return std::vector<Token*>();
|
||||
}
|
||||
return hidden;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the text of all tokens in this buffer.
|
||||
*/
|
||||
std::string BufferedTokenStream::getSourceName()
|
||||
{
|
||||
return tokenSource->getSourceName();
|
||||
}
|
||||
|
||||
std::wstring BufferedTokenStream::getText() {
|
||||
lazyInit();
|
||||
fill();
|
||||
return getText(misc::Interval::of(0, (int)size() - 1));
|
||||
}
|
||||
|
||||
std::wstring BufferedTokenStream::getText(misc::Interval *interval) {
|
||||
int start = interval->a;
|
||||
int stop = interval->b;
|
||||
if (start < 0 || stop < 0) {
|
||||
return L"";
|
||||
}
|
||||
lazyInit();
|
||||
if (stop >= (int)tokens.size()) {
|
||||
stop = (int)tokens.size() - 1;
|
||||
}
|
||||
|
||||
antlrcpp::StringBuilder *buf = new antlrcpp::StringBuilder();
|
||||
for (int i = start; i <= stop; i++) {
|
||||
Token *t = tokens[i];
|
||||
if (t->getType() == Token::_EOF) {
|
||||
break;
|
||||
}
|
||||
buf->append(t->getText());
|
||||
}
|
||||
return buf->toString();
|
||||
}
|
||||
|
||||
std::wstring BufferedTokenStream::getText(RuleContext *ctx) {
|
||||
return getText(ctx->getSourceInterval());
|
||||
}
|
||||
|
||||
std::wstring BufferedTokenStream::getText(Token *start, Token *stop) {
|
||||
if (start != nullptr && stop != nullptr) {
|
||||
return getText(misc::Interval::of(start->getTokenIndex(), stop->getTokenIndex()));
|
||||
}
|
||||
|
||||
return L"";
|
||||
}
|
||||
|
||||
void BufferedTokenStream::fill() {
|
||||
lazyInit();
|
||||
const int blockSize = 1000;
|
||||
while (true) {
|
||||
int fetched = fetch(blockSize);
|
||||
if (fetched < blockSize) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void BufferedTokenStream::InitializeInstanceFields() {
|
||||
tokens = antlrcpp::VectorHelper::VectorWithReservedSize<Token*>(100);
|
||||
p = -1;
|
||||
fetchedEOF = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,240 @@
|
|||
#pragma once
|
||||
|
||||
#include "Token.h"
|
||||
#include "Interval.h"
|
||||
#include "TokenStream.h"
|
||||
#include "TokenSource.h"
|
||||
#include "RuleContext.h"
|
||||
#include "vectorhelper.h"
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <set>
|
||||
|
||||
/*
|
||||
* [The "BSD license"]
|
||||
* Copyright (c) 2013 Terence Parr
|
||||
* Copyright (c) 2013 Dan McLaughlin
|
||||
* 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. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
||||
*/
|
||||
|
||||
namespace org {
|
||||
namespace antlr {
|
||||
namespace v4 {
|
||||
namespace runtime {
|
||||
/// <summary>
|
||||
/// Buffer all input tokens but do on-demand fetching of new tokens from lexer.
|
||||
/// Useful when the parser or lexer has to set context/mode info before proper
|
||||
/// lexing of future tokens. The ST template parser needs this, for example,
|
||||
/// because it has to constantly flip back and forth between inside/output
|
||||
/// templates. E.g., {@code <names:{hi, <it>}>} has to parse names as part of an
|
||||
/// expression but {@code "hi, <it>"} as a nested template.
|
||||
/// <p/>
|
||||
/// You can't use this stream if you pass whitespace or other off-channel tokens
|
||||
/// to the parser. The stream can't ignore off-channel tokens.
|
||||
/// (<seealso cref="UnbufferedTokenStream"/> is the same way.) Use
|
||||
/// <seealso cref="CommonTokenStream"/>.
|
||||
/// </summary>
|
||||
class BufferedTokenStream : public TokenStream {
|
||||
protected:
|
||||
TokenSource *tokenSource;
|
||||
|
||||
/// <summary>
|
||||
/// Record every single token pulled from the source so we can reproduce
|
||||
/// chunks of it later. This list captures everything so we can access
|
||||
/// complete input text.
|
||||
/// </summary>
|
||||
std::vector<Token*> tokens;
|
||||
|
||||
/// <summary>
|
||||
/// The index into <seealso cref="#tokens"/> of the current token (next token to
|
||||
/// consume). <seealso cref="#tokens"/>{@code [}<seealso cref="#p"/>{@code ]} should be
|
||||
/// <seealso cref="#LT LT(1)"/>. <seealso cref="#p"/>{@code =-1} indicates need to initialize
|
||||
/// with first token. The constructor doesn't get a token. First call to
|
||||
/// <seealso cref="#LT LT(1)"/> or whatever gets the first token and sets
|
||||
/// <seealso cref="#p"/>{@code =0;}.
|
||||
/// </summary>
|
||||
int p;
|
||||
|
||||
/// <summary>
|
||||
/// Set to {@code true} when the EOF token is fetched. Do not continue fetching
|
||||
/// tokens after that point, or multiple EOF tokens could end up in the
|
||||
/// <seealso cref="#tokens"/> array.
|
||||
/// </summary>
|
||||
/// <seealso cref= #fetch </seealso>
|
||||
bool fetchedEOF;
|
||||
|
||||
public:
|
||||
BufferedTokenStream(TokenSource *tokenSource);
|
||||
|
||||
virtual TokenSource *getTokenSource() override;
|
||||
virtual int index() override;
|
||||
virtual int mark() override;
|
||||
|
||||
virtual void release(int marker) override;
|
||||
|
||||
virtual void reset();
|
||||
|
||||
virtual void seek(int index) override;
|
||||
|
||||
virtual size_t size() override;
|
||||
virtual void consume() override;
|
||||
|
||||
/// <summary>
|
||||
/// Make sure index {@code i} in tokens has a token.
|
||||
/// </summary>
|
||||
/// <returns> {@code true} if a token is located at index {@code i}, otherwise
|
||||
/// {@code false}. </returns>
|
||||
/// <seealso cref= #get(int i) </seealso>
|
||||
protected:
|
||||
virtual bool sync(int i);
|
||||
|
||||
/// <summary>
|
||||
/// Add {@code n} elements to buffer.
|
||||
/// </summary>
|
||||
/// <returns> The actual number of elements added to the buffer. </returns>
|
||||
virtual int fetch(int n);
|
||||
|
||||
public:
|
||||
virtual Token *get(int i) override;
|
||||
|
||||
/// <summary>
|
||||
/// Get all tokens from start..stop inclusively </summary>
|
||||
virtual std::vector<Token*> get(int start, int stop);
|
||||
|
||||
virtual int LA(int i) override;
|
||||
|
||||
protected:
|
||||
virtual Token *LB(int k);
|
||||
|
||||
public:
|
||||
virtual Token *LT(int k) override;
|
||||
|
||||
/// <summary>
|
||||
/// Allowed derived classes to modify the behavior of operations which change
|
||||
/// the current stream position by adjusting the target token index of a seek
|
||||
/// operation. The default implementation simply returns {@code i}. If an
|
||||
/// exception is thrown in this method, the current stream index should not be
|
||||
/// changed.
|
||||
/// <p/>
|
||||
/// For example, <seealso cref="CommonTokenStream"/> overrides this method to ensure that
|
||||
/// the seek target is always an on-channel token.
|
||||
/// </summary>
|
||||
/// <param name="i"> The target token index. </param>
|
||||
/// <returns> The adjusted target token index. </returns>
|
||||
protected:
|
||||
virtual int adjustSeekIndex(int i);
|
||||
|
||||
void lazyInit();
|
||||
|
||||
virtual void setup();
|
||||
|
||||
/// <summary>
|
||||
/// Reset this token stream by setting its token source. </summary>
|
||||
public:
|
||||
virtual void setTokenSource(TokenSource *tokenSource);
|
||||
|
||||
virtual std::vector<Token*> getTokens();
|
||||
|
||||
virtual std::vector<Token*> getTokens(int start, int stop);
|
||||
|
||||
/// <summary>
|
||||
/// Given a start and stop index, return a List of all tokens in
|
||||
/// the token type BitSet. Return null if no tokens were found. This
|
||||
/// method looks at both on and off channel tokens.
|
||||
/// </summary>
|
||||
virtual std::vector<Token*> getTokens(int start, int stop, std::vector<int> *types);
|
||||
|
||||
virtual std::vector<Token*> getTokens(int start, int stop, int ttype);
|
||||
|
||||
/// <summary>
|
||||
/// Given a starting index, return the index of the next token on channel.
|
||||
/// Return i if tokens[i] is on channel. Return -1 if there are no tokens
|
||||
/// on channel between i and EOF.
|
||||
/// </summary>
|
||||
protected:
|
||||
virtual int nextTokenOnChannel(int i, int channel);
|
||||
|
||||
/// <summary>
|
||||
/// Given a starting index, return the index of the previous token on channel.
|
||||
/// Return i if tokens[i] is on channel. Return -1 if there are no tokens
|
||||
/// on channel between i and 0.
|
||||
/// </summary>
|
||||
virtual int previousTokenOnChannel(int i, int channel);
|
||||
|
||||
/// <summary>
|
||||
/// Collect all tokens on specified channel to the right of
|
||||
/// the current token up until we see a token on DEFAULT_TOKEN_CHANNEL or
|
||||
/// EOF. If channel is -1, find any non default channel token.
|
||||
/// </summary>
|
||||
public:
|
||||
virtual std::vector<Token*> getHiddenTokensToRight(int tokenIndex, int channel);
|
||||
|
||||
/// <summary>
|
||||
/// Collect all hidden tokens (any off-default channel) to the right of
|
||||
/// the current token up until we see a token on DEFAULT_TOKEN_CHANNEL
|
||||
/// of EOF.
|
||||
/// </summary>
|
||||
virtual std::vector<Token*> getHiddenTokensToRight(int tokenIndex);
|
||||
|
||||
/// <summary>
|
||||
/// Collect all tokens on specified channel to the left of
|
||||
/// the current token up until we see a token on DEFAULT_TOKEN_CHANNEL.
|
||||
/// If channel is -1, find any non default channel token.
|
||||
/// </summary>
|
||||
virtual std::vector<Token*> getHiddenTokensToLeft(int tokenIndex, int channel);
|
||||
|
||||
/// <summary>
|
||||
/// Collect all hidden tokens (any off-default channel) to the left of
|
||||
/// the current token up until we see a token on DEFAULT_TOKEN_CHANNEL.
|
||||
/// </summary>
|
||||
virtual std::vector<Token*> getHiddenTokensToLeft(int tokenIndex);
|
||||
|
||||
protected:
|
||||
virtual std::vector<Token*> filterForChannel(int from, int to, int channel);
|
||||
|
||||
public:
|
||||
virtual std::string getSourceName() override;
|
||||
virtual std::wstring getText() override;
|
||||
|
||||
virtual std::wstring getText(misc::Interval *interval) override;
|
||||
|
||||
virtual std::wstring getText(RuleContext *ctx) override;
|
||||
|
||||
virtual std::wstring getText(Token *start, Token *stop) override;
|
||||
|
||||
/// <summary>
|
||||
/// Get all tokens from lexer until EOF </summary>
|
||||
virtual void fill();
|
||||
|
||||
private:
|
||||
void InitializeInstanceFields();
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,42 @@
|
|||
#include "CharStream.h"
|
||||
|
||||
/*
|
||||
* [The "BSD license"]
|
||||
* Copyright (c) 2013 Terence Parr
|
||||
* Copyright (c) 2013 Dan McLaughlin
|
||||
* 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. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
||||
*/
|
||||
|
||||
namespace org {
|
||||
namespace antlr {
|
||||
namespace v4 {
|
||||
namespace runtime {
|
||||
CharStream::~CharStream(){};
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,68 @@
|
|||
#pragma once
|
||||
|
||||
#include "IntStream.h"
|
||||
#include "Declarations.h"
|
||||
|
||||
/*
|
||||
* [The "BSD license"]
|
||||
* Copyright (c) 2013 Terence Parr
|
||||
* Copyright (c) 2013 Dan McLaughlin
|
||||
* 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. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
||||
*/
|
||||
|
||||
namespace org {
|
||||
namespace antlr {
|
||||
namespace v4 {
|
||||
namespace runtime {
|
||||
|
||||
/// <summary>
|
||||
/// A source of characters for an ANTLR lexer. </summary>
|
||||
class CharStream : public IntStream {
|
||||
/// <summary>
|
||||
/// This method returns the text for a range of characters within this input
|
||||
/// stream. This method is guaranteed to not throw an exception if the
|
||||
/// specified {@code interval} lies entirely within a marked range. For more
|
||||
/// information about marked ranges, see <seealso cref="IntStream#mark"/>.
|
||||
/// </summary>
|
||||
/// <param name="interval"> an interval within the stream </param>
|
||||
/// <returns> the text of the specified interval
|
||||
/// </returns>
|
||||
/// <exception cref="NullPointerException"> if {@code interval} is {@code null} </exception>
|
||||
/// <exception cref="IllegalArgumentException"> if {@code interval.a < 0}, or if
|
||||
/// {@code interval.b < interval.a - 1}, or if {@code interval.b} lies at or
|
||||
/// past the end of the stream </exception>
|
||||
/// <exception cref="UnsupportedOperationException"> if the stream does not support
|
||||
/// getting the text of the specified interval </exception>
|
||||
public:
|
||||
virtual std::wstring getText(misc::Interval *interval) = 0;
|
||||
|
||||
virtual ~CharStream() = 0;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,204 @@
|
|||
#include "CommonToken.h"
|
||||
#include "Interval.h"
|
||||
#include "TokenSource.h"
|
||||
|
||||
#include "Strings.h"
|
||||
|
||||
/*
|
||||
* [The "BSD license"]
|
||||
* Copyright (c) 2013 Terence Parr
|
||||
* Copyright (c) 2013 Dan McLaughlin
|
||||
* 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. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
||||
*/
|
||||
|
||||
namespace org {
|
||||
namespace antlr {
|
||||
namespace v4 {
|
||||
namespace runtime {
|
||||
|
||||
std::pair<TokenSource*, CharStream*> *const CommonToken::EMPTY_SOURCE = new std::pair<TokenSource*, CharStream*>(nullptr, nullptr);
|
||||
|
||||
CommonToken::CommonToken(int type) {
|
||||
InitializeInstanceFields();
|
||||
this->type = type;
|
||||
}
|
||||
|
||||
CommonToken::CommonToken(std::pair<TokenSource*, CharStream*> *source, int type, int channel, int start, int stop) {
|
||||
InitializeInstanceFields();
|
||||
this->source = source;
|
||||
this->type = type;
|
||||
this->channel = channel;
|
||||
this->start = start;
|
||||
this->stop = stop;
|
||||
if (source->first != nullptr) {
|
||||
this->line = source->first->getLine();
|
||||
this->charPositionInLine = source->first->getCharPositionInLine();
|
||||
}
|
||||
}
|
||||
|
||||
CommonToken::CommonToken(int type, const std::wstring &text) {
|
||||
InitializeInstanceFields();
|
||||
this->type = type;
|
||||
this->channel = DEFAULT_CHANNEL;
|
||||
this->text = text;
|
||||
this->source = EMPTY_SOURCE;
|
||||
}
|
||||
|
||||
CommonToken::CommonToken(Token *oldToken) {
|
||||
InitializeInstanceFields();
|
||||
text = oldToken->getText();
|
||||
type = oldToken->getType();
|
||||
line = oldToken->getLine();
|
||||
index = oldToken->getTokenIndex();
|
||||
charPositionInLine = oldToken->getCharPositionInLine();
|
||||
channel = oldToken->getChannel();
|
||||
start = oldToken->getStartIndex();
|
||||
stop = oldToken->getStopIndex();
|
||||
|
||||
if (dynamic_cast<CommonToken*>(oldToken) != nullptr) {
|
||||
source = (static_cast<CommonToken*>(oldToken))->source;
|
||||
} else {
|
||||
source = new std::pair<TokenSource*, CharStream*>(oldToken->getTokenSource(), oldToken->getInputStream());
|
||||
}
|
||||
}
|
||||
|
||||
int CommonToken::getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
void CommonToken::setLine(int line) {
|
||||
this->line = line;
|
||||
}
|
||||
|
||||
std::wstring CommonToken::getText() {
|
||||
if (text != L"") {
|
||||
return text;
|
||||
}
|
||||
|
||||
CharStream *input = getInputStream();
|
||||
if (input == nullptr) {
|
||||
return L"";
|
||||
}
|
||||
size_t n = input->size();
|
||||
if ((size_t)start < n && (size_t)stop < n) {
|
||||
return input->getText(misc::Interval::of(start,stop));
|
||||
} else {
|
||||
return L"<EOF>";
|
||||
}
|
||||
}
|
||||
|
||||
void CommonToken::setText(const std::wstring &text) {
|
||||
this->text = text;
|
||||
}
|
||||
|
||||
int CommonToken::getLine() {
|
||||
return line;
|
||||
}
|
||||
|
||||
int CommonToken::getCharPositionInLine() {
|
||||
return charPositionInLine;
|
||||
}
|
||||
|
||||
void CommonToken::setCharPositionInLine(int charPositionInLine) {
|
||||
this->charPositionInLine = charPositionInLine;
|
||||
}
|
||||
|
||||
int CommonToken::getChannel() {
|
||||
return channel;
|
||||
}
|
||||
|
||||
void CommonToken::setChannel(int channel) {
|
||||
this->channel = channel;
|
||||
}
|
||||
|
||||
void CommonToken::setType(int type) {
|
||||
this->type = type;
|
||||
}
|
||||
|
||||
int CommonToken::getStartIndex() {
|
||||
return start;
|
||||
}
|
||||
|
||||
void CommonToken::setStartIndex(int start) {
|
||||
this->start = start;
|
||||
}
|
||||
|
||||
int CommonToken::getStopIndex() {
|
||||
return stop;
|
||||
}
|
||||
|
||||
void CommonToken::setStopIndex(int stop) {
|
||||
this->stop = stop;
|
||||
}
|
||||
|
||||
int CommonToken::getTokenIndex() {
|
||||
return index;
|
||||
}
|
||||
|
||||
void CommonToken::setTokenIndex(int index) {
|
||||
this->index = index;
|
||||
}
|
||||
|
||||
org::antlr::v4::runtime::TokenSource *CommonToken::getTokenSource() {
|
||||
return source->first;
|
||||
}
|
||||
|
||||
org::antlr::v4::runtime::CharStream *CommonToken::getInputStream() {
|
||||
return source->second;
|
||||
}
|
||||
|
||||
std::wstring CommonToken::toString() {
|
||||
std::wstring channelStr = L"";
|
||||
if (channel > 0) {
|
||||
channelStr = std::wstring(L",channel=") + std::to_wstring(channel);
|
||||
}
|
||||
std::wstring txt = getText();
|
||||
if (txt != L"") {
|
||||
|
||||
antlrcpp::replaceAll(txt, L"\n",L"\\n");
|
||||
|
||||
antlrcpp::replaceAll(txt, L"\r",L"\\r");
|
||||
|
||||
antlrcpp::replaceAll(txt, L"\t",L"\\t");
|
||||
} else {
|
||||
txt = L"<no text>";
|
||||
}
|
||||
return std::wstring(L"[@") + std::to_wstring(getTokenIndex()) + std::wstring(L",") + std::to_wstring(start) + std::wstring(L":") + std::to_wstring(stop) + std::wstring(L"='") + txt + std::wstring(L"',<") + std::to_wstring(type) + std::wstring(L">") + channelStr + std::wstring(L",") + std::to_wstring(line) + std::wstring(L":") + std::to_wstring(getCharPositionInLine()) + std::wstring(L"]");
|
||||
}
|
||||
|
||||
void CommonToken::InitializeInstanceFields() {
|
||||
type = 0;
|
||||
line = 0;
|
||||
charPositionInLine = -1;
|
||||
channel = DEFAULT_CHANNEL;
|
||||
index = -1;
|
||||
start = 0;
|
||||
stop = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,136 @@
|
|||
#pragma once
|
||||
|
||||
#include "WritableToken.h"
|
||||
#include "CharStream.h"
|
||||
#include "Declarations.h"
|
||||
|
||||
#include <string>
|
||||
#include <utility>
|
||||
|
||||
/*
|
||||
* [The "BSD license"]
|
||||
* Copyright (c) 2013 Terence Parr
|
||||
* Copyright (c) 2013 Dan McLaughlin
|
||||
* 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. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
||||
*/
|
||||
|
||||
namespace org {
|
||||
namespace antlr {
|
||||
namespace v4 {
|
||||
namespace runtime {
|
||||
|
||||
|
||||
class CommonToken : public WritableToken {
|
||||
protected:
|
||||
static std::pair<TokenSource*, CharStream*> *const EMPTY_SOURCE;
|
||||
|
||||
int type;
|
||||
int line;
|
||||
int charPositionInLine; // set to invalid position
|
||||
int channel;
|
||||
std::pair<TokenSource*, CharStream*> *source;
|
||||
|
||||
/// <summary>
|
||||
/// We need to be able to change the text once in a while. If
|
||||
/// this is non-null, then getText should return this. Note that
|
||||
/// start/stop are not affected by changing this.
|
||||
/// </summary>
|
||||
// TODO: can store these in map in token stream rather than as field here
|
||||
std::wstring text;
|
||||
|
||||
/// <summary>
|
||||
/// What token number is this from 0..n-1 tokens; < 0 implies invalid index </summary>
|
||||
int index;
|
||||
|
||||
/// <summary>
|
||||
/// The char position into the input buffer where this token starts </summary>
|
||||
int start;
|
||||
|
||||
/// <summary>
|
||||
/// The char position into the input buffer where this token stops </summary>
|
||||
int stop;
|
||||
|
||||
public:
|
||||
CommonToken(int type);
|
||||
|
||||
CommonToken(std::pair<TokenSource*, CharStream*> *source, int type, int channel, int start, int stop);
|
||||
|
||||
CommonToken(int type, const std::wstring &text);
|
||||
|
||||
CommonToken(Token *oldToken);
|
||||
|
||||
virtual int getType() override;
|
||||
|
||||
virtual void setLine(int line) override;
|
||||
|
||||
virtual std::wstring getText() override;
|
||||
|
||||
/// <summary>
|
||||
/// Override the text for this token. getText() will return this text
|
||||
/// rather than pulling from the buffer. Note that this does not mean
|
||||
/// that start/stop indexes are not valid. It means that that input
|
||||
/// was converted to a new string in the token object.
|
||||
/// </summary>
|
||||
virtual void setText(const std::wstring &text) override;
|
||||
|
||||
virtual int getLine() override;
|
||||
|
||||
virtual int getCharPositionInLine() override;
|
||||
|
||||
virtual void setCharPositionInLine(int charPositionInLine) override;
|
||||
|
||||
virtual int getChannel() override;
|
||||
|
||||
virtual void setChannel(int channel) override;
|
||||
|
||||
virtual void setType(int type) override;
|
||||
|
||||
virtual int getStartIndex() override;
|
||||
|
||||
virtual void setStartIndex(int start);
|
||||
|
||||
virtual int getStopIndex() override;
|
||||
|
||||
virtual void setStopIndex(int stop);
|
||||
|
||||
virtual int getTokenIndex() override;
|
||||
|
||||
virtual void setTokenIndex(int index) override;
|
||||
|
||||
virtual TokenSource *getTokenSource() override;
|
||||
|
||||
virtual CharStream *getInputStream() override;
|
||||
|
||||
virtual std::wstring toString() ;
|
||||
|
||||
private:
|
||||
void InitializeInstanceFields();
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,65 @@
|
|||
#include "CommonTokenFactory.h"
|
||||
#include "Interval.h"
|
||||
|
||||
/*
|
||||
* [The "BSD license"]
|
||||
* Copyright (c) 2013 Terence Parr
|
||||
* Copyright (c) 2013 Dan McLaughlin
|
||||
* 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. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
||||
*/
|
||||
|
||||
namespace org {
|
||||
namespace antlr {
|
||||
namespace v4 {
|
||||
namespace runtime {
|
||||
TokenFactory<CommonToken*> *const CommonTokenFactory::DEFAULT = new CommonTokenFactory();
|
||||
|
||||
CommonTokenFactory::CommonTokenFactory(bool copyText) : copyText(copyText) {
|
||||
}
|
||||
|
||||
CommonTokenFactory::CommonTokenFactory() : CommonTokenFactory(false) {
|
||||
}
|
||||
|
||||
CommonToken *CommonTokenFactory::create(std::pair<TokenSource*, CharStream*> *source, int type, const std::wstring &text, int channel, int start, int stop, int line, int charPositionInLine) {
|
||||
CommonToken *t = new CommonToken(source, type, channel, start, stop);
|
||||
t->setLine(line);
|
||||
t->setCharPositionInLine(charPositionInLine);
|
||||
if (text != L"") {
|
||||
t->setText(text);
|
||||
} else if (copyText && source->second != nullptr) {
|
||||
t->setText(source->second->getText(misc::Interval::of(start,stop)));
|
||||
}
|
||||
|
||||
return t;
|
||||
}
|
||||
|
||||
org::antlr::v4::runtime::CommonToken *CommonTokenFactory::create(int type, const std::wstring &text) {
|
||||
return new CommonToken(type, text);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,75 @@
|
|||
#pragma once
|
||||
|
||||
#include "CommonToken.h"
|
||||
#include "TokenFactory.h"
|
||||
#include "CharStream.h"
|
||||
#include "TokenSource.h"
|
||||
|
||||
#include <string>
|
||||
#include <utility>
|
||||
|
||||
|
||||
/*
|
||||
* [The "BSD license"]
|
||||
* Copyright (c) 2013 Terence Parr
|
||||
* Copyright (c) 2013 Dan McLaughlin
|
||||
* 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. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
||||
*/
|
||||
|
||||
namespace org {
|
||||
namespace antlr {
|
||||
namespace v4 {
|
||||
namespace runtime {
|
||||
|
||||
class CommonTokenFactory : public TokenFactory<CommonToken*> {
|
||||
public:
|
||||
static TokenFactory<CommonToken*> *const DEFAULT;
|
||||
|
||||
/// <summary>
|
||||
/// Copy text for token out of input char stream. Useful when input
|
||||
/// stream is unbuffered. </summary>
|
||||
/// <seealso cref= UnbufferedCharStream </seealso>
|
||||
protected:
|
||||
const bool copyText;
|
||||
|
||||
/// <summary>
|
||||
/// Create factory and indicate whether or not the factory copy
|
||||
/// text out of the char stream.
|
||||
/// </summary>
|
||||
public:
|
||||
CommonTokenFactory(bool copyText);
|
||||
|
||||
CommonTokenFactory();
|
||||
|
||||
virtual CommonToken *create(std::pair<TokenSource*, CharStream*> *source, int type, const std::wstring &text, int channel, int start, int stop, int line, int charPositionInLine) override;
|
||||
|
||||
virtual CommonToken *create(int type, const std::wstring &text) override;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,115 @@
|
|||
#include "CommonTokenStream.h"
|
||||
|
||||
/*
|
||||
* [The "BSD license"]
|
||||
* Copyright (c) 2013 Terence Parr
|
||||
* Copyright (c) 2013 Dan McLaughlin
|
||||
* 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. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
||||
*/
|
||||
|
||||
namespace org {
|
||||
namespace antlr {
|
||||
namespace v4 {
|
||||
namespace runtime {
|
||||
|
||||
CommonTokenStream::CommonTokenStream(TokenSource *tokenSource) : BufferedTokenStream(tokenSource) {
|
||||
InitializeInstanceFields();
|
||||
}
|
||||
|
||||
CommonTokenStream::CommonTokenStream(TokenSource *tokenSource, int channel)
|
||||
: BufferedTokenStream(tokenSource)
|
||||
{
|
||||
this->channel = channel;
|
||||
}
|
||||
|
||||
int CommonTokenStream::adjustSeekIndex(int i) {
|
||||
return nextTokenOnChannel(i, channel);
|
||||
}
|
||||
|
||||
Token *CommonTokenStream::LB(int k) {
|
||||
if (k == 0 || (p - k) < 0) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
int i = p;
|
||||
int n = 1;
|
||||
// find k good tokens looking backwards
|
||||
while (n <= k) {
|
||||
// skip off-channel tokens
|
||||
i = previousTokenOnChannel(i - 1, channel);
|
||||
n++;
|
||||
}
|
||||
if (i < 0) {
|
||||
return nullptr;
|
||||
}
|
||||
return tokens[i];
|
||||
}
|
||||
|
||||
Token *CommonTokenStream::LT(int k) {
|
||||
//System.out.println("enter LT("+k+")");
|
||||
lazyInit();
|
||||
if (k == 0) {
|
||||
return nullptr;
|
||||
}
|
||||
if (k < 0) {
|
||||
return LB(-k);
|
||||
}
|
||||
int i = p;
|
||||
int n = 1; // we know tokens[p] is a good one
|
||||
// find k good tokens
|
||||
while (n < k) {
|
||||
// skip off-channel tokens, but make sure to not look past EOF
|
||||
if (sync(i + 1)) {
|
||||
i = nextTokenOnChannel(i + 1, channel);
|
||||
}
|
||||
n++;
|
||||
}
|
||||
// if ( i>range ) range = i;
|
||||
return tokens[i];
|
||||
}
|
||||
|
||||
int CommonTokenStream::getNumberOfOnChannelTokens() {
|
||||
int n = 0;
|
||||
fill();
|
||||
for (size_t i = 0; i < tokens.size(); i++) {
|
||||
Token *t = tokens[i];
|
||||
if (t->getChannel() == channel) {
|
||||
n++;
|
||||
}
|
||||
if (t->getType() == Token::_EOF) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return n;
|
||||
}
|
||||
|
||||
void CommonTokenStream::InitializeInstanceFields() {
|
||||
channel = Token::DEFAULT_CHANNEL;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,89 @@
|
|||
#pragma once
|
||||
|
||||
#include "BufferedTokenStream.h"
|
||||
#include "TokenSource.h"
|
||||
#include "Token.h"
|
||||
|
||||
/*
|
||||
* [The "BSD license"]
|
||||
* Copyright (c) 2013 Terence Parr
|
||||
* Copyright (c) 2013 Dan McLaughlin
|
||||
* 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. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
||||
*/
|
||||
|
||||
namespace org {
|
||||
namespace antlr {
|
||||
namespace v4 {
|
||||
namespace runtime {
|
||||
|
||||
/// <summary>
|
||||
/// The most common stream of tokens where every token is buffered up
|
||||
/// and tokens are filtered for a certain channel (the parser will only
|
||||
/// see these tokens).
|
||||
///
|
||||
/// Even though it buffers all of the tokens, this token stream pulls tokens
|
||||
/// from the tokens source on demand. In other words, until you ask for a
|
||||
/// token using consume(), LT(), etc. the stream does not pull from the lexer.
|
||||
///
|
||||
/// The only difference between this stream and <seealso cref="BufferedTokenStream"/> superclass
|
||||
/// is that this stream knows how to ignore off channel tokens. There may be
|
||||
/// a performance advantage to using the superclass if you don't pass
|
||||
/// whitespace and comments etc. to the parser on a hidden channel (i.e.,
|
||||
/// you set {@code $channel} instead of calling {@code skip()} in lexer rules.)
|
||||
/// </summary>
|
||||
/// <seealso cref= UnbufferedTokenStream </seealso>
|
||||
/// <seealso cref= BufferedTokenStream </seealso>
|
||||
class CommonTokenStream : public BufferedTokenStream {
|
||||
/// <summary>
|
||||
/// Skip tokens on any channel but this one; this is how we skip whitespace... </summary>
|
||||
protected:
|
||||
int channel;
|
||||
|
||||
public:
|
||||
CommonTokenStream(TokenSource *tokenSource);
|
||||
|
||||
CommonTokenStream(TokenSource *tokenSource, int channel);
|
||||
|
||||
protected:
|
||||
virtual int adjustSeekIndex(int i) override;
|
||||
|
||||
virtual Token *LB(int k) override;
|
||||
|
||||
public:
|
||||
virtual Token *LT(int k) override;
|
||||
|
||||
/// <summary>
|
||||
/// Count EOF just once. </summary>
|
||||
virtual int getNumberOfOnChannelTokens();
|
||||
|
||||
private:
|
||||
void InitializeInstanceFields();
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,43 @@
|
|||
#include "ConsoleErrorListener.h"
|
||||
|
||||
/*
|
||||
* [The "BSD license"]
|
||||
* Copyright (c) 2013 Terence Parr
|
||||
* Copyright (c) 2013 Dan McLaughlin
|
||||
* 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. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
||||
*/
|
||||
|
||||
namespace org {
|
||||
namespace antlr {
|
||||
namespace v4 {
|
||||
namespace runtime {
|
||||
|
||||
ConsoleErrorListener *const ConsoleErrorListener::INSTANCE = new ConsoleErrorListener();
|
||||
|
||||
} // namespace runtime
|
||||
} // namespace v4
|
||||
} // namespace antlr
|
||||
} // namespace org
|
|
@ -0,0 +1,63 @@
|
|||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "BaseErrorListener.h"
|
||||
#include "RecognitionException.h"
|
||||
#include "IRecognizer.h"
|
||||
|
||||
/*
|
||||
* [The "BSD license"]
|
||||
* Copyright (c) 2013 Terence Parr
|
||||
* Copyright (c) 2013 Dan McLaughlin
|
||||
* 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. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
||||
*/
|
||||
|
||||
namespace org {
|
||||
namespace antlr {
|
||||
namespace v4 {
|
||||
namespace runtime {
|
||||
|
||||
///
|
||||
/// <summary>
|
||||
/// @author Sam Harwell
|
||||
/// </summary>
|
||||
class ConsoleErrorListener : public BaseErrorListener {
|
||||
public:
|
||||
static ConsoleErrorListener *const INSTANCE;
|
||||
|
||||
template <typename T1, typename T2>
|
||||
void syntaxError(IRecognizer<T1, T2> *recognizer, void *offendingSymbol,
|
||||
int line, int charPositionInLine, const std::wstring &msg,
|
||||
RecognitionException *e) {
|
||||
std::wcerr << L"line " << line << L":" << charPositionInLine << L" " << msg;
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace runtime
|
||||
} // namespace v4
|
||||
} // namespace antlr
|
||||
} // namespace org
|
|
@ -0,0 +1,378 @@
|
|||
#include <locale>
|
||||
#include <codecvt>
|
||||
#include <string>
|
||||
|
||||
#include "DefaultErrorStrategy.h"
|
||||
#include "NoViableAltException.h"
|
||||
#include "IntervalSet.h"
|
||||
#include "ParserATNSimulator.h"
|
||||
#include "InputMismatchException.h"
|
||||
#include "Exceptions.h"
|
||||
#include "ATN.h"
|
||||
#include "ATNState.h"
|
||||
#include "Transition.h"
|
||||
#include "Strings.h"
|
||||
#include "RuleTransition.h"
|
||||
#include "TokenSource.h"
|
||||
#include "FailedPredicateException.h"
|
||||
#include "ParserRuleContext.h"
|
||||
|
||||
|
||||
/*
|
||||
* [The "BSD license"]
|
||||
* Copyright (c) 2013 Terence Parr
|
||||
* Copyright (c) 2013 Dan McLaughlin
|
||||
* 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. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
||||
*/
|
||||
|
||||
namespace org {
|
||||
namespace antlr {
|
||||
namespace v4 {
|
||||
namespace runtime {
|
||||
|
||||
void DefaultErrorStrategy::reset(Parser *recognizer) {
|
||||
endErrorCondition(recognizer);
|
||||
}
|
||||
|
||||
void DefaultErrorStrategy::beginErrorCondition(Parser *recognizer) {
|
||||
errorRecoveryMode = true;
|
||||
}
|
||||
|
||||
bool DefaultErrorStrategy::inErrorRecoveryMode(Parser *recognizer) {
|
||||
return errorRecoveryMode;
|
||||
}
|
||||
|
||||
void DefaultErrorStrategy::endErrorCondition(Parser *recognizer) {
|
||||
errorRecoveryMode = false;
|
||||
delete lastErrorStates;
|
||||
lastErrorIndex = -1;
|
||||
}
|
||||
|
||||
void DefaultErrorStrategy::reportMatch(Parser *recognizer) {
|
||||
endErrorCondition(recognizer);
|
||||
}
|
||||
|
||||
void DefaultErrorStrategy::reportError(Parser *recognizer, RecognitionException *e) {
|
||||
// if we've already reported an error and have not matched a token
|
||||
// yet successfully, don't report any errors.
|
||||
if (inErrorRecoveryMode(recognizer)) {
|
||||
// System.err.print("[SPURIOUS] ");
|
||||
return; // don't report spurious errors
|
||||
}
|
||||
beginErrorCondition(recognizer);
|
||||
if (dynamic_cast<NoViableAltException*>(e) != nullptr) {
|
||||
reportNoViableAlternative(recognizer, static_cast<NoViableAltException*>(e));
|
||||
} else if (dynamic_cast<InputMismatchException*>(e) != nullptr) {
|
||||
reportInputMismatch(recognizer, static_cast<InputMismatchException*>(e));
|
||||
} else if (dynamic_cast<FailedPredicateException*>(e) != nullptr) {
|
||||
reportFailedPredicate(recognizer, dynamic_cast<FailedPredicateException*>(e));
|
||||
} else {
|
||||
|
||||
// This is really bush league, I hate libraries that gratuitiously print
|
||||
// stuff out
|
||||
std::wcerr << std::wstring(L"unknown recognition error type: " +
|
||||
antlrcpp::s2ws(typeid(e).name()));
|
||||
|
||||
recognizer->notifyErrorListeners(e->getOffendingToken(), antlrcpp::s2ws(e->what()), e);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void DefaultErrorStrategy::recover(Parser *recognizer, RecognitionException *e) {
|
||||
// System.out.println("recover in "+recognizer.getRuleInvocationStack()+
|
||||
// " index="+recognizer.getInputStream().index()+
|
||||
// ", lastErrorIndex="+
|
||||
// lastErrorIndex+
|
||||
// ", states="+lastErrorStates);
|
||||
if (lastErrorIndex == recognizer->getInputStream()->index() && lastErrorStates != nullptr && lastErrorStates->contains(recognizer->getState())) {
|
||||
// uh oh, another error at same token index and previously-visited
|
||||
// state in ATN; must be a case where LT(1) is in the recovery
|
||||
// token set so nothing got consumed. Consume a single token
|
||||
// at least to prevent an infinite loop; this is a failsafe.
|
||||
// System.err.println("seen error condition before index="+
|
||||
// lastErrorIndex+", states="+lastErrorStates);
|
||||
// System.err.println("FAILSAFE consumes "+recognizer.getTokenNames()[recognizer.getInputStream().LA(1)]);
|
||||
recognizer->consume();
|
||||
}
|
||||
lastErrorIndex = recognizer->getInputStream()->index();
|
||||
if (lastErrorStates == nullptr) {
|
||||
lastErrorStates = new misc::IntervalSet(0);
|
||||
}
|
||||
lastErrorStates->add(recognizer->getState());
|
||||
misc::IntervalSet *followSet = getErrorRecoverySet(recognizer);
|
||||
consumeUntil(recognizer, followSet);
|
||||
}
|
||||
|
||||
void DefaultErrorStrategy::sync(Parser *recognizer) {
|
||||
atn::ATNState *s = recognizer->getInterpreter()->atn->states[recognizer->getState()];
|
||||
// System.err.println("sync @ "+s.stateNumber+"="+s.getClass().getSimpleName());
|
||||
// If already recovering, don't try to sync
|
||||
if (inErrorRecoveryMode(recognizer)) {
|
||||
return;
|
||||
}
|
||||
|
||||
TokenStream *tokens = recognizer->getInputStream();
|
||||
int la = tokens->LA(1);
|
||||
|
||||
// try cheaper subset first; might get lucky. seems to shave a wee bit off
|
||||
if (recognizer->getATN()->nextTokens(s)->contains(la) || la == Token::_EOF) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Return but don't end recovery. only do that upon valid token match
|
||||
if (recognizer->isExpectedToken(la)) {
|
||||
return;
|
||||
}
|
||||
|
||||
switch (s->getStateType()) {
|
||||
case atn::ATNState::BLOCK_START:
|
||||
case atn::ATNState::STAR_BLOCK_START:
|
||||
case atn::ATNState::PLUS_BLOCK_START:
|
||||
case atn::ATNState::STAR_LOOP_ENTRY:
|
||||
// report error and recover if possible
|
||||
if (singleTokenDeletion(recognizer) != nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
throw new InputMismatchException(recognizer);
|
||||
|
||||
case atn::ATNState::PLUS_LOOP_BACK:
|
||||
case atn::ATNState::STAR_LOOP_BACK: {
|
||||
// System.err.println("at loop back: "+s.getClass().getSimpleName());
|
||||
reportUnwantedToken(recognizer);
|
||||
misc::IntervalSet *expecting = recognizer->getExpectedTokens();
|
||||
misc::IntervalSet *whatFollowsLoopIterationOrRule = expecting->Or(getErrorRecoverySet(recognizer));
|
||||
consumeUntil(recognizer, whatFollowsLoopIterationOrRule);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
// do nothing if we can't identify the exact kind of ATN state
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void DefaultErrorStrategy::reportNoViableAlternative(Parser *recognizer, NoViableAltException *e) {
|
||||
TokenStream *tokens = recognizer->getInputStream();
|
||||
std::wstring input;
|
||||
if (tokens != nullptr) {
|
||||
if (e->getStartToken()->getType() == Token::_EOF) {
|
||||
input = L"<EOF>";
|
||||
} else {
|
||||
input = tokens->getText(e->getStartToken(), e->getOffendingToken());
|
||||
}
|
||||
} else {
|
||||
input = L"<unknown input>";
|
||||
}
|
||||
std::wstring msg = std::wstring(L"no viable alternative at input ") + escapeWSAndQuote(input);
|
||||
recognizer->notifyErrorListeners(e->getOffendingToken(), msg, e);
|
||||
}
|
||||
|
||||
void DefaultErrorStrategy::reportInputMismatch(Parser *recognizer, InputMismatchException *e) {
|
||||
std::wstring msg = std::wstring(L"mismatched input ") + getTokenErrorDisplay(e->getOffendingToken()) + std::wstring(L" expecting ") + e->getExpectedTokens()->toString(recognizer->getTokenNames());
|
||||
recognizer->notifyErrorListeners(e->getOffendingToken(), msg, e);
|
||||
}
|
||||
|
||||
void DefaultErrorStrategy::reportFailedPredicate(Parser *recognizer, FailedPredicateException *e) {
|
||||
const std::wstring& ruleName = recognizer->getRuleNames()[recognizer->_ctx->getRuleIndex()];
|
||||
std::wstring msg = std::wstring(L"rule ") + ruleName + std::wstring(L" ") + e->getMessage();
|
||||
recognizer->notifyErrorListeners(e->getOffendingToken(), msg, e);
|
||||
}
|
||||
|
||||
void DefaultErrorStrategy::reportUnwantedToken(Parser *recognizer) {
|
||||
if (inErrorRecoveryMode(recognizer)) {
|
||||
return;
|
||||
}
|
||||
|
||||
beginErrorCondition(recognizer);
|
||||
|
||||
Token *t = recognizer->getCurrentToken();
|
||||
std::wstring tokenName = getTokenErrorDisplay(t);
|
||||
misc::IntervalSet *expecting = getExpectedTokens(recognizer);
|
||||
|
||||
std::wstring msg = std::wstring(L"extraneous input ") + tokenName + std::wstring(L" expecting ") + expecting->toString(recognizer->getTokenNames());
|
||||
recognizer->notifyErrorListeners(t, msg, nullptr);
|
||||
}
|
||||
|
||||
void DefaultErrorStrategy::reportMissingToken(Parser *recognizer) {
|
||||
if (inErrorRecoveryMode(recognizer)) {
|
||||
return;
|
||||
}
|
||||
|
||||
beginErrorCondition(recognizer);
|
||||
|
||||
Token *t = recognizer->getCurrentToken();
|
||||
misc::IntervalSet *expecting = getExpectedTokens(recognizer);
|
||||
std::wstring msg = std::wstring(L"missing ") + expecting->toString(recognizer->getTokenNames()) + std::wstring(L" at ") + getTokenErrorDisplay(t);
|
||||
|
||||
recognizer->notifyErrorListeners(t, msg, nullptr);
|
||||
}
|
||||
|
||||
Token *DefaultErrorStrategy::recoverInline(Parser *recognizer) {
|
||||
// SINGLE TOKEN DELETION
|
||||
Token *matchedSymbol = singleTokenDeletion(recognizer);
|
||||
if (matchedSymbol != nullptr) {
|
||||
// we have deleted the extra token.
|
||||
// now, move past ttype token as if all were ok
|
||||
recognizer->consume();
|
||||
return matchedSymbol;
|
||||
}
|
||||
|
||||
// SINGLE TOKEN INSERTION
|
||||
if (singleTokenInsertion(recognizer)) {
|
||||
return getMissingSymbol(recognizer);
|
||||
}
|
||||
|
||||
// even that didn't work; must throw the exception
|
||||
throw InputMismatchException(recognizer);
|
||||
}
|
||||
|
||||
bool DefaultErrorStrategy::singleTokenInsertion(Parser *recognizer) {
|
||||
int currentSymbolType = recognizer->getInputStream()->LA(1);
|
||||
// if current token is consistent with what could come after current
|
||||
// ATN state, then we know we're missing a token; error recovery
|
||||
// is free to conjure up and insert the missing token
|
||||
atn::ATNState *currentState = recognizer->getInterpreter()->atn->states[recognizer->getState()];
|
||||
atn::ATNState *next = currentState->transition(0)->target;
|
||||
atn::ATN *atn = recognizer->getInterpreter()->atn;
|
||||
misc::IntervalSet *expectingAtLL2 = atn->nextTokens(next, recognizer->_ctx);
|
||||
// System.out.println("LT(2) set="+expectingAtLL2.toString(recognizer.getTokenNames()));
|
||||
if (expectingAtLL2->contains(currentSymbolType)) {
|
||||
reportMissingToken(recognizer);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
Token *DefaultErrorStrategy::singleTokenDeletion(Parser *recognizer) {
|
||||
int nextTokenType = recognizer->getInputStream()->LA(2);
|
||||
misc::IntervalSet *expecting = getExpectedTokens(recognizer);
|
||||
if (expecting->contains(nextTokenType)) {
|
||||
reportUnwantedToken(recognizer);
|
||||
/*
|
||||
System.err.println("recoverFromMismatchedToken deleting "+
|
||||
((TokenStream)recognizer.getInputStream()).LT(1)+
|
||||
" since "+((TokenStream)recognizer.getInputStream()).LT(2)+
|
||||
" is what we want");
|
||||
*/
|
||||
recognizer->consume(); // simply delete extra token
|
||||
// we want to return the token we're actually matching
|
||||
Token *matchedSymbol = recognizer->getCurrentToken();
|
||||
reportMatch(recognizer); // we know current token is correct
|
||||
return matchedSymbol;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Token *DefaultErrorStrategy::getMissingSymbol(Parser *recognizer) {
|
||||
Token *currentSymbol = recognizer->getCurrentToken();
|
||||
misc::IntervalSet *expecting = getExpectedTokens(recognizer);
|
||||
int expectedTokenType = expecting->getMinElement(); // get any element
|
||||
std::wstring tokenText;
|
||||
if (expectedTokenType == Token::_EOF) {
|
||||
tokenText = L"<missing EOF>";
|
||||
} else {
|
||||
tokenText = std::wstring(L"<missing ") + recognizer->getTokenNames()[expectedTokenType].at(expectedTokenType) + std::wstring(L">");
|
||||
}
|
||||
Token *current = currentSymbol;
|
||||
Token *lookback = recognizer->getInputStream()->LT(-1);
|
||||
if (current->getType() == Token::_EOF && lookback != nullptr) {
|
||||
current = lookback;
|
||||
}
|
||||
return (Token*)recognizer->getTokenFactory()->create(new std::pair<TokenSource*, CharStream*>(current->getTokenSource(), current->getTokenSource()->getInputStream()), expectedTokenType, tokenText, Token::DEFAULT_CHANNEL, -1, -1, current->getLine(), current->getCharPositionInLine());
|
||||
}
|
||||
|
||||
misc::IntervalSet *DefaultErrorStrategy::getExpectedTokens(Parser *recognizer) {
|
||||
return recognizer->getExpectedTokens();
|
||||
}
|
||||
|
||||
std::wstring DefaultErrorStrategy::getTokenErrorDisplay(Token *t) {
|
||||
if (t == nullptr) {
|
||||
return L"<no token>";
|
||||
}
|
||||
std::wstring s = getSymbolText(t);
|
||||
if (s == L"") {
|
||||
if (getSymbolType(t) == Token::_EOF) {
|
||||
s = L"<EOF>";
|
||||
} else {
|
||||
s = std::wstring(L"<") + std::to_wstring(getSymbolType(t)) + std::wstring(L">");
|
||||
}
|
||||
}
|
||||
return escapeWSAndQuote(s);
|
||||
}
|
||||
|
||||
std::wstring DefaultErrorStrategy::getSymbolText(Token *symbol) {
|
||||
return symbol->getText();
|
||||
}
|
||||
|
||||
int DefaultErrorStrategy::getSymbolType(Token *symbol) {
|
||||
return symbol->getType();
|
||||
}
|
||||
|
||||
std::wstring DefaultErrorStrategy::escapeWSAndQuote(std::wstring &s) {
|
||||
// if ( s==null ) return s;
|
||||
antlrcpp::replaceAll(s, L"\n", L"\\n");
|
||||
antlrcpp::replaceAll(s, L"\r",L"\\r");
|
||||
antlrcpp::replaceAll(s, L"\t",L"\\t");
|
||||
return std::wstring(L"'") + s + std::wstring(L"'");
|
||||
}
|
||||
|
||||
misc::IntervalSet *DefaultErrorStrategy::getErrorRecoverySet(Parser *recognizer) {
|
||||
atn::ATN *atn = recognizer->getInterpreter()->atn;
|
||||
RuleContext *ctx = recognizer->_ctx;
|
||||
misc::IntervalSet *recoverSet = new misc::IntervalSet(0);
|
||||
while (ctx != nullptr && ctx->invokingState >= 0) {
|
||||
// compute what follows who invoked us
|
||||
atn::ATNState *invokingState = atn->states[ctx->invokingState];
|
||||
atn::RuleTransition *rt = dynamic_cast<atn::RuleTransition*>(invokingState->transition(0));
|
||||
misc::IntervalSet *follow = atn->nextTokens(rt->followState);
|
||||
recoverSet->addAll(follow);
|
||||
ctx = ctx->parent;
|
||||
}
|
||||
recoverSet->remove(Token::EPSILON);
|
||||
// System.out.println("recover set "+recoverSet.toString(recognizer.getTokenNames()));
|
||||
return recoverSet;
|
||||
}
|
||||
|
||||
void DefaultErrorStrategy::consumeUntil(Parser *recognizer, misc::IntervalSet *set) {
|
||||
// System.err.println("consumeUntil("+set.toString(recognizer.getTokenNames())+")");
|
||||
int ttype = recognizer->getInputStream()->LA(1);
|
||||
while (ttype != Token::_EOF && !set->contains(ttype)) {
|
||||
//System.out.println("consume during recover LA(1)="+getTokenNames()[input.LA(1)]);
|
||||
// recognizer.getInputStream().consume();
|
||||
recognizer->consume();
|
||||
ttype = recognizer->getInputStream()->LA(1);
|
||||
}
|
||||
}
|
||||
|
||||
void DefaultErrorStrategy::InitializeInstanceFields() {
|
||||
errorRecoveryMode = false;
|
||||
lastErrorIndex = -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,496 @@
|
|||
#pragma once
|
||||
|
||||
#include "ANTLRErrorStrategy.h"
|
||||
#include "Declarations.h"
|
||||
|
||||
#include <string>
|
||||
/*
|
||||
* [The "BSD license"]
|
||||
* Copyright (c) 2013 Terence Parr
|
||||
* Copyright (c) 2013 Dan McLaughlin
|
||||
* 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. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
||||
*/
|
||||
|
||||
namespace org {
|
||||
namespace antlr {
|
||||
namespace v4 {
|
||||
namespace runtime {
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// This is the default error handling mechanism for ANTLR parsers
|
||||
/// and tree parsers.
|
||||
/// </summary>
|
||||
class DefaultErrorStrategy : public ANTLRErrorStrategy {
|
||||
/// <summary>
|
||||
/// This is true after we see an error and before having successfully
|
||||
/// matched a token. Prevents generation of more than one error message
|
||||
/// per error.
|
||||
/// </summary>
|
||||
/// <seealso cref= #inErrorRecoveryMode </seealso>
|
||||
protected:
|
||||
bool errorRecoveryMode;
|
||||
|
||||
/// <summary>
|
||||
/// The index into the input stream where the last error occurred.
|
||||
/// This is used to prevent infinite loops where an error is found
|
||||
/// but no token is consumed during recovery...another error is found,
|
||||
/// ad nauseum. This is a failsafe mechanism to guarantee that at least
|
||||
/// one token/tree node is consumed for two errors.
|
||||
/// </summary>
|
||||
int lastErrorIndex;
|
||||
|
||||
misc::IntervalSet *lastErrorStates;
|
||||
|
||||
/// <summary>
|
||||
/// {@inheritDoc}
|
||||
/// <p/>
|
||||
/// The default implementation simply calls <seealso cref="#endErrorCondition"/> to
|
||||
/// ensure that the handler is not in error recovery mode.
|
||||
/// </summary>
|
||||
public:
|
||||
virtual void reset(Parser *recognizer) override;
|
||||
|
||||
/// <summary>
|
||||
/// This method is called to enter error recovery mode when a recognition
|
||||
/// exception is reported.
|
||||
/// </summary>
|
||||
/// <param name="recognizer"> the parser instance </param>
|
||||
protected:
|
||||
virtual void beginErrorCondition(Parser *recognizer);
|
||||
|
||||
/// <summary>
|
||||
/// {@inheritDoc}
|
||||
/// </summary>
|
||||
public:
|
||||
virtual bool inErrorRecoveryMode(Parser *recognizer) override;
|
||||
|
||||
/// <summary>
|
||||
/// This method is called to leave error recovery mode after recovering from
|
||||
/// a recognition exception.
|
||||
/// </summary>
|
||||
/// <param name="recognizer"> </param>
|
||||
protected:
|
||||
virtual void endErrorCondition(Parser *recognizer);
|
||||
|
||||
/// <summary>
|
||||
/// {@inheritDoc}
|
||||
/// <p/>
|
||||
/// The default implementation simply calls <seealso cref="#endErrorCondition"/>.
|
||||
/// </summary>
|
||||
public:
|
||||
virtual void reportMatch(Parser *recognizer) override;
|
||||
|
||||
/// <summary>
|
||||
/// {@inheritDoc}
|
||||
/// <p/>
|
||||
/// The default implementation returns immediately if the handler is already
|
||||
/// in error recovery mode. Otherwise, it calls <seealso cref="#beginErrorCondition"/>
|
||||
/// and dispatches the reporting task based on the runtime type of {@code e}
|
||||
/// according to the following table.
|
||||
///
|
||||
/// <ul>
|
||||
/// <li><seealso cref="NoViableAltException"/>: Dispatches the call to
|
||||
/// <seealso cref="#reportNoViableAlternative"/></li>
|
||||
/// <li><seealso cref="InputMismatchException"/>: Dispatches the call to
|
||||
/// <seealso cref="#reportInputMismatch"/></li>
|
||||
/// <li><seealso cref="FailedPredicateException"/>: Dispatches the call to
|
||||
/// <seealso cref="#reportFailedPredicate"/></li>
|
||||
/// <li>All other types: calls <seealso cref="Parser#notifyErrorListeners"/> to report
|
||||
/// the exception</li>
|
||||
/// </ul>
|
||||
/// </summary>
|
||||
virtual void reportError(Parser *recognizer, RecognitionException *e) override;
|
||||
|
||||
/// <summary>
|
||||
/// {@inheritDoc}
|
||||
/// <p/>
|
||||
/// The default implementation resynchronizes the parser by consuming tokens
|
||||
/// until we find one in the resynchronization set--loosely the set of tokens
|
||||
/// that can follow the current rule.
|
||||
/// </summary>
|
||||
virtual void recover(Parser *recognizer, RecognitionException *e) override;
|
||||
|
||||
/// <summary>
|
||||
/// The default implementation of <seealso cref="ANTLRErrorStrategy#sync"/> makes sure
|
||||
/// that the current lookahead symbol is consistent with what were expecting
|
||||
/// at this point in the ATN. You can call this anytime but ANTLR only
|
||||
/// generates code to check before subrules/loops and each iteration.
|
||||
/// <p/>
|
||||
/// Implements Jim Idle's magic sync mechanism in closures and optional
|
||||
/// subrules. E.g.,
|
||||
///
|
||||
/// <pre>
|
||||
/// a : sync ( stuff sync )* ;
|
||||
/// sync : {consume to what can follow sync} ;
|
||||
/// </pre>
|
||||
///
|
||||
/// At the start of a sub rule upon error, <seealso cref="#sync"/> performs single
|
||||
/// token deletion, if possible. If it can't do that, it bails on the current
|
||||
/// rule and uses the default error recovery, which consumes until the
|
||||
/// resynchronization set of the current rule.
|
||||
/// <p/>
|
||||
/// If the sub rule is optional ({@code (...)?}, {@code (...)*}, or block
|
||||
/// with an empty alternative), then the expected set includes what follows
|
||||
/// the subrule.
|
||||
/// <p/>
|
||||
/// During loop iteration, it consumes until it sees a token that can start a
|
||||
/// sub rule or what follows loop. Yes, that is pretty aggressive. We opt to
|
||||
/// stay in the loop as long as possible.
|
||||
/// <p/>
|
||||
/// <strong>ORIGINS</strong>
|
||||
/// <p/>
|
||||
/// Previous versions of ANTLR did a poor job of their recovery within loops.
|
||||
/// A single mismatch token or missing token would force the parser to bail
|
||||
/// out of the entire rules surrounding the loop. So, for rule
|
||||
///
|
||||
/// <pre>
|
||||
/// classDef : 'class' ID '{' member* '}'
|
||||
/// </pre>
|
||||
///
|
||||
/// input with an extra token between members would force the parser to
|
||||
/// consume until it found the next class definition rather than the next
|
||||
/// member definition of the current class.
|
||||
/// <p/>
|
||||
/// This functionality cost a little bit of effort because the parser has to
|
||||
/// compare token set at the start of the loop and at each iteration. If for
|
||||
/// some reason speed is suffering for you, you can turn off this
|
||||
/// functionality by simply overriding this method as a blank { }.
|
||||
/// </summary>
|
||||
virtual void sync(Parser *recognizer) override;
|
||||
|
||||
/// <summary>
|
||||
/// This is called by <seealso cref="#reportError"/> when the exception is a
|
||||
/// <seealso cref="NoViableAltException"/>.
|
||||
/// </summary>
|
||||
/// <seealso cref= #reportError
|
||||
/// </seealso>
|
||||
/// <param name="recognizer"> the parser instance </param>
|
||||
/// <param name="e"> the recognition exception </param>
|
||||
protected:
|
||||
virtual void reportNoViableAlternative(Parser *recognizer, NoViableAltException *e);
|
||||
|
||||
/// <summary>
|
||||
/// This is called by <seealso cref="#reportError"/> when the exception is an
|
||||
/// <seealso cref="InputMismatchException"/>.
|
||||
/// </summary>
|
||||
/// <seealso cref= #reportError
|
||||
/// </seealso>
|
||||
/// <param name="recognizer"> the parser instance </param>
|
||||
/// <param name="e"> the recognition exception </param>
|
||||
virtual void reportInputMismatch(Parser *recognizer, InputMismatchException *e);
|
||||
|
||||
/// <summary>
|
||||
/// This is called by <seealso cref="#reportError"/> when the exception is a
|
||||
/// <seealso cref="FailedPredicateException"/>.
|
||||
/// </summary>
|
||||
/// <seealso cref= #reportError
|
||||
/// </seealso>
|
||||
/// <param name="recognizer"> the parser instance </param>
|
||||
/// <param name="e"> the recognition exception </param>
|
||||
virtual void reportFailedPredicate(Parser *recognizer, FailedPredicateException *e);
|
||||
|
||||
/// <summary>
|
||||
/// This method is called to report a syntax error which requires the removal
|
||||
/// of a token from the input stream. At the time this method is called, the
|
||||
/// erroneous symbol is current {@code LT(1)} symbol and has not yet been
|
||||
/// removed from the input stream. When this method returns,
|
||||
/// {@code recognizer} is in error recovery mode.
|
||||
/// <p/>
|
||||
/// This method is called when <seealso cref="#singleTokenDeletion"/> identifies
|
||||
/// single-token deletion as a viable recovery strategy for a mismatched
|
||||
/// input error.
|
||||
/// <p/>
|
||||
/// The default implementation simply returns if the handler is already in
|
||||
/// error recovery mode. Otherwise, it calls <seealso cref="#beginErrorCondition"/> to
|
||||
/// enter error recovery mode, followed by calling
|
||||
/// <seealso cref="Parser#notifyErrorListeners"/>.
|
||||
/// </summary>
|
||||
/// <param name="recognizer"> the parser instance </param>
|
||||
virtual void reportUnwantedToken(Parser *recognizer);
|
||||
|
||||
/// <summary>
|
||||
/// This method is called to report a syntax error which requires the
|
||||
/// insertion of a missing token into the input stream. At the time this
|
||||
/// method is called, the missing token has not yet been inserted. When this
|
||||
/// method returns, {@code recognizer} is in error recovery mode.
|
||||
/// <p/>
|
||||
/// This method is called when <seealso cref="#singleTokenInsertion"/> identifies
|
||||
/// single-token insertion as a viable recovery strategy for a mismatched
|
||||
/// input error.
|
||||
/// <p/>
|
||||
/// The default implementation simply returns if the handler is already in
|
||||
/// error recovery mode. Otherwise, it calls <seealso cref="#beginErrorCondition"/> to
|
||||
/// enter error recovery mode, followed by calling
|
||||
/// <seealso cref="Parser#notifyErrorListeners"/>.
|
||||
/// </summary>
|
||||
/// <param name="recognizer"> the parser instance </param>
|
||||
virtual void reportMissingToken(Parser *recognizer);
|
||||
|
||||
/// <summary>
|
||||
/// {@inheritDoc}
|
||||
/// <p/>
|
||||
/// The default implementation attempts to recover from the mismatched input
|
||||
/// by using single token insertion and deletion as described below. If the
|
||||
/// recovery attempt fails, this method throws an
|
||||
/// <seealso cref="InputMismatchException"/>.
|
||||
/// <p/>
|
||||
/// <strong>EXTRA TOKEN</strong> (single token deletion)
|
||||
/// <p/>
|
||||
/// {@code LA(1)} is not what we are looking for. If {@code LA(2)} has the
|
||||
/// right token, however, then assume {@code LA(1)} is some extra spurious
|
||||
/// token and delete it. Then consume and return the next token (which was
|
||||
/// the {@code LA(2)} token) as the successful result of the match operation.
|
||||
/// <p/>
|
||||
/// This recovery strategy is implemented by <seealso cref="#singleTokenDeletion"/>.
|
||||
/// <p/>
|
||||
/// <strong>MISSING TOKEN</strong> (single token insertion)
|
||||
/// <p/>
|
||||
/// If current token (at {@code LA(1)}) is consistent with what could come
|
||||
/// after the expected {@code LA(1)} token, then assume the token is missing
|
||||
/// and use the parser's <seealso cref="TokenFactory"/> to create it on the fly. The
|
||||
/// "insertion" is performed by returning the created token as the successful
|
||||
/// result of the match operation.
|
||||
/// <p/>
|
||||
/// This recovery strategy is implemented by <seealso cref="#singleTokenInsertion"/>.
|
||||
/// <p/>
|
||||
/// <strong>EXAMPLE</strong>
|
||||
/// <p/>
|
||||
/// For example, Input {@code i=(3;} is clearly missing the {@code ')'}. When
|
||||
/// the parser returns from the nested call to {@code expr}, it will have
|
||||
/// call chain:
|
||||
///
|
||||
/// <pre>
|
||||
/// stat -> expr -> atom
|
||||
/// </pre>
|
||||
///
|
||||
/// and it will be trying to match the {@code ')'} at this point in the
|
||||
/// derivation:
|
||||
///
|
||||
/// <pre>
|
||||
/// => ID '=' '(' INT ')' ('+' atom)* ';'
|
||||
/// ^
|
||||
/// </pre>
|
||||
///
|
||||
/// The attempt to match {@code ')'} will fail when it sees {@code ';'} and
|
||||
/// call <seealso cref="#recoverInline"/>. To recover, it sees that {@code LA(1)==';'}
|
||||
/// is in the set of tokens that can follow the {@code ')'} token reference
|
||||
/// in rule {@code atom}. It can assume that you forgot the {@code ')'}.
|
||||
/// </summary>
|
||||
public:
|
||||
virtual Token *recoverInline(Parser *recognizer) override;
|
||||
|
||||
/// <summary>
|
||||
/// This method implements the single-token insertion inline error recovery
|
||||
/// strategy. It is called by <seealso cref="#recoverInline"/> if the single-token
|
||||
/// deletion strategy fails to recover from the mismatched input. If this
|
||||
/// method returns {@code true}, {@code recognizer} will be in error recovery
|
||||
/// mode.
|
||||
/// <p/>
|
||||
/// This method determines whether or not single-token insertion is viable by
|
||||
/// checking if the {@code LA(1)} input symbol could be successfully matched
|
||||
/// if it were instead the {@code LA(2)} symbol. If this method returns
|
||||
/// {@code true}, the caller is responsible for creating and inserting a
|
||||
/// token with the correct type to produce this behavior.
|
||||
/// </summary>
|
||||
/// <param name="recognizer"> the parser instance </param>
|
||||
/// <returns> {@code true} if single-token insertion is a viable recovery
|
||||
/// strategy for the current mismatched input, otherwise {@code false} </returns>
|
||||
protected:
|
||||
virtual bool singleTokenInsertion(Parser *recognizer);
|
||||
|
||||
/// <summary>
|
||||
/// This method implements the single-token deletion inline error recovery
|
||||
/// strategy. It is called by <seealso cref="#recoverInline"/> to attempt to recover
|
||||
/// from mismatched input. If this method returns null, the parser and error
|
||||
/// handler state will not have changed. If this method returns non-null,
|
||||
/// {@code recognizer} will <em>not</em> be in error recovery mode since the
|
||||
/// returned token was a successful match.
|
||||
/// <p/>
|
||||
/// If the single-token deletion is successful, this method calls
|
||||
/// <seealso cref="#reportUnwantedToken"/> to report the error, followed by
|
||||
/// <seealso cref="Parser#consume"/> to actually "delete" the extraneous token. Then,
|
||||
/// before returning <seealso cref="#reportMatch"/> is called to signal a successful
|
||||
/// match.
|
||||
/// </summary>
|
||||
/// <param name="recognizer"> the parser instance </param>
|
||||
/// <returns> the successfully matched <seealso cref="Token"/> instance if single-token
|
||||
/// deletion successfully recovers from the mismatched input, otherwise
|
||||
/// {@code null} </returns>
|
||||
virtual Token *singleTokenDeletion(Parser *recognizer);
|
||||
|
||||
/// <summary>
|
||||
/// Conjure up a missing token during error recovery.
|
||||
///
|
||||
/// The recognizer attempts to recover from single missing
|
||||
/// symbols. But, actions might refer to that missing symbol.
|
||||
/// For example, x=ID {f($x);}. The action clearly assumes
|
||||
/// that there has been an identifier matched previously and that
|
||||
/// $x points at that token. If that token is missing, but
|
||||
/// the next token in the stream is what we want we assume that
|
||||
/// this token is missing and we keep going. Because we
|
||||
/// have to return some token to replace the missing token,
|
||||
/// we have to conjure one up. This method gives the user control
|
||||
/// over the tokens returned for missing tokens. Mostly,
|
||||
/// you will want to create something special for identifier
|
||||
/// tokens. For literals such as '{' and ',', the default
|
||||
/// action in the parser or tree parser works. It simply creates
|
||||
/// a CommonToken of the appropriate type. The text will be the token.
|
||||
/// If you change what tokens must be created by the lexer,
|
||||
/// override this method to create the appropriate tokens.
|
||||
/// </summary>
|
||||
virtual Token *getMissingSymbol(Parser *recognizer);
|
||||
|
||||
virtual misc::IntervalSet *getExpectedTokens(Parser *recognizer);
|
||||
|
||||
/// <summary>
|
||||
/// How should a token be displayed in an error message? The default
|
||||
/// is to display just the text, but during development you might
|
||||
/// want to have a lot of information spit out. Override in that case
|
||||
/// to use t.toString() (which, for CommonToken, dumps everything about
|
||||
/// the token). This is better than forcing you to override a method in
|
||||
/// your token objects because you don't have to go modify your lexer
|
||||
/// so that it creates a new Java type.
|
||||
/// </summary>
|
||||
virtual std::wstring getTokenErrorDisplay(Token *t);
|
||||
|
||||
virtual std::wstring getSymbolText(Token *symbol);
|
||||
|
||||
virtual int getSymbolType(Token *symbol);
|
||||
|
||||
virtual std::wstring escapeWSAndQuote(std::wstring &s);
|
||||
|
||||
/* Compute the error recovery set for the current rule. During
|
||||
* rule invocation, the parser pushes the set of tokens that can
|
||||
* follow that rule reference on the stack; this amounts to
|
||||
* computing FIRST of what follows the rule reference in the
|
||||
* enclosing rule. See LinearApproximator.FIRST().
|
||||
* This local follow set only includes tokens
|
||||
* from within the rule; i.e., the FIRST computation done by
|
||||
* ANTLR stops at the end of a rule.
|
||||
*
|
||||
* EXAMPLE
|
||||
*
|
||||
* When you find a "no viable alt exception", the input is not
|
||||
* consistent with any of the alternatives for rule r. The best
|
||||
* thing to do is to consume tokens until you see something that
|
||||
* can legally follow a call to r *or* any rule that called r.
|
||||
* You don't want the exact set of viable next tokens because the
|
||||
* input might just be missing a token--you might consume the
|
||||
* rest of the input looking for one of the missing tokens.
|
||||
*
|
||||
* Consider grammar:
|
||||
*
|
||||
* a : '[' b ']'
|
||||
* | '(' b ')'
|
||||
* ;
|
||||
* b : c '^' INT ;
|
||||
* c : ID
|
||||
* | INT
|
||||
* ;
|
||||
*
|
||||
* At each rule invocation, the set of tokens that could follow
|
||||
* that rule is pushed on a stack. Here are the various
|
||||
* context-sensitive follow sets:
|
||||
*
|
||||
* FOLLOW(b1_in_a) = FIRST(']') = ']'
|
||||
* FOLLOW(b2_in_a) = FIRST(')') = ')'
|
||||
* FOLLOW(c_in_b) = FIRST('^') = '^'
|
||||
*
|
||||
* Upon erroneous input "[]", the call chain is
|
||||
*
|
||||
* a -> b -> c
|
||||
*
|
||||
* and, hence, the follow context stack is:
|
||||
*
|
||||
* depth follow set start of rule execution
|
||||
* 0 <EOF> a (from main())
|
||||
* 1 ']' b
|
||||
* 2 '^' c
|
||||
*
|
||||
* Notice that ')' is not included, because b would have to have
|
||||
* been called from a different context in rule a for ')' to be
|
||||
* included.
|
||||
*
|
||||
* For error recovery, we cannot consider FOLLOW(c)
|
||||
* (context-sensitive or otherwise). We need the combined set of
|
||||
* all context-sensitive FOLLOW sets--the set of all tokens that
|
||||
* could follow any reference in the call chain. We need to
|
||||
* resync to one of those tokens. Note that FOLLOW(c)='^' and if
|
||||
* we resync'd to that token, we'd consume until EOF. We need to
|
||||
* sync to context-sensitive FOLLOWs for a, b, and c: {']','^'}.
|
||||
* In this case, for input "[]", LA(1) is ']' and in the set, so we would
|
||||
* not consume anything. After printing an error, rule c would
|
||||
* return normally. Rule b would not find the required '^' though.
|
||||
* At this point, it gets a mismatched token error and throws an
|
||||
* exception (since LA(1) is not in the viable following token
|
||||
* set). The rule exception handler tries to recover, but finds
|
||||
* the same recovery set and doesn't consume anything. Rule b
|
||||
* exits normally returning to rule a. Now it finds the ']' (and
|
||||
* with the successful match exits errorRecovery mode).
|
||||
*
|
||||
* So, you can see that the parser walks up the call chain looking
|
||||
* for the token that was a member of the recovery set.
|
||||
*
|
||||
* Errors are not generated in errorRecovery mode.
|
||||
*
|
||||
* ANTLR's error recovery mechanism is based upon original ideas:
|
||||
*
|
||||
* "Algorithms + Data Structures = Programs" by Niklaus Wirth
|
||||
*
|
||||
* and
|
||||
*
|
||||
* "A note on error recovery in recursive descent parsers":
|
||||
* http://portal.acm.org/citation.cfm?id=947902.947905
|
||||
*
|
||||
* Later, Josef Grosch had some good ideas:
|
||||
*
|
||||
* "Efficient and Comfortable Error Recovery in Recursive Descent
|
||||
* Parsers":
|
||||
* ftp://www.cocolab.com/products/cocktail/doca4.ps/ell.ps.zip
|
||||
*
|
||||
* Like Grosch I implement context-sensitive FOLLOW sets that are combined
|
||||
* at run-time upon error to avoid overhead during parsing.
|
||||
*/
|
||||
virtual misc::IntervalSet *getErrorRecoverySet(Parser *recognizer);
|
||||
|
||||
/// <summary>
|
||||
/// Consume tokens until one matches the given token set. </summary>
|
||||
virtual void consumeUntil(Parser *recognizer, misc::IntervalSet *set);
|
||||
|
||||
private:
|
||||
void InitializeInstanceFields();
|
||||
|
||||
public:
|
||||
DefaultErrorStrategy() {
|
||||
InitializeInstanceFields();
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,116 @@
|
|||
#include "DiagnosticErrorListener.h"
|
||||
#include "ATNConfig.h"
|
||||
#include "ATNConfigSet.h"
|
||||
#include "Parser.h"
|
||||
#include "Interval.h"
|
||||
#include "DFA.h"
|
||||
#include "DecisionState.h"
|
||||
#include "stdio.h"
|
||||
#include "StringBuilder.h"
|
||||
#include "ATNState.h"
|
||||
|
||||
/*
|
||||
* [The "BSD license"]
|
||||
* Copyright (c) 2013 Terence Parr
|
||||
* Copyright (c) 2013 Dan McLaughlin
|
||||
* 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. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
||||
*/
|
||||
|
||||
|
||||
namespace org {
|
||||
namespace antlr {
|
||||
namespace v4 {
|
||||
namespace runtime {
|
||||
|
||||
|
||||
//JAVA TO C++ CONVERTER TODO TASK: Calls to same-class constructors are not supported in C++ prior to C++11:
|
||||
DiagnosticErrorListener::DiagnosticErrorListener() : exactOnly(true) {
|
||||
}
|
||||
|
||||
DiagnosticErrorListener::DiagnosticErrorListener(bool exactOnly) : exactOnly(exactOnly) {
|
||||
}
|
||||
|
||||
void DiagnosticErrorListener::reportAmbiguity(Parser *recognizer, dfa::DFA *dfa, int startIndex, int stopIndex, bool exact, antlrcpp::BitSet *ambigAlts, atn::ATNConfigSet *configs) {
|
||||
if (exactOnly && !exact) {
|
||||
return;
|
||||
}
|
||||
wchar_t buf[16];
|
||||
std::wstring decision = getDecisionDescription(recognizer, dfa);
|
||||
antlrcpp::BitSet *conflictingAlts = getConflictingAlts(ambigAlts, configs);
|
||||
std::wstring text = recognizer->getTokenStream()->getText(misc::Interval::of(startIndex, stopIndex));
|
||||
std::wstring message = L"reportAmbiguity d=" + decision + L": ambigAlts=" + conflictingAlts->toString() + L", input='" + text + L"'";
|
||||
swprintf(buf, sizeof(buf) / sizeof(*buf), L"%d", 5);
|
||||
recognizer->notifyErrorListeners(message);
|
||||
}
|
||||
|
||||
void DiagnosticErrorListener::reportAttemptingFullContext(Parser *recognizer, dfa::DFA *dfa, int startIndex, int stopIndex, antlrcpp::BitSet *conflictingAlts, atn::ATNConfigSet *configs) {
|
||||
std::wstring decision = getDecisionDescription(recognizer, dfa);
|
||||
std::wstring text = recognizer->getTokenStream()->getText(misc::Interval::of(startIndex, stopIndex));
|
||||
std::wstring message = L"reportAttemptingFullContext d=" + decision + L", input='" + text + L"'";
|
||||
recognizer->notifyErrorListeners(message);
|
||||
}
|
||||
|
||||
void DiagnosticErrorListener::reportContextSensitivity(Parser *recognizer, dfa::DFA *dfa, int startIndex, int stopIndex, int prediction, atn::ATNConfigSet *configs) {
|
||||
std::wstring decision = getDecisionDescription(recognizer, dfa);
|
||||
std::wstring text = recognizer->getTokenStream()->getText(misc::Interval::of(startIndex, stopIndex));
|
||||
std::wstring message = L"reportContextSensitivity d=" + decision + L", input='" + text + L"'";
|
||||
recognizer->notifyErrorListeners(message);
|
||||
}
|
||||
|
||||
std::wstring DiagnosticErrorListener::getDecisionDescription(Parser *recognizer, dfa::DFA *dfa) {
|
||||
int decision = dfa->decision;
|
||||
int ruleIndex = ((atn::ATNState*)dfa->atnStartState)->ruleIndex;
|
||||
|
||||
const std::vector<std::wstring>& ruleNames = recognizer->getRuleNames();
|
||||
if (ruleIndex < 0 || ruleIndex >= (int)ruleNames.size()) {
|
||||
return antlrcpp::StringConverterHelper::toString(decision);
|
||||
}
|
||||
|
||||
std::wstring ruleName = ruleNames[ruleIndex];
|
||||
if (ruleName == L"" || ruleName.empty()) {
|
||||
return antlrcpp::StringConverterHelper::toString(decision);
|
||||
}
|
||||
|
||||
return std::to_wstring(decision) + L"(" + ruleName + L")";
|
||||
}
|
||||
|
||||
antlrcpp::BitSet *DiagnosticErrorListener::getConflictingAlts(antlrcpp::BitSet *reportedAlts, atn::ATNConfigSet *configs) {
|
||||
if (reportedAlts != nullptr) {
|
||||
return reportedAlts;
|
||||
}
|
||||
|
||||
antlrcpp::BitSet *result = new antlrcpp::BitSet();
|
||||
for (size_t i = 0; i < configs->size(); i++) {
|
||||
atn::ATNConfig *config = configs->get((int)i);
|
||||
result->set(config->alt);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,114 @@
|
|||
#pragma once
|
||||
|
||||
|
||||
#include <string>
|
||||
#include "stringconverter.h"
|
||||
#include "Declarations.h"
|
||||
#include "BaseErrorListener.h"
|
||||
|
||||
/*
|
||||
* [The "BSD license"]
|
||||
* Copyright (c) 2013 Terence Parr
|
||||
* Copyright (c) 2013 Dan McLaughlin
|
||||
* 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. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
||||
*/
|
||||
|
||||
namespace org {
|
||||
namespace antlr {
|
||||
namespace v4 {
|
||||
namespace runtime {
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// This implementation of <seealso cref="ANTLRErrorListener"/> can be used to identify
|
||||
/// certain potential correctness and performance problems in grammars. "Reports"
|
||||
/// are made by calling <seealso cref="Parser#notifyErrorListeners"/> with the appropriate
|
||||
/// message.
|
||||
///
|
||||
/// <ul>
|
||||
/// <li><b>Ambiguities</b>: These are cases where more than one path through the
|
||||
/// grammar can match the input.</li>
|
||||
/// <li><b>Weak context sensitivity</b>: These are cases where full-context
|
||||
/// prediction resolved an SLL conflict to a unique alternative which equaled the
|
||||
/// minimum alternative of the SLL conflict.</li>
|
||||
/// <li><b>Strong (forced) context sensitivity</b>: These are cases where the
|
||||
/// full-context prediction resolved an SLL conflict to a unique alternative,
|
||||
/// <em>and</em> the minimum alternative of the SLL conflict was found to not be
|
||||
/// a truly viable alternative. Two-stage parsing cannot be used for inputs where
|
||||
/// this situation occurs.</li>
|
||||
/// </ul>
|
||||
///
|
||||
/// @author Sam Harwell
|
||||
/// </summary>
|
||||
class DiagnosticErrorListener : public BaseErrorListener {
|
||||
/// <summary>
|
||||
/// When {@code true}, only exactly known ambiguities are reported.
|
||||
/// </summary>
|
||||
protected:
|
||||
const bool exactOnly;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of <seealso cref="DiagnosticErrorListener"/> which only
|
||||
/// reports exact ambiguities.
|
||||
/// </summary>
|
||||
public:
|
||||
DiagnosticErrorListener(); //this(true);
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of <seealso cref="DiagnosticErrorListener"/>, specifying
|
||||
/// whether all ambiguities or only exact ambiguities are reported.
|
||||
/// </summary>
|
||||
/// <param name="exactOnly"> {@code true} to report only exact ambiguities, otherwise
|
||||
/// {@code false} to report all ambiguities. </param>
|
||||
DiagnosticErrorListener(bool exactOnly);
|
||||
|
||||
virtual void reportAmbiguity(Parser *recognizer, dfa::DFA *dfa, int startIndex, int stopIndex, bool exact, antlrcpp::BitSet *ambigAlts, atn::ATNConfigSet *configs) override;
|
||||
|
||||
virtual void reportAttemptingFullContext(Parser *recognizer, dfa::DFA *dfa, int startIndex, int stopIndex, antlrcpp::BitSet *conflictingAlts, atn::ATNConfigSet *configs) override;
|
||||
|
||||
virtual void reportContextSensitivity(Parser *recognizer, dfa::DFA *dfa, int startIndex, int stopIndex, int prediction, atn::ATNConfigSet *configs) override;
|
||||
|
||||
protected:
|
||||
virtual std::wstring getDecisionDescription(Parser *recognizer, dfa::DFA *dfa);
|
||||
|
||||
/// <summary>
|
||||
/// Computes the set of conflicting or ambiguous alternatives from a
|
||||
/// configuration set, if that information was not already provided by the
|
||||
/// parser.
|
||||
/// </summary>
|
||||
/// <param name="reportedAlts"> The set of conflicting or ambiguous alternatives, as
|
||||
/// reported by the parser. </param>
|
||||
/// <param name="configs"> The conflicting or ambiguous configuration set. </param>
|
||||
/// <returns> Returns {@code reportedAlts} if it is not {@code null}, otherwise
|
||||
/// returns the set of alternatives represented in {@code configs}. </returns>
|
||||
virtual antlrcpp::BitSet *getConflictingAlts(antlrcpp::BitSet *reportedAlts, atn::ATNConfigSet *configs);
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
/*
|
||||
* [The "BSD license"]
|
||||
* Copyright (c) 2013 Dan McLaughlin
|
||||
* 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. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
||||
*/
|
||||
|
||||
#include "Exceptions.h"
|
|
@ -0,0 +1,120 @@
|
|||
/*
|
||||
* [The "BSD license"]
|
||||
* Copyright (c) 2013 Dan McLaughlin
|
||||
* 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. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "Declarations.h"
|
||||
|
||||
#include <iostream>
|
||||
#include <exception>
|
||||
#include <string>
|
||||
|
||||
|
||||
namespace org {
|
||||
namespace antlr {
|
||||
namespace v4 {
|
||||
namespace runtime {
|
||||
class ANTLRException : public std::exception {
|
||||
private:
|
||||
std::wstring errormsg;
|
||||
|
||||
public:
|
||||
ANTLRException() {}
|
||||
ANTLRException(const std::wstring msg) {
|
||||
this->errormsg = msg;
|
||||
}
|
||||
std::wstring getMessage() {
|
||||
return errormsg;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
class IllegalClassException : public ANTLRException {
|
||||
public:
|
||||
IllegalClassException(const std::wstring msg) : ANTLRException(msg) {};
|
||||
IllegalClassException() {};
|
||||
};
|
||||
|
||||
class IllegalStateException : public ANTLRException {
|
||||
public:
|
||||
IllegalStateException(const std::wstring msg) : ANTLRException(msg) {};
|
||||
IllegalStateException(){};
|
||||
};
|
||||
|
||||
class IllegalArgumentException : public ANTLRException {
|
||||
public:
|
||||
IllegalArgumentException(const std::wstring msg) : ANTLRException(msg) {};
|
||||
IllegalArgumentException(const std::wstring msg, std::exception e);
|
||||
IllegalArgumentException(){};
|
||||
};
|
||||
|
||||
class NoSuchElementException : public ANTLRException {
|
||||
public:
|
||||
NoSuchElementException(const std::wstring msg) : ANTLRException(msg) {};
|
||||
NoSuchElementException(){};
|
||||
};
|
||||
|
||||
class NullPointerException : public ANTLRException {
|
||||
public:
|
||||
NullPointerException(const std::wstring msg) : ANTLRException(msg) {};
|
||||
NullPointerException(){};
|
||||
};
|
||||
class IndexOutOfBoundsException : public ANTLRException {
|
||||
public:
|
||||
IndexOutOfBoundsException(const std::wstring msg) : ANTLRException(msg) {};
|
||||
IndexOutOfBoundsException(){};
|
||||
};
|
||||
class UnsupportedOperationException : public ANTLRException {
|
||||
public:
|
||||
UnsupportedOperationException(const std::wstring msg) : ANTLRException(msg) {};
|
||||
UnsupportedOperationException(){};
|
||||
};
|
||||
class IOException : public ANTLRException {
|
||||
public:
|
||||
IOException(const std::wstring msg) : ANTLRException(msg) {};
|
||||
IOException(){};
|
||||
};
|
||||
class TODOException : public ANTLRException {
|
||||
public:
|
||||
TODOException(const std::wstring msg) : ANTLRException(msg) {};
|
||||
TODOException();
|
||||
};
|
||||
class ASSERTException : public ANTLRException {
|
||||
public:
|
||||
ASSERTException(const std::wstring location,
|
||||
const std::wstring condition)
|
||||
: ANTLRException(location + L" condition= " + condition) {};
|
||||
ASSERTException();
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,89 @@
|
|||
#include "FailedPredicateException.h"
|
||||
#include "ATNState.h"
|
||||
#include "AbstractPredicateTransition.h"
|
||||
#include "PredicateTransition.h"
|
||||
#include "Parser.h"
|
||||
#include "ParserATNSimulator.h"
|
||||
#include "ATN.h"
|
||||
|
||||
/*
|
||||
* [The "BSD license"]
|
||||
* Copyright (c) 2013 Terence Parr
|
||||
* Copyright (c) 2013 Dan McLaughlin
|
||||
* 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. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
||||
*/
|
||||
|
||||
namespace org {
|
||||
namespace antlr {
|
||||
namespace v4 {
|
||||
namespace runtime {
|
||||
FailedPredicateException::FailedPredicateException(Parser *recognizer) : RecognitionException() {
|
||||
}
|
||||
|
||||
FailedPredicateException::FailedPredicateException(Parser *recognizer, const std::wstring &predicate): RecognitionException() {
|
||||
}
|
||||
|
||||
FailedPredicateException::FailedPredicateException(Parser *recognizer, const std::wstring &predicate, const std::wstring &message)
|
||||
#ifdef TODO
|
||||
// Huston, a problem. "trans" isn't defined until below
|
||||
: RecognitionException(formatMessage(predicate, message), recognizer, recognizer->getInputStream(), recognizer->_ctx), ruleIndex((static_cast<atn::PredicateTransition*>(trans))->ruleIndex), predicateIndex((static_cast<atn::PredicateTransition*>(trans))->predIndex), predicate(predicate)
|
||||
#endif
|
||||
|
||||
{
|
||||
atn::ATNState *s = recognizer->getInterpreter()->atn->states[recognizer->getState()];
|
||||
|
||||
atn::AbstractPredicateTransition *trans = static_cast<atn::AbstractPredicateTransition*>(s->transition(0));
|
||||
if (dynamic_cast<atn::PredicateTransition*>(trans) != nullptr) {
|
||||
} else {
|
||||
this->ruleIndex = 0;
|
||||
this->predicateIndex = 0;
|
||||
}
|
||||
|
||||
this->setOffendingToken(recognizer->getCurrentToken());
|
||||
}
|
||||
|
||||
int FailedPredicateException::getRuleIndex() {
|
||||
return ruleIndex;
|
||||
}
|
||||
|
||||
int FailedPredicateException::getPredIndex() {
|
||||
return predicateIndex;
|
||||
}
|
||||
|
||||
std::wstring FailedPredicateException::getPredicate() {
|
||||
return predicate;
|
||||
}
|
||||
|
||||
std::wstring FailedPredicateException::formatMessage(const std::wstring &predicate, const std::wstring &message) {
|
||||
if (message != L"") {
|
||||
return message;
|
||||
}
|
||||
return L"failed predicate: " + predicate + L"?";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,75 @@
|
|||
#pragma once
|
||||
|
||||
#include "RecognitionException.h"
|
||||
#include "Declarations.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
/*
|
||||
* [The "BSD license"]
|
||||
* Copyright (c) 2013 Terence Parr
|
||||
* Copyright (c) 2013 Dan McLaughlin
|
||||
* 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. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
||||
*/
|
||||
namespace org {
|
||||
namespace antlr {
|
||||
namespace v4 {
|
||||
namespace runtime {
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// A semantic predicate failed during validation. Validation of predicates
|
||||
/// occurs when normally parsing the alternative just like matching a token.
|
||||
/// Disambiguating predicate evaluation occurs when we test a predicate during
|
||||
/// prediction.
|
||||
/// </summary>
|
||||
class FailedPredicateException : public RecognitionException {
|
||||
private:
|
||||
int ruleIndex;
|
||||
int predicateIndex;
|
||||
const std::wstring predicate;
|
||||
|
||||
public:
|
||||
FailedPredicateException(Parser *recognizer); //this(recognizer, nullptr);
|
||||
|
||||
FailedPredicateException(Parser *recognizer, const std::wstring &predicate); //this(recognizer, predicate, nullptr);
|
||||
|
||||
FailedPredicateException(Parser *recognizer, const std::wstring &predicate, const std::wstring &message);
|
||||
|
||||
virtual int getRuleIndex();
|
||||
|
||||
virtual int getPredIndex();
|
||||
|
||||
virtual std::wstring getPredicate();
|
||||
|
||||
private:
|
||||
static std::wstring formatMessage(const std::wstring &predicate, const std::wstring &message);
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,48 @@
|
|||
#pragma once
|
||||
|
||||
/*
|
||||
* [The "BSD license"]
|
||||
* Copyright (c) 2013 Terence Parr
|
||||
* Copyright (c) 2013 Dan McLaughlin
|
||||
* 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. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
||||
*/
|
||||
|
||||
|
||||
namespace org {
|
||||
namespace antlr {
|
||||
namespace v4 {
|
||||
namespace runtime {
|
||||
|
||||
class IErrorListener {
|
||||
public:
|
||||
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,50 @@
|
|||
#pragma once
|
||||
|
||||
/*
|
||||
* [The "BSD license"]
|
||||
* Copyright (c) 2013 Terence Parr
|
||||
* Copyright (c) 2013 Dan McLaughlin
|
||||
* 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. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
||||
*/
|
||||
|
||||
|
||||
namespace org {
|
||||
namespace antlr {
|
||||
namespace v4 {
|
||||
namespace runtime {
|
||||
|
||||
template<typename Symbol, typename ATNInterpreter>
|
||||
class IRecognizer {
|
||||
public:
|
||||
|
||||
virtual int getState() = 0;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,48 @@
|
|||
#include "InputMismatchException.h"
|
||||
|
||||
/*
|
||||
* [The "BSD license"]
|
||||
* Copyright (c) 2013 Terence Parr
|
||||
* Copyright (c) 2013 Dan McLaughlin
|
||||
* 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. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
||||
*/
|
||||
|
||||
namespace org {
|
||||
namespace antlr {
|
||||
namespace v4 {
|
||||
namespace runtime {
|
||||
|
||||
InputMismatchException::InputMismatchException(Parser *recognizer)
|
||||
: RecognitionException(recognizer,
|
||||
recognizer->getInputStream(),
|
||||
recognizer->_ctx) {
|
||||
this->setOffendingToken(recognizer->getCurrentToken());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,53 @@
|
|||
#pragma once
|
||||
|
||||
#include "RecognitionException.h"
|
||||
#include "Parser.h"
|
||||
|
||||
/*
|
||||
* [The "BSD license"]
|
||||
* Copyright (c) 2013 Terence Parr
|
||||
* Copyright (c) 2013 Dan McLaughlin
|
||||
* 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. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
||||
*/
|
||||
|
||||
namespace org {
|
||||
namespace antlr {
|
||||
namespace v4 {
|
||||
namespace runtime {
|
||||
|
||||
/// <summary>
|
||||
/// This signifies any kind of mismatched input exceptions such as
|
||||
/// when the current input does not match the expected token.
|
||||
/// </summary>
|
||||
class InputMismatchException : public RecognitionException {
|
||||
public:
|
||||
InputMismatchException(Parser *recognizer);
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,41 @@
|
|||
#include "IntStream.h"
|
||||
|
||||
/*
|
||||
* [The "BSD license"]
|
||||
* Copyright (c) 2013 Terence Parr
|
||||
* Copyright (c) 2013 Dan McLaughlin
|
||||
* 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. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
||||
*/
|
||||
|
||||
namespace org {
|
||||
namespace antlr {
|
||||
namespace v4 {
|
||||
namespace runtime {
|
||||
const std::wstring IntStream::UNKNOWN_SOURCE_NAME = L"<unknown>";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,249 @@
|
|||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <ios>
|
||||
|
||||
/*
|
||||
* [The "BSD license"]
|
||||
* Copyright (c) 2013 Terence Parr
|
||||
* Copyright (c) 2013 Dan McLaughlin
|
||||
* 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. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
||||
*/
|
||||
|
||||
namespace org {
|
||||
namespace antlr {
|
||||
namespace v4 {
|
||||
namespace runtime {
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// A simple stream of symbols whose values are represented as integers. This
|
||||
/// interface provides <em>marked ranges</em> with support for a minimum level
|
||||
/// of buffering necessary to implement arbitrary lookahead during prediction.
|
||||
/// For more information on marked ranges, see <seealso cref="#mark"/>.
|
||||
/// <p/>
|
||||
/// <strong>Initializing Methods:</strong> Some methods in this interface have
|
||||
/// unspecified behavior if no call to an initializing method has occurred after
|
||||
/// the stream was constructed. The following is a list of initializing methods:
|
||||
///
|
||||
/// <ul>
|
||||
/// <li><seealso cref="#LA"/></li>
|
||||
/// <li><seealso cref="#consume"/></li>
|
||||
/// <li><seealso cref="#size"/></li>
|
||||
/// </ul>
|
||||
/// </summary>
|
||||
class IntStream {
|
||||
/// <summary>
|
||||
/// The value returned by <seealso cref="#LA LA()"/> when the end of the stream is
|
||||
/// reached.
|
||||
/// </summary>
|
||||
public:
|
||||
// EOF Conflict with OS X, change to _EOF
|
||||
static const int _EOF = std::ios::eofbit;
|
||||
|
||||
/// <summary>
|
||||
/// The value returned by <seealso cref="#getSourceName"/> when the actual name of the
|
||||
/// underlying source is not known.
|
||||
/// </summary>
|
||||
static const std::wstring UNKNOWN_SOURCE_NAME;
|
||||
|
||||
/// <summary>
|
||||
/// Consumes the current symbol in the stream. This method has the following
|
||||
/// effects:
|
||||
///
|
||||
/// <ul>
|
||||
/// <li><strong>Forward movement:</strong> The value of <seealso cref="#index index()"/>
|
||||
/// before calling this method is less than the value of {@code index()}
|
||||
/// after calling this method.</li>
|
||||
/// <li><strong>Ordered lookahead:</strong> The value of {@code LA(1)} before
|
||||
/// calling this method becomes the value of {@code LA(-1)} after calling
|
||||
/// this method.</li>
|
||||
/// </ul>
|
||||
///
|
||||
/// Note that calling this method does not guarantee that {@code index()} is
|
||||
/// incremented by exactly 1, as that would preclude the ability to implement
|
||||
/// filtering streams (e.g. <seealso cref="CommonTokenStream"/> which distinguishes
|
||||
/// between "on-channel" and "off-channel" tokens).
|
||||
/// </summary>
|
||||
/// <exception cref="IllegalStateException"> if an attempt is made to consume the the
|
||||
/// end of the stream (i.e. if {@code LA(1)==}<seealso cref="#EOF EOF"/> before calling
|
||||
/// {@code consume}). </exception>
|
||||
virtual void consume() = 0;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the value of the symbol at offset {@code i} from the current
|
||||
/// position. When {@code i==1}, this method returns the value of the current
|
||||
/// symbol in the stream (which is the next symbol to be consumed). When
|
||||
/// {@code i==-1}, this method returns the value of the previously read
|
||||
/// symbol in the stream. It is not valid to call this method with
|
||||
/// {@code i==0}, but the specific behavior is unspecified because this
|
||||
/// method is frequently called from performance-critical code.
|
||||
/// <p/>
|
||||
/// This method is guaranteed to succeed if any of the following are true:
|
||||
///
|
||||
/// <ul>
|
||||
/// <li>{@code i>0}</li>
|
||||
/// <li>{@code i==-1} and <seealso cref="#index index()"/> returns a value greater
|
||||
/// than the value of {@code index()} after the stream was constructed
|
||||
/// and {@code LA(1)} was called in that order. Specifying the current
|
||||
/// {@code index()} relative to the index after the stream was created
|
||||
/// allows for filtering implementations that do not return every symbol
|
||||
/// from the underlying source. Specifying the call to {@code LA(1)}
|
||||
/// allows for lazily initialized streams.</li>
|
||||
/// <li>{@code LA(i)} refers to a symbol consumed within a marked region
|
||||
/// that has not yet been released.</li>
|
||||
/// </ul>
|
||||
///
|
||||
/// If {@code i} represents a position at or beyond the end of the stream,
|
||||
/// this method returns <seealso cref="#EOF"/>.
|
||||
/// <p/>
|
||||
/// The return value is unspecified if {@code i<0} and fewer than {@code -i}
|
||||
/// calls to <seealso cref="#consume consume()"/> have occurred from the beginning of
|
||||
/// the stream before calling this method.
|
||||
/// </summary>
|
||||
/// <exception cref="UnsupportedOperationException"> if the stream does not support
|
||||
/// retrieving the value of the specified symbol </exception>
|
||||
virtual int LA(int i) = 0;
|
||||
|
||||
/// <summary>
|
||||
/// A mark provides a guarantee that <seealso cref="#seek seek()"/> operations will be
|
||||
/// valid over a "marked range" extending from the index where {@code mark()}
|
||||
/// was called to the current <seealso cref="#index index()"/>. This allows the use of
|
||||
/// streaming input sources by specifying the minimum buffering requirements
|
||||
/// to support arbitrary lookahead during prediction.
|
||||
/// <p/>
|
||||
/// The returned mark is an opaque handle (type {@code int}) which is passed
|
||||
/// to <seealso cref="#release release()"/> when the guarantees provided by the marked
|
||||
/// range are no longer necessary. When calls to
|
||||
/// {@code mark()}/{@code release()} are nested, the marks must be released
|
||||
/// in reverse order of which they were obtained. Since marked regions are
|
||||
/// used during performance-critical sections of prediction, the specific
|
||||
/// behavior of invalid usage is unspecified (i.e. a mark is not released, or
|
||||
/// a mark is released twice, or marks are not released in reverse order from
|
||||
/// which they were created).
|
||||
/// <p/>
|
||||
/// The behavior of this method is unspecified if no call to an
|
||||
/// <seealso cref="IntStream initializing method"/> has occurred after this stream was
|
||||
/// constructed.
|
||||
/// <p/>
|
||||
/// This method does not change the current position in the input stream.
|
||||
/// <p/>
|
||||
/// The following example shows the use of <seealso cref="#mark mark()"/>,
|
||||
/// <seealso cref="#release release(mark)"/>, <seealso cref="#index index()"/>, and
|
||||
/// <seealso cref="#seek seek(index)"/> as part of an operation to safely work within a
|
||||
/// marked region, then restore the stream position to its original value and
|
||||
/// release the mark.
|
||||
/// <pre>
|
||||
/// IntStream stream = ...;
|
||||
/// int index = -1;
|
||||
/// int mark = stream.mark();
|
||||
/// try {
|
||||
/// index = stream.index();
|
||||
/// // perform work here...
|
||||
/// } finally {
|
||||
/// if (index != -1) {
|
||||
/// stream.seek(index);
|
||||
/// }
|
||||
/// stream.release(mark);
|
||||
/// }
|
||||
/// </pre>
|
||||
/// </summary>
|
||||
/// <returns> An opaque marker which should be passed to
|
||||
/// <seealso cref="#release release()"/> when the marked range is no longer required. </returns>
|
||||
virtual int mark() = 0;
|
||||
|
||||
/// <summary>
|
||||
/// This method releases a marked range created by a call to
|
||||
/// <seealso cref="#mark mark()"/>. Calls to {@code release()} must appear in the
|
||||
/// reverse order of the corresponding calls to {@code mark()}. If a mark is
|
||||
/// released twice, or if marks are not released in reverse order of the
|
||||
/// corresponding calls to {@code mark()}, the behavior is unspecified.
|
||||
/// <p/>
|
||||
/// For more information and an example, see <seealso cref="#mark"/>.
|
||||
/// </summary>
|
||||
/// <param name="marker"> A marker returned by a call to {@code mark()}. </param>
|
||||
/// <seealso cref= #mark </seealso>
|
||||
virtual void release(int marker) = 0;
|
||||
|
||||
/// <summary>
|
||||
/// Return the index into the stream of the input symbol referred to by
|
||||
/// {@code LA(1)}.
|
||||
/// <p/>
|
||||
/// The behavior of this method is unspecified if no call to an
|
||||
/// <seealso cref="IntStream initializing method"/> has occurred after this stream was
|
||||
/// constructed.
|
||||
/// </summary>
|
||||
virtual int index() = 0;
|
||||
|
||||
/// <summary>
|
||||
/// Set the input cursor to the position indicated by {@code index}. If the
|
||||
/// specified index lies past the end of the stream, the operation behaves as
|
||||
/// though {@code index} was the index of the EOF symbol. After this method
|
||||
/// returns without throwing an exception, the at least one of the following
|
||||
/// will be true.
|
||||
///
|
||||
/// <ul>
|
||||
/// <li><seealso cref="#index index()"/> will return the index of the first symbol
|
||||
/// appearing at or after the specified {@code index}. Specifically,
|
||||
/// implementations which filter their sources should automatically
|
||||
/// adjust {@code index} forward the minimum amount required for the
|
||||
/// operation to target a non-ignored symbol.</li>
|
||||
/// <li>{@code LA(1)} returns <seealso cref="#EOF"/></li>
|
||||
/// </ul>
|
||||
///
|
||||
/// This operation is guaranteed to not throw an exception if {@code index}
|
||||
/// lies within a marked region. For more information on marked regions, see
|
||||
/// <seealso cref="#mark"/>. The behavior of this method is unspecified if no call to
|
||||
/// an <seealso cref="IntStream initializing method"/> has occurred after this stream
|
||||
/// was constructed.
|
||||
/// </summary>
|
||||
/// <param name="index"> The absolute index to seek to.
|
||||
/// </param>
|
||||
/// <exception cref="IllegalArgumentException"> if {@code index} is less than 0 </exception>
|
||||
/// <exception cref="UnsupportedOperationException"> if the stream does not support
|
||||
/// seeking to the specified index </exception>
|
||||
virtual void seek(int index) = 0;
|
||||
|
||||
/// <summary>
|
||||
/// Returns the total number of symbols in the stream, including a single EOF
|
||||
/// symbol.
|
||||
/// </summary>
|
||||
/// <exception cref="UnsupportedOperationException"> if the size of the stream is
|
||||
/// unknown. </exception>
|
||||
virtual size_t size() = 0;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the name of the underlying symbol source. This method returns a
|
||||
/// non-null, non-empty string. If such a name is not known, this method
|
||||
/// returns <seealso cref="#UNKNOWN_SOURCE_NAME"/>.
|
||||
/// </summary>
|
||||
virtual std::string getSourceName() = 0;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,46 @@
|
|||
#include "InterpreterRuleContext.h"
|
||||
|
||||
/*
|
||||
* [The "BSD license"]
|
||||
* Copyright (c) 2013 Terence Parr
|
||||
* Copyright (c) 2013 Dan McLaughlin
|
||||
* 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. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
||||
*/
|
||||
|
||||
namespace org {
|
||||
namespace antlr {
|
||||
namespace v4 {
|
||||
namespace runtime {
|
||||
InterpreterRuleContext::InterpreterRuleContext(ParserRuleContext *parent, int invokingStateNumber, int ruleIndex) : ParserRuleContext(parent, invokingStateNumber), ruleIndex(ruleIndex) {
|
||||
}
|
||||
|
||||
int InterpreterRuleContext::getRuleIndex() {
|
||||
return ruleIndex;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,58 @@
|
|||
#pragma once
|
||||
|
||||
#include "ParserRuleContext.h"
|
||||
|
||||
/*
|
||||
* [The "BSD license"]
|
||||
* Copyright (c) 2013 Terence Parr
|
||||
* Copyright (c) 2013 Dan McLaughlin
|
||||
* 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. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
||||
*/
|
||||
|
||||
namespace org {
|
||||
namespace antlr {
|
||||
namespace v4 {
|
||||
namespace runtime {
|
||||
|
||||
/// <summary>
|
||||
/// This object is used by the ParserInterpreter and is the same as a regular
|
||||
/// ParserRuleContext except that we need to track the rule index of the
|
||||
/// current context so that we can build parse trees.
|
||||
/// </summary>
|
||||
class InterpreterRuleContext : public ParserRuleContext {
|
||||
private:
|
||||
const int ruleIndex;
|
||||
|
||||
public:
|
||||
InterpreterRuleContext(ParserRuleContext *parent, int invokingStateNumber, int ruleIndex);
|
||||
|
||||
virtual int getRuleIndex() override;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,365 @@
|
|||
#include "Lexer.h"
|
||||
|
||||
#include "LexerATNSimulator.h"
|
||||
#include "Exceptions.h"
|
||||
#include "ANTLRErrorListener.h"
|
||||
#include "Interval.h"
|
||||
#include "StringBuilder.h"
|
||||
#include "CommonTokenFactory.h"
|
||||
#include "LexerNoViableAltException.h"
|
||||
|
||||
/*
|
||||
* [The "BSD license"]
|
||||
* Copyright (c) 2013 Terence Parr
|
||||
* Copyright (c) 2013 Dan McLaughlin
|
||||
* 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. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
||||
*/
|
||||
|
||||
namespace org {
|
||||
namespace antlr {
|
||||
namespace v4 {
|
||||
namespace runtime {
|
||||
|
||||
|
||||
Lexer::Lexer() {
|
||||
InitializeInstanceFields();
|
||||
}
|
||||
|
||||
Lexer::Lexer(CharStream *input) {
|
||||
InitializeInstanceFields();
|
||||
this->_input = input;
|
||||
this->_tokenFactorySourcePair = new std::pair<TokenSource*, CharStream*>(this, input);
|
||||
}
|
||||
|
||||
void Lexer::reset() {
|
||||
// wack Lexer state variables
|
||||
if (_input != nullptr) {
|
||||
_input->seek(0); // rewind the input
|
||||
}
|
||||
delete _token;
|
||||
_type = Token::INVALID_TYPE;
|
||||
_channel = Token::DEFAULT_CHANNEL;
|
||||
_tokenStartCharIndex = -1;
|
||||
_tokenStartCharPositionInLine = -1;
|
||||
_tokenStartLine = -1;
|
||||
_text = L"";
|
||||
|
||||
_hitEOF = false;
|
||||
_mode = Lexer::DEFAULT_MODE;
|
||||
_modeStack.clear();
|
||||
|
||||
getInterpreter()->reset();
|
||||
}
|
||||
|
||||
Token *Lexer::nextToken() {
|
||||
if (_input == nullptr) {
|
||||
throw new IllegalStateException(L"nextToken requires a non-null input stream.");
|
||||
}
|
||||
|
||||
// Mark start location in char stream so unbuffered streams are
|
||||
// guaranteed at least have text of current token
|
||||
int tokenStartMarker = _input->mark();
|
||||
try {
|
||||
while (true) {
|
||||
outerContinue:
|
||||
if (_hitEOF) {
|
||||
emitEOF();
|
||||
return _token;
|
||||
}
|
||||
|
||||
delete _token;
|
||||
_channel = Token::DEFAULT_CHANNEL;
|
||||
_tokenStartCharIndex = _input->index();
|
||||
_tokenStartCharPositionInLine = getInterpreter()->getCharPositionInLine();
|
||||
_tokenStartLine = getInterpreter()->getLine();
|
||||
_text = L"";
|
||||
do {
|
||||
_type = Token::INVALID_TYPE;
|
||||
// System.out.println("nextToken line "+tokenStartLine+" at "+((char)input.LA(1))+
|
||||
// " in mode "+mode+
|
||||
// " at index "+input.index());
|
||||
int ttype;
|
||||
try {
|
||||
ttype = getInterpreter()->match(_input, _mode);
|
||||
} catch (LexerNoViableAltException *e) {
|
||||
notifyListeners(e); // report error
|
||||
recover(e);
|
||||
ttype = SKIP;
|
||||
}
|
||||
if (_input->LA(1) == IntStream::_EOF) {
|
||||
_hitEOF = true;
|
||||
}
|
||||
if (_type == Token::INVALID_TYPE) {
|
||||
_type = ttype;
|
||||
}
|
||||
if (_type == SKIP) {
|
||||
goto outerContinue;
|
||||
}
|
||||
} while (_type == MORE);
|
||||
if (_token == nullptr) {
|
||||
emit();
|
||||
}
|
||||
return _token;
|
||||
}
|
||||
|
||||
}
|
||||
catch(...) {
|
||||
#ifdef TODO
|
||||
// Do something intelligent here for once
|
||||
#endif
|
||||
}
|
||||
|
||||
// make sure we release marker after match or
|
||||
// unbuffered char stream will keep buffering
|
||||
_input->release(tokenStartMarker);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void Lexer::skip() {
|
||||
_type = SKIP;
|
||||
}
|
||||
|
||||
void Lexer::more() {
|
||||
_type = MORE;
|
||||
}
|
||||
|
||||
void Lexer::mode(int m) {
|
||||
_mode = m;
|
||||
}
|
||||
|
||||
void Lexer::pushMode(int m) {
|
||||
if (atn::LexerATNSimulator::debug) {
|
||||
std::wcout << std::wstring(L"pushMode ") << m << std::endl;
|
||||
}
|
||||
_modeStack.push_back(_mode);
|
||||
mode(m);
|
||||
}
|
||||
|
||||
int Lexer::popMode() {
|
||||
if (_modeStack.empty()) {
|
||||
throw EmptyStackException();
|
||||
}
|
||||
if (atn::LexerATNSimulator::debug) {
|
||||
std::wcout << std::wstring(L"popMode back to ") << _modeStack.back() << std::endl;
|
||||
}
|
||||
mode(_modeStack.back());
|
||||
_modeStack.pop_back();
|
||||
return _mode;
|
||||
}
|
||||
|
||||
|
||||
TokenFactory<CommonToken*> *Lexer::getTokenFactory() {
|
||||
return _factory;
|
||||
}
|
||||
|
||||
void Lexer::setInputStream(IntStream *input) {
|
||||
delete this->_input;
|
||||
this->_tokenFactorySourcePair = new std::pair<TokenSource*, CharStream*>(this, _input);
|
||||
reset();
|
||||
this->_input = static_cast<CharStream*>(input);
|
||||
this->_tokenFactorySourcePair = new std::pair<TokenSource*, CharStream*>(this, _input);
|
||||
}
|
||||
|
||||
std::string Lexer::getSourceName() {
|
||||
return _input->getSourceName();
|
||||
}
|
||||
|
||||
CharStream *Lexer::getInputStream() {
|
||||
return _input;
|
||||
}
|
||||
|
||||
void Lexer::emit(Token *token) {
|
||||
//System.err.println("emit "+token);
|
||||
this->_token = token;
|
||||
}
|
||||
|
||||
Token *Lexer::emit() {
|
||||
Token *t = (Token*)_factory->create(_tokenFactorySourcePair, _type, _text, _channel, _tokenStartCharIndex, getCharIndex() - 1, _tokenStartLine, _tokenStartCharPositionInLine);
|
||||
emit(t);
|
||||
return t;
|
||||
}
|
||||
|
||||
Token *Lexer::emitEOF() {
|
||||
int cpos = getCharPositionInLine();
|
||||
// The character position for EOF is one beyond the position of
|
||||
// the previous token's last character
|
||||
if (_token != nullptr) {
|
||||
int n = _token->getStopIndex() - _token->getStartIndex() + 1;
|
||||
cpos = _token->getCharPositionInLine() + n;
|
||||
}
|
||||
Token *eof = (Token*)_factory->create(_tokenFactorySourcePair, Token::_EOF, L"", Token::DEFAULT_CHANNEL, _input->index(), _input->index() - 1, getLine(), cpos);
|
||||
emit(eof);
|
||||
return eof;
|
||||
}
|
||||
|
||||
int Lexer::getLine() {
|
||||
return getInterpreter()->getLine();
|
||||
}
|
||||
|
||||
int Lexer::getCharPositionInLine() {
|
||||
return getInterpreter()->getCharPositionInLine();
|
||||
}
|
||||
|
||||
void Lexer::setLine(int line) {
|
||||
getInterpreter()->setLine(line);
|
||||
}
|
||||
|
||||
void Lexer::setCharPositionInLine(int charPositionInLine) {
|
||||
getInterpreter()->setCharPositionInLine(charPositionInLine);
|
||||
}
|
||||
|
||||
int Lexer::getCharIndex() {
|
||||
return _input->index();
|
||||
}
|
||||
|
||||
std::wstring Lexer::getText() {
|
||||
if (_text != L"") {
|
||||
return _text;
|
||||
}
|
||||
return getInterpreter()->getText(_input);
|
||||
}
|
||||
|
||||
void Lexer::setText(const std::wstring &text) {
|
||||
this->_text = text;
|
||||
}
|
||||
|
||||
Token *Lexer::getToken() {
|
||||
return _token;
|
||||
}
|
||||
|
||||
void Lexer::setToken(Token *_token) {
|
||||
this->_token = _token;
|
||||
}
|
||||
|
||||
void Lexer::setType(int ttype) {
|
||||
_type = ttype;
|
||||
}
|
||||
|
||||
int Lexer::getType() {
|
||||
return _type;
|
||||
}
|
||||
|
||||
void Lexer::setChannel(int channel) {
|
||||
_channel = channel;
|
||||
}
|
||||
|
||||
int Lexer::getChannel() {
|
||||
return _channel;
|
||||
}
|
||||
|
||||
const std::vector<std::wstring>& Lexer::getModeNames() {
|
||||
return _modeNames;
|
||||
}
|
||||
|
||||
const std::vector<std::wstring>& Lexer::getTokenNames() {
|
||||
return _tokenNames;
|
||||
}
|
||||
|
||||
std::vector<Token*> Lexer::getAllTokens() {
|
||||
std::vector<Token*> tokens = std::vector<Token*>();
|
||||
Token *t = nextToken();
|
||||
while (t->getType() != Token::_EOF) {
|
||||
tokens.push_back(t);
|
||||
t = nextToken();
|
||||
}
|
||||
return tokens;
|
||||
}
|
||||
|
||||
void Lexer::recover(LexerNoViableAltException *e) {
|
||||
if (_input->LA(1) != IntStream::_EOF) {
|
||||
// skip a char and try again
|
||||
getInterpreter()->consume(_input);
|
||||
}
|
||||
}
|
||||
|
||||
void Lexer::notifyListeners(LexerNoViableAltException *e) {
|
||||
std::wstring text = _input->getText(misc::Interval::of(_tokenStartCharIndex, _input->index()));
|
||||
std::wstring msg = std::wstring(L"token recognition error at: '") + getErrorDisplay(text) + std::wstring(L"'");
|
||||
|
||||
ANTLRErrorListener *listener = getErrorListenerDispatch();
|
||||
listener->syntaxError(this, nullptr, _tokenStartLine, _tokenStartCharPositionInLine, msg, e);
|
||||
}
|
||||
|
||||
std::wstring Lexer::getErrorDisplay(const std::wstring &s) {
|
||||
antlrcpp::StringBuilder *buf = new antlrcpp::StringBuilder();
|
||||
|
||||
for (size_t i = 0; i < s.length(); i++) {
|
||||
char c = ((char*)s.c_str())[i];
|
||||
buf->append(getErrorDisplay(c));
|
||||
}
|
||||
/*
|
||||
for (auto c : s.toCharArray()) {
|
||||
buf->append(getErrorDisplay(c));
|
||||
}*/
|
||||
|
||||
return buf->toString();
|
||||
}
|
||||
|
||||
std::wstring Lexer::getErrorDisplay(int c) {
|
||||
std::wstring s = antlrcpp::StringConverterHelper::toString(static_cast<wchar_t>(c));
|
||||
switch (c) {
|
||||
case Token::_EOF :
|
||||
s = L"<EOF>";
|
||||
break;
|
||||
case L'\n' :
|
||||
s = L"\\n";
|
||||
break;
|
||||
case L'\t' :
|
||||
s = L"\\t";
|
||||
break;
|
||||
case L'\r' :
|
||||
s = L"\\r";
|
||||
break;
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
std::wstring Lexer::getCharErrorDisplay(int c) {
|
||||
std::wstring s = getErrorDisplay(c);
|
||||
return std::wstring(L"'") + s + std::wstring(L"'");
|
||||
}
|
||||
|
||||
void Lexer::recover(RecognitionException *re) {
|
||||
//System.out.println("consuming char "+(char)input.LA(1)+" during recovery");
|
||||
//re.printStackTrace();
|
||||
// TODO: Do we lose character or line position information?
|
||||
_input->consume();
|
||||
}
|
||||
|
||||
void Lexer::InitializeInstanceFields() {
|
||||
_factory = CommonTokenFactory::DEFAULT;
|
||||
_tokenStartCharIndex = -1;
|
||||
_tokenStartLine = 0;
|
||||
_tokenStartCharPositionInLine = 0;
|
||||
_hitEOF = false;
|
||||
_channel = 0;
|
||||
_type = 0;
|
||||
_mode = Lexer::DEFAULT_MODE;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,268 @@
|
|||
#pragma once
|
||||
|
||||
#include "Declarations.h"
|
||||
#include "Recognizer.h"
|
||||
#include "Token.h"
|
||||
#include "TokenSource.h"
|
||||
#include "stringconverter.h"
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
/*
|
||||
* [The "BSD license"]
|
||||
* Copyright (c) 2013 Terence Parr
|
||||
* Copyright (c) 2013 Dan McLaughlin
|
||||
* 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. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
||||
*/
|
||||
|
||||
namespace org {
|
||||
namespace antlr {
|
||||
namespace v4 {
|
||||
namespace runtime {
|
||||
/// <summary>
|
||||
/// A lexer is recognizer that draws input symbols from a character stream.
|
||||
/// lexer grammars result in a subclass of this object. A Lexer object
|
||||
/// uses simplified match() and error recovery mechanisms in the interest
|
||||
/// of speed.
|
||||
/// </summary>
|
||||
class Lexer : public Recognizer<int, atn::LexerATNSimulator*>, public TokenSource {
|
||||
public:
|
||||
static const int DEFAULT_MODE = 0;
|
||||
static const int MORE = -2;
|
||||
static const int SKIP = -3;
|
||||
|
||||
static const int DEFAULT_TOKEN_CHANNEL = Token::DEFAULT_CHANNEL;
|
||||
static const int HIDDEN = Token::HIDDEN_CHANNEL;
|
||||
static const wchar_t MIN_CHAR_VALUE = L'\0';
|
||||
static const wchar_t MAX_CHAR_VALUE = L'\uFFFE';
|
||||
|
||||
CharStream *_input;
|
||||
protected:
|
||||
std::pair<TokenSource*, CharStream*> *_tokenFactorySourcePair;
|
||||
|
||||
std::vector<std::wstring> _modeNames;
|
||||
std::vector<std::wstring> _tokenNames;
|
||||
|
||||
/// <summary>
|
||||
/// How to create token objects </summary>
|
||||
TokenFactory<CommonToken*> *_factory;
|
||||
|
||||
/// <summary>
|
||||
/// The goal of all lexer rules/methods is to create a token object.
|
||||
/// This is an instance variable as multiple rules may collaborate to
|
||||
/// create a single token. nextToken will return this object after
|
||||
/// matching lexer rule(s). If you subclass to allow multiple token
|
||||
/// emissions, then set this to the last token to be matched or
|
||||
/// something nonnull so that the auto token emit mechanism will not
|
||||
/// emit another token.
|
||||
/// </summary>
|
||||
public:
|
||||
Token *_token;
|
||||
|
||||
/// <summary>
|
||||
/// What character index in the stream did the current token start at?
|
||||
/// Needed, for example, to get the text for current token. Set at
|
||||
/// the start of nextToken.
|
||||
/// </summary>
|
||||
int _tokenStartCharIndex;
|
||||
|
||||
/// <summary>
|
||||
/// The line on which the first character of the token resides </summary>
|
||||
int _tokenStartLine;
|
||||
|
||||
/// <summary>
|
||||
/// The character position of first character within the line </summary>
|
||||
int _tokenStartCharPositionInLine;
|
||||
|
||||
/// <summary>
|
||||
/// Once we see EOF on char stream, next token will be EOF.
|
||||
/// If you have DONE : EOF ; then you see DONE EOF.
|
||||
/// </summary>
|
||||
bool _hitEOF;
|
||||
|
||||
/// <summary>
|
||||
/// The channel number for the current token </summary>
|
||||
int _channel;
|
||||
|
||||
/// <summary>
|
||||
/// The token type for the current token </summary>
|
||||
int _type;
|
||||
|
||||
// Use the vector as a stack.
|
||||
std::vector<int> _modeStack;
|
||||
int _mode;
|
||||
|
||||
/// <summary>
|
||||
/// You can set the text for the current token to override what is in
|
||||
/// the input char buffer. Use setText() or can set this instance var.
|
||||
/// </summary>
|
||||
std::wstring _text;
|
||||
|
||||
Lexer();
|
||||
|
||||
Lexer(CharStream *input);
|
||||
|
||||
virtual void reset();
|
||||
|
||||
/// <summary>
|
||||
/// Return a token from this source; i.e., match a token on the char
|
||||
/// stream.
|
||||
/// </summary>
|
||||
virtual Token *nextToken();
|
||||
|
||||
/// <summary>
|
||||
/// Instruct the lexer to skip creating a token for current lexer rule
|
||||
/// and look for another token. nextToken() knows to keep looking when
|
||||
/// a lexer rule finishes with token set to SKIP_TOKEN. Recall that
|
||||
/// if token==null at end of any token rule, it creates one for you
|
||||
/// and emits it.
|
||||
/// </summary>
|
||||
virtual void skip();
|
||||
|
||||
virtual void more();
|
||||
|
||||
virtual void mode(int m);
|
||||
|
||||
virtual void pushMode(int m);
|
||||
|
||||
virtual int popMode();
|
||||
|
||||
template<typename T1>
|
||||
void setTokenFactory(TokenFactory<T1> *factory) {
|
||||
this->_factory = factory;
|
||||
}
|
||||
|
||||
virtual TokenFactory<CommonToken*> *getTokenFactory() override;
|
||||
|
||||
/// <summary>
|
||||
/// Set the char stream and reset the lexer </summary>
|
||||
virtual void setInputStream(IntStream *input);
|
||||
|
||||
virtual std::string getSourceName() override;
|
||||
|
||||
virtual CharStream *getInputStream() override;
|
||||
|
||||
/// <summary>
|
||||
/// By default does not support multiple emits per nextToken invocation
|
||||
/// for efficiency reasons. Subclass and override this method, nextToken,
|
||||
/// and getToken (to push tokens into a list and pull from that list
|
||||
/// rather than a single variable as this implementation does).
|
||||
/// </summary>
|
||||
virtual void emit(Token *token);
|
||||
|
||||
/// <summary>
|
||||
/// The standard method called to automatically emit a token at the
|
||||
/// outermost lexical rule. The token object should point into the
|
||||
/// char buffer start..stop. If there is a text override in 'text',
|
||||
/// use that to set the token's text. Override this method to emit
|
||||
/// custom Token objects or provide a new factory.
|
||||
/// </summary>
|
||||
virtual Token *emit();
|
||||
|
||||
virtual Token *emitEOF();
|
||||
|
||||
virtual int getLine() override;
|
||||
|
||||
virtual int getCharPositionInLine() override;
|
||||
|
||||
virtual void setLine(int line);
|
||||
|
||||
virtual void setCharPositionInLine(int charPositionInLine);
|
||||
|
||||
/// <summary>
|
||||
/// What is the index of the current character of lookahead? </summary>
|
||||
virtual int getCharIndex();
|
||||
|
||||
/// <summary>
|
||||
/// Return the text matched so far for the current token or any
|
||||
/// text override.
|
||||
/// </summary>
|
||||
virtual std::wstring getText();
|
||||
|
||||
/// <summary>
|
||||
/// Set the complete text of this token; it wipes any previous
|
||||
/// changes to the text.
|
||||
/// </summary>
|
||||
virtual void setText(const std::wstring &text);
|
||||
|
||||
/// <summary>
|
||||
/// Override if emitting multiple tokens. </summary>
|
||||
virtual Token *getToken();
|
||||
|
||||
virtual void setToken(Token *_token);
|
||||
|
||||
virtual void setType(int ttype);
|
||||
|
||||
virtual int getType();
|
||||
|
||||
virtual void setChannel(int channel);
|
||||
|
||||
virtual int getChannel();
|
||||
|
||||
virtual const std::vector<std::wstring>& getModeNames();
|
||||
|
||||
/// <summary>
|
||||
/// Used to print out token names like ID during debugging and
|
||||
/// error reporting. The generated parsers implement a method
|
||||
/// that overrides this to point to their String[] tokenNames.
|
||||
/// </summary>
|
||||
virtual const std::vector<std::wstring>& getTokenNames() override;
|
||||
|
||||
/// <summary>
|
||||
/// Return a list of all Token objects in input char stream.
|
||||
/// Forces load of all tokens. Does not include EOF token.
|
||||
/// </summary>
|
||||
virtual std::vector<Token*> getAllTokens();
|
||||
|
||||
virtual void recover(LexerNoViableAltException *e);
|
||||
|
||||
virtual void notifyListeners(LexerNoViableAltException *e);
|
||||
|
||||
virtual std::wstring getErrorDisplay(const std::wstring &s);
|
||||
|
||||
virtual std::wstring getErrorDisplay(int c);
|
||||
|
||||
virtual std::wstring getCharErrorDisplay(int c);
|
||||
|
||||
/// <summary>
|
||||
/// Lexers can normally match any char in it's vocabulary after matching
|
||||
/// a token, so do the easy thing and just kill a character and hope
|
||||
/// it all works out. You can instead use the rule invocation stack
|
||||
/// to do sophisticated error recovery if you are in a fragment rule.
|
||||
/// </summary>
|
||||
virtual void recover(RecognitionException *re);
|
||||
|
||||
private:
|
||||
void InitializeInstanceFields();
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,86 @@
|
|||
#include "LexerInterpreter.h"
|
||||
#include "ATNType.h"
|
||||
#include "LexerATNSimulator.h"
|
||||
#include "ATN.h"
|
||||
#include "DFA.h"
|
||||
#include "Exceptions.h"
|
||||
#include "PredictionContextCache.h"
|
||||
|
||||
/*
|
||||
* [The "BSD license"]
|
||||
* Copyright (c) 2013 Terence Parr
|
||||
* Copyright (c) 2013 Dan McLaughlin
|
||||
* 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. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
||||
*/
|
||||
|
||||
namespace org {
|
||||
namespace antlr {
|
||||
namespace v4 {
|
||||
namespace runtime {
|
||||
LexerInterpreter::LexerInterpreter(const std::wstring &grammarFileName, std::vector<std::wstring> *tokenNames, std::vector<std::wstring> *ruleNames, std::vector<std::wstring> *modeNames, atn::ATN *atn, CharStream *input) : Lexer(_input), grammarFileName(grammarFileName), atn(atn), _sharedContextCache(new atn::PredictionContextCache()) {
|
||||
|
||||
if (atn->grammarType != atn::ATNType::LEXER) {
|
||||
throw new IllegalArgumentException(L"The ATN must be a lexer ATN.");
|
||||
}
|
||||
|
||||
|
||||
for (int i = 0; i < (int)_decisionToDFA.size(); i++) {
|
||||
_decisionToDFA[i] = new dfa::DFA(atn->getDecisionState(i), i);
|
||||
}
|
||||
this->_interp = new atn::LexerATNSimulator(atn,_decisionToDFA,_sharedContextCache);
|
||||
if (tokenNames) {
|
||||
_tokenNames = *tokenNames;
|
||||
}
|
||||
if (ruleNames) {
|
||||
_ruleNames = *ruleNames;
|
||||
}
|
||||
if (modeNames) {
|
||||
_modeNames = *modeNames;
|
||||
}
|
||||
}
|
||||
atn::ATN *LexerInterpreter::getATN() {
|
||||
return atn;
|
||||
}
|
||||
|
||||
std::wstring LexerInterpreter::getGrammarFileName() {
|
||||
return grammarFileName;
|
||||
}
|
||||
|
||||
const std::vector<std::wstring>& LexerInterpreter::getTokenNames() {
|
||||
return _tokenNames;
|
||||
}
|
||||
|
||||
const std::vector<std::wstring>& LexerInterpreter::getRuleNames() {
|
||||
return _ruleNames;
|
||||
}
|
||||
|
||||
const std::vector<std::wstring>& LexerInterpreter::getModeNames() {
|
||||
return _modeNames;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,75 @@
|
|||
#pragma once
|
||||
|
||||
#include "Lexer.h"
|
||||
#include "Declarations.h"
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
/*
|
||||
* [The "BSD license"]
|
||||
* Copyright (c) 2013 Terence Parr
|
||||
* Copyright (c) 2013 Dan McLaughlin
|
||||
* 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. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
||||
*/
|
||||
|
||||
namespace org {
|
||||
namespace antlr {
|
||||
namespace v4 {
|
||||
namespace runtime {
|
||||
class LexerInterpreter : public Lexer {
|
||||
protected:
|
||||
const std::wstring grammarFileName;
|
||||
atn::ATN *const atn;
|
||||
|
||||
|
||||
std::vector<std::wstring> _tokenNames;
|
||||
|
||||
std::vector<std::wstring> _ruleNames;
|
||||
|
||||
std::vector<std::wstring> _modeNames;
|
||||
|
||||
std::vector<dfa::DFA*> _decisionToDFA;
|
||||
|
||||
atn::PredictionContextCache *const _sharedContextCache;
|
||||
|
||||
public:
|
||||
LexerInterpreter(const std::wstring &grammarFileName, std::vector<std::wstring> *tokenNames, std::vector<std::wstring> *ruleNames, std::vector<std::wstring> *modeNames, atn::ATN *atn, CharStream *input);
|
||||
|
||||
virtual atn::ATN *getATN() override;
|
||||
|
||||
virtual std::wstring getGrammarFileName() override;
|
||||
|
||||
virtual const std::vector<std::wstring>& getTokenNames() override;
|
||||
|
||||
virtual const std::vector<std::wstring>& getRuleNames() override;
|
||||
|
||||
virtual const std::vector<std::wstring>& getModeNames() override;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,73 @@
|
|||
#include "LexerNoViableAltException.h"
|
||||
#include "RecognitionException.h"
|
||||
#include "Interval.h"
|
||||
#include "CPPUtils.h"
|
||||
#include "CharStream.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <wchar.h>
|
||||
|
||||
/*
|
||||
* [The "BSD license"]
|
||||
* Copyright (c) 2013 Terence Parr
|
||||
* Copyright (c) 2013 Dan McLaughlin
|
||||
* 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. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
||||
*/
|
||||
|
||||
namespace org {
|
||||
namespace antlr {
|
||||
namespace v4 {
|
||||
namespace runtime {
|
||||
|
||||
|
||||
LexerNoViableAltException::LexerNoViableAltException(Lexer *lexer, CharStream *input, int startIndex, atn::ATNConfigSet *deadEndConfigs) : RecognitionException()/*TODO RecognitionException(lexer, input, nullptr)*/, startIndex(startIndex), deadEndConfigs(deadEndConfigs) {
|
||||
}
|
||||
|
||||
int LexerNoViableAltException::getStartIndex() {
|
||||
return startIndex;
|
||||
}
|
||||
|
||||
atn::ATNConfigSet *LexerNoViableAltException::getDeadEndConfigs() {
|
||||
return deadEndConfigs;
|
||||
}
|
||||
|
||||
runtime::CharStream *LexerNoViableAltException::getInputStream() {
|
||||
return (CharStream*)(RecognitionException::getInputStream());
|
||||
}
|
||||
|
||||
std::wstring LexerNoViableAltException::toString() {
|
||||
std::wstring symbol = L"";
|
||||
if (startIndex >= 0 && startIndex < (int)getInputStream()->size()) {
|
||||
symbol = getInputStream()->getText(misc::Interval::of(startIndex,startIndex));
|
||||
symbol = antlrcpp::escapeWhitespace(symbol, false);
|
||||
}
|
||||
std::wstring format = L"LexerNoViableAltException('" + symbol + L"')";
|
||||
return format;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,72 @@
|
|||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "RecognitionException.h"
|
||||
#include "Declarations.h"
|
||||
|
||||
|
||||
/*
|
||||
* [The "BSD license"]
|
||||
* Copyright (c) 2013 Terence Parr
|
||||
* Copyright (c) 2013 Dan McLaughlin
|
||||
* 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. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
||||
*/
|
||||
|
||||
#include "CharStream.h"
|
||||
|
||||
namespace org {
|
||||
namespace antlr {
|
||||
namespace v4 {
|
||||
namespace runtime {
|
||||
|
||||
|
||||
class LexerNoViableAltException : public RecognitionException {
|
||||
/// <summary>
|
||||
/// Matching attempted at what input index? </summary>
|
||||
private:
|
||||
const int startIndex;
|
||||
|
||||
/// <summary>
|
||||
/// Which configurations did we try at input.index() that couldn't match input.LA(1)? </summary>
|
||||
atn::ATNConfigSet *const deadEndConfigs;
|
||||
|
||||
public:
|
||||
LexerNoViableAltException(Lexer *lexer, CharStream *input, int startIndex, atn::ATNConfigSet *deadEndConfigs);
|
||||
|
||||
virtual int getStartIndex();
|
||||
|
||||
virtual atn::ATNConfigSet *getDeadEndConfigs();
|
||||
|
||||
virtual CharStream *getInputStream() override;
|
||||
|
||||
virtual std::wstring toString();
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,157 @@
|
|||
#include "ListTokenSource.h"
|
||||
#include "Token.h"
|
||||
|
||||
/*
|
||||
* [The "BSD license"]
|
||||
* Copyright (c) 2013 Terence Parr
|
||||
* Copyright (c) 2013 Dan McLaughlin
|
||||
* 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. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
||||
*/
|
||||
|
||||
namespace org {
|
||||
namespace antlr {
|
||||
namespace v4 {
|
||||
namespace runtime {
|
||||
|
||||
int ListTokenSource::getCharPositionInLine() {
|
||||
if (i < tokens.size()) {
|
||||
return ((Token*)tokens[i])->getCharPositionInLine();
|
||||
} else if (eofToken != nullptr) {
|
||||
return eofToken->getCharPositionInLine();
|
||||
} else if (tokens.size() > 0) {
|
||||
// have to calculate the result from the line/column of the previous
|
||||
// token, along with the text of the token.
|
||||
Token *lastToken = tokens[tokens.size() - 1];
|
||||
std::wstring tokenText = lastToken->getText();
|
||||
if (tokenText != L"") {
|
||||
int lastNewLine = (int)tokenText.rfind(L'\n');
|
||||
if (lastNewLine >= 0) {
|
||||
return (int)tokenText.length() - lastNewLine - 1;
|
||||
}
|
||||
}
|
||||
|
||||
return lastToken->getCharPositionInLine() + lastToken->getStopIndex() - lastToken->getStartIndex() + 1;
|
||||
}
|
||||
|
||||
// only reach this if tokens is empty, meaning EOF occurs at the first
|
||||
// position in the input
|
||||
return 0;
|
||||
}
|
||||
|
||||
Token *ListTokenSource::nextToken() {
|
||||
if (i >= tokens.size()) {
|
||||
if (eofToken == nullptr) {
|
||||
int start = -1;
|
||||
if (tokens.size() > 0) {
|
||||
int previousStop = ((Token*)tokens[tokens.size() - 1])->getStopIndex();
|
||||
if (previousStop != -1) {
|
||||
start = previousStop + 1;
|
||||
}
|
||||
}
|
||||
|
||||
int stop = std::max(-1, start - 1);
|
||||
eofToken = _factory->create(new std::pair<TokenSource*, CharStream*>(this, getInputStream()), Token::_EOF, L"EOF", Token::DEFAULT_CHANNEL, start, stop, getLine(), getCharPositionInLine());
|
||||
}
|
||||
|
||||
return eofToken;
|
||||
}
|
||||
|
||||
Token *t = tokens[i];
|
||||
if (i == tokens.size() - 1 && t->getType() == Token::_EOF) {
|
||||
eofToken = t;
|
||||
}
|
||||
|
||||
i++;
|
||||
return t;
|
||||
}
|
||||
|
||||
int ListTokenSource::getLine() {
|
||||
if (i < tokens.size()) {
|
||||
return tokens[i]->getLine();
|
||||
} else if (eofToken != nullptr) {
|
||||
return eofToken->getLine();
|
||||
} else if (tokens.size() > 0) {
|
||||
// have to calculate the result from the line/column of the previous
|
||||
// token, along with the text of the token.
|
||||
Token *lastToken = tokens[tokens.size() - 1];
|
||||
int line = lastToken->getLine();
|
||||
|
||||
std::wstring tokenText = lastToken->getText();
|
||||
if (tokenText != L"") {
|
||||
for (size_t i = 0; i < tokenText.length(); i++) {
|
||||
if (tokenText[i] == L'\n') {
|
||||
line++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// if no text is available, assume the token did not contain any newline characters.
|
||||
return line;
|
||||
}
|
||||
|
||||
// only reach this if tokens is empty, meaning EOF occurs at the first
|
||||
// position in the input
|
||||
return 1;
|
||||
}
|
||||
|
||||
CharStream *ListTokenSource::getInputStream() {
|
||||
if (i < tokens.size()) {
|
||||
return tokens[i]->getInputStream();
|
||||
} else if (eofToken != nullptr) {
|
||||
return eofToken->getInputStream();
|
||||
} else if (tokens.size() > 0) {
|
||||
return tokens[tokens.size() - 1]->getInputStream();
|
||||
}
|
||||
|
||||
// no input stream information is available
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::string ListTokenSource::getSourceName() {
|
||||
if (sourceName != "") {
|
||||
return sourceName;
|
||||
}
|
||||
|
||||
CharStream *inputStream = getInputStream();
|
||||
if (inputStream != nullptr) {
|
||||
return inputStream->getSourceName();
|
||||
}
|
||||
|
||||
return "List";
|
||||
}
|
||||
|
||||
TokenFactory<CommonToken*> *ListTokenSource::getTokenFactory() {
|
||||
return _factory;
|
||||
}
|
||||
|
||||
void ListTokenSource::InitializeInstanceFields() {
|
||||
i = 0;
|
||||
_factory = CommonTokenFactory::DEFAULT;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,170 @@
|
|||
#pragma once
|
||||
|
||||
#include "TokenSource.h"
|
||||
#include "TokenFactory.h"
|
||||
#include "CharStream.h"
|
||||
#include "CommonTokenFactory.h"
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
/*
|
||||
* [The "BSD license"]
|
||||
* Copyright (c) 2013 Terence Parr
|
||||
* Copyright (c) 2013 Dan McLaughlin
|
||||
* 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. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
namespace org {
|
||||
namespace antlr {
|
||||
namespace v4 {
|
||||
namespace runtime {
|
||||
|
||||
/// <summary>
|
||||
/// Provides an implementation of <seealso cref="TokenSource"/> as a wrapper around a list
|
||||
/// of <seealso cref="Token"/> objects.
|
||||
/// <p/>
|
||||
/// If the final token in the list is an <seealso cref="Token#EOF"/> token, it will be used
|
||||
/// as the EOF token for every call to <seealso cref="#nextToken"/> after the end of the
|
||||
/// list is reached. Otherwise, an EOF token will be created.
|
||||
/// </summary>
|
||||
class ListTokenSource : public TokenSource {
|
||||
/// <summary>
|
||||
/// The wrapped collection of <seealso cref="Token"/> objects to return.
|
||||
/// </summary>
|
||||
protected:
|
||||
const std::vector<Token *> tokens;
|
||||
|
||||
/// <summary>
|
||||
/// The name of the input source. If this value is {@code null}, a call to
|
||||
/// <seealso cref="#getSourceName"/> should return the source name used to create the
|
||||
/// the next token in <seealso cref="#tokens"/> (or the previous token if the end of
|
||||
/// the input has been reached).
|
||||
/// </summary>
|
||||
private:
|
||||
const std::string sourceName;
|
||||
|
||||
/// <summary>
|
||||
/// The index into <seealso cref="#tokens"/> of token to return by the next call to
|
||||
/// <seealso cref="#nextToken"/>. The end of the input is indicated by this value
|
||||
/// being greater than or equal to the number of items in <seealso cref="#tokens"/>.
|
||||
/// </summary>
|
||||
protected:
|
||||
size_t i;
|
||||
|
||||
/// <summary>
|
||||
/// This field caches the EOF token for the token source.
|
||||
/// </summary>
|
||||
Token *eofToken;
|
||||
|
||||
/// <summary>
|
||||
/// This is the backing field for <seealso cref="#getTokenFactory"/> and
|
||||
/// <seealso cref="setTokenFactory"/>.
|
||||
/// </summary>
|
||||
private:
|
||||
TokenFactory<CommonToken *> *_factory = CommonTokenFactory::DEFAULT;
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a new <seealso cref="ListTokenSource"/> instance from the specified
|
||||
/// collection of <seealso cref="Token"/> objects.
|
||||
/// </summary>
|
||||
/// <param name="tokens"> The collection of <seealso cref="Token"/> objects to provide as a
|
||||
/// <seealso cref="TokenSource"/>. </param>
|
||||
/// <exception cref="NullPointerException"> if {@code tokens} is {@code null} </exception>
|
||||
public:
|
||||
|
||||
template<typename T1> //where T1 : Token
|
||||
ListTokenSource(std::vector<T1> tokens) //this(tokens, nullptr);
|
||||
{}
|
||||
/// <summary>
|
||||
/// Constructs a new <seealso cref="ListTokenSource"/> instance from the specified
|
||||
/// collection of <seealso cref="Token"/> objects and source name.
|
||||
/// </summary>
|
||||
/// <param name="tokens"> The collection of <seealso cref="Token"/> objects to provide as a
|
||||
/// <seealso cref="TokenSource"/>. </param>
|
||||
/// <param name="sourceName"> The name of the <seealso cref="TokenSource"/>. If this value is
|
||||
/// {@code null}, <seealso cref="#getSourceName"/> will attempt to infer the name from
|
||||
/// the next <seealso cref="Token"/> (or the previous token if the end of the input has
|
||||
/// been reached).
|
||||
/// </param>
|
||||
/// <exception cref="NullPointerException"> if {@code tokens} is {@code null} </exception>
|
||||
|
||||
template<typename T1> //where T1 : Token
|
||||
ListTokenSource(std::vector<T1> tokens, const std::string &sourceName) {
|
||||
InitializeInstanceFields();
|
||||
if (tokens.empty()) {
|
||||
throw L"tokens cannot be null";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// @inheritDoc
|
||||
/// </summary>
|
||||
virtual int getCharPositionInLine() override;
|
||||
|
||||
/// <summary>
|
||||
/// @inheritDoc
|
||||
/// </summary>
|
||||
virtual Token *nextToken() override;
|
||||
|
||||
/// <summary>
|
||||
/// @inheritDoc
|
||||
/// </summary>
|
||||
virtual int getLine() override;
|
||||
|
||||
/// <summary>
|
||||
/// @inheritDoc
|
||||
/// </summary>
|
||||
virtual CharStream *getInputStream() override;
|
||||
|
||||
/// <summary>
|
||||
/// @inheritDoc
|
||||
/// </summary>
|
||||
virtual std::string getSourceName() override;
|
||||
|
||||
/// <summary>
|
||||
/// @inheritDoc
|
||||
/// </summary>
|
||||
template<typename T1>
|
||||
void setTokenFactory(TokenFactory<T1> *factory) {
|
||||
this->_factory = factory;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// @inheritDoc
|
||||
/// </summary>
|
||||
virtual TokenFactory<CommonToken *> *getTokenFactory();
|
||||
|
||||
private:
|
||||
void InitializeInstanceFields();
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,63 @@
|
|||
#include "NoViableAltException.h"
|
||||
|
||||
#include "atn/ATNConfigSet.h"
|
||||
#include "Token.h"
|
||||
#include "Parser.h"
|
||||
#include "ParserRuleContext.h"
|
||||
#include "TokenStream.h"
|
||||
|
||||
/*
|
||||
* [The "BSD license"]
|
||||
* Copyright (c) 2013 Terence Parr
|
||||
* Copyright (c) 2013 Dan McLaughlin
|
||||
* 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. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
||||
*/
|
||||
|
||||
namespace org {
|
||||
namespace antlr {
|
||||
namespace v4 {
|
||||
namespace runtime {
|
||||
|
||||
|
||||
NoViableAltException::NoViableAltException(Parser *recognizer) :deadEndConfigs(nullptr), startToken(nullptr) {
|
||||
}
|
||||
|
||||
NoViableAltException::NoViableAltException(Parser *recognizer, TokenStream *input, Token *startToken, Token *offendingToken, ATNConfigSet *deadEndConfigs, ParserRuleContext *ctx) : RecognitionException(recognizer, input, ctx),
|
||||
deadEndConfigs(deadEndConfigs), startToken(startToken) {
|
||||
this->setOffendingToken(offendingToken);
|
||||
}
|
||||
|
||||
Token *NoViableAltException::getStartToken() {
|
||||
return startToken;
|
||||
}
|
||||
|
||||
atn::ATNConfigSet *NoViableAltException::getDeadEndConfigs() {
|
||||
return deadEndConfigs;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,77 @@
|
|||
#pragma once
|
||||
|
||||
#include "RecognitionException.h"
|
||||
|
||||
|
||||
/*
|
||||
* [The "BSD license"]
|
||||
* Copyright (c) 2013 Terence Parr
|
||||
* Copyright (c) 2013 Dan McLaughlin
|
||||
* 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. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
||||
*/
|
||||
namespace org {
|
||||
namespace antlr {
|
||||
namespace v4 {
|
||||
namespace runtime {
|
||||
|
||||
using org::antlr::v4::runtime::atn::ATNConfigSet;
|
||||
using org::antlr::v4::runtime::misc::NotNull;
|
||||
|
||||
/// <summary>
|
||||
/// Indicates that the parser could not decide which of two or more paths
|
||||
/// to take based upon the remaining input. It tracks the starting token
|
||||
/// of the offending input and also knows where the parser was
|
||||
/// in the various paths when the error. Reported by reportNoViableAlternative()
|
||||
/// </summary>
|
||||
class NoViableAltException : public RecognitionException {
|
||||
/// <summary>
|
||||
/// Which configurations did we try at input.index() that couldn't match input.LT(1)? </summary>
|
||||
private:
|
||||
ATNConfigSet *const deadEndConfigs;
|
||||
|
||||
/// <summary>
|
||||
/// The token object at the start index; the input stream might
|
||||
/// not be buffering tokens so get a reference to it. (At the
|
||||
/// time the error occurred, of course the stream needs to keep a
|
||||
/// buffer all of the tokens but later we might not have access to those.)
|
||||
/// </summary>
|
||||
Token *const startToken;
|
||||
|
||||
public:
|
||||
NoViableAltException(Parser *recognizer); // LL(1) error - this(recognizer, recognizer.getInputStream(), recognizer.getCurrentToken(), recognizer.getCurrentToken(), nullptr, recognizer._ctx);
|
||||
|
||||
NoViableAltException(Parser *recognizer, TokenStream *input, Token *startToken, Token *offendingToken, ATNConfigSet *deadEndConfigs, ParserRuleContext *ctx);
|
||||
|
||||
virtual Token *getStartToken();
|
||||
|
||||
virtual ATNConfigSet *getDeadEndConfigs();
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,625 @@
|
|||
#include <locale>
|
||||
#include <vector>
|
||||
|
||||
#include "Parser.h"
|
||||
#include "ATNSimulator.h"
|
||||
#include "ATNDeserializationOptions.h"
|
||||
#include "ATNDeserializer.h"
|
||||
#include "TokenSource.h"
|
||||
#include "tree/pattern/ParseTreePatternMatcher.h"
|
||||
#include "ANTLRErrorListener.h"
|
||||
#include "ATNState.h"
|
||||
#include "DFA.h"
|
||||
#include "ParserRuleContext.h"
|
||||
#include "Token.h"
|
||||
#include "TerminalNode.h"
|
||||
#include "TokenStream.h"
|
||||
#include "ANTLRErrorStrategy.h"
|
||||
#include "Exceptions.h"
|
||||
#include "ParseTreeListener.h"
|
||||
#include "ParseTree.h"
|
||||
#include "Lexer.h"
|
||||
#include "ATN.h"
|
||||
#include "ParserATNSimulator.h"
|
||||
#include "IntervalSet.h"
|
||||
#include "RuleStartState.h"
|
||||
#include "DefaultErrorStrategy.h"
|
||||
#include "Strings.h"
|
||||
|
||||
/*
|
||||
* [The "BSD license"]
|
||||
* Copyright (c) 2013 Terence Parr
|
||||
* Copyright (c) 2013 Dan McLaughlin
|
||||
* 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. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
||||
*/
|
||||
namespace org {
|
||||
namespace antlr {
|
||||
namespace v4 {
|
||||
namespace runtime {
|
||||
|
||||
std::map<std::wstring, atn::ATN*> * Parser::bypassAltsAtnCache = new std::map<std::wstring, atn::ATN*>();
|
||||
|
||||
Parser::TraceListener::TraceListener(Parser *outerInstance) : outerInstance(outerInstance) {
|
||||
}
|
||||
|
||||
void Parser::TraceListener::enterEveryRule(ParserRuleContext *ctx) {
|
||||
std::cout << "enter "
|
||||
<< antlrcpp::ws2s(outerInstance->getRuleNames()[ctx->getRuleIndex()])
|
||||
<< ", LT(1)=" << antlrcpp::ws2s(outerInstance->_input->LT(1)->getText())
|
||||
<< std::endl;
|
||||
}
|
||||
|
||||
void Parser::TraceListener::visitTerminal(tree::TerminalNode *node) {
|
||||
std::cout << "consume "
|
||||
<< node->getSymbol() << " rule "
|
||||
<< antlrcpp::ws2s(outerInstance->getRuleNames()[outerInstance->_ctx->getRuleIndex()])
|
||||
<< std::endl;
|
||||
}
|
||||
|
||||
void Parser::TraceListener::visitErrorNode(tree::ErrorNode *node) {
|
||||
}
|
||||
|
||||
void Parser::TraceListener::exitEveryRule(ParserRuleContext *ctx) {
|
||||
std::cout << "exit "
|
||||
<< antlrcpp::ws2s(outerInstance->getRuleNames()[ctx->getRuleIndex()])
|
||||
<< ", LT(1)=" << antlrcpp::ws2s(outerInstance->_input->LT(1)->getText())
|
||||
<< std::endl;
|
||||
}
|
||||
|
||||
Parser::TrimToSizeListener *const Parser::TrimToSizeListener::INSTANCE = new Parser::TrimToSizeListener();
|
||||
|
||||
void Parser::TrimToSizeListener::enterEveryRule(ParserRuleContext *ctx) {
|
||||
}
|
||||
|
||||
void Parser::TrimToSizeListener::visitTerminal(tree::TerminalNode *node) {
|
||||
}
|
||||
|
||||
void Parser::TrimToSizeListener::visitErrorNode(tree::ErrorNode *node) {
|
||||
}
|
||||
|
||||
void Parser::TrimToSizeListener::exitEveryRule(ParserRuleContext *ctx) {
|
||||
// TODO: Need to figure out what type this is going to be. In Java we expect it to be set by the generator.
|
||||
std::vector<tree::ParseTree*>* tmp = dynamic_cast<std::vector<tree::ParseTree*>*>(&ctx->children);
|
||||
if (tmp != nullptr) {
|
||||
tmp->shrink_to_fit();
|
||||
}
|
||||
}
|
||||
|
||||
Parser::Parser(TokenStream* input) {
|
||||
InitializeInstanceFields();
|
||||
setInputStream(input);
|
||||
|
||||
// TODO: Initialize this safely and handle concurrent accesses.
|
||||
// TODO: For now treat this as a member variable but it should be shared across instances for speed.
|
||||
Parser::bypassAltsAtnCache =
|
||||
new std::map<std::wstring, atn::ATN*>();
|
||||
}
|
||||
|
||||
void Parser::reset() {
|
||||
if (getInputStream() != nullptr) {
|
||||
getInputStream()->seek(0);
|
||||
}
|
||||
_errHandler->reset(this);
|
||||
|
||||
delete _ctx;
|
||||
_syntaxErrors = 0;
|
||||
setTrace(false);
|
||||
_precedenceStack.clear();
|
||||
_precedenceStack.push_back(0);
|
||||
atn::ATNSimulator *interpreter = getInterpreter();
|
||||
if (interpreter != nullptr) {
|
||||
interpreter->reset();
|
||||
}
|
||||
}
|
||||
|
||||
Token *Parser::match(int ttype) {
|
||||
Token *t = getCurrentToken();
|
||||
if (t->getType() == ttype) {
|
||||
_errHandler->reportMatch(this);
|
||||
consume();
|
||||
} else {
|
||||
t = _errHandler->recoverInline(this);
|
||||
if (_buildParseTrees && t->getTokenIndex() == -1) {
|
||||
// we must have conjured up a new token during single token insertion
|
||||
// if it's not the current symbol
|
||||
_ctx->addErrorNode(t);
|
||||
}
|
||||
}
|
||||
return t;
|
||||
}
|
||||
|
||||
Token *Parser::matchWildcard() {
|
||||
Token *t = getCurrentToken();
|
||||
if (t->getType() > 0) {
|
||||
_errHandler->reportMatch(this);
|
||||
consume();
|
||||
} else {
|
||||
t = _errHandler->recoverInline(this);
|
||||
if (_buildParseTrees && t->getTokenIndex() == -1) {
|
||||
// we must have conjured up a new token during single token insertion
|
||||
// if it's not the current symbol
|
||||
_ctx->addErrorNode(t);
|
||||
}
|
||||
}
|
||||
|
||||
return t;
|
||||
}
|
||||
|
||||
void Parser::setBuildParseTree(bool buildParseTrees) {
|
||||
this->_buildParseTrees = buildParseTrees;
|
||||
}
|
||||
|
||||
bool Parser::getBuildParseTree() {
|
||||
return _buildParseTrees;
|
||||
}
|
||||
|
||||
void Parser::setTrimParseTree(bool trimParseTrees) {
|
||||
if (trimParseTrees) {
|
||||
if (getTrimParseTree()) {
|
||||
return;
|
||||
}
|
||||
addParseListener(TrimToSizeListener::INSTANCE);
|
||||
} else {
|
||||
removeParseListener(TrimToSizeListener::INSTANCE);
|
||||
}
|
||||
}
|
||||
|
||||
bool Parser::getTrimParseTree() {
|
||||
return std::find(getParseListeners().begin(), getParseListeners().end(), TrimToSizeListener::INSTANCE) != getParseListeners().end();
|
||||
}
|
||||
|
||||
std::vector<tree::ParseTreeListener*> Parser::getParseListeners() {
|
||||
std::vector<tree::ParseTreeListener*> listeners = _parseListeners;
|
||||
if (listeners.empty()) {
|
||||
std::vector<tree::ParseTreeListener*> emptyList;
|
||||
return emptyList;
|
||||
}
|
||||
|
||||
return listeners;
|
||||
}
|
||||
|
||||
void Parser::addParseListener(tree::ParseTreeListener *listener) {
|
||||
if (listener == nullptr) {
|
||||
throw NullPointerException(L"listener");
|
||||
}
|
||||
|
||||
if (_parseListeners.empty()) {
|
||||
_parseListeners = std::vector<tree::ParseTreeListener*>();
|
||||
}
|
||||
|
||||
this->_parseListeners.push_back(listener);
|
||||
}
|
||||
|
||||
void Parser::removeParseListener(tree::ParseTreeListener *listener) {
|
||||
if (!_parseListeners.empty()) {
|
||||
auto it = std::find(_parseListeners.begin(), _parseListeners.end(), listener);
|
||||
if (it != _parseListeners.end()) {
|
||||
_parseListeners.erase(it);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Parser::removeParseListeners() {
|
||||
_parseListeners.clear();
|
||||
}
|
||||
|
||||
void Parser::triggerEnterRuleEvent() {
|
||||
for (auto listener : _parseListeners) {
|
||||
listener->enterEveryRule(_ctx);
|
||||
_ctx->enterRule(listener);
|
||||
}
|
||||
}
|
||||
|
||||
void Parser::triggerExitRuleEvent() {
|
||||
// reverse order walk of listeners
|
||||
for (auto it = _parseListeners.rbegin(); it != _parseListeners.rend(); ++it) {
|
||||
tree::ParseTreeListener *listener = *it;
|
||||
_ctx->exitRule(*it);
|
||||
listener->exitEveryRule(_ctx);
|
||||
}
|
||||
}
|
||||
|
||||
int Parser::getNumberOfSyntaxErrors() {
|
||||
return _syntaxErrors;
|
||||
}
|
||||
|
||||
TokenFactory<CommonToken*> *Parser::getTokenFactory() {
|
||||
return _input->getTokenSource()->getTokenFactory();
|
||||
}
|
||||
|
||||
|
||||
atn::ATN *Parser::getATNWithBypassAlts() {
|
||||
std::wstring serializedAtn = getSerializedATN();
|
||||
if (serializedAtn == L"") {
|
||||
throw UnsupportedOperationException(L"The current parser does not support an ATN with bypass alternatives.");
|
||||
}
|
||||
|
||||
if (bypassAltsAtnCache != nullptr) {
|
||||
std::lock_guard<std::mutex> lck(mtx);
|
||||
atn::ATN *result = bypassAltsAtnCache->at(serializedAtn);
|
||||
if (result == nullptr) {
|
||||
atn::ATNDeserializationOptions *deserializationOptions = new atn::ATNDeserializationOptions();
|
||||
deserializationOptions->setGenerateRuleBypassTransitions(true);
|
||||
result = (new atn::ATNDeserializer(deserializationOptions))->deserialize(serializedAtn);
|
||||
bypassAltsAtnCache->emplace(serializedAtn, result);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
tree::pattern::ParseTreePattern *Parser::compileParseTreePattern(const std::wstring &pattern, int patternRuleIndex) {
|
||||
if (getTokenStream() != nullptr) {
|
||||
TokenSource *tokenSource = getTokenStream()->getTokenSource();
|
||||
if (dynamic_cast<Lexer*>(tokenSource) != nullptr) {
|
||||
Lexer *lexer = static_cast<Lexer*>(tokenSource);
|
||||
return compileParseTreePattern(pattern, patternRuleIndex, lexer);
|
||||
}
|
||||
}
|
||||
throw UnsupportedOperationException(L"Parser can't discover a lexer to use");
|
||||
}
|
||||
|
||||
tree::pattern::ParseTreePattern *Parser::compileParseTreePattern(const std::wstring &pattern, int patternRuleIndex, Lexer *lexer) {
|
||||
tree::pattern::ParseTreePatternMatcher *m = new tree::pattern::ParseTreePatternMatcher(lexer, this);
|
||||
return m->compile(pattern, patternRuleIndex);
|
||||
}
|
||||
|
||||
ANTLRErrorStrategy *Parser::getErrorHandler() {
|
||||
return _errHandler;
|
||||
}
|
||||
|
||||
void Parser::setErrorHandler(ANTLRErrorStrategy *handler) {
|
||||
this->_errHandler = handler;
|
||||
}
|
||||
|
||||
TokenStream *Parser::getInputStream() {
|
||||
return getTokenStream();
|
||||
}
|
||||
|
||||
void Parser::setInputStream(IntStream *input) {
|
||||
setTokenStream(static_cast<TokenStream*>(input));
|
||||
}
|
||||
|
||||
TokenStream *Parser::getTokenStream() {
|
||||
return _input;
|
||||
}
|
||||
|
||||
void Parser::setTokenStream(TokenStream *input) {
|
||||
delete this->_input;
|
||||
reset();
|
||||
this->_input = input;
|
||||
}
|
||||
|
||||
Token *Parser::getCurrentToken() {
|
||||
return _input->LT(1);
|
||||
}
|
||||
|
||||
void Parser::notifyErrorListeners(const std::wstring &msg) {
|
||||
notifyErrorListeners(getCurrentToken(), msg, nullptr);
|
||||
}
|
||||
|
||||
void Parser::notifyErrorListeners(Token *offendingToken, const std::wstring &msg, RecognitionException *e) {
|
||||
_syntaxErrors++;
|
||||
int line = -1;
|
||||
int charPositionInLine = -1;
|
||||
line = offendingToken->getLine();
|
||||
charPositionInLine = offendingToken->getCharPositionInLine();
|
||||
|
||||
ANTLRErrorListener *listener = getErrorListenerDispatch();
|
||||
listener->syntaxError(this, offendingToken, line, charPositionInLine, msg, e);
|
||||
}
|
||||
|
||||
Token *Parser::consume() {
|
||||
Token *o = getCurrentToken();
|
||||
if (o->getType() != EOF) {
|
||||
getInputStream()->consume();
|
||||
}
|
||||
bool hasListener = _parseListeners.size() > 0 && !_parseListeners.empty();
|
||||
if (_buildParseTrees || hasListener) {
|
||||
if (_errHandler->inErrorRecoveryMode(this)) {
|
||||
tree::ErrorNode *node = _ctx->addErrorNode(o);
|
||||
if (_parseListeners.size() > 0) {
|
||||
for (auto listener : _parseListeners) {
|
||||
listener->visitErrorNode(node);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
tree::TerminalNode *node = _ctx->addChild(o);
|
||||
if (_parseListeners.size() > 0) {
|
||||
for (auto listener : _parseListeners) {
|
||||
listener->visitTerminal(node);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return o;
|
||||
}
|
||||
|
||||
void Parser::addContextToParseTree() {
|
||||
ParserRuleContext *parent = static_cast<ParserRuleContext*>(_ctx->parent);
|
||||
// add current context to parent if we have a parent
|
||||
if (parent != nullptr) {
|
||||
parent->addChild(_ctx);
|
||||
}
|
||||
}
|
||||
|
||||
void Parser::enterRule(ParserRuleContext *localctx, int state, int ruleIndex) {
|
||||
setState(state);
|
||||
_ctx = localctx;
|
||||
_ctx->start = _input->LT(1);
|
||||
if (_buildParseTrees) {
|
||||
addContextToParseTree();
|
||||
}
|
||||
if (_parseListeners.size() > 0) {
|
||||
triggerEnterRuleEvent();
|
||||
}
|
||||
}
|
||||
|
||||
void Parser::exitRule() {
|
||||
_ctx->stop = _input->LT(-1);
|
||||
// trigger event on _ctx, before it reverts to parent
|
||||
if (_parseListeners.size() > 0) {
|
||||
triggerExitRuleEvent();
|
||||
}
|
||||
setState(_ctx->invokingState);
|
||||
_ctx = static_cast<ParserRuleContext*>(_ctx->parent);
|
||||
}
|
||||
|
||||
void Parser::enterOuterAlt(ParserRuleContext *localctx, int altNum) {
|
||||
// if we have new localctx, make sure we replace existing ctx
|
||||
// that is previous child of parse tree
|
||||
if (_buildParseTrees && _ctx != localctx) {
|
||||
ParserRuleContext *parent = static_cast<ParserRuleContext*>(_ctx->parent);
|
||||
if (parent != nullptr) {
|
||||
parent->removeLastChild();
|
||||
parent->addChild(localctx);
|
||||
}
|
||||
}
|
||||
_ctx = localctx;
|
||||
}
|
||||
|
||||
void Parser::enterRecursionRule(ParserRuleContext *localctx, int ruleIndex) {
|
||||
enterRecursionRule(localctx, getATN()->ruleToStartState[ruleIndex]->stateNumber, ruleIndex, 0);
|
||||
}
|
||||
|
||||
void Parser::enterRecursionRule(ParserRuleContext *localctx, int state, int ruleIndex, int precedence) {
|
||||
setState(state);
|
||||
_precedenceStack.push_back(precedence);
|
||||
_ctx = localctx;
|
||||
_ctx->start = _input->LT(1);
|
||||
if (_parseListeners.size() > 0) {
|
||||
triggerEnterRuleEvent(); // simulates rule entry for left-recursive rules
|
||||
}
|
||||
}
|
||||
|
||||
void Parser::pushNewRecursionContext(ParserRuleContext *localctx, int state, int ruleIndex) {
|
||||
ParserRuleContext *previous = _ctx;
|
||||
previous->parent = localctx;
|
||||
previous->invokingState = state;
|
||||
previous->stop = _input->LT(-1);
|
||||
|
||||
_ctx = localctx;
|
||||
_ctx->start = previous->start;
|
||||
if (_buildParseTrees) {
|
||||
_ctx->addChild(previous);
|
||||
}
|
||||
|
||||
if (_parseListeners.size() > 0) {
|
||||
triggerEnterRuleEvent(); // simulates rule entry for left-recursive rules
|
||||
}
|
||||
}
|
||||
|
||||
void Parser::unrollRecursionContexts(ParserRuleContext *_parentctx) {
|
||||
_precedenceStack.pop_back();
|
||||
_ctx->stop = _input->LT(-1);
|
||||
ParserRuleContext *retctx = _ctx; // save current ctx (return value)
|
||||
|
||||
// unroll so _ctx is as it was before call to recursive method
|
||||
if (_parseListeners.size() > 0) {
|
||||
while (_ctx != _parentctx) {
|
||||
triggerExitRuleEvent();
|
||||
_ctx = static_cast<ParserRuleContext*>(_ctx->parent);
|
||||
}
|
||||
} else {
|
||||
_ctx = _parentctx;
|
||||
}
|
||||
|
||||
// hook into tree
|
||||
retctx->parent = _parentctx;
|
||||
|
||||
if (_buildParseTrees && _parentctx != nullptr) {
|
||||
// add return ctx into invoking rule's tree
|
||||
_parentctx->addChild(retctx);
|
||||
}
|
||||
}
|
||||
|
||||
ParserRuleContext *Parser::getInvokingContext(int ruleIndex) {
|
||||
ParserRuleContext *p = _ctx;
|
||||
while (p != nullptr) {
|
||||
if (p->getRuleIndex() == ruleIndex) {
|
||||
return p;
|
||||
}
|
||||
p = static_cast<ParserRuleContext*>(p->parent);
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
ParserRuleContext *Parser::getContext() {
|
||||
return _ctx;
|
||||
}
|
||||
|
||||
void Parser::setContext(ParserRuleContext *ctx) {
|
||||
_ctx = ctx;
|
||||
}
|
||||
|
||||
bool Parser::precpred(RuleContext *localctx, int precedence) {
|
||||
return precedence >= _precedenceStack.back();
|
||||
}
|
||||
|
||||
bool Parser::inContext(const std::wstring &context) {
|
||||
// TODO: useful in parser?
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Parser::isExpectedToken(int symbol) {
|
||||
// return getInterpreter().atn.nextTokens(_ctx);
|
||||
atn::ATN *atn = getInterpreter()->atn;
|
||||
ParserRuleContext *ctx = _ctx;
|
||||
atn::ATNState *s = atn->states[getState()];
|
||||
misc::IntervalSet *following = atn->nextTokens(s);
|
||||
if (following->contains(symbol)) {
|
||||
return true;
|
||||
}
|
||||
// System.out.println("following "+s+"="+following);
|
||||
if (!following->contains(Token::EPSILON)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
while (ctx != nullptr && ctx->invokingState >= 0 && following->contains(Token::EPSILON)) {
|
||||
atn::ATNState *invokingState = atn->states[ctx->invokingState];
|
||||
atn::RuleTransition *rt = static_cast<atn::RuleTransition*>(invokingState->transition(0));
|
||||
following = atn->nextTokens(rt->followState);
|
||||
if (following->contains(symbol)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
ctx = static_cast<ParserRuleContext*>(ctx->parent);
|
||||
}
|
||||
|
||||
if (following->contains(Token::EPSILON) && symbol == Token::_EOF) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
misc::IntervalSet *Parser::getExpectedTokens() {
|
||||
return getATN()->getExpectedTokens(getState(), getContext());
|
||||
}
|
||||
|
||||
misc::IntervalSet *Parser::getExpectedTokensWithinCurrentRule() {
|
||||
atn::ATN *atn = getInterpreter()->atn;
|
||||
atn::ATNState *s = atn->states[getState()];
|
||||
return atn->nextTokens(s);
|
||||
}
|
||||
|
||||
int Parser::getRuleIndex(const std::wstring &ruleName) {
|
||||
std::map<std::wstring, int>* m = getRuleIndexMap();
|
||||
if (m->find(ruleName) == m->end()) {
|
||||
return -1;
|
||||
}
|
||||
return m->at(ruleName);
|
||||
}
|
||||
|
||||
ParserRuleContext *Parser::getRuleContext() {
|
||||
return _ctx;
|
||||
}
|
||||
|
||||
std::vector<std::wstring> Parser::getRuleInvocationStack() {
|
||||
return getRuleInvocationStack(_ctx);
|
||||
}
|
||||
|
||||
std::vector<std::wstring> Parser::getRuleInvocationStack(RuleContext *p) {
|
||||
std::vector<std::wstring> ruleNames = getRuleNames();
|
||||
std::vector<std::wstring> stack = std::vector<std::wstring>();
|
||||
while (p != nullptr) {
|
||||
// compute what follows who invoked us
|
||||
int ruleIndex = p->getRuleIndex();
|
||||
if (ruleIndex < 0) {
|
||||
stack.push_back(L"n/a");
|
||||
} else {
|
||||
stack.push_back(ruleNames[ruleIndex]);
|
||||
}
|
||||
p = p->parent;
|
||||
}
|
||||
return stack;
|
||||
}
|
||||
|
||||
std::vector<std::wstring> Parser::getDFAStrings() {
|
||||
if (!_interp->_decisionToDFA.empty()) {
|
||||
std::lock_guard<std::mutex> lck(mtx);
|
||||
std::vector<std::wstring> s = std::vector<std::wstring>();
|
||||
for (size_t d = 0; d < _interp->_decisionToDFA.size(); d++) {
|
||||
dfa::DFA *dfa = &_interp->_decisionToDFA[d];
|
||||
s.push_back(dfa->toString(getTokenNames()));
|
||||
}
|
||||
return s;
|
||||
}
|
||||
return std::vector<std::wstring>();
|
||||
}
|
||||
|
||||
void Parser::dumpDFA() {
|
||||
|
||||
if (!_interp->_decisionToDFA.empty()) {
|
||||
std::lock_guard<std::mutex> lck(mtx);
|
||||
bool seenOne = false;
|
||||
for (size_t d = 0; d < _interp->_decisionToDFA.size(); d++) {
|
||||
dfa::DFA *dfa = &_interp->_decisionToDFA[d];
|
||||
if (!dfa->states->empty()) {
|
||||
if (seenOne) {
|
||||
std::cout << std::endl;
|
||||
}
|
||||
std::cout << L"Decision " << dfa->decision << L":" << std::endl;
|
||||
dfa->toString(getTokenNames());
|
||||
std::wcout << dfa->toString(getTokenNames());
|
||||
seenOne = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::string Parser::getSourceName() {
|
||||
return _input->getSourceName();
|
||||
}
|
||||
|
||||
void Parser::setTrace(bool trace) {
|
||||
if (!trace) {
|
||||
removeParseListener(_tracer);
|
||||
// TODO
|
||||
//JAVA TO C++ CONVERTER WARNING: Java to C++ Converter converted the original 'null' assignment to a call to 'delete', but you should review memory allocation of all pointer variables in the converted code:
|
||||
delete _tracer;
|
||||
} else {
|
||||
if (_tracer != nullptr) {
|
||||
removeParseListener(_tracer);
|
||||
} else {
|
||||
_tracer = new TraceListener(this);
|
||||
}
|
||||
addParseListener(_tracer);
|
||||
}
|
||||
}
|
||||
|
||||
void Parser::InitializeInstanceFields() {
|
||||
_errHandler = new DefaultErrorStrategy();
|
||||
_precedenceStack.clear();
|
||||
_precedenceStack.push_back(0);
|
||||
_buildParseTrees = true;
|
||||
_syntaxErrors = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,490 @@
|
|||
#pragma once
|
||||
|
||||
#include <mutex>
|
||||
#include <stack>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
#include <map>
|
||||
|
||||
#include "Recognizer.h"
|
||||
#include "ParseTreeListener.h"
|
||||
#include "TokenStream.h"
|
||||
#include "BitSet.h"
|
||||
#include "Declarations.h"
|
||||
#include "TokenSource.h"
|
||||
|
||||
/*
|
||||
* [The "BSD license"]
|
||||
* Copyright (c) 2013 Terence Parr
|
||||
* Copyright (c) 2013 Dan McLaughlin
|
||||
* 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. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
||||
*/
|
||||
|
||||
namespace org {
|
||||
namespace antlr {
|
||||
namespace v4 {
|
||||
namespace runtime {
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// This is all the parsing support code essentially; most of it is error recovery stuff. </summary>
|
||||
class Parser : public Recognizer<Token*, atn::ParserATNSimulator*> {
|
||||
public:
|
||||
class TraceListener : public tree::ParseTreeListener {
|
||||
private:
|
||||
Parser *const outerInstance;
|
||||
|
||||
public:
|
||||
TraceListener(Parser *outerInstance);
|
||||
virtual ~TraceListener() {};
|
||||
|
||||
virtual void enterEveryRule(ParserRuleContext *ctx) override;
|
||||
|
||||
virtual void visitTerminal(tree::TerminalNode *node) override;
|
||||
|
||||
virtual void visitErrorNode(tree::ErrorNode *node) override;
|
||||
|
||||
virtual void exitEveryRule(ParserRuleContext *ctx) override;
|
||||
};
|
||||
|
||||
public:
|
||||
class TrimToSizeListener : public tree::ParseTreeListener {
|
||||
public:
|
||||
static TrimToSizeListener *const INSTANCE;
|
||||
|
||||
virtual void enterEveryRule(ParserRuleContext *ctx) override;
|
||||
virtual void visitTerminal(tree::TerminalNode *node) override;
|
||||
virtual void visitErrorNode(tree::ErrorNode *node) override;
|
||||
virtual void exitEveryRule(ParserRuleContext *ctx) override;
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// This field maps from the serialized ATN string to the deserialized <seealso cref="ATN"/> with
|
||||
/// bypass alternatives.
|
||||
/// </summary>
|
||||
/// <seealso cref= ATNDeserializationOptions#isGenerateRuleBypassTransitions() </seealso>
|
||||
private:
|
||||
static std::map<std::wstring, atn::ATN*> * bypassAltsAtnCache;
|
||||
|
||||
/// <summary>
|
||||
/// The error handling strategy for the parser. The default value is a new
|
||||
/// instance of <seealso cref="DefaultErrorStrategy"/>.
|
||||
/// </summary>
|
||||
/// <seealso cref= #getErrorHandler </seealso>
|
||||
/// <seealso cref= #setErrorHandler </seealso>
|
||||
protected:
|
||||
ANTLRErrorStrategy *_errHandler;
|
||||
|
||||
/// <summary>
|
||||
/// The input stream.
|
||||
/// </summary>
|
||||
/// <seealso cref= #getInputStream </seealso>
|
||||
/// <seealso cref= #setInputStream </seealso>
|
||||
TokenStream *_input;
|
||||
|
||||
std::vector<int> _precedenceStack;
|
||||
//Mutex to manage synchronized access for multithreading in the parser
|
||||
std::mutex mtx;
|
||||
/// <summary>
|
||||
/// The <seealso cref="ParserRuleContext"/> object for the currently executing rule.
|
||||
/// This is always non-null during the parsing process.
|
||||
/// </summary>
|
||||
public:
|
||||
ParserRuleContext *_ctx;
|
||||
|
||||
/// <summary>
|
||||
/// Specifies whether or not the parser should construct a parse tree during
|
||||
/// the parsing process. The default value is {@code true}.
|
||||
/// </summary>
|
||||
/// <seealso cref= #getBuildParseTree </seealso>
|
||||
/// <seealso cref= #setBuildParseTree </seealso>
|
||||
protected:
|
||||
bool _buildParseTrees;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// When <seealso cref="#setTrace"/>{@code (true)} is called, a reference to the
|
||||
/// <seealso cref="TraceListener"/> is stored here so it can be easily removed in a
|
||||
/// later call to <seealso cref="#setTrace"/>{@code (false)}. The listener itself is
|
||||
/// implemented as a parser listener so this field is not directly used by
|
||||
/// other parser methods.
|
||||
/// </summary>
|
||||
private:
|
||||
TraceListener *_tracer;
|
||||
|
||||
/// <summary>
|
||||
/// The list of <seealso cref="ParseTreeListener"/> listeners registered to receive
|
||||
/// events during the parse.
|
||||
/// </summary>
|
||||
/// <seealso cref= #addParseListener </seealso>
|
||||
protected:
|
||||
std::vector<tree::ParseTreeListener*> _parseListeners;
|
||||
|
||||
/// <summary>
|
||||
/// The number of syntax errors reported during parsing. This value is
|
||||
/// incremented each time <seealso cref="#notifyErrorListeners"/> is called.
|
||||
/// </summary>
|
||||
int _syntaxErrors;
|
||||
|
||||
public:
|
||||
Parser(TokenStream *input);
|
||||
|
||||
/// <summary>
|
||||
/// reset the parser's state </summary>
|
||||
virtual void reset();
|
||||
|
||||
/// <summary>
|
||||
/// Match current input symbol against {@code ttype}. If the symbol type
|
||||
/// matches, <seealso cref="ANTLRErrorStrategy#reportMatch"/> and <seealso cref="#consume"/> are
|
||||
/// called to complete the match process.
|
||||
/// <p/>
|
||||
/// If the symbol type does not match,
|
||||
/// <seealso cref="ANTLRErrorStrategy#recoverInline"/> is called on the current error
|
||||
/// strategy to attempt recovery. If <seealso cref="#getBuildParseTree"/> is
|
||||
/// {@code true} and the token index of the symbol returned by
|
||||
/// <seealso cref="ANTLRErrorStrategy#recoverInline"/> is -1, the symbol is added to
|
||||
/// the parse tree by calling <seealso cref="ParserRuleContext#addErrorNode"/>.
|
||||
/// </summary>
|
||||
/// <param name="ttype"> the token type to match </param>
|
||||
/// <returns> the matched symbol </returns>
|
||||
/// <exception cref="RecognitionException"> if the current input symbol did not match
|
||||
/// {@code ttype} and the error strategy could not recover from the
|
||||
/// mismatched symbol </exception>
|
||||
virtual Token *match(int ttype);
|
||||
|
||||
/// <summary>
|
||||
/// Match current input symbol as a wildcard. If the symbol type matches
|
||||
/// (i.e. has a value greater than 0), <seealso cref="ANTLRErrorStrategy#reportMatch"/>
|
||||
/// and <seealso cref="#consume"/> are called to complete the match process.
|
||||
/// <p/>
|
||||
/// If the symbol type does not match,
|
||||
/// <seealso cref="ANTLRErrorStrategy#recoverInline"/> is called on the current error
|
||||
/// strategy to attempt recovery. If <seealso cref="#getBuildParseTree"/> is
|
||||
/// {@code true} and the token index of the symbol returned by
|
||||
/// <seealso cref="ANTLRErrorStrategy#recoverInline"/> is -1, the symbol is added to
|
||||
/// the parse tree by calling <seealso cref="ParserRuleContext#addErrorNode"/>.
|
||||
/// </summary>
|
||||
/// <returns> the matched symbol </returns>
|
||||
/// <exception cref="RecognitionException"> if the current input symbol did not match
|
||||
/// a wildcard and the error strategy could not recover from the mismatched
|
||||
/// symbol </exception>
|
||||
virtual Token *matchWildcard();
|
||||
|
||||
/// <summary>
|
||||
/// Track the <seealso cref="ParserRuleContext"/> objects during the parse and hook
|
||||
/// them up using the <seealso cref="ParserRuleContext#children"/> list so that it
|
||||
/// forms a parse tree. The <seealso cref="ParserRuleContext"/> returned from the start
|
||||
/// rule represents the root of the parse tree.
|
||||
/// <p/>
|
||||
/// Note that if we are not building parse trees, rule contexts only point
|
||||
/// upwards. When a rule exits, it returns the context but that gets garbage
|
||||
/// collected if nobody holds a reference. It points upwards but nobody
|
||||
/// points at it.
|
||||
/// <p/>
|
||||
/// When we build parse trees, we are adding all of these contexts to
|
||||
/// <seealso cref="ParserRuleContext#children"/> list. Contexts are then not candidates
|
||||
/// for garbage collection.
|
||||
/// </summary>
|
||||
virtual void setBuildParseTree(bool buildParseTrees);
|
||||
|
||||
/// <summary>
|
||||
/// Gets whether or not a complete parse tree will be constructed while
|
||||
/// parsing. This property is {@code true} for a newly constructed parser.
|
||||
/// </summary>
|
||||
/// <returns> {@code true} if a complete parse tree will be constructed while
|
||||
/// parsing, otherwise {@code false} </returns>
|
||||
virtual bool getBuildParseTree();
|
||||
|
||||
/// <summary>
|
||||
/// Trim the internal lists of the parse tree during parsing to conserve memory.
|
||||
/// This property is set to {@code false} by default for a newly constructed parser.
|
||||
/// </summary>
|
||||
/// <param name="trimParseTrees"> {@code true} to trim the capacity of the <seealso cref="ParserRuleContext#children"/>
|
||||
/// list to its size after a rule is parsed. </param>
|
||||
virtual void setTrimParseTree(bool trimParseTrees);
|
||||
|
||||
/// <returns> {@code true} if the <seealso cref="ParserRuleContext#children"/> list is trimmed
|
||||
/// using the default <seealso cref="Parser.TrimToSizeListener"/> during the parse process. </returns>
|
||||
virtual bool getTrimParseTree();
|
||||
|
||||
virtual std::vector<tree::ParseTreeListener*> getParseListeners();
|
||||
|
||||
/// <summary>
|
||||
/// Registers {@code listener} to receive events during the parsing process.
|
||||
/// <p/>
|
||||
/// To support output-preserving grammar transformations (including but not
|
||||
/// limited to left-recursion removal, automated left-factoring, and
|
||||
/// optimized code generation), calls to listener methods during the parse
|
||||
/// may differ substantially from calls made by
|
||||
/// <seealso cref="ParseTreeWalker#DEFAULT"/> used after the parse is complete. In
|
||||
/// particular, rule entry and exit events may occur in a different order
|
||||
/// during the parse than after the parser. In addition, calls to certain
|
||||
/// rule entry methods may be omitted.
|
||||
/// <p/>
|
||||
/// With the following specific exceptions, calls to listener events are
|
||||
/// <em>deterministic</em>, i.e. for identical input the calls to listener
|
||||
/// methods will be the same.
|
||||
///
|
||||
/// <ul>
|
||||
/// <li>Alterations to the grammar used to generate code may change the
|
||||
/// behavior of the listener calls.</li>
|
||||
/// <li>Alterations to the command line options passed to ANTLR 4 when
|
||||
/// generating the parser may change the behavior of the listener calls.</li>
|
||||
/// <li>Changing the version of the ANTLR Tool used to generate the parser
|
||||
/// may change the behavior of the listener calls.</li>
|
||||
/// </ul>
|
||||
/// </summary>
|
||||
/// <param name="listener"> the listener to add
|
||||
/// </param>
|
||||
/// <exception cref="NullPointerException"> if {@code} listener is {@code null} </exception>
|
||||
virtual void addParseListener(tree::ParseTreeListener *listener);
|
||||
|
||||
/// <summary>
|
||||
/// Remove {@code listener} from the list of parse listeners.
|
||||
/// <p/>
|
||||
/// If {@code listener} is {@code null} or has not been added as a parse
|
||||
/// listener, this method does nothing.
|
||||
/// </summary>
|
||||
/// <seealso cref= #addParseListener
|
||||
/// </seealso>
|
||||
/// <param name="listener"> the listener to remove </param>
|
||||
virtual void removeParseListener(tree::ParseTreeListener *listener);
|
||||
|
||||
/// <summary>
|
||||
/// Remove all parse listeners.
|
||||
/// </summary>
|
||||
/// <seealso cref= #addParseListener </seealso>
|
||||
virtual void removeParseListeners();
|
||||
|
||||
/// <summary>
|
||||
/// Notify any parse listeners of an enter rule event.
|
||||
/// </summary>
|
||||
/// <seealso cref= #addParseListener </seealso>
|
||||
protected:
|
||||
virtual void triggerEnterRuleEvent();
|
||||
|
||||
/// <summary>
|
||||
/// Notify any parse listeners of an exit rule event.
|
||||
/// </summary>
|
||||
/// <seealso cref= #addParseListener </seealso>
|
||||
virtual void triggerExitRuleEvent();
|
||||
|
||||
/// <summary>
|
||||
/// Gets the number of syntax errors reported during parsing. This value is
|
||||
/// incremented each time <seealso cref="#notifyErrorListeners"/> is called.
|
||||
/// </summary>
|
||||
/// <seealso cref= #notifyErrorListeners </seealso>
|
||||
public:
|
||||
virtual int getNumberOfSyntaxErrors();
|
||||
|
||||
virtual TokenFactory<CommonToken*> *getTokenFactory() override;
|
||||
|
||||
/// <summary>
|
||||
/// Tell our token source and error strategy about a new way to create tokens. </summary>
|
||||
template<typename T1>
|
||||
void setTokenFactory(TokenFactory<T1> *factory) {
|
||||
_input->getTokenSource()->setTokenFactory(factory);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The ATN with bypass alternatives is expensive to create so we create it
|
||||
/// lazily.
|
||||
/// </summary>
|
||||
/// <exception cref="UnsupportedOperationException"> if the current parser does not
|
||||
/// implement the <seealso cref="#getSerializedATN()"/> method. </exception>
|
||||
virtual atn::ATN *getATNWithBypassAlts();
|
||||
|
||||
/// <summary>
|
||||
/// The preferred method of getting a tree pattern. For example, here's a
|
||||
/// sample use:
|
||||
///
|
||||
/// <pre>
|
||||
/// ParseTree t = parser.expr();
|
||||
/// ParseTreePattern p = parser.compileParseTreePattern("<ID>+0", MyParser.RULE_expr);
|
||||
/// ParseTreeMatch m = p.match(t);
|
||||
/// String id = m.get("ID");
|
||||
/// </pre>
|
||||
/// </summary>
|
||||
virtual tree::pattern::ParseTreePattern *compileParseTreePattern(const std::wstring &pattern, int patternRuleIndex);
|
||||
|
||||
/// <summary>
|
||||
/// The same as <seealso cref="#compileParseTreePattern(String, int)"/> but specify a
|
||||
/// <seealso cref="Lexer"/> rather than trying to deduce it from this parser.
|
||||
/// </summary>
|
||||
virtual tree::pattern::ParseTreePattern *compileParseTreePattern(const std::wstring &pattern, int patternRuleIndex, Lexer *lexer);
|
||||
|
||||
virtual ANTLRErrorStrategy *getErrorHandler();
|
||||
|
||||
virtual void setErrorHandler(ANTLRErrorStrategy *handler);
|
||||
|
||||
virtual TokenStream *getInputStream() override;
|
||||
void setInputStream(IntStream *input) override;
|
||||
|
||||
virtual TokenStream *getTokenStream();
|
||||
|
||||
/// <summary>
|
||||
/// Set the token stream and reset the parser. </summary>
|
||||
virtual void setTokenStream(TokenStream *input);
|
||||
|
||||
/// <summary>
|
||||
/// Match needs to return the current input symbol, which gets put
|
||||
/// into the label for the associated token ref; e.g., x=ID.
|
||||
/// </summary>
|
||||
virtual Token *getCurrentToken();
|
||||
|
||||
void notifyErrorListeners(const std::wstring &msg);
|
||||
|
||||
virtual void notifyErrorListeners(Token *offendingToken, const std::wstring &msg, RecognitionException *e);
|
||||
|
||||
/// <summary>
|
||||
/// Consume and return the <seealso cref="#getCurrentToken current symbol"/>.
|
||||
/// <p/>
|
||||
/// E.g., given the following input with {@code A} being the current
|
||||
/// lookahead symbol, this function moves the cursor to {@code B} and returns
|
||||
/// {@code A}.
|
||||
///
|
||||
/// <pre>
|
||||
/// A B
|
||||
/// ^
|
||||
/// </pre>
|
||||
///
|
||||
/// If the parser is not in error recovery mode, the consumed symbol is added
|
||||
/// to the parse tree using <seealso cref="ParserRuleContext#addChild(Token)"/>, and
|
||||
/// <seealso cref="ParseTreeListener#visitTerminal"/> is called on any parse listeners.
|
||||
/// If the parser <em>is</em> in error recovery mode, the consumed symbol is
|
||||
/// added to the parse tree using
|
||||
/// <seealso cref="ParserRuleContext#addErrorNode(Token)"/>, and
|
||||
/// <seealso cref="ParseTreeListener#visitErrorNode"/> is called on any parse
|
||||
/// listeners.
|
||||
/// </summary>
|
||||
virtual Token *consume();
|
||||
|
||||
protected:
|
||||
virtual void addContextToParseTree();
|
||||
|
||||
/// <summary>
|
||||
/// Always called by generated parsers upon entry to a rule. Access field
|
||||
/// <seealso cref="#_ctx"/> get the current context.
|
||||
/// </summary>
|
||||
public:
|
||||
virtual void enterRule(ParserRuleContext *localctx, int state, int ruleIndex);
|
||||
|
||||
virtual void exitRule();
|
||||
|
||||
virtual void enterOuterAlt(ParserRuleContext *localctx, int altNum);
|
||||
|
||||
/// @deprecated Use
|
||||
/// <seealso cref="#enterRecursionRule(ParserRuleContext, int, int, int)"/> instead.
|
||||
virtual void enterRecursionRule(ParserRuleContext *localctx, int ruleIndex);
|
||||
|
||||
virtual void enterRecursionRule(ParserRuleContext *localctx, int state, int ruleIndex, int precedence);
|
||||
|
||||
/// <summary>
|
||||
/// Like <seealso cref="#enterRule"/> but for recursive rules.
|
||||
/// </summary>
|
||||
virtual void pushNewRecursionContext(ParserRuleContext *localctx, int state, int ruleIndex);
|
||||
|
||||
virtual void unrollRecursionContexts(ParserRuleContext *_parentctx);
|
||||
|
||||
virtual ParserRuleContext *getInvokingContext(int ruleIndex);
|
||||
|
||||
virtual ParserRuleContext *getContext();
|
||||
|
||||
virtual void setContext(ParserRuleContext *ctx);
|
||||
|
||||
virtual bool precpred(RuleContext *localctx, int precedence) override;
|
||||
|
||||
virtual bool inContext(const std::wstring &context);
|
||||
|
||||
/// <summary>
|
||||
/// Checks whether or not {@code symbol} can follow the current state in the
|
||||
/// ATN. The behavior of this method is equivalent to the following, but is
|
||||
/// implemented such that the complete context-sensitive follow set does not
|
||||
/// need to be explicitly constructed.
|
||||
///
|
||||
/// <pre>
|
||||
/// return getExpectedTokens().contains(symbol);
|
||||
/// </pre>
|
||||
/// </summary>
|
||||
/// <param name="symbol"> the symbol type to check </param>
|
||||
/// <returns> {@code true} if {@code symbol} can follow the current state in
|
||||
/// the ATN, otherwise {@code false}. </returns>
|
||||
virtual bool isExpectedToken(int symbol);
|
||||
|
||||
/// <summary>
|
||||
/// Computes the set of input symbols which could follow the current parser
|
||||
/// state and context, as given by <seealso cref="#getState"/> and <seealso cref="#getContext"/>,
|
||||
/// respectively.
|
||||
/// </summary>
|
||||
/// <seealso cref= ATN#getExpectedTokens(int, RuleContext) </seealso>
|
||||
virtual misc::IntervalSet *getExpectedTokens();
|
||||
|
||||
virtual misc::IntervalSet *getExpectedTokensWithinCurrentRule();
|
||||
|
||||
/// <summary>
|
||||
/// Get a rule's index (i.e., {@code RULE_ruleName} field) or -1 if not found. </summary>
|
||||
virtual int getRuleIndex(const std::wstring &ruleName);
|
||||
|
||||
virtual ParserRuleContext *getRuleContext();
|
||||
|
||||
/// <summary>
|
||||
/// Return List<String> of the rule names in your parser instance
|
||||
/// leading up to a call to the current rule. You could override if
|
||||
/// you want more details such as the file/line info of where
|
||||
/// in the ATN a rule is invoked.
|
||||
///
|
||||
/// This is very useful for error messages.
|
||||
/// </summary>
|
||||
virtual std::vector<std::wstring> getRuleInvocationStack();
|
||||
|
||||
virtual std::vector<std::wstring> getRuleInvocationStack(RuleContext *p);
|
||||
|
||||
/// <summary>
|
||||
/// For debugging and other purposes. </summary>
|
||||
virtual std::vector<std::wstring> getDFAStrings();
|
||||
|
||||
/// <summary>
|
||||
/// For debugging and other purposes. </summary>
|
||||
virtual void dumpDFA();
|
||||
|
||||
virtual std::string getSourceName();
|
||||
|
||||
/// <summary>
|
||||
/// During a parse is sometimes useful to listen in on the rule entry and exit
|
||||
/// events as well as token matches. This is for quick and dirty debugging.
|
||||
/// </summary>
|
||||
virtual void setTrace(bool trace);
|
||||
|
||||
private:
|
||||
void InitializeInstanceFields();
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,243 @@
|
|||
#include <deque>
|
||||
|
||||
#include "ParserInterpreter.h"
|
||||
#include "ATN.h"
|
||||
#include "DFA.h"
|
||||
#include "RuleStartState.h"
|
||||
#include "InterpreterRuleContext.h"
|
||||
#include "ParserATNSimulator.h"
|
||||
#include "DecisionState.h"
|
||||
#include "Transition.h"
|
||||
#include "ANTLRErrorStrategy.h"
|
||||
#include "Token.h"
|
||||
#include "AtomTransition.h"
|
||||
#include "ActionTransition.h"
|
||||
#include "Exceptions.h"
|
||||
#include "RuleTransition.h"
|
||||
#include "PrecedencePredicateTransition.h"
|
||||
#include "PredicateTransition.h"
|
||||
#include "LoopEndState.h"
|
||||
#include "FailedPredicateException.h"
|
||||
#include "RuleStartState.h"
|
||||
#include "StarLoopEntryState.h"
|
||||
#include "PredictionContextCache.h"
|
||||
#include "IntervalSet.h"
|
||||
|
||||
/*
|
||||
* [The "BSD license"]
|
||||
* Copyright (c) 2013 Terence Parr
|
||||
* Copyright (c) 2013 Dan McLaughlin
|
||||
* 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. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
||||
*/
|
||||
|
||||
namespace org {
|
||||
namespace antlr {
|
||||
namespace v4 {
|
||||
namespace runtime {
|
||||
|
||||
ParserInterpreter::ParserInterpreter(const std::wstring &grammarFileName, const std::vector<std::wstring>& tokenNames, const std::vector<std::wstring>& ruleNames, atn::ATN *atn, TokenStream *input) : Parser(_input), grammarFileName(grammarFileName), _tokenNames(tokenNames), atn(atn), _ruleNames(ruleNames), pushRecursionContextStates(new antlrcpp::BitSet()), sharedContextCache(new atn::PredictionContextCache()), _parentContextStack(new std::deque<std::pair<ParserRuleContext *, int>*>()) {
|
||||
|
||||
|
||||
for (int i = 0; i < atn->getNumberOfDecisions(); i++) {
|
||||
_decisionToDFA.emplace_back(atn->getDecisionState(i), i);
|
||||
}
|
||||
|
||||
// identify the ATN states where pushNewRecursionContext must be called
|
||||
for (auto state : atn->states) {
|
||||
if (!(dynamic_cast<atn::StarLoopEntryState*>(state) != nullptr)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
atn::RuleStartState *ruleStartState = atn->ruleToStartState[state->ruleIndex];
|
||||
if (!ruleStartState->isPrecedenceRule) {
|
||||
continue;
|
||||
}
|
||||
|
||||
atn::ATNState *maybeLoopEndState = state->transition(state->getNumberOfTransitions() - 1)->target;
|
||||
if (!(dynamic_cast<atn::LoopEndState*>(maybeLoopEndState) != nullptr)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (maybeLoopEndState->epsilonOnlyTransitions && dynamic_cast<atn::RuleStopState*>(maybeLoopEndState->transition(0)->target) != nullptr) {
|
||||
this->pushRecursionContextStates->set(state->stateNumber);
|
||||
}
|
||||
}
|
||||
|
||||
// get atn simulator that knows how to do predictions
|
||||
setInterpreter(new atn::ParserATNSimulator(this, atn, _decisionToDFA, sharedContextCache));
|
||||
}
|
||||
|
||||
org::antlr::v4::runtime::atn::ATN *ParserInterpreter::getATN() {
|
||||
return atn;
|
||||
}
|
||||
|
||||
const std::vector<std::wstring>& ParserInterpreter::getTokenNames() {
|
||||
return _tokenNames;
|
||||
}
|
||||
|
||||
const std::vector<std::wstring>& ParserInterpreter::getRuleNames() {
|
||||
return _ruleNames;
|
||||
}
|
||||
|
||||
std::wstring ParserInterpreter::getGrammarFileName() {
|
||||
return grammarFileName;
|
||||
}
|
||||
|
||||
ParserRuleContext *ParserInterpreter::parse(int startRuleIndex) {
|
||||
atn::RuleStartState *startRuleStartState = atn->ruleToStartState[startRuleIndex];
|
||||
|
||||
InterpreterRuleContext *rootContext = new InterpreterRuleContext(nullptr, atn::ATNState::INVALID_STATE_NUMBER, startRuleIndex);
|
||||
if (startRuleStartState->isPrecedenceRule) {
|
||||
enterRecursionRule(rootContext, startRuleStartState->stateNumber, startRuleIndex, 0);
|
||||
} else {
|
||||
enterRule(rootContext, startRuleStartState->stateNumber, startRuleIndex);
|
||||
}
|
||||
|
||||
while (true) {
|
||||
atn::ATNState *p = getATNState();
|
||||
switch (p->getStateType()) {
|
||||
case atn::ATNState::RULE_STOP :
|
||||
// pop; return from rule
|
||||
if (_ctx->isEmpty()) {
|
||||
exitRule();
|
||||
return rootContext;
|
||||
}
|
||||
|
||||
visitRuleStopState(p);
|
||||
break;
|
||||
|
||||
default :
|
||||
visitState(p);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ParserInterpreter::enterRecursionRule(ParserRuleContext *localctx, int state, int ruleIndex, int precedence) {
|
||||
_parentContextStack->push_back(new std::pair<ParserRuleContext*, int>(_ctx, localctx->invokingState));
|
||||
Parser::enterRecursionRule(localctx, state, ruleIndex, precedence);
|
||||
}
|
||||
|
||||
atn::ATNState *ParserInterpreter::getATNState() {
|
||||
return atn->states.at(getState());
|
||||
}
|
||||
|
||||
void ParserInterpreter::visitState(atn::ATNState *p) {
|
||||
int edge;
|
||||
if (p->getNumberOfTransitions() > 1) {
|
||||
edge = getInterpreter()->adaptivePredict(_input, ((atn::DecisionState*)p)->decision, _ctx);
|
||||
} else {
|
||||
edge = 1;
|
||||
}
|
||||
|
||||
atn::Transition *transition = p->transition(edge - 1);
|
||||
switch (transition->getSerializationType()) {
|
||||
case atn::Transition::EPSILON:
|
||||
if (pushRecursionContextStates->data[p->stateNumber] == 1 && !(dynamic_cast<atn::LoopEndState*>(transition->target) != nullptr)) {
|
||||
InterpreterRuleContext *ctx = new InterpreterRuleContext(_parentContextStack->front()->first, _parentContextStack->front()->second, _ctx->getRuleIndex());
|
||||
pushNewRecursionContext(ctx, atn->ruleToStartState[p->ruleIndex]->stateNumber, _ctx->getRuleIndex());
|
||||
}
|
||||
break;
|
||||
|
||||
case atn::Transition::ATOM:
|
||||
match(((atn::AtomTransition*)(transition))->_label);
|
||||
break;
|
||||
|
||||
case atn::Transition::RANGE:
|
||||
case atn::Transition::SET:
|
||||
case atn::Transition::NOT_SET:
|
||||
if (!transition->matches(_input->LA(1), Token::MIN_USER_TOKEN_TYPE, 65535)) {
|
||||
_errHandler->recoverInline(this);
|
||||
}
|
||||
matchWildcard();
|
||||
break;
|
||||
|
||||
case atn::Transition::WILDCARD:
|
||||
matchWildcard();
|
||||
break;
|
||||
|
||||
case atn::Transition::RULE:
|
||||
{
|
||||
atn::RuleStartState *ruleStartState = (atn::RuleStartState*)(transition->target);
|
||||
int ruleIndex = ruleStartState->ruleIndex;
|
||||
InterpreterRuleContext *ctx = new InterpreterRuleContext(_ctx, p->stateNumber, ruleIndex);
|
||||
if (ruleStartState->isPrecedenceRule) {
|
||||
enterRecursionRule(ctx, ruleStartState->stateNumber, ruleIndex, ((atn::RuleTransition*)(transition))->precedence);
|
||||
} else {
|
||||
enterRule(ctx, transition->target->stateNumber, ruleIndex);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case atn::Transition::PREDICATE:
|
||||
{
|
||||
atn::PredicateTransition *predicateTransition = (atn::PredicateTransition*)(transition);
|
||||
if (!sempred(_ctx, predicateTransition->ruleIndex, predicateTransition->predIndex)) {
|
||||
throw new FailedPredicateException(this);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case atn::Transition::ACTION:
|
||||
{
|
||||
atn::ActionTransition *actionTransition = (atn::ActionTransition*)(transition);
|
||||
action(_ctx, actionTransition->ruleIndex, actionTransition->actionIndex);
|
||||
}
|
||||
break;
|
||||
|
||||
case atn::Transition::PRECEDENCE:
|
||||
{
|
||||
if (!precpred(_ctx, ((atn::PrecedencePredicateTransition*)(transition))->precedence)) {
|
||||
throw new FailedPredicateException(this, L"precpred(_ctx, " + std::to_wstring(((atn::PrecedencePredicateTransition*)(transition))->precedence) + L")");
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
throw UnsupportedOperationException(L"Unrecognized ATN transition type.");
|
||||
}
|
||||
|
||||
setState(transition->target->stateNumber);
|
||||
}
|
||||
|
||||
void ParserInterpreter::visitRuleStopState(atn::ATNState *p) {
|
||||
atn::RuleStartState *ruleStartState = atn->ruleToStartState[p->ruleIndex];
|
||||
if (ruleStartState->isPrecedenceRule) {
|
||||
std::pair<ParserRuleContext*, int> *parentContext = _parentContextStack->back(); // Dan - make sure this is equivalent
|
||||
_parentContextStack->pop_back();
|
||||
unrollRecursionContexts(parentContext->first);
|
||||
setState(parentContext->second);
|
||||
} else {
|
||||
exitRule();
|
||||
}
|
||||
|
||||
atn::RuleTransition *ruleTransition = static_cast<atn::RuleTransition*>(atn->states.at(getState())->transition(0));
|
||||
setState(ruleTransition->followState->stateNumber);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,106 @@
|
|||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <deque>
|
||||
|
||||
#include "Parser.h"
|
||||
#include "Declarations.h"
|
||||
|
||||
|
||||
/*
|
||||
* [The "BSD license"]
|
||||
* Copyright (c) 2013 Terence Parr
|
||||
* Copyright (c) 2013 Dan McLaughlin
|
||||
* 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. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
||||
*/
|
||||
|
||||
namespace org {
|
||||
namespace antlr {
|
||||
namespace v4 {
|
||||
namespace runtime {
|
||||
|
||||
/// <summary>
|
||||
/// A parser simulator that mimics what ANTLR's generated
|
||||
/// parser code does. A ParserATNSimulator is used to make
|
||||
/// predictions via adaptivePredict but this class moves a pointer through the
|
||||
/// ATN to simulate parsing. ParserATNSimulator just
|
||||
/// makes us efficient rather than having to backtrack, for example.
|
||||
///
|
||||
/// This properly creates parse trees even for left recursive rules.
|
||||
///
|
||||
/// We rely on the left recursive rule invocation and special predicate
|
||||
/// transitions to make left recursive rules work.
|
||||
///
|
||||
/// See TestParserInterpreter for examples.
|
||||
/// </summary>
|
||||
class ParserInterpreter : public Parser {
|
||||
protected:
|
||||
//TODO check this
|
||||
static const int DEFAULT_BITSET_SIZE = 1024; // atn->states.size() ideally
|
||||
|
||||
const std::wstring grammarFileName;
|
||||
std::vector<std::wstring> _tokenNames;
|
||||
atn::ATN *const atn;
|
||||
|
||||
std::vector<std::wstring> _ruleNames;
|
||||
antlrcpp::BitSet *const pushRecursionContextStates;
|
||||
|
||||
std::vector<dfa::DFA> _decisionToDFA; // not shared like it is for generated parsers
|
||||
atn::PredictionContextCache *const sharedContextCache;
|
||||
|
||||
|
||||
|
||||
std::deque<std::pair<ParserRuleContext*, int>*> *const _parentContextStack;
|
||||
|
||||
public:
|
||||
ParserInterpreter(const std::wstring &grammarFileName, const std::vector<std::wstring>& tokenNames, const std::vector<std::wstring>& ruleNames, atn::ATN *atn, TokenStream *input);
|
||||
|
||||
virtual atn::ATN *getATN() override;
|
||||
|
||||
virtual const std::vector<std::wstring>& getTokenNames() override;
|
||||
|
||||
virtual const std::vector<std::wstring>& getRuleNames() override;
|
||||
|
||||
virtual std::wstring getGrammarFileName() override;
|
||||
|
||||
/// <summary>
|
||||
/// Begin parsing at startRuleIndex </summary>
|
||||
virtual ParserRuleContext *parse(int startRuleIndex);
|
||||
|
||||
virtual void enterRecursionRule(ParserRuleContext *localctx, int state, int ruleIndex, int precedence) override;
|
||||
|
||||
protected:
|
||||
virtual atn::ATNState *getATNState();
|
||||
|
||||
virtual void visitState(atn::ATNState *p);
|
||||
|
||||
virtual void visitRuleStopState(atn::ATNState *p);
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,194 @@
|
|||
#include "ParserRuleContext.h"
|
||||
#include "TerminalNodeImpl.h"
|
||||
#include "ErrorNodeImpl.h"
|
||||
#include "Interval.h"
|
||||
#include "Parser.h"
|
||||
|
||||
#include <typeinfo>
|
||||
|
||||
/*
|
||||
* [The "BSD license"]
|
||||
* Copyright (c) 2013 Terence Parr
|
||||
* Copyright (c) 2013 Dan McLaughlin
|
||||
* 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. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
||||
*/
|
||||
|
||||
namespace org {
|
||||
namespace antlr {
|
||||
namespace v4 {
|
||||
namespace runtime {
|
||||
|
||||
ParserRuleContext::ParserRuleContext() {
|
||||
}
|
||||
|
||||
void ParserRuleContext::copyFrom(ParserRuleContext *ctx) {
|
||||
// from RuleContext
|
||||
this->parent = ctx->parent;
|
||||
this->invokingState = ctx->invokingState;
|
||||
|
||||
this->start = ctx->start;
|
||||
this->stop = ctx->stop;
|
||||
}
|
||||
|
||||
ParserRuleContext::ParserRuleContext(ParserRuleContext *parent, int invokingStateNumber) : RuleContext(parent, invokingStateNumber) {
|
||||
}
|
||||
|
||||
void ParserRuleContext::enterRule(tree::ParseTreeListener *listener) {
|
||||
}
|
||||
|
||||
void ParserRuleContext::exitRule(tree::ParseTreeListener *listener) {
|
||||
}
|
||||
|
||||
tree::TerminalNode *ParserRuleContext::addChild(tree::TerminalNode *t) {
|
||||
if (children.empty()) {
|
||||
children = std::vector<ParseTree*>();
|
||||
}
|
||||
children.push_back(t);
|
||||
return t;
|
||||
}
|
||||
|
||||
RuleContext *ParserRuleContext::addChild(RuleContext *ruleInvocation) {
|
||||
if (children.empty()) {
|
||||
children = std::vector<ParseTree*>();
|
||||
}
|
||||
children.push_back(ruleInvocation);
|
||||
return ruleInvocation;
|
||||
}
|
||||
|
||||
void ParserRuleContext::removeLastChild() {
|
||||
if (children.size() > 0) {
|
||||
children.pop_back();
|
||||
}
|
||||
}
|
||||
|
||||
tree::TerminalNode *ParserRuleContext::addChild(Token *matchedToken) {
|
||||
tree::TerminalNodeImpl *t = new tree::TerminalNodeImpl(matchedToken);
|
||||
addChild(t);
|
||||
t->parent = this;
|
||||
return t;
|
||||
}
|
||||
|
||||
tree::ErrorNode *ParserRuleContext::addErrorNode(Token *badToken) {
|
||||
tree::ErrorNodeImpl *t = new tree::ErrorNodeImpl(badToken);
|
||||
addChild(t);
|
||||
t->parent = this;
|
||||
return t;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Override to make type more specific </summary>
|
||||
ParserRuleContext *ParserRuleContext::getParent()
|
||||
{
|
||||
return static_cast<ParserRuleContext*>(RuleContext::getParent());
|
||||
}
|
||||
|
||||
tree::ParseTree *ParserRuleContext::getChild(int i) {
|
||||
// TODO: i should really be size_t
|
||||
return children.size() > 0 && i >= 0 && i < (int)children.size() ? children[i] : nullptr;
|
||||
}
|
||||
|
||||
|
||||
|
||||
tree::TerminalNode *ParserRuleContext::getToken(int ttype, int i) {
|
||||
if (children.empty() || i < 0 || i >= (int)children.size()) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
int j = -1; // what token with ttype have we found?
|
||||
for (auto o : children) {
|
||||
if (dynamic_cast<tree::TerminalNode*>(o) != nullptr) {
|
||||
tree::TerminalNode *tnode = static_cast<tree::TerminalNode*>(o);
|
||||
Token *symbol = tnode->getSymbol();
|
||||
if (symbol->getType() == ttype) {
|
||||
j++;
|
||||
if (j == i) {
|
||||
return tnode;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// I think this should be changed to a pointer?
|
||||
std::vector<tree::TerminalNode*> ParserRuleContext::getTokens(int ttype) {
|
||||
if (children.empty()) {
|
||||
return std::vector<tree::TerminalNode*>();
|
||||
}
|
||||
|
||||
std::vector<tree::TerminalNode*> tokens;
|
||||
for (auto o : children) {
|
||||
if (dynamic_cast<tree::TerminalNode*>(o) != nullptr) {
|
||||
tree::TerminalNode *tnode = static_cast<tree::TerminalNode*>(o);
|
||||
Token *symbol = tnode->getSymbol();
|
||||
if (symbol->getType() == ttype) {
|
||||
if (tokens.empty()) {
|
||||
tokens = std::vector<tree::TerminalNode*>();
|
||||
}
|
||||
tokens.push_back(tnode);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (tokens.empty()) {
|
||||
return std::vector<tree::TerminalNode*>();
|
||||
}
|
||||
|
||||
return tokens;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int ParserRuleContext::getChildCount() {
|
||||
return (int)children.size() > 0 ? (int)children.size() : 0;
|
||||
}
|
||||
|
||||
misc::Interval *ParserRuleContext::getSourceInterval() {
|
||||
if (start == nullptr || stop == nullptr) {
|
||||
return misc::Interval::INVALID;
|
||||
}
|
||||
return misc::Interval::of(start->getTokenIndex(), stop->getTokenIndex());
|
||||
}
|
||||
|
||||
Token *ParserRuleContext::getStart() {
|
||||
return start;
|
||||
}
|
||||
|
||||
Token *ParserRuleContext::getStop() {
|
||||
return stop;
|
||||
}
|
||||
|
||||
std::wstring ParserRuleContext::toInfoString(Parser *recognizer) {
|
||||
std::vector<std::wstring> rules = recognizer->getRuleInvocationStack(this);
|
||||
std::reverse(rules.begin(), rules.end());
|
||||
std::wstring rulesStr = antlrcpp::arrayToString(rules);
|
||||
return std::wstring(L"ParserRuleContext") + rulesStr + std::wstring(L"{") + std::wstring(L"start=") + std::to_wstring(start->getTokenIndex()) + std::wstring(L", stop=") + std::to_wstring(stop->getTokenIndex()) + L'}';
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,211 @@
|
|||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
|
||||
#include "RuleContext.h"
|
||||
#include "Declarations.h"
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* [The "BSD license"]
|
||||
* Copyright (c) 2013 Terence Parr
|
||||
* Copyright (c) 2013 Dan McLaughlin
|
||||
* 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. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
||||
*/
|
||||
namespace org {
|
||||
namespace antlr {
|
||||
namespace v4 {
|
||||
namespace runtime {
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// A rule invocation record for parsing.
|
||||
///
|
||||
/// Contains all of the information about the current rule not stored in the
|
||||
/// RuleContext. It handles parse tree children list, Any ATN state
|
||||
/// tracing, and the default values available for rule indications:
|
||||
/// start, stop, rule index, current alt number, current
|
||||
/// ATN state.
|
||||
///
|
||||
/// Subclasses made for each rule and grammar track the parameters,
|
||||
/// return values, locals, and labels specific to that rule. These
|
||||
/// are the objects that are returned from rules.
|
||||
///
|
||||
/// Note text is not an actual field of a rule return value; it is computed
|
||||
/// from start and stop using the input stream's toString() method. I
|
||||
/// could add a ctor to this so that we can pass in and store the input
|
||||
/// stream, but I'm not sure we want to do that. It would seem to be undefined
|
||||
/// to get the .text property anyway if the rule matches tokens from multiple
|
||||
/// input streams.
|
||||
///
|
||||
/// I do not use getters for fields of objects that are used simply to
|
||||
/// group values such as this aggregate. The getters/setters are there to
|
||||
/// satisfy the superclass interface.
|
||||
/// </summary>
|
||||
class ParserRuleContext : public RuleContext {
|
||||
/// <summary>
|
||||
/// If we are debugging or building a parse tree for a visitor,
|
||||
/// we need to track all of the tokens and rule invocations associated
|
||||
/// with this rule's context. This is empty for parsing w/o tree constr.
|
||||
/// operation because we don't the need to track the details about
|
||||
/// how we parse this rule.
|
||||
/// </summary>
|
||||
public:
|
||||
std::vector<ParseTree*> children;
|
||||
|
||||
/// <summary>
|
||||
/// For debugging/tracing purposes, we want to track all of the nodes in
|
||||
/// the ATN traversed by the parser for a particular rule.
|
||||
/// This list indicates the sequence of ATN nodes used to match
|
||||
/// the elements of the children list. This list does not include
|
||||
/// ATN nodes and other rules used to match rule invocations. It
|
||||
/// traces the rule invocation node itself but nothing inside that
|
||||
/// other rule's ATN submachine.
|
||||
///
|
||||
/// There is NOT a one-to-one correspondence between the children and
|
||||
/// states list. There are typically many nodes in the ATN traversed
|
||||
/// for each element in the children list. For example, for a rule
|
||||
/// invocation there is the invoking state and the following state.
|
||||
///
|
||||
/// The parser setState() method updates field s and adds it to this list
|
||||
/// if we are debugging/tracing.
|
||||
///
|
||||
/// This does not trace states visited during prediction.
|
||||
/// </summary>
|
||||
// public List<Integer> states;
|
||||
|
||||
Token *start, *stop;
|
||||
|
||||
/// <summary>
|
||||
/// The exception that forced this rule to return. If the rule successfully
|
||||
/// completed, this is {@code null}.
|
||||
/// </summary>
|
||||
RecognitionException *exception;
|
||||
|
||||
ParserRuleContext();
|
||||
virtual ~ParserRuleContext() {}
|
||||
|
||||
/// <summary>
|
||||
/// COPY a ctx (I'm deliberately not copy constructor) </summary>
|
||||
virtual void copyFrom(ParserRuleContext *ctx);
|
||||
|
||||
ParserRuleContext(ParserRuleContext *parent, int invokingStateNumber);
|
||||
|
||||
// Double dispatch methods for listeners
|
||||
|
||||
virtual void enterRule(tree::ParseTreeListener *listener);
|
||||
virtual void exitRule(tree::ParseTreeListener *listener);
|
||||
|
||||
/// <summary>
|
||||
/// Does not set parent link; other add methods do that </summary>
|
||||
virtual tree::TerminalNode *addChild(tree::TerminalNode *t);
|
||||
|
||||
virtual RuleContext *addChild(RuleContext *ruleInvocation);
|
||||
|
||||
/// <summary>
|
||||
/// Used by enterOuterAlt to toss out a RuleContext previously added as
|
||||
/// we entered a rule. If we have # label, we will need to remove
|
||||
/// generic ruleContext object.
|
||||
/// </summary>
|
||||
virtual void removeLastChild();
|
||||
|
||||
virtual tree::TerminalNode *addChild(Token *matchedToken);
|
||||
|
||||
virtual tree::ErrorNode *addErrorNode(Token *badToken);
|
||||
|
||||
virtual ParserRuleContext *getParent() override;
|
||||
|
||||
virtual ParseTree *getChild(int i) override;
|
||||
|
||||
template<typename T>
|
||||
T getChild(void *ctxType, int i) {
|
||||
if (children.empty() || i < 0 || i >= (int) children.size()) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
int j = -1; // what element have we found with ctxType?
|
||||
for (auto o : children) {
|
||||
if (typeid(ctxType) == typeid(o)) {
|
||||
j++;
|
||||
if (j == i) {
|
||||
return dynamic_cast<T>(o);
|
||||
}
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
virtual tree::TerminalNode *getToken(int ttype, int i);
|
||||
|
||||
virtual std::vector<tree::TerminalNode*> getTokens(int ttype);
|
||||
|
||||
template<typename T>
|
||||
T getRuleContext(void *ctxType, int i) {
|
||||
return getChild<T>(ctxType, i);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
std::vector<T> getRuleContexts(void *ctxType) {
|
||||
if (children.empty()) {
|
||||
return std::vector<T>();
|
||||
}
|
||||
|
||||
std::vector<T> contexts;
|
||||
for (auto o : children) {
|
||||
if (typeid(ctxType) == typeid(o)) {
|
||||
if (contexts.empty()) {
|
||||
contexts = std::vector<T>();
|
||||
}
|
||||
|
||||
contexts.push_back((ParserRuleContext*)(o));
|
||||
}
|
||||
}
|
||||
|
||||
if (contexts.empty()) {
|
||||
return std::vector<T>();
|
||||
}
|
||||
|
||||
return contexts;
|
||||
}
|
||||
|
||||
virtual int getChildCount() override;
|
||||
virtual misc::Interval *getSourceInterval() override;
|
||||
|
||||
virtual Token *getStart();
|
||||
virtual Token *getStop();
|
||||
|
||||
/// <summary>
|
||||
/// Used for rule context info debugging during parse-time, not so much for ATN debugging </summary>
|
||||
virtual std::wstring toInfoString(Parser *recognizer);
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,61 @@
|
|||
#include "ProxyErrorListener.h"
|
||||
#include "RecognitionException.h"
|
||||
#include "atn/ATNConfigSet.h"
|
||||
#include "dfa/DFA.h"
|
||||
#include "Exceptions.h"
|
||||
|
||||
/*
|
||||
* [The "BSD license"]
|
||||
* Copyright (c) 2013 Terence Parr
|
||||
* Copyright (c) 2013 Dan McLaughlin
|
||||
* 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. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
||||
*/
|
||||
|
||||
namespace org {
|
||||
namespace antlr {
|
||||
namespace v4 {
|
||||
namespace runtime {
|
||||
void ProxyErrorListener::reportAmbiguity(Parser *recognizer, dfa::DFA *dfa, int startIndex, int stopIndex, bool exact, antlrcpp::BitSet *ambigAlts, atn::ATNConfigSet *configs) {
|
||||
for (auto listener : *delegates) {
|
||||
listener->reportAmbiguity(recognizer, dfa, startIndex, stopIndex, exact, ambigAlts, configs);
|
||||
}
|
||||
}
|
||||
|
||||
void ProxyErrorListener::reportAttemptingFullContext(Parser *recognizer, dfa::DFA *dfa, int startIndex, int stopIndex, antlrcpp::BitSet *conflictingAlts, atn::ATNConfigSet *configs) {
|
||||
for (auto listener : *delegates) {
|
||||
listener->reportAttemptingFullContext(recognizer, dfa, startIndex, stopIndex, conflictingAlts, configs);
|
||||
}
|
||||
}
|
||||
|
||||
void ProxyErrorListener::reportContextSensitivity(Parser *recognizer, dfa::DFA *dfa, int startIndex, int stopIndex, int prediction, atn::ATNConfigSet *configs) {
|
||||
for (auto listener : *delegates) {
|
||||
listener->reportContextSensitivity(recognizer, dfa, startIndex, stopIndex, prediction, configs);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,80 @@
|
|||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "ANTLRErrorListener.h"
|
||||
#include "Declarations.h"
|
||||
#include "Exceptions.h"
|
||||
|
||||
/*
|
||||
* [The "BSD license"]
|
||||
* Copyright (c) 2013 Terence Parr
|
||||
* Copyright (c) 2013 Dan McLaughlin
|
||||
* 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. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
||||
*/
|
||||
namespace org {
|
||||
namespace antlr {
|
||||
namespace v4 {
|
||||
namespace runtime {
|
||||
/// <summary>
|
||||
/// This implementation of <seealso cref="ANTLRErrorListener"/> dispatches all calls to a
|
||||
/// collection of delegate listeners. This reduces the effort required to support multiple
|
||||
/// listeners.
|
||||
/// </summary>
|
||||
|
||||
class ProxyErrorListener : public ANTLRErrorListener {
|
||||
private:
|
||||
std::vector<ANTLRErrorListener*> *const delegates;
|
||||
|
||||
public:
|
||||
template<typename T1> //where T1 : ANTLRErrorListener
|
||||
ProxyErrorListener(std::vector<T1> *delegates) : delegates(delegates) {
|
||||
if (delegates == nullptr) {
|
||||
throw new NullPointerException(L"delegates");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
template<typename T1, typename T2>
|
||||
void syntaxError(IRecognizer<T1, T2> *recognizer, void *offendingSymbol, int line, int charPositionInLine, const std::wstring &msg, RecognitionException *e) {
|
||||
|
||||
for (auto listener : *delegates) {
|
||||
listener->syntaxError(recognizer, offendingSymbol, line, charPositionInLine, msg, e);
|
||||
}
|
||||
}
|
||||
|
||||
virtual void reportAmbiguity(Parser *recognizer, dfa::DFA *dfa, int startIndex, int stopIndex, bool exact, antlrcpp::BitSet *ambigAlts, atn::ATNConfigSet *configs) override;
|
||||
|
||||
virtual void reportAttemptingFullContext(Parser *recognizer, dfa::DFA *dfa, int startIndex, int stopIndex, antlrcpp::BitSet *conflictingAlts, atn::ATNConfigSet *configs) override;
|
||||
|
||||
virtual void reportContextSensitivity(Parser *recognizer, dfa::DFA *dfa, int startIndex, int stopIndex, int prediction, atn::ATNConfigSet *configs) override;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,87 @@
|
|||
#include "RecognitionException.h"
|
||||
#include "ATN.h"
|
||||
#include "Recognizer.h"
|
||||
|
||||
/*
|
||||
* [The "BSD license"]
|
||||
* Copyright (c) 2013 Terence Parr
|
||||
* Copyright (c) 2013 Dan McLaughlin
|
||||
* 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. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
||||
*/
|
||||
|
||||
namespace org {
|
||||
namespace antlr {
|
||||
namespace v4 {
|
||||
namespace runtime {
|
||||
|
||||
int RecognitionException::getOffendingState() {
|
||||
return offendingState;
|
||||
}
|
||||
|
||||
void RecognitionException::setOffendingState(int offendingState) {
|
||||
this->offendingState = offendingState;
|
||||
}
|
||||
|
||||
misc::IntervalSet *RecognitionException::getExpectedTokens() {
|
||||
// Terence and Sam used some fancy Java wildcard generics which
|
||||
// cause us trouble here. TODO - can a Recognizer<void*, void*>
|
||||
// substitute for any other type of recognizer?
|
||||
if (recognizer != nullptr) {
|
||||
return ((Recognizer<void*, void*>*)recognizer)->getATN()->getExpectedTokens(offendingState, ctx);
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
RuleContext *RecognitionException::getCtx() {
|
||||
return ctx;
|
||||
}
|
||||
|
||||
IntStream *RecognitionException::getInputStream() {
|
||||
return input;
|
||||
}
|
||||
|
||||
Token *RecognitionException::getOffendingToken() {
|
||||
return offendingToken;
|
||||
}
|
||||
|
||||
void RecognitionException::setOffendingToken(Token *offendingToken) {
|
||||
this->offendingToken = offendingToken;
|
||||
}
|
||||
|
||||
IRecognizer<void*, void*> *RecognitionException::getRecognizer() {
|
||||
// Terence and Sam used some fancy Java wildcard generics which
|
||||
// cause us trouble here. TODO - can a Recognizer<void*, void*>
|
||||
// substitute for any other type of recognizer?
|
||||
return (IRecognizer<void*, void*> *)recognizer;
|
||||
}
|
||||
|
||||
void RecognitionException::InitializeInstanceFields() {
|
||||
offendingState = -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,181 @@
|
|||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <stdexcept>
|
||||
|
||||
#include "IRecognizer.h"
|
||||
#include "Declarations.h"
|
||||
#include "Exceptions.h"
|
||||
|
||||
|
||||
/*
|
||||
* [The "BSD license"]
|
||||
* Copyright (c) 2013 Terence Parr
|
||||
* Copyright (c) 2013 Dan McLaughlin
|
||||
* 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. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
||||
*/
|
||||
namespace org {
|
||||
namespace antlr {
|
||||
namespace v4 {
|
||||
namespace runtime {
|
||||
|
||||
class RuntimeException : public ANTLRException {
|
||||
public:
|
||||
RuntimeException(const std::wstring msg) : ANTLRException(msg) {}
|
||||
RuntimeException() {};
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// The root of the ANTLR exception hierarchy. In general, ANTLR tracks just
|
||||
/// 3 kinds of errors: prediction errors, failed predicate errors, and
|
||||
/// mismatched input errors. In each case, the parser knows where it is
|
||||
/// in the input, where it is in the ATN, the rule invocation stack,
|
||||
/// and what kind of problem occurred.
|
||||
/// </summary>
|
||||
class RecognitionException : public RuntimeException {
|
||||
/// <summary>
|
||||
/// The <seealso cref="Recognizer"/> where this exception originated. </summary>
|
||||
private:
|
||||
// Hairy wildcard generics from Java, attempt to fix with a raw void*
|
||||
// Recognizer<void*, void*> *const recognizer;
|
||||
void * recognizer;
|
||||
IntStream *const input;
|
||||
RuleContext *const ctx;
|
||||
|
||||
/// <summary>
|
||||
/// The current <seealso cref="Token"/> when an error occurred. Since not all streams
|
||||
/// support accessing symbols by index, we have to track the <seealso cref="Token"/>
|
||||
/// instance itself.
|
||||
/// </summary>
|
||||
Token *offendingToken;
|
||||
|
||||
int offendingState;
|
||||
|
||||
public:
|
||||
template<typename T1, typename T2>
|
||||
RecognitionException(IRecognizer<T1, T2> *recognizer, IntStream *input,
|
||||
ParserRuleContext * const ctx)
|
||||
: recognizer(recognizer), input(input), ctx((RuleContext*)ctx) {
|
||||
InitializeInstanceFields();
|
||||
if (recognizer != nullptr) {
|
||||
this->offendingState = recognizer->getState();
|
||||
}
|
||||
}
|
||||
|
||||
template<typename T1, typename T2>
|
||||
RecognitionException(const std::wstring &message, IRecognizer<T1, T2> *recognizer, IntStream *input, ParserRuleContext *ctx){
|
||||
InitializeInstanceFields();
|
||||
if (recognizer != nullptr) {
|
||||
this->offendingState = recognizer->getState();
|
||||
}
|
||||
}
|
||||
|
||||
RecognitionException() : recognizer(nullptr), input(nullptr), ctx(nullptr), offendingToken(nullptr) {}
|
||||
|
||||
/// <summary>
|
||||
/// Get the ATN state number the parser was in at the time the error
|
||||
/// occurred. For <seealso cref="NoViableAltException"/> and
|
||||
/// <seealso cref="LexerNoViableAltException"/> exceptions, this is the
|
||||
/// <seealso cref="DecisionState"/> number. For others, it is the state whose outgoing
|
||||
/// edge we couldn't match.
|
||||
/// <p/>
|
||||
/// If the state number is not known, this method returns -1.
|
||||
/// </summary>
|
||||
virtual int getOffendingState();
|
||||
|
||||
protected:
|
||||
void setOffendingState(int offendingState);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the set of input symbols which could potentially follow the
|
||||
/// previously matched symbol at the time this exception was thrown.
|
||||
/// <p/>
|
||||
/// If the set of expected tokens is not known and could not be computed,
|
||||
/// this method returns {@code null}.
|
||||
/// </summary>
|
||||
/// <returns> The set of token types that could potentially follow the current
|
||||
/// state in the ATN, or {@code null} if the information is not available. </returns>
|
||||
public:
|
||||
virtual misc::IntervalSet *getExpectedTokens();
|
||||
|
||||
/// <summary>
|
||||
/// Gets the <seealso cref="RuleContext"/> at the time this exception was thrown.
|
||||
/// <p/>
|
||||
/// If the context is not available, this method returns {@code null}.
|
||||
/// </summary>
|
||||
/// <returns> The <seealso cref="RuleContext"/> at the time this exception was thrown.
|
||||
/// If the context is not available, this method returns {@code null}. </returns>
|
||||
virtual RuleContext *getCtx();
|
||||
|
||||
/// <summary>
|
||||
/// Gets the input stream which is the symbol source for the recognizer where
|
||||
/// this exception was thrown.
|
||||
/// <p/>
|
||||
/// If the input stream is not available, this method returns {@code null}.
|
||||
/// </summary>
|
||||
/// <returns> The input stream which is the symbol source for the recognizer
|
||||
/// where this exception was thrown, or {@code null} if the stream is not
|
||||
/// available. </returns>
|
||||
virtual IntStream *getInputStream();
|
||||
|
||||
virtual Token *getOffendingToken();
|
||||
|
||||
protected:
|
||||
void setOffendingToken(Token *offendingToken);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the <seealso cref="Recognizer"/> where this exception occurred.
|
||||
/// <p/>
|
||||
/// If the recognizer is not available, this method returns {@code null}.
|
||||
/// </summary>
|
||||
/// <returns> The recognizer where this exception occurred, or {@code null} if
|
||||
/// the recognizer is not available. </returns>
|
||||
public:
|
||||
virtual IRecognizer<void*, void*> *getRecognizer();
|
||||
|
||||
private:
|
||||
void InitializeInstanceFields();
|
||||
};
|
||||
|
||||
// Recognition exceptions, TODO fill out the code
|
||||
|
||||
class ParseCancellationException : public RecognitionException {
|
||||
public:
|
||||
ParseCancellationException(const std::wstring msg) {};
|
||||
ParseCancellationException(RecognitionException*) {};
|
||||
ParseCancellationException() {};
|
||||
};
|
||||
|
||||
class EmptyStackException : public RecognitionException {
|
||||
public:
|
||||
EmptyStackException(const std::wstring msg) {}
|
||||
EmptyStackException() {};
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,232 @@
|
|||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include <list>
|
||||
#include <mutex>
|
||||
#include <algorithm>
|
||||
|
||||
#include "TokenFactory.h"
|
||||
#include "ATNSimulator.h"
|
||||
#include "Declarations.h"
|
||||
#include "ConsoleErrorListener.h"
|
||||
#include "Token.h"
|
||||
#include "StringBuilder.h"
|
||||
#include "ProxyErrorListener.h"
|
||||
#include "Strings.h"
|
||||
#include "CPPUtils.h"
|
||||
#include "RecognitionException.h"
|
||||
#include "IRecognizer.h"
|
||||
|
||||
/*
|
||||
* [The "BSD license"]
|
||||
* Copyright (c) 2013 Terence Parr
|
||||
* Copyright (c) 2013 Dan McLaughlin
|
||||
* 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. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
||||
*/
|
||||
|
||||
namespace org {
|
||||
namespace antlr {
|
||||
namespace v4 {
|
||||
namespace runtime {
|
||||
template<typename Symbol, typename ATNInterpreter>
|
||||
class Recognizer : public IRecognizer<Symbol, ATNInterpreter> {
|
||||
public:
|
||||
static const int _EOF = -1;
|
||||
|
||||
private:
|
||||
static std::map<std::vector<std::wstring>, std::map<std::wstring, int>*> _tokenTypeMapCache;
|
||||
static std::map<std::vector<std::wstring>, std::map<std::wstring, int>*> _ruleIndexMapCache;
|
||||
|
||||
std::vector<ANTLRErrorListener*> _listeners;
|
||||
//Mutex to manage synchronized access for multithreading
|
||||
std::mutex mtx;
|
||||
|
||||
#ifdef TODO
|
||||
// Damn code isn't even being used, why is it here?
|
||||
private:
|
||||
class CopyOnWriteArrayListAnonymousInnerClassHelper : public std::vector<ANTLRErrorListener*> {
|
||||
public:
|
||||
CopyOnWriteArrayListAnonymousInnerClassHelper();
|
||||
};
|
||||
#endif
|
||||
|
||||
protected:
|
||||
ATNInterpreter _interp;
|
||||
|
||||
private:
|
||||
int _stateNumber;
|
||||
|
||||
/// <summary>
|
||||
/// Used to print out token names like ID during debugging and
|
||||
/// error reporting. The generated parsers implement a method
|
||||
/// that overrides this to point to their String[] tokenNames.
|
||||
/// </summary>
|
||||
public:
|
||||
virtual const std::vector<std::wstring>& getTokenNames(){
|
||||
throw new ASSERTException(L"Recognizer", L"getTokenNames should never be called, abstract class");
|
||||
};// = 0;
|
||||
|
||||
virtual const std::vector<std::wstring>& getRuleNames() {
|
||||
throw new ASSERTException(L"Recognizer", L"getRuleNames should never be called, abstract class");
|
||||
};// = 0;
|
||||
|
||||
/// <summary>
|
||||
/// Get a map from token names to token types.
|
||||
/// <p/>
|
||||
/// Used for XPath and tree pattern compilation.
|
||||
/// </summary>
|
||||
virtual std::map<std::wstring, int> *getTokenTypeMap();
|
||||
|
||||
/// <summary>
|
||||
/// Get a map from rule names to rule indexes.
|
||||
/// <p/>
|
||||
/// Used for XPath and tree pattern compilation.
|
||||
/// </summary>
|
||||
virtual std::map<std::wstring, int> *getRuleIndexMap();
|
||||
|
||||
virtual int getTokenType(const std::wstring &tokenName);
|
||||
|
||||
/// <summary>
|
||||
/// If this recognizer was generated, it will have a serialized ATN
|
||||
/// representation of the grammar.
|
||||
/// <p/>
|
||||
/// For interpreters, we don't know their serialized ATN despite having
|
||||
/// created the interpreter from it.
|
||||
/// </summary>
|
||||
virtual std::wstring getSerializedATN() {
|
||||
throw L"there is no serialized ATN";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// For debugging and other purposes, might want the grammar name.
|
||||
/// Have ANTLR generate an implementation for this method.
|
||||
/// </summary>
|
||||
virtual std::wstring getGrammarFileName() = 0;
|
||||
|
||||
/// <summary>
|
||||
/// Get the <seealso cref="ATN"/> used by the recognizer for prediction.
|
||||
/// </summary>
|
||||
/// <returns> The <seealso cref="ATN"/> used by the recognizer for prediction. </returns>
|
||||
virtual atn::ATN *getATN() = 0;
|
||||
|
||||
/// <summary>
|
||||
/// Get the ATN interpreter used by the recognizer for prediction.
|
||||
/// </summary>
|
||||
/// <returns> The ATN interpreter used by the recognizer for prediction. </returns>
|
||||
virtual ATNInterpreter getInterpreter() {
|
||||
return _interp;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set the ATN interpreter used by the recognizer for prediction.
|
||||
/// </summary>
|
||||
/// <param name="interpreter"> The ATN interpreter used by the recognizer for
|
||||
/// prediction. </param>
|
||||
virtual void setInterpreter(ATNInterpreter interpreter) {
|
||||
_interp = interpreter;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// What is the error header, normally line/character position information? </summary>
|
||||
virtual std::wstring getErrorHeader(RecognitionException *e);
|
||||
|
||||
/// <summary>
|
||||
/// How should a token be displayed in an error message? The default
|
||||
/// is to display just the text, but during development you might
|
||||
/// want to have a lot of information spit out. Override in that case
|
||||
/// to use t.toString() (which, for CommonToken, dumps everything about
|
||||
/// the token). This is better than forcing you to override a method in
|
||||
/// your token objects because you don't have to go modify your lexer
|
||||
/// so that it creates a new Java type.
|
||||
/// </summary>
|
||||
virtual std::wstring getTokenErrorDisplay(Token *t);
|
||||
|
||||
/// <exception cref="NullPointerException"> if {@code listener} is {@code null}. </exception>
|
||||
virtual void addErrorListener(ANTLRErrorListener *listener);
|
||||
|
||||
virtual void removeErrorListener(ANTLRErrorListener *listener);
|
||||
|
||||
virtual void removeErrorListeners();
|
||||
|
||||
virtual std::vector<ANTLRErrorListener *> *getErrorListeners() {
|
||||
return &_listeners;
|
||||
}
|
||||
|
||||
virtual ANTLRErrorListener *getErrorListenerDispatch();
|
||||
|
||||
// subclass needs to override these if there are sempreds or actions
|
||||
// that the ATN interp needs to execute
|
||||
virtual bool sempred(RuleContext *_localctx, int ruleIndex, int actionIndex);
|
||||
|
||||
virtual bool precpred(RuleContext *localctx, int precedence);
|
||||
|
||||
virtual void action(RuleContext *_localctx, int ruleIndex, int actionIndex);
|
||||
|
||||
int getState();
|
||||
|
||||
/// <summary>
|
||||
/// Indicate that the recognizer has changed internal state that is
|
||||
/// consistent with the ATN state passed in. This way we always know
|
||||
/// where we are in the ATN as the parser goes along. The rule
|
||||
/// context objects form a stack that lets us see the stack of
|
||||
/// invoking rules. Combine this and we have complete ATN
|
||||
/// configuration information.
|
||||
/// </summary>
|
||||
void setState(int atnState);
|
||||
|
||||
virtual IntStream *getInputStream(){
|
||||
throw new ASSERTException(L"Recognizer::getInputStream", L"Should never be called, abstract class");
|
||||
|
||||
};// = 0;
|
||||
|
||||
virtual void setInputStream(IntStream *input){
|
||||
throw new ASSERTException(L"Recognizer::setInputStream", L"Should never be called, abstract class");
|
||||
};// = 0;
|
||||
|
||||
virtual TokenFactory<CommonToken *> *getTokenFactory(){
|
||||
throw new ASSERTException(L"Recognizer::getTokenFactory", L"Should never be called, abstract class");
|
||||
};// = 0;
|
||||
|
||||
template<typename T1>
|
||||
void setTokenFactory(TokenFactory<T1> *input);
|
||||
|
||||
private:
|
||||
void InitializeInstanceFields();
|
||||
|
||||
public:
|
||||
Recognizer();
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#include "Recognizer.inl"
|
||||
|
||||
|
|
@ -0,0 +1,218 @@
|
|||
#pragma once
|
||||
|
||||
/*
|
||||
* [The "BSD license"]
|
||||
* Copyright (c) 2013 Terence Parr
|
||||
* Copyright (c) 2013 Dan McLaughlin
|
||||
* 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. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
||||
*/
|
||||
|
||||
|
||||
namespace org {
|
||||
namespace antlr {
|
||||
namespace v4 {
|
||||
namespace runtime {
|
||||
template<typename T1, typename T2>
|
||||
std::map<std::vector<std::wstring>, std::map<std::wstring, int>*>
|
||||
Recognizer<T1, T2>::_tokenTypeMapCache;
|
||||
|
||||
template<typename T1, typename T2>
|
||||
std::map<std::vector<std::wstring>, std::map<std::wstring, int>*>
|
||||
Recognizer<T1, T2>::_ruleIndexMapCache;
|
||||
|
||||
template<typename T1, typename T2>
|
||||
std::map<std::wstring, int> *Recognizer<T1, T2>::getTokenTypeMap() {
|
||||
std::vector<std::wstring> tokenNames = getTokenNames();
|
||||
if (tokenNames.empty()) {
|
||||
throw L"The current recognizer does not provide a list of token names.";
|
||||
}
|
||||
|
||||
|
||||
{ // mutex lock
|
||||
std::lock_guard<std::mutex> lck(mtx);
|
||||
std::map<std::wstring, int> *result = _tokenTypeMapCache.at(tokenNames);
|
||||
if (result == nullptr) {
|
||||
// From Java - why ? result = misc::Utils::toMap(tokenNames);
|
||||
(*result)[L"EOF"] = Token::_EOF;
|
||||
|
||||
// TODO
|
||||
// From Java - why ? result = std::vector::unmodifiableMap(result);
|
||||
_tokenTypeMapCache[tokenNames] = result;
|
||||
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
template<typename T1, typename T2>
|
||||
std::map<std::wstring, int> *Recognizer<T1, T2>::getRuleIndexMap() {
|
||||
const std::vector<std::wstring>& ruleNames = getRuleNames();
|
||||
if (ruleNames.empty()) {
|
||||
throw L"The current recognizer does not provide a list of rule names.";
|
||||
}
|
||||
|
||||
{
|
||||
std::lock_guard<std::mutex> lck(mtx);
|
||||
std::map<std::wstring, int> *result = _ruleIndexMapCache.at(ruleNames);
|
||||
|
||||
if (result == nullptr) {
|
||||
result = antlrcpp::toMap(ruleNames);
|
||||
std::pair<std::vector<std::wstring>, std::map<std::wstring, int>*> tmp (ruleNames, result);
|
||||
_ruleIndexMapCache.insert(_ruleIndexMapCache.begin(), tmp);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
template<typename T1, typename T2>
|
||||
int Recognizer<T1, T2>::getTokenType(const std::wstring &tokenName) {
|
||||
|
||||
std::map<std::wstring, int> * map = getTokenTypeMap();
|
||||
int ttype = map->at(tokenName);
|
||||
|
||||
if (ttype != Token::INVALID_TYPE) {
|
||||
return ttype;
|
||||
}
|
||||
return Token::INVALID_TYPE;
|
||||
}
|
||||
|
||||
template<typename T1, typename T2>
|
||||
std::wstring Recognizer<T1, T2>::getErrorHeader(RecognitionException *e) {
|
||||
// We're having issues with cross header dependencies, these two classes will need to be
|
||||
// rewritten to remove that.
|
||||
int line = e->getOffendingToken()->getLine();
|
||||
int charPositionInLine = e->getOffendingToken()->getCharPositionInLine();
|
||||
return std::wstring(L"line ") + std::to_wstring(line) + std::wstring(L":") + std::to_wstring(charPositionInLine);
|
||||
|
||||
}
|
||||
|
||||
template<typename T1, typename T2>
|
||||
std::wstring Recognizer<T1, T2>::getTokenErrorDisplay(Token *t) {
|
||||
if (t == nullptr) {
|
||||
return L"<no token>";
|
||||
}
|
||||
std::wstring s = t->getText();
|
||||
if (s == L"") {
|
||||
if (t->getType() == Token::_EOF) {
|
||||
s = L"<EOF>";
|
||||
} else {
|
||||
s = std::wstring(L"<") + std::to_wstring(t->getType()) + std::wstring(L">");
|
||||
}
|
||||
}
|
||||
|
||||
antlrcpp::replaceAll(s, L"\n", L"\\n");
|
||||
|
||||
antlrcpp::replaceAll(s, L"\r",L"\\r");
|
||||
|
||||
antlrcpp::replaceAll(s, L"\t", L"\\t");
|
||||
|
||||
return std::wstring(L"'") + s + std::wstring(L"'");
|
||||
}
|
||||
|
||||
template<typename T1, typename T2>
|
||||
void Recognizer<T1, T2>::addErrorListener(ANTLRErrorListener *listener) {
|
||||
if (listener == nullptr) {
|
||||
throw L"listener cannot be null.";
|
||||
}
|
||||
|
||||
_listeners.insert(_listeners.end(), listener);
|
||||
}
|
||||
|
||||
template<typename T1, typename T2>
|
||||
void Recognizer<T1, T2>::removeErrorListener(ANTLRErrorListener *listener) {
|
||||
//_listeners.remove(listener); does this work the same way?
|
||||
std::vector<ANTLRErrorListener*>::iterator it;
|
||||
it = std::find(_listeners.begin(), _listeners.end(), listener);
|
||||
_listeners.erase(it);
|
||||
}
|
||||
|
||||
template<typename T1, typename T2>
|
||||
void Recognizer<T1, T2>::removeErrorListeners() {
|
||||
_listeners.clear();
|
||||
}
|
||||
|
||||
template<typename T1, typename T2>
|
||||
ANTLRErrorListener *Recognizer<T1, T2>::getErrorListenerDispatch() {
|
||||
return (ANTLRErrorListener *)new ProxyErrorListener(getErrorListeners());
|
||||
}
|
||||
|
||||
template<typename T1, typename T2>
|
||||
bool Recognizer<T1, T2>::sempred(RuleContext *_localctx, int ruleIndex, int actionIndex) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
template<typename T1, typename T2>
|
||||
bool Recognizer<T1, T2>::precpred(RuleContext *localctx, int precedence) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
template<typename T1, typename T2>
|
||||
void Recognizer<T1, T2>::action(RuleContext *_localctx, int ruleIndex, int actionIndex) {
|
||||
}
|
||||
|
||||
|
||||
template<typename T1, typename T2>
|
||||
int Recognizer<T1, T2>::getState() {
|
||||
return _stateNumber;
|
||||
}
|
||||
|
||||
template<typename T1, typename T2>
|
||||
void Recognizer<T1, T2>::setState(int atnState) {
|
||||
// System.err.println("setState "+atnState);
|
||||
_stateNumber = atnState;
|
||||
// if ( traceATNStates ) _ctx.trace(atnState);
|
||||
}
|
||||
|
||||
template<typename T1, typename T2>
|
||||
void Recognizer<T1, T2>::InitializeInstanceFields() {
|
||||
_stateNumber = -1;
|
||||
}
|
||||
|
||||
template<typename T1, typename T2>
|
||||
Recognizer<T1, T2>::Recognizer() {
|
||||
InitializeInstanceFields();
|
||||
_listeners = std::vector<ANTLRErrorListener*>();
|
||||
}
|
||||
|
||||
#ifdef TODO
|
||||
template<typename T1, typename T2>
|
||||
Recognizer<T1, T2>::
|
||||
CopyOnWriteArrayListAnonymousInnerClassHelper::CopyOnWriteArrayListAnonymousInnerClassHelper()
|
||||
{
|
||||
add(&ConsoleErrorListener::INSTANCE)
|
||||
}
|
||||
#endif
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,222 @@
|
|||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "RuleContext.h"
|
||||
#include "Trees.h"
|
||||
#include "Interval.h"
|
||||
#include "StringBuilder.h"
|
||||
#include "ParserRuleContext.h"
|
||||
#include "Parser.h"
|
||||
#include "Arrays.h"
|
||||
|
||||
/*
|
||||
* [The "BSD license"]
|
||||
* Copyright (c) 2013 Terence Parr
|
||||
* Copyright (c) 2013 Dan McLaughlin
|
||||
* 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. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
||||
*/
|
||||
|
||||
namespace org {
|
||||
namespace antlr {
|
||||
namespace v4 {
|
||||
namespace runtime {
|
||||
|
||||
ParserRuleContext *const RuleContext::EMPTY = new ParserRuleContext();
|
||||
|
||||
RuleContext::RuleContext() {
|
||||
InitializeInstanceFields();
|
||||
}
|
||||
|
||||
RuleContext::RuleContext(RuleContext *parent, int invokingState) {
|
||||
InitializeInstanceFields();
|
||||
this->parent = parent;
|
||||
//if ( parent!=null ) System.out.println("invoke "+stateNumber+" from "+parent);
|
||||
this->invokingState = invokingState;
|
||||
}
|
||||
|
||||
int RuleContext::depth() {
|
||||
int n = 0;
|
||||
RuleContext *p = this;
|
||||
while (p != nullptr) {
|
||||
p = p->parent;
|
||||
n++;
|
||||
}
|
||||
return n;
|
||||
}
|
||||
|
||||
bool RuleContext::isEmpty() {
|
||||
return invokingState == -1;
|
||||
}
|
||||
|
||||
misc::Interval *RuleContext::getSourceInterval() {
|
||||
return misc::Interval::INVALID;
|
||||
}
|
||||
|
||||
RuleContext *RuleContext::getRuleContext() {
|
||||
return this;
|
||||
}
|
||||
|
||||
RuleContext *RuleContext::getParent() {
|
||||
return parent;
|
||||
}
|
||||
|
||||
void *RuleContext::getPayload()
|
||||
/// <summary>
|
||||
/// Return the combined text of all child nodes. This method only considers
|
||||
/// tokens which have been added to the parse tree.
|
||||
/// <para>
|
||||
/// Since tokens on hidden channels (e.g. whitespace or comments) are not
|
||||
/// added to the parse trees, they will not appear in the output of this
|
||||
/// method.
|
||||
/// </para>
|
||||
/// </summary>
|
||||
{
|
||||
return this;
|
||||
}
|
||||
|
||||
std::wstring RuleContext::getText() {
|
||||
if (getChildCount() == 0) {
|
||||
return L"";
|
||||
}
|
||||
|
||||
antlrcpp::StringBuilder *builder = new antlrcpp::StringBuilder();
|
||||
for (int i = 0; i < getChildCount(); i++) {
|
||||
builder->append(getChild(i)->getText());
|
||||
}
|
||||
|
||||
return builder->toString();
|
||||
}
|
||||
|
||||
int RuleContext::getRuleIndex() {
|
||||
return -1;
|
||||
}
|
||||
|
||||
tree::ParseTree *RuleContext::getChild(int i) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
int RuleContext::getChildCount() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef TODO
|
||||
Future<JDialog*> *RuleContext::inspect(Parser *parser) {
|
||||
return inspect(parser->getRuleNames());
|
||||
}
|
||||
|
||||
|
||||
Future<JDialog*> *RuleContext::inspect(const std::vector<std::wstring> &ruleNames) {
|
||||
TreeViewer *viewer = new TreeViewer(ruleNames, this);
|
||||
return viewer->open();
|
||||
}
|
||||
#endif
|
||||
void RuleContext::save(Parser *parser, const std::wstring &fileName) {
|
||||
std::vector<std::wstring> ruleNames;
|
||||
if (parser != nullptr) {
|
||||
ruleNames = parser->getRuleNames();
|
||||
}
|
||||
save(ruleNames, fileName);
|
||||
}
|
||||
|
||||
void RuleContext::save(Parser *parser, const std::wstring &fileName, const std::wstring &fontName, int fontSize) {
|
||||
std::vector<std::wstring> ruleNames;
|
||||
if (parser != nullptr) {
|
||||
ruleNames = parser->getRuleNames();
|
||||
}
|
||||
save(ruleNames, fileName, fontName, fontSize);
|
||||
}
|
||||
|
||||
void RuleContext::save(std::vector<std::wstring> &ruleNames, const std::wstring &fileName) {
|
||||
#ifdef TODO
|
||||
tree::Trees::writePS(this, ruleNames, fileName);
|
||||
#endif
|
||||
}
|
||||
|
||||
void RuleContext::save(std::vector<std::wstring> &ruleNames, const std::wstring &fileName, const std::wstring &fontName, int fontSize) {
|
||||
#ifdef TODO
|
||||
tree::Trees::writePS(this, ruleNames, fileName, fontName, fontSize);
|
||||
#endif
|
||||
}
|
||||
|
||||
std::wstring RuleContext::toStringTree(Parser *recog) {
|
||||
return tree::Trees::toStringTree(this, recog);
|
||||
}
|
||||
|
||||
std::wstring RuleContext::toStringTree(std::vector<std::wstring> &ruleNames) {
|
||||
return tree::Trees::toStringTree(this, ruleNames);
|
||||
}
|
||||
|
||||
std::wstring RuleContext::toStringTree() {
|
||||
return toStringTree(nullptr);
|
||||
}
|
||||
|
||||
|
||||
std::wstring RuleContext::toString(const std::vector<std::wstring> &ruleNames) {
|
||||
return toString(ruleNames, static_cast<RuleContext*>(nullptr));
|
||||
}
|
||||
|
||||
|
||||
std::wstring RuleContext::toString(const std::vector<std::wstring> &ruleNames, RuleContext *stop) {
|
||||
antlrcpp::StringBuilder *buf = new antlrcpp::StringBuilder();
|
||||
RuleContext *p = this;
|
||||
buf->append(L"[");
|
||||
while (p != nullptr && p != stop) {
|
||||
if (ruleNames.empty()) {
|
||||
if (!p->isEmpty()) {
|
||||
buf->append(p->invokingState);
|
||||
}
|
||||
} else {
|
||||
int ruleIndex = p->getRuleIndex();
|
||||
|
||||
std::wstring ruleName = ruleIndex >= 0 && ruleIndex < (int)ruleNames.size() ? ruleNames[ruleIndex] : std::to_wstring(ruleIndex);
|
||||
buf->append(ruleName);
|
||||
}
|
||||
|
||||
if (p->parent != nullptr && (ruleNames.size() > 0 || !p->parent->isEmpty())) {
|
||||
buf->append(L" ");
|
||||
}
|
||||
|
||||
p = p->parent;
|
||||
}
|
||||
|
||||
buf->append(L"]");
|
||||
|
||||
return buf->toString();
|
||||
}
|
||||
|
||||
std::wstring RuleContext::toString() {
|
||||
#ifdef TODO
|
||||
#endif
|
||||
return L"TODO";
|
||||
};
|
||||
|
||||
void RuleContext::InitializeInstanceFields() {
|
||||
invokingState = -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,185 @@
|
|||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "RuleNode.h"
|
||||
#include "ParseTreeVisitor.h"
|
||||
#include "Recognizer.h"
|
||||
#include "Declarations.h"
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* [The "BSD license"]
|
||||
* Copyright (c) 2013 Terence Parr
|
||||
* Copyright (c) 2013 Dan McLaughlin
|
||||
* 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. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
||||
*/
|
||||
|
||||
namespace org {
|
||||
namespace antlr {
|
||||
namespace v4 {
|
||||
namespace runtime {
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// A rule context is a record of a single rule invocation. It knows
|
||||
/// which context invoked it, if any. If there is no parent context, then
|
||||
/// naturally the invoking state is not valid. The parent link
|
||||
/// provides a chain upwards from the current rule invocation to the root
|
||||
/// of the invocation tree, forming a stack. We actually carry no
|
||||
/// information about the rule associated with this context (except
|
||||
/// when parsing). We keep only the state number of the invoking state from
|
||||
/// the ATN submachine that invoked this. Contrast this with the s
|
||||
/// pointer inside ParserRuleContext that tracks the current state
|
||||
/// being "executed" for the current rule.
|
||||
///
|
||||
/// The parent contexts are useful for computing lookahead sets and
|
||||
/// getting error information.
|
||||
///
|
||||
/// These objects are used during parsing and prediction.
|
||||
/// For the special case of parsers, we use the subclass
|
||||
/// ParserRuleContext.
|
||||
/// </summary>
|
||||
/// <seealso cref= ParserRuleContext </seealso>
|
||||
class RuleContext : public tree::RuleNode {
|
||||
public:
|
||||
static ParserRuleContext *const EMPTY;
|
||||
|
||||
/// <summary>
|
||||
/// What context invoked this rule? </summary>
|
||||
RuleContext *parent;
|
||||
|
||||
/// <summary>
|
||||
/// What state invoked the rule associated with this context?
|
||||
/// The "return address" is the followState of invokingState
|
||||
/// If parent is null, this should be -1.
|
||||
/// </summary>
|
||||
int invokingState;
|
||||
|
||||
RuleContext();
|
||||
|
||||
RuleContext(RuleContext *parent, int invokingState);
|
||||
|
||||
virtual int depth();
|
||||
|
||||
/// <summary>
|
||||
/// A context is empty if there is no invoking state; meaning nobody call
|
||||
/// current context.
|
||||
/// </summary>
|
||||
virtual bool isEmpty();
|
||||
|
||||
// satisfy the ParseTree / SyntaxTree interface
|
||||
|
||||
virtual misc::Interval *getSourceInterval() override;
|
||||
|
||||
virtual RuleContext *getRuleContext() override;
|
||||
virtual RuleContext *getParent() override;
|
||||
virtual void *getPayload() override;
|
||||
virtual std::wstring getText() override;
|
||||
|
||||
virtual int getRuleIndex();
|
||||
|
||||
virtual ParseTree *getChild(int i) override;
|
||||
|
||||
virtual int getChildCount() override;
|
||||
|
||||
template<typename T, typename T1>
|
||||
T accept(tree::ParseTreeVisitor<T1> *visitor) {
|
||||
return visitor->visitChildren(this);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Call this method to view a parse tree in a dialog box visually. </summary>
|
||||
#ifdef TODO
|
||||
virtual Future<JDialog*> *inspect(Parser *parser);
|
||||
|
||||
virtual Future<JDialog*> *inspect(std::vector<std::wstring> &ruleNames);
|
||||
#endif
|
||||
/// <summary>
|
||||
/// Save this tree in a postscript file </summary>
|
||||
virtual void save(Parser *parser, const std::wstring &fileName);
|
||||
|
||||
/// <summary>
|
||||
/// Save this tree in a postscript file using a particular font name and size </summary>
|
||||
virtual void save(Parser *parser, const std::wstring &fileName, const std::wstring &fontName, int fontSize);
|
||||
|
||||
/// <summary>
|
||||
/// Save this tree in a postscript file </summary>
|
||||
virtual void save(std::vector<std::wstring> &ruleNames, const std::wstring &fileName);
|
||||
|
||||
/// <summary>
|
||||
/// Save this tree in a postscript file using a particular font name and size </summary>
|
||||
virtual void save(std::vector<std::wstring> &ruleNames, const std::wstring &fileName, const std::wstring &fontName, int fontSize);
|
||||
|
||||
/// <summary>
|
||||
/// Print out a whole tree, not just a node, in LISP format
|
||||
/// (root child1 .. childN). Print just a node if this is a leaf.
|
||||
/// We have to know the recognizer so we can get rule names.
|
||||
/// </summary>
|
||||
virtual std::wstring toStringTree(Parser *recog);
|
||||
|
||||
/// <summary>
|
||||
/// Print out a whole tree, not just a node, in LISP format
|
||||
/// (root child1 .. childN). Print just a node if this is a leaf.
|
||||
/// </summary>
|
||||
virtual std::wstring toStringTree(std::vector<std::wstring> &ruleNames);
|
||||
|
||||
virtual std::wstring toStringTree() override;
|
||||
|
||||
virtual std::wstring toString();
|
||||
|
||||
|
||||
template<typename T1, typename T2>
|
||||
std::wstring toString(Recognizer<T1, T2> *recog) {
|
||||
// Circular include issue, TODO
|
||||
//return toString(recog, ParserRuleContext::EMPTY);
|
||||
return toString(recog, nullptr);
|
||||
}
|
||||
|
||||
std::wstring toString(const std::vector<std::wstring> &ruleNames);
|
||||
|
||||
// recog null unless ParserRuleContext, in which case we use subclass toString(...)
|
||||
template<typename T1, typename T2>
|
||||
std::wstring toString(Recognizer<T1, T2> *recog, RuleContext *stop) {
|
||||
return toString(recog->getRuleNames(), stop);
|
||||
}
|
||||
|
||||
std::wstring toString(Token *, atn::ParserATNSimulator *) {
|
||||
return L"TODO";
|
||||
}
|
||||
|
||||
virtual std::wstring toString(const std::vector<std::wstring> &ruleNames, RuleContext *stop);
|
||||
|
||||
private:
|
||||
void InitializeInstanceFields();
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,46 @@
|
|||
#include "Token.h"
|
||||
|
||||
/*
|
||||
* [The "BSD license"]
|
||||
* Copyright (c) 2013 Terence Parr
|
||||
* Copyright (c) 2013 Dan McLaughlin
|
||||
* 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. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
||||
*/
|
||||
|
||||
namespace org {
|
||||
namespace antlr {
|
||||
namespace v4 {
|
||||
namespace runtime {
|
||||
const int Token::INVALID_TYPE;
|
||||
const int Token::EPSILON;
|
||||
const int Token::MIN_USER_TOKEN_TYPE;
|
||||
const int Token::_EOF;
|
||||
const int Token::DEFAULT_CHANNEL;
|
||||
const int Token::HIDDEN_CHANNEL;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue