├── Languages ├── npeg_java │ ├── nbproject │ │ ├── private │ │ │ ├── config.properties │ │ │ └── private.properties │ │ ├── genfiles.properties │ │ └── project.xml │ ├── manifest.mf │ ├── robusthaven │ │ ├── robusthaven │ │ │ └── text │ │ │ │ ├── ICreateCustomAstNode.java │ │ │ │ ├── IAstNodeVisitor.java │ │ │ │ ├── InfiniteLoopException.java │ │ │ │ ├── IAstNodeReplacement.java │ │ │ │ ├── FileInputIterator.java │ │ │ │ ├── ParsingFatalTerminalException.java │ │ │ │ ├── Warn.java │ │ │ │ ├── TokenMatch.java │ │ │ │ ├── StringInputIterator.java │ │ │ │ ├── PrintVisitor.java │ │ │ │ └── AstNode.java │ │ └── Makefile │ ├── .project │ ├── .classpath │ └── robusthaven.test │ │ ├── run_tests.sh │ │ ├── Makefile │ │ ├── FatalTerminalTest.java │ │ ├── InputIteratorEmptyTest.java │ │ ├── lib_tests.sh │ │ ├── robusthaven │ │ └── text │ │ │ └── npeg │ │ │ └── tests │ │ │ └── parsers │ │ │ ├── OneOrMoreInfiniteLoopTest.java.bk │ │ │ ├── ZeroOrMoreInfiniteLoopTest.java.bk │ │ │ ├── NpegNode.java │ │ │ └── LimitingRepetitionInfiniteLoopTest.java.bk │ │ ├── WarnTerminalTest.java │ │ ├── parser_tests │ │ └── NpegNodeTest.java │ │ └── InputIteratorStdLookupsTest.java ├── npeg_c │ ├── robusthaven.tests │ │ ├── pedantic_build.sh │ │ ├── ParserTest_SimpleSentence │ │ │ ├── SimpleSentence.h │ │ │ └── Makefile │ │ ├── ParserTest_NpegNode │ │ │ ├── Makefile │ │ │ ├── NpegNode.h │ │ │ └── NpegNode.c │ │ ├── ParserTest_PhoneNumber │ │ │ ├── Makefile │ │ │ └── PhoneNumber.h │ │ ├── ParserTest_SimpleXml │ │ │ ├── Makefile │ │ │ └── SimpleXml.h │ │ ├── ParserTest_MathematicalFormula │ │ │ └── Makefile │ │ ├── test_ast_constructor.c │ │ ├── test_stack_constructor.c │ │ ├── test_stackstack_constructor.c │ │ ├── Makefile │ │ ├── test_hashmap_constructor.c │ │ ├── lib_tests.sh │ │ ├── test_inthashmap_constructor.c │ │ ├── run_memorychecker.sh │ │ ├── test_inputiterator_empty.c │ │ ├── test_inthashmap_insert_lookup.c │ │ ├── run_tests.sh │ │ ├── test_inputiterator_std_lookups.c │ │ ├── test_inputiterator_get_text.c │ │ ├── robusthaven.tests.cproj │ │ ├── test_list_all.c │ │ ├── test_terminal_npeg_Fatal.c │ │ └── test_terminal_npeg_Warn.c │ └── robusthaven │ │ ├── types │ │ └── types.h │ │ ├── text │ │ ├── npeg_token.h │ │ ├── printvisitor.h │ │ └── printvisitor.c │ │ ├── Makefile │ │ └── structures │ │ ├── list.h │ │ ├── list.c │ │ └── stackstack.h ├── npeg_csharp │ ├── RobustHaven.Text.Npeg.Tests │ │ ├── Externs │ │ │ ├── nunit.core.dll │ │ │ └── nunit.framework.dll │ │ ├── NpegNUnitProject.nunit │ │ ├── CustomAstNodeCreationTests.cs │ │ ├── InputIteratorTests.cs │ │ ├── Parsers │ │ │ ├── NpegNode.cs │ │ │ ├── OneOrMoreInfiniteLoopTest.cs │ │ │ ├── ZeroOrMoreInfiniteLoopTest.cs │ │ │ └── LimitingRepetitionInfiniteLoopTest.cs │ │ ├── InfiniteLoopDetectedTests.cs │ │ ├── ParserTests.cs │ │ └── Properties │ │ │ └── AssemblyInfo.cs │ └── RobustHaven.Text.Npeg │ │ ├── IAstNodeFactory.cs │ │ ├── IAstNodeVisitor.cs │ │ ├── IteratorUsageException.cs │ │ ├── InvalidInputException.cs │ │ ├── ParsingExpressionGrammarException.cs │ │ ├── ParsingFatalTerminalException.cs │ │ ├── Warn.cs │ │ ├── InfiniteLoopDetectedException.cs │ │ ├── TokenMatch.cs │ │ ├── IAstNodeReplacement.cs │ │ ├── AstNode.cs │ │ ├── InputIterator.cs │ │ ├── FileInputIterator.cs │ │ ├── StringInputIterator.cs │ │ ├── RobustHaven.Text.Npeg.sln │ │ └── Properties │ │ └── AssemblyInfo.cs ├── npeg_php │ ├── ICreateCustomAstNode.php │ ├── FileInputIterator.php │ ├── IAstNodeVisitor.php │ ├── ParsingExpressionGrammarException.php │ ├── ParsingFatalTerminalException.php │ ├── IAstNodeReplacement.php │ ├── InputIterator.php │ ├── TokenMatch.php │ ├── InfiniteLoopDetectedException.php │ ├── Warn.php │ ├── AstNode.php │ └── StringInputIterator.php ├── npeg_javascript │ ├── tools │ │ ├── Yahoo.Yui.Compressor v2.0.0.0 │ │ │ ├── NAnt.Core.dll │ │ │ ├── EcmaScript.NET.dll │ │ │ ├── Iesi.Collections.dll │ │ │ ├── Yahoo.Yui.Compressor.dll │ │ │ ├── Yahoo.Yui.Compressor.Build.Nant.dll │ │ │ ├── Yahoo.Yui.Compressor.Build.MsBuild.dll │ │ │ └── New BSD License.txt │ │ └── combine-compress.proj │ ├── _Build.bat │ ├── Expression.js │ ├── IAstNodeVisitor.js │ ├── ParsingExpressionGrammarException.js │ ├── InfiniteLoopException.js │ ├── InputIterator.js │ ├── Warn.js │ ├── TokenMatch.js │ ├── ParsingFatalTerminalException.js │ ├── helper.js │ └── AstNode.js └── npeg_c++ │ ├── robusthaven │ ├── text │ │ ├── Warn.cpp │ │ ├── FileInputIterator.cpp │ │ ├── IAstNodeFactory.h │ │ ├── IAstNodeVisitor.h │ │ ├── FileInputIterator.h │ │ ├── IAstNodeReplacement.h │ │ ├── StringInputIterator.cpp │ │ ├── Warn.h │ │ ├── StringInputIterator.h │ │ ├── Exceptions.h │ │ ├── TokenMatch.h │ │ ├── InputIterator.cpp │ │ ├── AstNode.cpp │ │ ├── PrintVisitor.h │ │ └── AstNode.h │ └── Makefile │ └── robusthaven.tests │ ├── ParserTest_NpegNode │ ├── Makefile │ ├── NpegNode.h │ └── NpegNode.cpp │ ├── ParserTest_SimpleXml │ ├── Makefile │ └── SimpleXml.h │ ├── ParserTest_PhoneNumber │ ├── Makefile │ └── PhoneNumber.h │ ├── ParserTest_MathematicalFormula │ └── Makefile │ ├── test_ast_constructor.cpp │ ├── lib_tests.sh │ ├── Makefile │ ├── test_inputiterator_empty.cpp │ ├── run_memorychecker.sh │ ├── run_tests.sh │ ├── test_terminal_npeg_Fatal.cpp │ ├── test_inputiterator_std_lookups.cpp │ ├── test_terminal_npeg_Warn.cpp │ ├── test_inputiterator_get_text.cpp │ └── test_terminal_npeg_AnyCharacter.cpp ├── .nuget ├── NuGet.exe └── NuGet.Config ├── GlobalAssemblyInfo.cs ├── LanguageWorkbench ├── Icons │ ├── npeg_16x16.png │ ├── npeg_32x32.png │ ├── npeg_48x48.png │ └── npeg_128x128.png ├── Properties │ ├── AppManifest.xml │ ├── InBrowserSettings.xml │ ├── OutOfBrowserSettings.xml │ └── AssemblyInfo.cs ├── Algorithms │ ├── LanguageWriters │ │ ├── WriterBase.cs │ │ └── MethodInfo.cs │ └── PrintAST.cs ├── SupportedLanguagesCollection.cs ├── App.xaml ├── SupportedLanguageItem.cs ├── WorkBenchView.xaml.cs ├── Converters │ └── RemoveNameSpaceConverter.cs ├── UIHelper.cs └── MultiBinding │ └── MultiBindingValidationError.cs ├── Externs ├── RobustHaven.Windows.Controls.dll └── silverlight │ └── prism │ ├── Microsoft.Practices.Composite.dll │ ├── Microsoft.Practices.ServiceLocation.dll │ ├── Microsoft.Practices.Unity.Silverlight.dll │ ├── Microsoft.Practices.Composite.Presentation.dll │ └── Microsoft.Practices.Composite.UnityExtensions.dll ├── Documentation ├── codepoint-byte-consumption.jpg ├── Packrat Parsing - Simple, Powerful, Lazy, Linear Time.pdf └── Parsing Expression Grammars.A Recognition-Based Syntactic Foundation.pdf ├── LanguageWorkbench.Web ├── ClientBin │ └── LanguageWorkbench.xap ├── _PostDeploy.ps1 ├── Web.config └── Properties │ └── AssemblyInfo.cs ├── NPEG ├── IAstNodeFactory.cs ├── Terminals │ ├── AnyCharacter.cs │ ├── CharacterClass.cs │ ├── Fatal.cs │ ├── RecursionCall.cs │ ├── Warn.cs │ ├── Literal.cs │ ├── DynamicBackReference.cs │ └── CodePoint.cs ├── GrammarInterpreter │ ├── NpegOptions.cs │ ├── InterpreterParseException.cs │ ├── AstNodes │ │ ├── PeGrammarAstNodeFactory.cs │ │ └── StatementAstNode.cs │ ├── LimitingRepetitionVariableLengthExpressionParser.cs │ └── NpegLog.cs ├── IAstNodeReplacement.cs ├── ALeaf.cs ├── ApplicationExceptions │ ├── IteratorUsageException.cs │ ├── NpegException.cs │ ├── InvalidInputException.cs │ ├── InvalidRuleException.cs │ └── ParsingFatalTerminalException.cs ├── AExpression.cs ├── Extensions │ ├── StackExtensions.cs │ ├── TokenMatchExtensions.cs │ └── StringExtensions.cs ├── NPEG.standard2.0.csproj ├── Properties │ └── AssemblyInfo.cs ├── NonTerminals │ ├── OneOrMore.cs │ ├── Optional.cs │ ├── ZeroOrMore.cs │ ├── NotPredicate.cs │ ├── AndPredicate.cs │ ├── Sequence.cs │ ├── PrioritizedChoice.cs │ ├── RecursionCreate.cs │ ├── CapturingGroup.cs │ └── LimitingRepetition.cs ├── TokenMatch.cs ├── IInputIterator.cs ├── Algorithms │ └── AstWriter.cs ├── AstNode.cs ├── StreamInputIterator.cs └── ByteInputIterator.cs ├── .editorconfig ├── NPEG.Tests ├── Properties │ └── AssemblyInfo.cs ├── packages.config ├── Extensions │ └── Timing.cs └── PredicateTests.cs ├── .gitignore ├── NPEG.standard2.0.sln └── NPEG.sln /Languages/npeg_java/nbproject/private/config.properties: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.nuget/NuGet.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leblancmeneses/NPEG/HEAD/.nuget/NuGet.exe -------------------------------------------------------------------------------- /GlobalAssemblyInfo.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leblancmeneses/NPEG/HEAD/GlobalAssemblyInfo.cs -------------------------------------------------------------------------------- /Languages/npeg_java/manifest.mf: -------------------------------------------------------------------------------- 1 | Manifest-Version: 1.0 2 | X-COMMENT: Main-Class will be added automatically by build 3 | 4 | -------------------------------------------------------------------------------- /LanguageWorkbench/Icons/npeg_16x16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leblancmeneses/NPEG/HEAD/LanguageWorkbench/Icons/npeg_16x16.png -------------------------------------------------------------------------------- /LanguageWorkbench/Icons/npeg_32x32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leblancmeneses/NPEG/HEAD/LanguageWorkbench/Icons/npeg_32x32.png -------------------------------------------------------------------------------- /LanguageWorkbench/Icons/npeg_48x48.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leblancmeneses/NPEG/HEAD/LanguageWorkbench/Icons/npeg_48x48.png -------------------------------------------------------------------------------- /Externs/RobustHaven.Windows.Controls.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leblancmeneses/NPEG/HEAD/Externs/RobustHaven.Windows.Controls.dll -------------------------------------------------------------------------------- /LanguageWorkbench/Icons/npeg_128x128.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leblancmeneses/NPEG/HEAD/LanguageWorkbench/Icons/npeg_128x128.png -------------------------------------------------------------------------------- /Documentation/codepoint-byte-consumption.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leblancmeneses/NPEG/HEAD/Documentation/codepoint-byte-consumption.jpg -------------------------------------------------------------------------------- /LanguageWorkbench.Web/ClientBin/LanguageWorkbench.xap: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leblancmeneses/NPEG/HEAD/LanguageWorkbench.Web/ClientBin/LanguageWorkbench.xap -------------------------------------------------------------------------------- /NPEG/IAstNodeFactory.cs: -------------------------------------------------------------------------------- 1 | namespace NPEG 2 | { 3 | public interface IAstNodeFactory 4 | { 5 | IAstNodeReplacement Create(AstNode original); 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /Externs/silverlight/prism/Microsoft.Practices.Composite.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leblancmeneses/NPEG/HEAD/Externs/silverlight/prism/Microsoft.Practices.Composite.dll -------------------------------------------------------------------------------- /Languages/npeg_c/robusthaven.tests/pedantic_build.sh: -------------------------------------------------------------------------------- 1 | make -C ../robusthaven CFLAGS="-ggdb -Wall -pedantic" clean all 2 | make CFLAGS="-ggdb -Wall -pedantic -I../" clean all -------------------------------------------------------------------------------- /LanguageWorkbench.Web/_PostDeploy.ps1: -------------------------------------------------------------------------------- 1 | cp ClientBin\LanguageWorkbench.xap \\SRVSQL1\central-storage-cms\Tenants\www.robusthaven.com\Data\PostModule\66\LanguageWorkbench.xap 2 | 3 | -------------------------------------------------------------------------------- /Externs/silverlight/prism/Microsoft.Practices.ServiceLocation.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leblancmeneses/NPEG/HEAD/Externs/silverlight/prism/Microsoft.Practices.ServiceLocation.dll -------------------------------------------------------------------------------- /Externs/silverlight/prism/Microsoft.Practices.Unity.Silverlight.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leblancmeneses/NPEG/HEAD/Externs/silverlight/prism/Microsoft.Practices.Unity.Silverlight.dll -------------------------------------------------------------------------------- /Documentation/Packrat Parsing - Simple, Powerful, Lazy, Linear Time.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leblancmeneses/NPEG/HEAD/Documentation/Packrat Parsing - Simple, Powerful, Lazy, Linear Time.pdf -------------------------------------------------------------------------------- /.nuget/NuGet.Config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Externs/silverlight/prism/Microsoft.Practices.Composite.Presentation.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leblancmeneses/NPEG/HEAD/Externs/silverlight/prism/Microsoft.Practices.Composite.Presentation.dll -------------------------------------------------------------------------------- /Languages/npeg_c/robusthaven/types/types.h: -------------------------------------------------------------------------------- 1 | #ifndef ROBUSTHAVEN_TYPES_TYPES_H 2 | #define ROBUSTHAVEN_TYPES_TYPES_H 3 | 4 | typedef unsigned int uint; 5 | typedef unsigned char uchar; 6 | 7 | #endif 8 | -------------------------------------------------------------------------------- /Languages/npeg_csharp/RobustHaven.Text.Npeg.Tests/Externs/nunit.core.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leblancmeneses/NPEG/HEAD/Languages/npeg_csharp/RobustHaven.Text.Npeg.Tests/Externs/nunit.core.dll -------------------------------------------------------------------------------- /Languages/npeg_php/ICreateCustomAstNode.php: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /NPEG/Terminals/AnyCharacter.cs: -------------------------------------------------------------------------------- 1 | using System.Runtime.Serialization; 2 | 3 | namespace NPEG.Terminals 4 | { 5 | [DataContract] 6 | public class AnyCharacter : ALeaf 7 | { 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /Externs/silverlight/prism/Microsoft.Practices.Composite.UnityExtensions.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leblancmeneses/NPEG/HEAD/Externs/silverlight/prism/Microsoft.Practices.Composite.UnityExtensions.dll -------------------------------------------------------------------------------- /Languages/npeg_javascript/tools/Yahoo.Yui.Compressor v2.0.0.0/NAnt.Core.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leblancmeneses/NPEG/HEAD/Languages/npeg_javascript/tools/Yahoo.Yui.Compressor v2.0.0.0/NAnt.Core.dll -------------------------------------------------------------------------------- /Languages/npeg_csharp/RobustHaven.Text.Npeg.Tests/Externs/nunit.framework.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leblancmeneses/NPEG/HEAD/Languages/npeg_csharp/RobustHaven.Text.Npeg.Tests/Externs/nunit.framework.dll -------------------------------------------------------------------------------- /Languages/npeg_csharp/RobustHaven.Text.Npeg/IAstNodeFactory.cs: -------------------------------------------------------------------------------- 1 | namespace RobustHaven.Text.Npeg 2 | { 3 | public interface IAstNodeFactory 4 | { 5 | IAstNodeReplacement Create(AstNode original); 6 | } 7 | } -------------------------------------------------------------------------------- /Languages/npeg_javascript/_Build.bat: -------------------------------------------------------------------------------- 1 | @setlocal enableextensions 2 | @cd /d "%~dp0" 3 | %windir%\Microsoft.NET\Framework\v4.0.30319\msbuild.exe tools\combine-compress.proj /fl /flp:v=diag;logfile=build.log 4 | pause -------------------------------------------------------------------------------- /Languages/npeg_java/robusthaven/robusthaven/text/ICreateCustomAstNode.java: -------------------------------------------------------------------------------- 1 | package robusthaven.text; 2 | 3 | public interface ICreateCustomAstNode { 4 | IAstNodeReplacement create(AstNode original); 5 | } 6 | 7 | -------------------------------------------------------------------------------- /Languages/npeg_javascript/tools/Yahoo.Yui.Compressor v2.0.0.0/EcmaScript.NET.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leblancmeneses/NPEG/HEAD/Languages/npeg_javascript/tools/Yahoo.Yui.Compressor v2.0.0.0/EcmaScript.NET.dll -------------------------------------------------------------------------------- /Languages/npeg_php/FileInputIterator.php: -------------------------------------------------------------------------------- 1 | 11 | 12 | -------------------------------------------------------------------------------- /Languages/npeg_javascript/tools/Yahoo.Yui.Compressor v2.0.0.0/Iesi.Collections.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leblancmeneses/NPEG/HEAD/Languages/npeg_javascript/tools/Yahoo.Yui.Compressor v2.0.0.0/Iesi.Collections.dll -------------------------------------------------------------------------------- /Documentation/Parsing Expression Grammars.A Recognition-Based Syntactic Foundation.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leblancmeneses/NPEG/HEAD/Documentation/Parsing Expression Grammars.A Recognition-Based Syntactic Foundation.pdf -------------------------------------------------------------------------------- /Languages/npeg_javascript/tools/Yahoo.Yui.Compressor v2.0.0.0/Yahoo.Yui.Compressor.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leblancmeneses/NPEG/HEAD/Languages/npeg_javascript/tools/Yahoo.Yui.Compressor v2.0.0.0/Yahoo.Yui.Compressor.dll -------------------------------------------------------------------------------- /Languages/npeg_java/nbproject/private/private.properties: -------------------------------------------------------------------------------- 1 | compile.on.save=true 2 | do.depend=false 3 | do.jar=true 4 | javac.debug=true 5 | javadoc.preview=true 6 | user.properties.file=/home/sfj/.netbeans/6.5/build.properties 7 | -------------------------------------------------------------------------------- /Languages/npeg_java/robusthaven/robusthaven/text/IAstNodeVisitor.java: -------------------------------------------------------------------------------- 1 | package robusthaven.text; 2 | 3 | public interface IAstNodeVisitor { 4 | public void visitEnter(AstNode node); 5 | public void visitLeave(AstNode node); 6 | } 7 | -------------------------------------------------------------------------------- /LanguageWorkbench/Properties/AppManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | -------------------------------------------------------------------------------- /LanguageWorkbench/Properties/InBrowserSettings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /LanguageWorkbench/Algorithms/LanguageWriters/WriterBase.cs: -------------------------------------------------------------------------------- 1 | using NPEG; 2 | 3 | namespace LanguageWorkbench.Algorithms.LanguageWriters 4 | { 5 | public abstract class WriterBase : IParseTreeVisitor 6 | { 7 | public abstract void Write(); 8 | } 9 | } -------------------------------------------------------------------------------- /Languages/npeg_javascript/tools/Yahoo.Yui.Compressor v2.0.0.0/Yahoo.Yui.Compressor.Build.Nant.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leblancmeneses/NPEG/HEAD/Languages/npeg_javascript/tools/Yahoo.Yui.Compressor v2.0.0.0/Yahoo.Yui.Compressor.Build.Nant.dll -------------------------------------------------------------------------------- /NPEG/GrammarInterpreter/NpegOptions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace NPEG.GrammarInterpreter 4 | { 5 | [Flags] 6 | public enum NpegOptions 7 | { 8 | Optimize = 0x2, 9 | Cached = 0x1, 10 | None = 0x0 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Languages/npeg_javascript/tools/Yahoo.Yui.Compressor v2.0.0.0/Yahoo.Yui.Compressor.Build.MsBuild.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leblancmeneses/NPEG/HEAD/Languages/npeg_javascript/tools/Yahoo.Yui.Compressor v2.0.0.0/Yahoo.Yui.Compressor.Build.MsBuild.dll -------------------------------------------------------------------------------- /LanguageWorkbench/SupportedLanguagesCollection.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.ObjectModel; 2 | 3 | namespace LanguageWorkbench 4 | { 5 | public class SupportedLanguagesCollection : ObservableCollection 6 | { 7 | 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /Languages/npeg_csharp/RobustHaven.Text.Npeg/IAstNodeVisitor.cs: -------------------------------------------------------------------------------- 1 | namespace RobustHaven.Text.Npeg 2 | { 3 | public interface IAstNodeVisitor 4 | { 5 | void VisitEnter(AstNode node); 6 | void VisitExecute(AstNode node); 7 | void VisitLeave(AstNode node); 8 | } 9 | } -------------------------------------------------------------------------------- /NPEG/IAstNodeReplacement.cs: -------------------------------------------------------------------------------- 1 | namespace NPEG 2 | { 3 | // visitor 4 | public abstract class IAstNodeReplacement : AstNode 5 | { 6 | public abstract void VisitEnter(AstNode node); 7 | public abstract void VisitLeave(AstNode node); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /Languages/npeg_java/robusthaven/robusthaven/text/InfiniteLoopException.java: -------------------------------------------------------------------------------- 1 | package robusthaven.text; 2 | 3 | public class InfiniteLoopException extends ParsingFatalTerminalException { 4 | InfiniteLoopException(String msg, long pos) { 5 | super(msg, pos); 6 | } 7 | } -------------------------------------------------------------------------------- /Languages/npeg_php/IAstNodeVisitor.php: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /Languages/npeg_c/robusthaven/text/npeg_token.h: -------------------------------------------------------------------------------- 1 | #ifndef ROBUSTHAVEN_TEXT_NPEG_TOKEN_H 2 | #define ROBUSTHAVEN_TEXT_NPEG_TOKEN_H 3 | 4 | 5 | typedef struct npeg_token { 6 | char* name; // name of token 7 | int start; 8 | int end; 9 | } npeg_token; 10 | 11 | #endif 12 | -------------------------------------------------------------------------------- /Languages/npeg_java/robusthaven/robusthaven/text/IAstNodeReplacement.java: -------------------------------------------------------------------------------- 1 | package robusthaven.text; 2 | 3 | public abstract class IAstNodeReplacement extends AstNode implements IAstNodeVisitor { 4 | public IAstNodeReplacement(TokenMatch token) { 5 | super(token); 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /Languages/npeg_javascript/Expression.js: -------------------------------------------------------------------------------- 1 | if(!RobustHaven) var RobustHaven={}; 2 | if(!RobustHaven.Text) RobustHaven.Text={}; 3 | if(!RobustHaven.Text.Npeg) RobustHaven.Text.Npeg={}; 4 | 5 | var Expression = function() { 6 | this.npeg = null; 7 | 8 | this.evaluate = function() {} 9 | } -------------------------------------------------------------------------------- /NPEG/ALeaf.cs: -------------------------------------------------------------------------------- 1 | using System.Runtime.Serialization; 2 | 3 | namespace NPEG 4 | { 5 | [DataContract] 6 | public class ALeaf : AExpression 7 | { 8 | public override void Accept(IParseTreeVisitor visitor) 9 | { 10 | visitor.Visit(this); 11 | } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /NPEG/ApplicationExceptions/IteratorUsageException.cs: -------------------------------------------------------------------------------- 1 | namespace NPEG.ApplicationExceptions 2 | { 3 | public class IteratorUsageException : NpegException 4 | { 5 | public IteratorUsageException(string message) 6 | : base(message) 7 | { 8 | } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /LanguageWorkbench/Algorithms/LanguageWriters/MethodInfo.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace LanguageWorkbench.Algorithms.LanguageWriters 4 | { 5 | internal class MethodInfo 6 | { 7 | public String methodData = String.Empty; 8 | public String methodName = String.Empty; 9 | } 10 | } -------------------------------------------------------------------------------- /NPEG/Terminals/CharacterClass.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.Serialization; 3 | 4 | namespace NPEG.Terminals 5 | { 6 | [DataContract] 7 | public class CharacterClass : ALeaf 8 | { 9 | [DataMember] 10 | public String ClassExpression { get; set; } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Languages/npeg_csharp/RobustHaven.Text.Npeg/IteratorUsageException.cs: -------------------------------------------------------------------------------- 1 | namespace RobustHaven.Text.Npeg 2 | { 3 | public class IteratorUsageException : ParsingExpressionGrammarException 4 | { 5 | public IteratorUsageException(string message) 6 | : base(message) 7 | { 8 | } 9 | } 10 | } -------------------------------------------------------------------------------- /Languages/npeg_php/ParsingExpressionGrammarException.php: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /Languages/npeg_c++/robusthaven/text/Warn.cpp: -------------------------------------------------------------------------------- 1 | #include "Warn.h" 2 | 3 | using namespace RobustHaven::Text; 4 | 5 | const std::string& Warn::getMessage() const 6 | { 7 | return this->m_message; 8 | } 9 | 10 | int Warn::getIteratorIndex() const 11 | { 12 | return this->m_iteratorIndex; 13 | } 14 | 15 | -------------------------------------------------------------------------------- /Languages/npeg_php/ParsingFatalTerminalException.php: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /Languages/npeg_csharp/RobustHaven.Text.Npeg.Tests/NpegNUnitProject.nunit: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /Languages/npeg_csharp/RobustHaven.Text.Npeg/InvalidInputException.cs: -------------------------------------------------------------------------------- 1 | namespace RobustHaven.Text.Npeg 2 | { 3 | public class InvalidInputException : ParsingExpressionGrammarException 4 | { 5 | public InvalidInputException() 6 | : base("Supplied input could not be parsed by compiled parse tree.") 7 | { 8 | } 9 | } 10 | } -------------------------------------------------------------------------------- /NPEG/GrammarInterpreter/InterpreterParseException.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using NPEG.ApplicationExceptions; 3 | 4 | namespace NPEG.GrammarInterpreter 5 | { 6 | public class InterpreterParseException : NpegException 7 | { 8 | public InterpreterParseException(String message) : base(message) 9 | { 10 | } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Languages/npeg_csharp/RobustHaven.Text.Npeg/ParsingExpressionGrammarException.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace RobustHaven.Text.Npeg 4 | { 5 | public class ParsingExpressionGrammarException : ApplicationException 6 | { 7 | public ParsingExpressionGrammarException(String message) 8 | : base(message) 9 | { 10 | } 11 | } 12 | } -------------------------------------------------------------------------------- /Languages/npeg_csharp/RobustHaven.Text.Npeg/ParsingFatalTerminalException.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace RobustHaven.Text.Npeg 4 | { 5 | public class ParsingFatalTerminalException : ParsingExpressionGrammarException 6 | { 7 | public ParsingFatalTerminalException(String message) 8 | : base(message) 9 | { 10 | } 11 | } 12 | } -------------------------------------------------------------------------------- /Languages/npeg_c++/robusthaven/text/FileInputIterator.cpp: -------------------------------------------------------------------------------- 1 | #include "FileInputIterator.h" 2 | 3 | using namespace std; 4 | using namespace RobustHaven::Text; 5 | 6 | FileInputIterator::FileInputIterator(const char path[]) : InputIterator(new ifstream(path)) {} 7 | 8 | FileInputIterator::~FileInputIterator() { 9 | delete m_stream; 10 | } 11 | -------------------------------------------------------------------------------- /Languages/npeg_php/IAstNodeReplacement.php: -------------------------------------------------------------------------------- 1 | 12 | -------------------------------------------------------------------------------- /NPEG/Terminals/Fatal.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.Serialization; 3 | 4 | namespace NPEG.Terminals 5 | { 6 | [DataContract] 7 | public class Fatal : ALeaf 8 | { 9 | public Fatal() 10 | { 11 | Message = String.Empty; 12 | } 13 | 14 | [DataMember] 15 | public String Message { get; set; } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Languages/npeg_c/robusthaven.tests/ParserTest_SimpleSentence/SimpleSentence.h: -------------------------------------------------------------------------------- 1 | #ifndef ROBUSTHAVEN_GENERATEDPARSER_PHONENUMBER 2 | #define ROBUSTHAVEN_GENERATEDPARSER_PHONENUMBER 3 | 4 | #include "robusthaven/text/npeg_inputiterator.h" 5 | #include "robusthaven/text/npeg.h" 6 | 7 | int sentence_root(npeg_inputiterator*, npeg_context*); 8 | 9 | #endif 10 | -------------------------------------------------------------------------------- /NPEG/AExpression.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.Serialization; 3 | 4 | namespace NPEG 5 | { 6 | [DataContract] 7 | public abstract class AExpression 8 | { 9 | public Int32 RuleStart { get; set; } 10 | 11 | public Int32 RuleEnd { set; get; } 12 | 13 | public abstract void Accept(IParseTreeVisitor visitor); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | 5 | # change these settings to your own preference 6 | indent_style = space 7 | indent_size = 2 8 | 9 | # we recommend you to keep these unchanged 10 | end_of_line = lf 11 | charset = utf-8 12 | trim_trailing_whitespace = true 13 | insert_final_newline = true 14 | 15 | [*.md] 16 | trim_trailing_whitespace = false 17 | -------------------------------------------------------------------------------- /Languages/npeg_javascript/IAstNodeVisitor.js: -------------------------------------------------------------------------------- 1 | if(!RobustHaven) var RobustHaven={}; 2 | if(!RobustHaven.Text) RobustHaven.Text={}; 3 | if(!RobustHaven.Text.Npeg) RobustHaven.Text.Npeg={}; 4 | 5 | RobustHaven.Text.Npeg.IAstNodeVisitor = function() { 6 | this.visitEnter = function(node) {}; 7 | this.visitExecute = function(node) {}; 8 | this.visitLeave = function(node) {}; 9 | } -------------------------------------------------------------------------------- /Languages/npeg_c/robusthaven/text/printvisitor.h: -------------------------------------------------------------------------------- 1 | #ifndef ROBUSTHAVEN_TEXT_PRINTVISITOR_H 2 | #define ROBUSTHAVEN_TEXT_PRINTVISITOR_H 3 | #include 4 | #include "npeg.h" 5 | 6 | /* 7 | * Recursively prints an AST 8 | * out is the FILE pointer used for output. If the user passes NULL, sdout is used. 9 | */ 10 | void npeg_printVisitor(npeg_astnode *root, FILE *out); 11 | 12 | #endif 13 | -------------------------------------------------------------------------------- /NPEG/Terminals/RecursionCall.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.Serialization; 3 | 4 | namespace NPEG.Terminals 5 | { 6 | [DataContract] 7 | public class RecursionCall : ALeaf 8 | { 9 | public RecursionCall(String bindunique) 10 | { 11 | FunctionName = bindunique; 12 | } 13 | 14 | [DataMember] 15 | public String FunctionName { get; set; } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /NPEG.Tests/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.InteropServices; 3 | 4 | 5 | [assembly: AssemblyTitle("TestProject1")] 6 | [assembly: AssemblyDescription("")] 7 | [assembly: AssemblyCulture("")] 8 | 9 | 10 | // The following GUID is for the ID of the typelib if this project is exposed to COM 11 | 12 | [assembly: Guid("6c3aa6d5-c775-46c9-816e-bf19a3542fa9")] 13 | -------------------------------------------------------------------------------- /Languages/npeg_java/robusthaven/robusthaven/text/FileInputIterator.java: -------------------------------------------------------------------------------- 1 | package robusthaven.text; 2 | import java.io.FileInputStream; 3 | import java.io.IOException; 4 | import java.io.File; 5 | 6 | public class FileInputIterator extends InputIterator { 7 | public FileInputIterator(String path) throws IOException { 8 | super(new FileInputStream(new File(path)), new File(path).length()); 9 | } 10 | } -------------------------------------------------------------------------------- /NPEG.Tests/packages.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /Languages/npeg_c++/robusthaven/text/IAstNodeFactory.h: -------------------------------------------------------------------------------- 1 | #ifndef ROBUSTHAVEN_TEXT_ASTNODEFACTORY_H 2 | #define ROBUSTHAVEN_TEXT_ASTNODEFACTORY_H 3 | 4 | #include "IAstNodeReplacement.h" 5 | 6 | namespace RobustHaven 7 | { 8 | namespace Text 9 | { 10 | class IAstNodeFactory { 11 | public: 12 | virtual IAstNodeReplacement* create(AstNode *oldNode) = 0; 13 | }; 14 | } 15 | } 16 | 17 | #endif 18 | -------------------------------------------------------------------------------- /NPEG/Terminals/Warn.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.Serialization; 3 | 4 | namespace NPEG.Terminals 5 | { 6 | [DataContract] 7 | public class Warn : ALeaf 8 | { 9 | public Warn() 10 | { 11 | Message = String.Empty; 12 | } 13 | 14 | [DataMember] 15 | public String Message { get; set; } 16 | 17 | [DataMember] 18 | public Int32 Position { get; set; } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Languages/npeg_java/robusthaven/robusthaven/text/ParsingFatalTerminalException.java: -------------------------------------------------------------------------------- 1 | package robusthaven.text; 2 | 3 | public class ParsingFatalTerminalException extends RuntimeException { 4 | long m_errorPos; 5 | 6 | public long getErrorPosistion() { 7 | return m_errorPos; 8 | } 9 | 10 | public ParsingFatalTerminalException(String msg, long pos) { 11 | super(msg); 12 | m_errorPos = pos; 13 | } 14 | } -------------------------------------------------------------------------------- /Languages/npeg_javascript/ParsingExpressionGrammarException.js: -------------------------------------------------------------------------------- 1 | if(!RobustHaven) var RobustHaven={}; 2 | if(!RobustHaven.Text) RobustHaven.Text={}; 3 | if(!RobustHaven.Text.Npeg) RobustHaven.Text.Npeg={}; 4 | 5 | RobustHaven.Text.Npeg.ParsingExpressionGrammarException = function(message) { 6 | this.toString = function() { 7 | return message; 8 | } 9 | 10 | this.getMessage = function() {return message;} 11 | } 12 | -------------------------------------------------------------------------------- /NPEG/Terminals/Literal.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.Serialization; 3 | 4 | namespace NPEG.Terminals 5 | { 6 | [DataContract] 7 | public class Literal : ALeaf 8 | { 9 | public Literal() 10 | { 11 | IsCaseSensitive = true; 12 | } 13 | 14 | [DataMember] 15 | public String MatchText { get; set; } 16 | 17 | [DataMember] 18 | public Boolean IsCaseSensitive { get; set; } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Languages/npeg_csharp/RobustHaven.Text.Npeg.Tests/CustomAstNodeCreationTests.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using NUnit.Framework; 3 | 4 | namespace RobustHaven.Text.Npeg.Tests 5 | { 6 | [TestFixture] 7 | public class CustomAstNodeCreationTests 8 | { 9 | [Test] 10 | [ExpectedException(typeof (InfiniteLoopDetectedException))] 11 | public void IntermediateRepresentation_001() 12 | { 13 | throw new NotImplementedException(); 14 | } 15 | } 16 | } -------------------------------------------------------------------------------- /Languages/npeg_csharp/RobustHaven.Text.Npeg/Warn.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace RobustHaven.Text.Npeg 4 | { 5 | public class Warn 6 | { 7 | public Warn() 8 | { 9 | Message = String.Empty; 10 | } 11 | 12 | public Warn(String message, Int32 position) 13 | { 14 | Message = message; 15 | Position = position; 16 | } 17 | 18 | public String Message { get; set; } 19 | 20 | public Int32 Position { get; set; } 21 | } 22 | } -------------------------------------------------------------------------------- /NPEG/Extensions/StackExtensions.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace NPEG.Extensions 4 | { 5 | public static class StackExtensions 6 | { 7 | public static Stack Reverse(this Stack original) 8 | { 9 | var newStack = new Stack(); 10 | while (original.Count != 0) 11 | { 12 | newStack.Push(original.Pop()); 13 | } 14 | 15 | return newStack; 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Languages/npeg_c++/robusthaven/text/IAstNodeVisitor.h: -------------------------------------------------------------------------------- 1 | #ifndef ROBUSTHAVEN_TEXT_IASTNODEVISITOR_H 2 | #define ROBUSTHAVEN_TEXT_IASTNODEVISITOR_H 3 | 4 | #include "AstNode.h" 5 | 6 | 7 | namespace RobustHaven 8 | { 9 | namespace Text 10 | { 11 | class IAstNodeVisitor { 12 | public: 13 | virtual void visitEnter(AstNode &node) = 0; 14 | virtual void visitLeave(AstNode &node) = 0; 15 | }; 16 | } 17 | } 18 | 19 | #endif 20 | -------------------------------------------------------------------------------- /Languages/npeg_java/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | NPEG Java 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | 15 | org.eclipse.jdt.core.javanature 16 | 17 | 18 | -------------------------------------------------------------------------------- /Languages/npeg_java/robusthaven/robusthaven/text/Warn.java: -------------------------------------------------------------------------------- 1 | package robusthaven.text; 2 | 3 | public class Warn { 4 | long m_iteratorIndex; 5 | String m_message; 6 | 7 | public long getIteratorIndex() { 8 | return m_iteratorIndex; 9 | } 10 | 11 | public String getMessage() { 12 | return m_message; 13 | } 14 | 15 | public Warn(String msg, long iteratorIndex) { 16 | m_iteratorIndex = iteratorIndex; 17 | m_message = msg; 18 | } 19 | } -------------------------------------------------------------------------------- /NPEG/NPEG.standard2.0.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netstandard2.0 5 | NPEG 6 | NPEG 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /Languages/npeg_csharp/RobustHaven.Text.Npeg/InfiniteLoopDetectedException.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace RobustHaven.Text.Npeg 4 | { 5 | public class InfiniteLoopDetectedException : ParsingExpressionGrammarException 6 | { 7 | public InfiniteLoopDetectedException() 8 | : base("Supplied grammar rules caused an infinite loop.") 9 | { 10 | } 11 | 12 | public InfiniteLoopDetectedException(String message) 13 | : base(message) 14 | { 15 | } 16 | } 17 | } -------------------------------------------------------------------------------- /NPEG.Tests/Extensions/Timing.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Diagnostics; 3 | 4 | namespace NPEG.Tests.Extensions 5 | { 6 | public class Timing 7 | { 8 | public static Stopwatch TimedFor(Action action, Int32 loops) 9 | { 10 | var sw = new Stopwatch(); 11 | sw.Start(); 12 | for (int i = 0; i < loops; ++i) 13 | { 14 | action.Invoke(); 15 | } 16 | sw.Stop(); 17 | 18 | return sw; 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /NPEG/ApplicationExceptions/NpegException.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace NPEG.ApplicationExceptions 4 | { 5 | public class NpegException : Exception 6 | { 7 | public NpegException() 8 | { 9 | } 10 | 11 | public NpegException(String message) 12 | : base(message) 13 | { 14 | } 15 | 16 | public NpegException(String message, Exception innerException) 17 | : base(message, innerException) 18 | { 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /NPEG/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | 6 | [assembly: AssemblyTitle("NPEG")] 7 | [assembly: AssemblyDescription("")] 8 | [assembly: AssemblyCulture("")] 9 | 10 | 11 | // The following GUID is for the ID of the typelib if this project is exposed to COM 12 | 13 | [assembly: Guid("6728c9b9-2442-4a2b-adfc-b88021b86f8c")] 14 | 15 | [assembly: InternalsVisibleTo("NPEG.Tests")] -------------------------------------------------------------------------------- /Languages/npeg_c/robusthaven.tests/ParserTest_NpegNode/Makefile: -------------------------------------------------------------------------------- 1 | CFLAGS=-ggdb 2 | ROBUSTHAVEN_HEADERS = ../../ 3 | STATIC_LIBRARIES = $(ROBUSTHAVEN_HEADERS)robusthaven/robusthaven.a 4 | OBJ = NpegNode.o 5 | 6 | %.o: %.c 7 | @mkdir -p bin 8 | gcc $(CFLAGS) -I $(ROBUSTHAVEN_HEADERS) -c $< -o bin/$@ 9 | 10 | all: $(OBJ) 11 | gcc $(CFLAGS) -I $(ROBUSTHAVEN_HEADERS) $(addprefix bin/, $(OBJ)) main.c ${STATIC_LIBRARIES} -o program 12 | 13 | clean: 14 | rm -Rf $(OBJ) Makefile~ program *.teststderr *.teststdin bin 15 | -------------------------------------------------------------------------------- /Languages/npeg_c/robusthaven.tests/ParserTest_NpegNode/NpegNode.h: -------------------------------------------------------------------------------- 1 | #ifndef ROBUSTHAVEN_GENERATEDPARSER_NPEGNODE 2 | #define ROBUSTHAVEN_GENERATEDPARSER_NPEGNODE 3 | 4 | #include "robusthaven/text/npeg_inputiterator.h" 5 | #include "robusthaven/text/npeg.h" 6 | 7 | int NpegNode_impl_0(npeg_inputiterator*, npeg_context*); 8 | int NpegNode_impl_1(npeg_inputiterator*, npeg_context*); 9 | int NpegNode_impl_3(npeg_inputiterator*, npeg_context*); 10 | int NpegNode_impl_2(npeg_inputiterator*, npeg_context*); 11 | 12 | #endif 13 | -------------------------------------------------------------------------------- /Languages/npeg_c/robusthaven.tests/ParserTest_PhoneNumber/Makefile: -------------------------------------------------------------------------------- 1 | CFLAGS=-ggdb 2 | ROBUSTHAVEN_HEADERS = ../../ 3 | STATIC_LIBRARIES = $(ROBUSTHAVEN_HEADERS)robusthaven/robusthaven.a 4 | OBJ = PhoneNumber.o 5 | 6 | %.o: %.c 7 | @mkdir -p bin 8 | gcc $(CFLAGS) -I $(ROBUSTHAVEN_HEADERS) -c $< -o bin/$@ 9 | 10 | all: $(OBJ) 11 | gcc $(CFLAGS) -I $(ROBUSTHAVEN_HEADERS) $(addprefix bin/, $(OBJ)) main.c ${STATIC_LIBRARIES} -o program 12 | 13 | clean: 14 | rm -Rf $(OBJ) Makefile~ program *.teststderr *.teststdin bin 15 | -------------------------------------------------------------------------------- /Languages/npeg_c/robusthaven.tests/ParserTest_SimpleXml/Makefile: -------------------------------------------------------------------------------- 1 | CFLAGS=-ggdb 2 | ROBUSTHAVEN_HEADERS = ../../ 3 | STATIC_LIBRARIES = $(ROBUSTHAVEN_HEADERS)robusthaven/robusthaven.a 4 | OBJ = SimpleXml.o 5 | 6 | %.o: %.c 7 | @mkdir -p bin 8 | gcc $(CFLAGS) -I $(ROBUSTHAVEN_HEADERS) -c $< -o bin/$@ 9 | 10 | all: $(OBJ) 11 | gcc $(CFLAGS) -I $(ROBUSTHAVEN_HEADERS) $(addprefix bin/, $(OBJ)) main.c ${STATIC_LIBRARIES} -o program 12 | 13 | clean: 14 | rm -Rf $(OBJ) Makefile~ program *.teststderr *.teststdin bin 15 | -------------------------------------------------------------------------------- /Languages/npeg_java/nbproject/genfiles.properties: -------------------------------------------------------------------------------- 1 | nbbuild.xml.data.CRC32=840267c5 2 | nbbuild.xml.script.CRC32=399e1802 3 | nbbuild.xml.stylesheet.CRC32=958a1d3e 4 | # This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. 5 | # Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. 6 | nbproject/build-impl.xml.data.CRC32=840267c5 7 | nbproject/build-impl.xml.script.CRC32=780173b4 8 | nbproject/build-impl.xml.stylesheet.CRC32=65b8de21 9 | -------------------------------------------------------------------------------- /NPEG/NonTerminals/OneOrMore.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Runtime.Serialization; 3 | 4 | namespace NPEG.NonTerminals 5 | { 6 | [DataContract] 7 | public class OneOrMore : AComposite 8 | { 9 | private readonly AExpression Exp; 10 | 11 | public OneOrMore(AExpression exp) 12 | { 13 | Exp = exp; 14 | } 15 | 16 | [DataMember] 17 | public override List Children 18 | { 19 | get { return new List { Exp }; } 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /NPEG/NonTerminals/Optional.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Runtime.Serialization; 3 | 4 | namespace NPEG.NonTerminals 5 | { 6 | [DataContract] 7 | public class Optional : AComposite 8 | { 9 | private readonly AExpression Exp; 10 | 11 | public Optional(AExpression exp) 12 | { 13 | Exp = exp; 14 | } 15 | 16 | [DataMember] 17 | public override List Children 18 | { 19 | get { return new List { Exp }; } 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Languages/npeg_c/robusthaven.tests/ParserTest_SimpleSentence/Makefile: -------------------------------------------------------------------------------- 1 | CFLAGS=-ggdb 2 | ROBUSTHAVEN_HEADERS = ../../ 3 | STATIC_LIBRARIES = $(ROBUSTHAVEN_HEADERS)robusthaven/robusthaven.a 4 | OBJ = SimpleSentence.o 5 | 6 | %.o: %.c 7 | @mkdir -p bin 8 | gcc $(CFLAGS) -I $(ROBUSTHAVEN_HEADERS) -c $< -o bin/$@ 9 | 10 | all: $(OBJ) 11 | gcc $(CFLAGS) -I $(ROBUSTHAVEN_HEADERS) $(addprefix bin/, $(OBJ)) main.c ${STATIC_LIBRARIES} -o program 12 | 13 | clean: 14 | rm -Rf $(OBJ) Makefile~ program *.teststderr *.teststdin bin 15 | -------------------------------------------------------------------------------- /NPEG/NonTerminals/ZeroOrMore.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Runtime.Serialization; 3 | 4 | namespace NPEG.NonTerminals 5 | { 6 | [DataContract] 7 | public class ZeroOrMore : AComposite 8 | { 9 | private readonly AExpression Exp; 10 | 11 | public ZeroOrMore(AExpression exp) 12 | { 13 | Exp = exp; 14 | } 15 | 16 | [DataMember] 17 | public override List Children 18 | { 19 | get { return new List { Exp }; } 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /NPEG/NonTerminals/NotPredicate.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Runtime.Serialization; 3 | 4 | namespace NPEG.NonTerminals 5 | { 6 | [DataContract] 7 | public class NotPredicate : AComposite 8 | { 9 | private readonly AExpression Exp; 10 | 11 | public NotPredicate(AExpression exp) 12 | { 13 | Exp = exp; 14 | } 15 | 16 | [DataMember] 17 | public override List Children 18 | { 19 | get { return new List { Exp }; } 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Languages/npeg_c/robusthaven.tests/ParserTest_MathematicalFormula/Makefile: -------------------------------------------------------------------------------- 1 | CFLAGS=-ggdb 2 | ROBUSTHAVEN_HEADERS = ../../ 3 | STATIC_LIBRARIES = $(ROBUSTHAVEN_HEADERS)robusthaven/robusthaven.a 4 | OBJ = MathematicalFormula.o 5 | 6 | %.o: %.c 7 | @mkdir -p bin 8 | gcc $(CFLAGS) -I $(ROBUSTHAVEN_HEADERS) -c $< -o bin/$@ 9 | 10 | all: $(OBJ) 11 | gcc $(CFLAGS) -I $(ROBUSTHAVEN_HEADERS) $(addprefix bin/, $(OBJ)) main.c ${STATIC_LIBRARIES} -o program 12 | 13 | clean: 14 | rm -Rf $(OBJ) Makefile~ program *.teststderr *.teststdin bin 15 | -------------------------------------------------------------------------------- /Languages/npeg_csharp/RobustHaven.Text.Npeg/TokenMatch.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace RobustHaven.Text.Npeg 4 | { 5 | public class TokenMatch 6 | { 7 | public TokenMatch(String name, Int32 start, Int32 end, Byte[] value) 8 | { 9 | Name = name; 10 | Start = start; 11 | End = end; 12 | Value = value; 13 | } 14 | 15 | public String Name { private set; get; } 16 | public Int32 Start { private set; get; } 17 | 18 | public Int32 End { private set; get; } 19 | 20 | public Byte[] Value { get; set; } 21 | } 22 | } -------------------------------------------------------------------------------- /Languages/npeg_java/robusthaven/robusthaven/text/TokenMatch.java: -------------------------------------------------------------------------------- 1 | package robusthaven.text; 2 | 3 | public class TokenMatch { 4 | String m_name; 5 | long m_start, m_end; 6 | 7 | public final String getName() { 8 | return m_name; 9 | } 10 | 11 | public long getStart() { 12 | return m_start; 13 | } 14 | 15 | public long getEnd() { 16 | return m_end; 17 | } 18 | 19 | public TokenMatch(String name, long start, long end) { 20 | m_name = name; 21 | m_start = start; 22 | m_end = end; 23 | } 24 | } -------------------------------------------------------------------------------- /NPEG/NonTerminals/AndPredicate.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Runtime.Serialization; 3 | 4 | namespace NPEG.NonTerminals 5 | { 6 | [DataContract] 7 | public class AndPredicate : AComposite 8 | { 9 | private readonly AExpression exp; 10 | 11 | public AndPredicate(AExpression exp) 12 | { 13 | this.exp = exp; 14 | } 15 | 16 | [DataMember] 17 | public override List Children 18 | { 19 | get { return new List { exp }; } 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Languages/npeg_csharp/RobustHaven.Text.Npeg/IAstNodeReplacement.cs: -------------------------------------------------------------------------------- 1 | namespace RobustHaven.Text.Npeg 2 | { 3 | // Understand that node replacement should not have any logic this.Parent 4 | // since full tree is not yet created. 5 | public abstract class IAstNodeReplacement : AstNode, IAstNodeVisitor 6 | { 7 | #region IAstNodeVisitor Members 8 | 9 | public abstract void VisitEnter(AstNode node); 10 | 11 | public abstract void VisitExecute(AstNode node); 12 | 13 | public abstract void VisitLeave(AstNode node); 14 | 15 | #endregion 16 | } 17 | } -------------------------------------------------------------------------------- /LanguageWorkbench/App.xaml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /Languages/npeg_java/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /Languages/npeg_c++/robusthaven/text/FileInputIterator.h: -------------------------------------------------------------------------------- 1 | #ifndef ROBUSTHAVEN_TEXT_FILEINPUTITERATOR_H 2 | #define ROBUSTHAVEN_TEXT_FILEINPUTITERATOR_H 3 | 4 | #include "InputIterator.h" 5 | 6 | namespace RobustHaven 7 | { 8 | namespace Text 9 | { 10 | class FileInputIterator : public InputIterator { 11 | public: 12 | /* 13 | * Builds a new InputIterator with an underlying file stream. 14 | */ 15 | FileInputIterator(const char path[]); 16 | 17 | virtual ~FileInputIterator(void); 18 | }; 19 | } 20 | } 21 | 22 | #endif 23 | -------------------------------------------------------------------------------- /Languages/npeg_c++/robusthaven/text/IAstNodeReplacement.h: -------------------------------------------------------------------------------- 1 | #ifndef ROBUSTHAVEN_TEXT_IASTNODEREPLACEMENT_H 2 | #define ROBUSTHAVEN_TEXT_IASTNODEREPLACEMENT_H 3 | 4 | #include "IAstNodeVisitor.h" 5 | #include "AstNode.h" 6 | 7 | 8 | namespace RobustHaven 9 | { 10 | namespace Text 11 | { 12 | class IAstNodeReplacement : public AstNode, public IAstNodeVisitor { 13 | public: 14 | IAstNodeReplacement(TokenMatch *token, const bool deleteToken) : AstNode(token, deleteToken) {} 15 | 16 | virtual ~IAstNodeReplacement(void) {} 17 | }; 18 | } 19 | } 20 | 21 | #endif 22 | -------------------------------------------------------------------------------- /NPEG/ApplicationExceptions/InvalidInputException.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace NPEG.ApplicationExceptions 4 | { 5 | public class InvalidInputException : NpegException 6 | { 7 | public InvalidInputException() 8 | : base("Supplied input could not be parsed by compiled parse tree.") 9 | { 10 | } 11 | 12 | public InvalidInputException(String message) 13 | : base(message) 14 | { 15 | } 16 | 17 | public InvalidInputException(String message, Exception innerException) 18 | : base(message, innerException) 19 | { 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /NPEG/ApplicationExceptions/InvalidRuleException.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace NPEG.ApplicationExceptions 4 | { 5 | public class InvalidRuleException : NpegException 6 | { 7 | public InvalidRuleException() 8 | : base("Supplied grammar rules could not be compiled into a parse tree.") 9 | { 10 | } 11 | 12 | public InvalidRuleException(String message) 13 | : base(message) 14 | { 15 | } 16 | 17 | public InvalidRuleException(String message, Exception innerException) 18 | : base(message, innerException) 19 | { 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Languages/npeg_c++/robusthaven/text/StringInputIterator.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "StringInputIterator.h" 3 | 4 | using namespace std; 5 | using namespace RobustHaven::Text; 6 | 7 | StringInputIterator::StringInputIterator(const char* string, const size_t length) { 8 | stringstream *p_tmp; 9 | 10 | p_tmp = new stringstream("", ios_base::in|ios_base::out|ios_base::binary); 11 | p_tmp->write(string, length); 12 | p_tmp->seekg(0, ios::beg); 13 | m_stream = p_tmp; 14 | m_length = length; 15 | } 16 | 17 | StringInputIterator::~StringInputIterator() { 18 | delete m_stream; 19 | } 20 | -------------------------------------------------------------------------------- /NPEG/Extensions/TokenMatchExtensions.cs: -------------------------------------------------------------------------------- 1 | using System.Text; 2 | 3 | namespace NPEG.Extensions 4 | { 5 | public static class TokenMatchExtensions 6 | { 7 | public static string ValueAsString(this TokenMatch match, IInputIterator iterator) 8 | { 9 | var matchedBytes = iterator.Text(match.Start, match.End); 10 | return Encoding.UTF8.GetString(matchedBytes, 0, matchedBytes.Length); 11 | } 12 | 13 | public static byte[] ValueAsBytes(this TokenMatch match, IInputIterator iterator) 14 | { 15 | return iterator.Text(match.Start, match.End); 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Languages/npeg_c++/robusthaven.tests/ParserTest_NpegNode/Makefile: -------------------------------------------------------------------------------- 1 | CXX=g++ 2 | CXXFLAGS=-ggdb -Wno-deprecated 3 | CPPFLAGS= -I ../ 4 | 5 | ROBUSTHAVEN_HEADERS = ../../ 6 | STATIC_LIBRARIES = $(ROBUSTHAVEN_HEADERS)robusthaven/robusthaven.a 7 | OBJ = NpegNode.o 8 | 9 | %.o: %.cpp 10 | @mkdir -p bin 11 | $(CXX) $(CXXFLAGS) $(CPPFLAGS) -I $(ROBUSTHAVEN_HEADERS) -c $< -o bin/$@ 12 | 13 | all: $(OBJ) 14 | $(CXX) $(CXXFLAGS) $(CPPFLAGS) -I $(ROBUSTHAVEN_HEADERS) $(addprefix bin/, $(OBJ)) main.cpp ${STATIC_LIBRARIES} -o program 15 | 16 | clean: 17 | rm -Rf $(OBJ) Makefile~ program *.teststderr *.teststdin bin 18 | -------------------------------------------------------------------------------- /Languages/npeg_c++/robusthaven.tests/ParserTest_SimpleXml/Makefile: -------------------------------------------------------------------------------- 1 | CXX=g++ 2 | CXXFLAGS=-ggdb -Wno-deprecated 3 | CPPFLAGS= -I ../ 4 | 5 | ROBUSTHAVEN_HEADERS = ../../ 6 | STATIC_LIBRARIES = $(ROBUSTHAVEN_HEADERS)robusthaven/robusthaven.a 7 | OBJ = SimpleXml.o 8 | 9 | %.o: %.cpp 10 | @mkdir -p bin 11 | $(CXX) $(CXXFLAGS) $(CPPFLAGS) -I $(ROBUSTHAVEN_HEADERS) -c $< -o bin/$@ 12 | 13 | all: $(OBJ) 14 | $(CXX) $(CXXFLAGS) $(CPPFLAGS) -I $(ROBUSTHAVEN_HEADERS) $(addprefix bin/, $(OBJ)) main.cpp ${STATIC_LIBRARIES} -o program 15 | 16 | clean: 17 | rm -Rf $(OBJ) Makefile~ program *.teststderr *.teststdin bin 18 | -------------------------------------------------------------------------------- /Languages/npeg_c++/robusthaven.tests/ParserTest_PhoneNumber/Makefile: -------------------------------------------------------------------------------- 1 | CXX=g++ 2 | CXXFLAGS=-ggdb -Wno-deprecated 3 | CPPFLAGS= -I ../ 4 | 5 | ROBUSTHAVEN_HEADERS = ../../ 6 | STATIC_LIBRARIES = $(ROBUSTHAVEN_HEADERS)robusthaven/robusthaven.a 7 | OBJ = PhoneNumber.o 8 | 9 | %.o: %.cpp 10 | @mkdir -p bin 11 | $(CXX) $(CXXFLAGS) $(CPPFLAGS) -I $(ROBUSTHAVEN_HEADERS) -c $< -o bin/$@ 12 | 13 | all: $(OBJ) 14 | $(CXX) $(CXXFLAGS) $(CPPFLAGS) -I $(ROBUSTHAVEN_HEADERS) $(addprefix bin/, $(OBJ)) main.cpp ${STATIC_LIBRARIES} -o program 15 | 16 | clean: 17 | rm -Rf $(OBJ) Makefile~ program *.teststderr *.teststdin bin 18 | -------------------------------------------------------------------------------- /Languages/npeg_c/robusthaven/Makefile: -------------------------------------------------------------------------------- 1 | CFLAGS=-ggdb 2 | 3 | OBJ = structures/hashmap.o structures/inthashmap.o structures/stack.o structures/stackstack.o \ 4 | structures/list.o text/npeg.o text/npeg_ast.o text/npeg_inputiterator.o text/printvisitor.o 5 | 6 | 7 | define cc-command 8 | # compile do not link use: -c 9 | $(CC) $(CFLAGS) -c $< -o $@ 10 | endef 11 | 12 | %.o: %.c 13 | $(cc-command) 14 | 15 | 16 | 17 | all: robusthaven.a 18 | 19 | robusthaven.a: $(OBJ) 20 | # use archiver utility to create library. 21 | ar rvs robusthaven.a $(OBJ) 22 | 23 | clean: 24 | rm -f robusthaven.a 25 | rm -f -R $(OBJ) 26 | -------------------------------------------------------------------------------- /Languages/npeg_javascript/InfiniteLoopException.js: -------------------------------------------------------------------------------- 1 | if(!RobustHaven) var RobustHaven={}; 2 | if(!RobustHaven.Text) RobustHaven.Text={}; 3 | if(!RobustHaven.Text.Npeg) RobustHaven.Text.Npeg={}; 4 | 5 | RobustHaven.Text.Npeg.InfiniteLoopException = function(message, pos) { 6 | var message = (typeof message == "undefined") ? "Supplied grammar rules caused an infinite loop." : message; 7 | RobustHaven.Text.Npeg.InfiniteLoopException.superclass.constructor.call(this, message, pos); 8 | } 9 | RobustHaven.Text.Npeg.extend( 10 | RobustHaven.Text.Npeg.InfiniteLoopException, RobustHaven.Text.Npeg.ParsingFatalTerminalException); -------------------------------------------------------------------------------- /Languages/npeg_c++/robusthaven.tests/ParserTest_MathematicalFormula/Makefile: -------------------------------------------------------------------------------- 1 | CXX=g++ 2 | CXXFLAGS=-ggdb -Wno-deprecated 3 | CPPFLAGS= -I ../ 4 | 5 | ROBUSTHAVEN_HEADERS = ../../ 6 | STATIC_LIBRARIES = $(ROBUSTHAVEN_HEADERS)robusthaven/robusthaven.a 7 | OBJ = MathematicalFormula.o 8 | 9 | %.o: %.cpp 10 | @mkdir -p bin 11 | $(CXX) $(CXXFLAGS) $(CPPFLAGS) -I $(ROBUSTHAVEN_HEADERS) -c $< -o bin/$@ 12 | 13 | all: $(OBJ) 14 | $(CXX) $(CXXFLAGS) $(CPPFLAGS) -I $(ROBUSTHAVEN_HEADERS) $(addprefix bin/, $(OBJ)) main.cpp ${STATIC_LIBRARIES} -o program 15 | 16 | clean: 17 | rm -Rf $(OBJ) Makefile~ program *.teststderr *.teststdin bin 18 | -------------------------------------------------------------------------------- /NPEG/ApplicationExceptions/ParsingFatalTerminalException.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace NPEG.ApplicationExceptions 4 | { 5 | public class ParsingFatalTerminalException : NpegException 6 | { 7 | public ParsingFatalTerminalException() 8 | : base("Parse tree encountered an invalid path of execution.") 9 | { 10 | } 11 | 12 | public ParsingFatalTerminalException(String message) 13 | : base(message) 14 | { 15 | } 16 | 17 | public ParsingFatalTerminalException(String message, Exception innerException) 18 | : base(message, innerException) 19 | { 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /NPEG/NonTerminals/Sequence.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Runtime.Serialization; 3 | 4 | namespace NPEG.NonTerminals 5 | { 6 | [DataContract] 7 | public class Sequence : AComposite 8 | { 9 | private readonly AExpression left; 10 | private readonly AExpression right; 11 | 12 | public Sequence(AExpression left, AExpression right) 13 | { 14 | this.left = left; 15 | this.right = right; 16 | } 17 | 18 | [DataMember] 19 | public override List Children 20 | { 21 | get { return new List { left, right }; } 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Languages/npeg_javascript/InputIterator.js: -------------------------------------------------------------------------------- 1 | if(!RobustHaven) var RobustHaven={}; 2 | if(!RobustHaven.Text) RobustHaven.Text={}; 3 | if(!RobustHaven.Text.Npeg) RobustHaven.Text.Npeg={}; 4 | 5 | RobustHaven.Text.Npeg.InputIterator = function(length) { 6 | this.index = 0; 7 | this.length = length; 8 | 9 | this.getIndex = function () { return this.index; }; 10 | this.setIndex = function ( value ) { this.index = value; }; 11 | 12 | this.getLength = function () { return this.length; }; 13 | 14 | this.getText = null; 15 | this.getCurrent = null; 16 | this.getNext = null; 17 | this.getPrevious = null; 18 | } -------------------------------------------------------------------------------- /Languages/npeg_javascript/Warn.js: -------------------------------------------------------------------------------- 1 | if(!RobustHaven) var RobustHaven={}; 2 | if(!RobustHaven.Text) RobustHaven.Text={}; 3 | if(!RobustHaven.Text.Npeg) RobustHaven.Text.Npeg={}; 4 | 5 | RobustHaven.Text.Npeg.Warn = function (message, position) { 6 | var message = (message != undefined) ? message : '', 7 | position = (position != undefined) ? position : null; 8 | 9 | this.getMessage = function () { return message; }; 10 | this.setMessage = function ( value ) { message = value; }; 11 | 12 | this.getPosition = function () { return position; }; 13 | this.setPosition = function ( value ) { position = value; }; 14 | } -------------------------------------------------------------------------------- /Languages/npeg_c++/robusthaven/Makefile: -------------------------------------------------------------------------------- 1 | CXXFLAGS=-ggdb -Wall -Wno-deprecated 2 | 3 | OBJ= text/AstNode.o text/InputIterator.o text/Npeg.o text/Warn.o text/StringInputIterator.o \ 4 | text/FileInputIterator.o 5 | 6 | 7 | # compile do not link use: -c 8 | define cpp-command 9 | $(CXX) $(CXXFLAGS) $(CPPFLAGS) -c $< -o $@ 10 | endef 11 | 12 | 13 | BUILDDIR= text 14 | 15 | %.o: %.cpp 16 | $(cpp-command) 17 | 18 | 19 | 20 | all: robusthaven.a 21 | 22 | robusthaven.a: $(OBJ) 23 | # use archiver utility to create library. 24 | ar rvs robusthaven.a $(OBJ) 25 | 26 | clean: 27 | rm -f robusthaven.a 28 | rm -f -R $(OBJ) *.h~ *.cpp~ 29 | -------------------------------------------------------------------------------- /Languages/npeg_csharp/RobustHaven.Text.Npeg.Tests/InputIteratorTests.cs: -------------------------------------------------------------------------------- 1 | using System.Text; 2 | using NUnit.Framework; 3 | 4 | namespace RobustHaven.Text.Npeg.Tests 5 | { 6 | [TestFixture] 7 | public class InputIteratorTests 8 | { 9 | [Test] 10 | public void StringInputIterator_InitializationTest() 11 | { 12 | var iterator = new StringInputIterator( 13 | Encoding.ASCII.GetBytes("")); 14 | Assert.IsTrue(iterator.Length == 0); 15 | Assert.IsTrue(iterator.Index == 0); 16 | Assert.IsTrue(iterator.Current() == -1); 17 | Assert.IsTrue(iterator.Next() == -1); 18 | Assert.IsTrue(iterator.Previous() == -1); 19 | } 20 | } 21 | } -------------------------------------------------------------------------------- /Languages/npeg_c++/robusthaven/text/Warn.h: -------------------------------------------------------------------------------- 1 | #ifndef ROBUSTHAVEN_TEXT_WARN_H 2 | #define ROBUSTHAVEN_TEXT_WARN_H 3 | 4 | #include 5 | 6 | namespace RobustHaven 7 | { 8 | namespace Text 9 | { 10 | class Warn 11 | { 12 | public: 13 | Warn(const char message[], int iteratorIndex) 14 | : m_message(message), m_iteratorIndex(iteratorIndex) 15 | { 16 | 17 | } 18 | 19 | ~Warn(void) 20 | { 21 | } 22 | 23 | const std::string& getMessage() const; 24 | 25 | int getIteratorIndex() const; 26 | 27 | private: 28 | std::string m_message; 29 | int m_iteratorIndex; 30 | }; 31 | } 32 | } 33 | #endif 34 | -------------------------------------------------------------------------------- /NPEG/NonTerminals/PrioritizedChoice.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Runtime.Serialization; 3 | 4 | namespace NPEG.NonTerminals 5 | { 6 | [DataContract] 7 | public class PrioritizedChoice : AComposite 8 | { 9 | private readonly AExpression left; 10 | private readonly AExpression right; 11 | 12 | public PrioritizedChoice(AExpression left, AExpression right) 13 | { 14 | this.left = left; 15 | this.right = right; 16 | } 17 | 18 | [DataMember] 19 | public override List Children 20 | { 21 | get { return new List { left, right }; } 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /NPEG/TokenMatch.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Diagnostics; 3 | using System.Runtime.Serialization; 4 | 5 | namespace NPEG 6 | { 7 | [DataContract] 8 | [DebuggerDisplay("TokenMatch: {Name} = ({Start},{End})")] 9 | public class TokenMatch 10 | { 11 | public TokenMatch(String name, Int32 start, Int32 end) 12 | { 13 | Name = name; 14 | Start = start; 15 | End = end; 16 | } 17 | 18 | [DataMember] 19 | public String Name { private set; get; } 20 | 21 | [DataMember] 22 | public Int32 Start { private set; get; } 23 | 24 | [DataMember] 25 | public Int32 End { private set; get; } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Languages/npeg_java/nbproject/project.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | org.netbeans.modules.java.j2seproject 4 | 5 | 6 | NPEG Java 7 | 1.6.5 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /Languages/npeg_c/robusthaven.tests/test_ast_constructor.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "robusthaven/text/npeg_ast.h" 4 | 5 | int main(int argc, char *argv[]) { 6 | npeg_token* const token_test_address = (npeg_token*)0x00001234; 7 | const uint test_capacity = 152; 8 | 9 | npeg_astnode root; 10 | 11 | npeg_astnode_constructor(&root, token_test_address, test_capacity); 12 | assert(root.nof_children == 0); 13 | assert(root.capacity == test_capacity); 14 | assert(root.token == token_test_address); 15 | npeg_astnode_destructor(&root); 16 | printf("\tVerified: Correct initialization.\n"); 17 | 18 | return 0; 19 | } /* main */ 20 | -------------------------------------------------------------------------------- /Languages/npeg_c/robusthaven.tests/test_stack_constructor.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include "robusthaven/structures/stack.h" 6 | 7 | /* 8 | * Tests the constructor/destructors of the stack module 9 | */ 10 | int main(int argc, char *argv[]) { 11 | rh_stack_instance stack; 12 | 13 | rh_stack_constructor(&stack, NULL); 14 | assert(stack.head == stack.tail); 15 | printf("\tVerified: Correct pointer assignment.\n"); 16 | 17 | assert(rh_stack_count(&stack) == 0); 18 | printf("\tVerified: intial number of items.\n"); 19 | rh_stack_destructor(&stack); 20 | 21 | return 0; 22 | } /* main */ 23 | -------------------------------------------------------------------------------- /LanguageWorkbench.Web/Web.config: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /Languages/npeg_c++/robusthaven.tests/ParserTest_NpegNode/NpegNode.h: -------------------------------------------------------------------------------- 1 | #ifndef ROBUSTHAVEN_GENERATEDPARSER_NPEGNODE 2 | #define ROBUSTHAVEN_GENERATEDPARSER_NPEGNODE 3 | 4 | #include "robusthaven/text/InputIterator.h" 5 | #include "robusthaven/text/Npeg.h" 6 | 7 | using namespace RobustHaven::Text; 8 | 9 | class NpegNode : public Npeg 10 | { 11 | public: 12 | NpegNode(InputIterator* inputstream): Npeg(inputstream){} 13 | 14 | virtual int isMatch() throw (ParsingFatalTerminalException) 15 | { return NpegNode_impl_0(); } 16 | 17 | 18 | private: 19 | int NpegNode_impl_0(); 20 | int NpegNode_impl_1(); 21 | int NpegNode_impl_3(); 22 | int NpegNode_impl_2(); 23 | }; 24 | 25 | #endif 26 | -------------------------------------------------------------------------------- /Languages/npeg_javascript/TokenMatch.js: -------------------------------------------------------------------------------- 1 | 2 | if(!RobustHaven) var RobustHaven={}; 3 | if(!RobustHaven.Text) RobustHaven.Text={}; 4 | if(!RobustHaven.Text.Npeg) RobustHaven.Text.Npeg={}; 5 | 6 | RobustHaven.Text.Npeg.TokenMatch = function (name, start, end) { 7 | var name = name, 8 | start = start, 9 | end = end; 10 | 11 | this.getName = function () {return name;}; 12 | this.setName = function ( value ) { name = value; }; 13 | 14 | this.getStart = function () { return start; }; 15 | this.setStart = function ( value ) { start = value; }; 16 | 17 | this.getEnd = function () { return end; }; 18 | this.setEnd = function ( value ){ end = value; }; 19 | } 20 | 21 | -------------------------------------------------------------------------------- /Languages/npeg_javascript/ParsingFatalTerminalException.js: -------------------------------------------------------------------------------- 1 | if(!RobustHaven) var RobustHaven={}; 2 | if(!RobustHaven.Text) RobustHaven.Text={}; 3 | if(!RobustHaven.Text.Npeg) RobustHaven.Text.Npeg={}; 4 | 5 | RobustHaven.Text.Npeg.ParsingFatalTerminalException = function(message, pos) { 6 | var m_errorPos = pos, 7 | message = (typeof message == undefined) ? '' : message; 8 | 9 | RobustHaven.Text.Npeg.ParsingFatalTerminalException.superclass.constructor.call(this, message); 10 | 11 | this.getErrorPosition = function() { 12 | return m_errorPos; 13 | } 14 | } 15 | RobustHaven.Text.Npeg.extend( 16 | RobustHaven.Text.Npeg.ParsingFatalTerminalException, RobustHaven.Text.Npeg.ParsingExpressionGrammarException); -------------------------------------------------------------------------------- /Languages/npeg_c/robusthaven.tests/test_stackstack_constructor.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "robusthaven/structures/stackstack.h" 4 | 5 | static void _dummy(void *node) { 6 | } 7 | 8 | int main(int argc, char *argv[]) { 9 | rh_stackstack_instance stackstack; 10 | 11 | rh_stackstack_constructor(&stackstack, _dummy); 12 | assert(rh_stackstack_count(&stackstack) == 0 && rh_stack_count(&stackstack.basestack) == 0); 13 | assert(stackstack.stack_deletion_callback == _dummy); 14 | printf("\tVerfied: assignment of all critical fields by constructor.\n"); 15 | rh_stackstack_destructor(&stackstack); 16 | printf("\tVerfied: memory integrity after destroying empty stack.\n"); 17 | 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /Languages/npeg_php/InputIterator.php: -------------------------------------------------------------------------------- 1 | index = 0; 12 | $this->length = $length; 13 | } 14 | 15 | public function setIndex( $value ) 16 | { 17 | $this->index = $value; 18 | } 19 | 20 | public function getIndex() 21 | { 22 | return $this->index; 23 | } 24 | 25 | public function getLength() 26 | { 27 | return $this->length; 28 | } 29 | 30 | public abstract function Text($start, $end); 31 | 32 | public abstract function Current(); 33 | public abstract function Next(); 34 | public abstract function Previous(); 35 | 36 | } 37 | 38 | ?> -------------------------------------------------------------------------------- /Languages/npeg_c++/robusthaven/text/StringInputIterator.h: -------------------------------------------------------------------------------- 1 | #ifndef ROBUSTHAVEN_TEXT_STRINGINPUTITERATOR_H 2 | #define ROBUSTHAVEN_TEXT_STRINGINPUTITERATOR_H 3 | 4 | #include "InputIterator.h" 5 | 6 | namespace RobustHaven 7 | { 8 | namespace Text 9 | { 10 | class StringInputIterator : public InputIterator { 11 | public: 12 | /* 13 | * Builds a new InputIterator with an underlying string stream. 14 | * The user has to know the length of the string since the data is interpreted as being binary. 15 | * A trailing 0 is not required. 16 | */ 17 | StringInputIterator(const char* string, const size_t length); 18 | 19 | virtual ~StringInputIterator(void); 20 | }; 21 | } 22 | } 23 | #endif 24 | 25 | -------------------------------------------------------------------------------- /LanguageWorkbench/SupportedLanguageItem.cs: -------------------------------------------------------------------------------- 1 | using System.ComponentModel; 2 | 3 | namespace LanguageWorkbench 4 | { 5 | public class SupportedLanguageItem : INotifyPropertyChanged 6 | { 7 | private string _text = string.Empty; 8 | public string Text 9 | { 10 | get { return _text; } 11 | set 12 | { 13 | if (_text != value) 14 | { 15 | _text = value; 16 | RaisePropertyChanged("Text"); 17 | } 18 | } 19 | } 20 | 21 | 22 | 23 | public event PropertyChangedEventHandler PropertyChanged; 24 | 25 | 26 | protected void RaisePropertyChanged(string propertyName) 27 | { 28 | if (PropertyChanged != null) 29 | { 30 | PropertyChanged(this, new PropertyChangedEventArgs(propertyName)); 31 | } 32 | } 33 | } 34 | } -------------------------------------------------------------------------------- /NPEG/Terminals/DynamicBackReference.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.Serialization; 3 | 4 | namespace NPEG.Terminals 5 | { 6 | // PEG by nature already support static back referencing. 7 | // this allows a user to match (, {, /*, and appropriate closing character. 8 | // however if a user wanted to parse xml DynamicBackReferencing is needed as what the parser must match 9 | // is not known ahead of time. 10 | [DataContract] 11 | public class DynamicBackReference : ALeaf 12 | { 13 | public DynamicBackReference() 14 | { 15 | IsCaseSensitive = true; 16 | } 17 | 18 | [DataMember] 19 | public String BackReferenceName { get; set; } 20 | 21 | [DataMember] 22 | public Boolean IsCaseSensitive { get; set; } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Languages/npeg_c/robusthaven/text/printvisitor.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "printvisitor.h" 3 | 4 | static void _recursive_print(npeg_astnode *root, FILE *out) { 5 | if (root->nof_children) { 6 | int i; 7 | 8 | fprintf(out, "Visit enter: %s\n", root->token->name); 9 | 10 | for (i = 0; i < root->nof_children; i++) { 11 | _recursive_print(root->children[i], out); 12 | } 13 | } else { 14 | fprintf(out, "Visit enter: %s: captures %d-%d\n", 15 | root->token->name, root->token->start, root->token->end); 16 | } 17 | 18 | fprintf(out, "Visit leave: %s\n", root->token->name); 19 | } 20 | 21 | void npeg_printVisitor(npeg_astnode *root, FILE *out) { 22 | puts("START - PrintVisitor"); 23 | _recursive_print(root, out == NULL? stdout : out); 24 | } 25 | -------------------------------------------------------------------------------- /Languages/npeg_java/robusthaven/Makefile: -------------------------------------------------------------------------------- 1 | JAVAC=javac 2 | OBJ= robusthaven/text/AstNode.class robusthaven/text/InputIterator.class \ 3 | robusthaven/text/IAstNodeReplacement.class \ 4 | robusthaven/text/TokenMatch.class robusthaven/text/Npeg.class \ 5 | robusthaven/text/ParsingFatalTerminalException.class robusthaven/text/Warn.class\ 6 | robusthaven/text/InfiniteLoopException.class robusthaven/text/IAstNodeVisitor.class \ 7 | robusthaven/text/PrintVisitor.class 8 | 9 | 10 | 11 | BUILDDIR= text 12 | 13 | all: ../robusthaven.jar 14 | 15 | ../robusthaven.jar: 16 | # use archiver utility to create library. 17 | $(JAVAC) robusthaven/text/*.java 18 | jar cvf robusthaven.jar robusthaven/text/*.class 19 | mv robusthaven.jar ../ 20 | 21 | clean: 22 | rm -f ../robusthaven.jar 23 | rm -f robusthaven/text/*.class 24 | -------------------------------------------------------------------------------- /NPEG/Extensions/StringExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Text.RegularExpressions; 6 | 7 | namespace NPEG.Extensions 8 | { 9 | public static class StringExtensions 10 | { 11 | public static string ToHexStringFromByteArray(this byte[] bytes) 12 | { 13 | var hex = new StringBuilder(bytes.Length * 2); 14 | foreach (byte b in bytes) 15 | hex.AppendFormat(" {0:x2}", b); 16 | return hex.ToString(); 17 | } 18 | 19 | public static List ToBytesFromHexString(string hexString) 20 | { 21 | var items = Regex.Matches(hexString, @"(?[0-9a-fA-F]{2})"); 22 | 23 | return (from Match item in items select Convert.ToByte(item.Groups["Hex"].Value, 16)).ToList(); 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Languages/npeg_csharp/RobustHaven.Text.Npeg/AstNode.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace RobustHaven.Text.Npeg 5 | { 6 | public class AstNode 7 | { 8 | public AstNode() 9 | { 10 | Children = new List(); 11 | } 12 | 13 | public AstNode Parent { get; set; } 14 | 15 | public List Children { get; set; } 16 | 17 | public TokenMatch Token { get; set; } 18 | 19 | 20 | public void Accept(IAstNodeVisitor visitor) 21 | { 22 | visitor.VisitEnter(this); 23 | 24 | Boolean isFirstTime = true; 25 | foreach (AstNode node in Children) 26 | { 27 | if (!isFirstTime) 28 | { 29 | visitor.VisitExecute(this); 30 | } 31 | 32 | isFirstTime = false; 33 | node.Accept(visitor); 34 | } 35 | 36 | visitor.VisitLeave(this); 37 | } 38 | } 39 | } -------------------------------------------------------------------------------- /Languages/npeg_c++/robusthaven.tests/ParserTest_NpegNode/NpegNode.cpp: -------------------------------------------------------------------------------- 1 | #include "NpegNode.h" 2 | 3 | using namespace RobustHaven::Text; 4 | 5 | int NpegNode::NpegNode_impl_0() 6 | { 7 | const char* _nodeName_0 = "NpegNode"; 8 | 9 | return this->capturingGroup((Npeg::IsMatchPredicate)&NpegNode::NpegNode_impl_1, _nodeName_0, 0, NULL); 10 | } 11 | int NpegNode::NpegNode_impl_1() 12 | { 13 | return this->prioritizedChoice((Npeg::IsMatchPredicate)&NpegNode::NpegNode_impl_2, (Npeg::IsMatchPredicate)&NpegNode::NpegNode_impl_3); 14 | } 15 | int NpegNode::NpegNode_impl_3() 16 | { 17 | const char* _literal_0 = ".NET Parsing Expression Grammar"; 18 | 19 | return this->literal(_literal_0, 31, 0); 20 | } 21 | int NpegNode::NpegNode_impl_2() 22 | { 23 | const char* _literal_0 = "NPEG"; 24 | 25 | return this->literal(_literal_0, 4, 0); 26 | } 27 | -------------------------------------------------------------------------------- /NPEG/NonTerminals/RecursionCreate.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Runtime.Serialization; 4 | 5 | namespace NPEG.NonTerminals 6 | { 7 | [DataContract] 8 | public class RecursionCreate : AComposite 9 | { 10 | private readonly AExpression exp; 11 | 12 | public RecursionCreate(String unique, AExpression exp) 13 | { 14 | FunctionName = unique; 15 | this.exp = exp; 16 | } 17 | 18 | [DataMember] 19 | public String FunctionName { get; set; } 20 | 21 | // type cannot be serialized in wcf service 22 | public Type TypeContains 23 | { 24 | get { return exp.GetType(); } 25 | } 26 | 27 | [DataMember] 28 | public override List Children 29 | { 30 | get { return new List { exp }; } 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /Languages/npeg_php/TokenMatch.php: -------------------------------------------------------------------------------- 1 | name = $name; 13 | $this->start = $start; 14 | $this->end = $end; 15 | } 16 | 17 | public function setName( $value ) 18 | { 19 | $this->name = $value; 20 | } 21 | 22 | public function getName() 23 | { 24 | return $this->name; 25 | } 26 | 27 | public function setStart( $value ) 28 | { 29 | $this->start = $value; 30 | } 31 | 32 | public function getStart() 33 | { 34 | return $this->start; 35 | } 36 | 37 | public function setEnd( $value ) 38 | { 39 | $this->end = $value; 40 | } 41 | 42 | public function getEnd() 43 | { 44 | return $this->end; 45 | } 46 | } 47 | 48 | ?> 49 | -------------------------------------------------------------------------------- /LanguageWorkbench/WorkBenchView.xaml.cs: -------------------------------------------------------------------------------- 1 | using System.Windows.Controls; 2 | 3 | namespace LanguageWorkbench 4 | { 5 | public partial class WorkBenchView : UserControl 6 | { 7 | public WorkBenchView() 8 | { 9 | InitializeComponent(); 10 | } 11 | 12 | public WorkBenchViewModel ViewModel 13 | { 14 | get { return DataContext as WorkBenchViewModel; } 15 | set 16 | { 17 | DataContext = value; 18 | 19 | value.PropertyChanged += ViewModelPropertyChanged; 20 | } 21 | } 22 | 23 | void ViewModelPropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e) 24 | { 25 | if (e.PropertyName == "AbstractSyntaxTree") 26 | { 27 | UIHelper.SetTimeout(500, () => astDiagram.ExpandAllHierarchyItems()); 28 | } 29 | 30 | if (e.PropertyName == "ParseTree") 31 | { 32 | UIHelper.SetTimeout(1000, () => parseTree.ExpandAll()); 33 | } 34 | } 35 | } 36 | } -------------------------------------------------------------------------------- /Languages/npeg_c++/robusthaven.tests/test_ast_constructor.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "robusthaven/text/AstNode.h" 4 | 5 | using namespace RobustHaven::Text; 6 | using namespace std; 7 | 8 | int main(int argc, char *argv[]) { 9 | TokenMatch *p_token; 10 | AstNode *p_root; 11 | 12 | p_root = new AstNode(NULL, false); 13 | assert(p_root->getChildren().size() == 0); 14 | assert(p_root->getToken() == NULL); 15 | delete p_root; 16 | cout << "\tVerified: Correct initialization w/o token.\n"; 17 | 18 | p_token = new TokenMatch("a token", 0, 0); 19 | // AstNode is responsible to delete p_token 20 | p_root = new AstNode(p_token, true); 21 | assert(p_root->getChildren().size() == 0); 22 | assert(p_root->getToken() == p_token); 23 | delete p_root; 24 | cout << "\tVerified: Correct initialization w/ token.\n"; 25 | 26 | return 0; 27 | } /* main */ 28 | -------------------------------------------------------------------------------- /LanguageWorkbench/Converters/RemoveNameSpaceConverter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Globalization; 3 | using System.Linq; 4 | using System.Windows.Data; 5 | 6 | namespace LanguageWorkbench.Converters 7 | { 8 | public class RemoveNameSpaceConverter : IValueConverter 9 | { 10 | #region IValueConverter Members 11 | 12 | public object Convert(object value, Type targetType, object parameter, CultureInfo culture) 13 | { 14 | if (value == null) 15 | return null; 16 | 17 | string data = value.ToString(); 18 | if (String.IsNullOrEmpty(data)) 19 | { 20 | return value; 21 | } 22 | string[] split = data.Split('.'); 23 | return split.Count() > 1 ? split[split.Count() - 1] : data; 24 | } 25 | 26 | public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) 27 | { 28 | throw new NotImplementedException(); 29 | } 30 | 31 | #endregion 32 | } 33 | } -------------------------------------------------------------------------------- /Languages/npeg_php/InfiniteLoopDetectedException.php: -------------------------------------------------------------------------------- 1 | __call('__construct0', null); 14 | break; 15 | case 1: 16 | $this->__call('__construct1', $args); 17 | break; 18 | default: 19 | throw new Exception(); 20 | } 21 | } 22 | 23 | public function __construct0() 24 | { 25 | parent::__construct('Supplied grammar rules caused an infinite loop.'); 26 | } 27 | 28 | public function __construct1($message) 29 | { 30 | parent::__construct($message); 31 | } 32 | } 33 | 34 | ?> -------------------------------------------------------------------------------- /Languages/npeg_c/robusthaven.tests/ParserTest_NpegNode/NpegNode.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "NpegNode.h" 3 | 4 | int NpegNode_impl_0(npeg_inputiterator* iterator, npeg_context* context) 5 | { 6 | char* _nodeName_0 = "NpegNode"; 7 | 8 | return npeg_CapturingGroup(iterator, context, &NpegNode_impl_1, _nodeName_0, 0, 0); 9 | } 10 | int NpegNode_impl_1(npeg_inputiterator* iterator, npeg_context* context) 11 | { 12 | return npeg_PrioritizedChoice(iterator, context, &NpegNode_impl_2, &NpegNode_impl_3); 13 | } 14 | int NpegNode_impl_3(npeg_inputiterator* iterator, npeg_context* context) 15 | { 16 | char* _literal_0 = ".NET Parsing Expression Grammar"; 17 | 18 | return npeg_Literal(iterator, context, _literal_0, 31, 0); 19 | } 20 | int NpegNode_impl_2(npeg_inputiterator* iterator, npeg_context* context) 21 | { 22 | char* _literal_0 = "NPEG"; 23 | 24 | return npeg_Literal(iterator, context, _literal_0, 4, 0); 25 | } 26 | -------------------------------------------------------------------------------- /LanguageWorkbench/Properties/OutOfBrowserSettings.xml: -------------------------------------------------------------------------------- 1 | 2 | Language Workbench Application on your desktop; at home, at work or on the go. 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | Icons/npeg_16x16.png 11 | Icons/npeg_32x32.png 12 | Icons/npeg_48x48.png 13 | Icons/npeg_128x128.png 14 | 15 | -------------------------------------------------------------------------------- /Languages/npeg_java/robusthaven/robusthaven/text/StringInputIterator.java: -------------------------------------------------------------------------------- 1 | package robusthaven.text; 2 | import java.io.ByteArrayInputStream; 3 | import java.io.IOException; 4 | 5 | public class StringInputIterator extends InputIterator { 6 | public StringInputIterator(byte[] input, int length) throws IOException { 7 | super(new ByteArrayInputStream(input, 0, length), length); 8 | } 9 | 10 | public static byte[] stringToByteArray(String instring) { 11 | byte[] outArray; 12 | int i, len; 13 | 14 | len = instring.length(); 15 | outArray = new byte[len]; 16 | for (i = 0; i < len; i++) { 17 | outArray[i] = (byte)instring.charAt(i); 18 | } 19 | 20 | return outArray; 21 | } 22 | 23 | public StringInputIterator(String instring) throws IOException { 24 | super(new ByteArrayInputStream(stringToByteArray(instring), 0, instring.length()), 25 | instring.length()); 26 | } 27 | } -------------------------------------------------------------------------------- /NPEG/NonTerminals/CapturingGroup.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Runtime.Serialization; 4 | 5 | namespace NPEG.NonTerminals 6 | { 7 | [DataContract] 8 | public class CapturingGroup : AComposite 9 | { 10 | private readonly AExpression Exp; 11 | 12 | public CapturingGroup(String uniquename, AExpression exp) 13 | { 14 | Exp = exp; 15 | Name = uniquename; 16 | DoReplaceBySingleChildNode = false; 17 | DoCreateCustomAstNode = false; 18 | } 19 | 20 | [DataMember] 21 | public String Name { get; set; } 22 | 23 | [DataMember] 24 | public Boolean DoReplaceBySingleChildNode { get; set; } 25 | 26 | [DataMember] 27 | public Boolean DoCreateCustomAstNode { get; set; } 28 | 29 | 30 | [DataMember] 31 | public override List Children 32 | { 33 | get { return new List { Exp }; } 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /LanguageWorkbench/Algorithms/PrintAST.cs: -------------------------------------------------------------------------------- 1 | using NPEG; 2 | using NPEG.Extensions; 3 | 4 | namespace LanguageWorkbench.Algorithms 5 | { 6 | public class PrintAST : IAstNodeReplacement 7 | { 8 | private readonly IInputIterator _inputIterator; 9 | 10 | private readonly IndentedStringBuilder _sb = new IndentedStringBuilder(); 11 | 12 | public PrintAST(IInputIterator inputIterator) 13 | { 14 | _inputIterator = inputIterator; 15 | } 16 | 17 | public override void VisitEnter(AstNode node) 18 | { 19 | _sb.AppendLine("VisitEnter: " + node.Token.Name + " " + ((node.Children.Count == 0) ? node.Token.ValueAsString(_inputIterator) : "")); 20 | _sb.IncreaseIndent(); 21 | } 22 | 23 | public override void VisitLeave(AstNode node) 24 | { 25 | _sb.DecreaseIndent(); 26 | _sb.AppendLine("VisitLeave: " + node.Token.Name); 27 | } 28 | 29 | public override string ToString() 30 | { 31 | return _sb.ToString(); 32 | } 33 | } 34 | } -------------------------------------------------------------------------------- /Languages/npeg_c/robusthaven.tests/Makefile: -------------------------------------------------------------------------------- 1 | CC=gcc 2 | CFLAGS=-ggdb -I ../ 3 | 4 | STATIC_LIBRARIES = ../robusthaven/robusthaven.a 5 | 6 | PARSER_TESTS = ParserTest_NpegNode.o ParserTest_PhoneNumber.o ParserTest_SimpleSentence.o \ 7 | ParserTest_MathematicalFormula.o ParserTest_SimpleXml.o 8 | 9 | TESTS = $(subst .c,.o,$(shell ls *.c)) 10 | 11 | %.o: %.c 12 | @mkdir -p bin 13 | $(CC) $(CFLAGS) $< ${STATIC_LIBRARIES} -o bin/$@ 14 | 15 | 16 | all: ${STATIC_LIBRARIES} ${TESTS} ${PARSER_TESTS} 17 | 18 | ../robusthaven/robusthaven.a: 19 | $(MAKE) -f Makefile --directory=../robusthaven all 20 | 21 | ${PARSER_TESTS}: 22 | $(MAKE) -f Makefile --directory=./$(subst .o,,$@) all 23 | 24 | clean: 25 | $(MAKE) -f Makefile --directory=../robusthaven clean 26 | for folder in $(subst .o,,${PARSER_TESTS}); do \ 27 | $(MAKE) -f Makefile --directory=./$${folder} clean; \ 28 | done ; 29 | 30 | rm -Rf *.c~ *.o Makefile~ *.teststderr *.teststdin *.sh~ bin 31 | 32 | -------------------------------------------------------------------------------- /Languages/npeg_c/robusthaven.tests/test_hashmap_constructor.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include "robusthaven/structures/hashmap.h" 6 | 7 | /* 8 | * Runs some tests on a newly created hashmap: 9 | * - Test correct capacity 10 | * - Test inactivity of all fields 11 | */ 12 | int main(int argc, char *argv[]) { 13 | rh_hashmap_instance hashmap; 14 | uint i, start_cap; 15 | 16 | srand(time(NULL)); 17 | start_cap = rand()%31; 18 | 19 | rh_hashmap_constructor(&hashmap, start_cap, NULL); 20 | assert(hashmap.capacity == start_cap); 21 | printf("\tVerified: hashmap constructor allocates memory specified by constructor argument.\n"); 22 | 23 | for (i = 0; i < hashmap.capacity; i++) { 24 | assert(!hashmap.baseptr[i].active); 25 | } 26 | printf("\tVerified: all buckets are marked inactive.\n"); 27 | 28 | rh_hashmap_destructor(&hashmap); 29 | 30 | return 0; 31 | } /* main */ 32 | -------------------------------------------------------------------------------- /Languages/npeg_c++/robusthaven.tests/lib_tests.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | fn_test_status() 4 | { 5 | case $1 in 6 | 0) 7 | echo -n "Passed" 8 | ;; 9 | *) 10 | echo -n "Failed" 11 | echo 12 | ;; 13 | esac 14 | } 15 | 16 | 17 | fn_test_run() 18 | { 19 | pattern=$1 20 | isverbose=$2 21 | for TEST in ${pattern}*; do 22 | if [ -x ${TEST} ]; then 23 | ./${TEST} >out.teststdin 2>out.teststderr 24 | status=$? 25 | printf "%-50.43s %-22s\n" $TEST `fn_test_status $status` 26 | 27 | if [ $status -ne 0 ] || [ $isverbose = 1 ]; then 28 | cat out.teststdin 29 | cat out.teststderr 30 | echo 31 | fi 32 | fi 33 | done 34 | } 35 | 36 | 37 | fn_test_memory() 38 | { 39 | pattern=$1 40 | isverbose=$2 41 | for TEST in ${pattern}*; do 42 | if [ -x ${TEST} ]; then 43 | #-v 44 | valgrind --tool=memcheck --show-reachable=yes --leak-check=yes ./${TEST} >out.teststdin 2>out.teststderr 45 | cat out.teststderr 46 | fi 47 | done 48 | } 49 | -------------------------------------------------------------------------------- /Languages/npeg_c/robusthaven.tests/lib_tests.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | fn_test_status() 4 | { 5 | case $1 in 6 | 0) 7 | echo -n "Passed" 8 | ;; 9 | *) 10 | echo -n "Failed" 11 | echo 12 | ;; 13 | esac 14 | } 15 | 16 | 17 | fn_test_run() 18 | { 19 | pattern=$1 20 | isverbose=$2 21 | for TEST in ${pattern}*; do 22 | if [ -x ${TEST} ]; then 23 | ./${TEST} >out.teststdin 2>out.teststderr 24 | status=$? 25 | printf "%-50.43s %-22s\n" $TEST `fn_test_status $status` 26 | 27 | if [ $status -ne 0 ] || [ $isverbose = 1 ]; then 28 | cat out.teststdin 29 | cat out.teststderr 30 | echo 31 | fi 32 | fi 33 | done 34 | } 35 | 36 | 37 | fn_test_memory() 38 | { 39 | pattern=$1 40 | isverbose=$2 41 | for TEST in ${pattern}*; do 42 | if [ -x ${TEST} ]; then 43 | #-v 44 | valgrind --tool=memcheck --show-reachable=yes --leak-check=yes ./${TEST} >out.teststdin 2>out.teststderr 45 | cat out.teststderr 46 | fi 47 | done 48 | } 49 | -------------------------------------------------------------------------------- /Languages/npeg_c/robusthaven.tests/test_inthashmap_constructor.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include "robusthaven/structures/inthashmap.h" 6 | 7 | /* 8 | * Runs some tests on a newly created hashmap: 9 | * - Test correct capacity 10 | * - Test inactivity of all fields 11 | */ 12 | int main(int argc, char *argv[]) { 13 | rh_inthashmap_instance hashmap; 14 | uint i, start_cap; 15 | 16 | srand(time(NULL)); 17 | start_cap = rand()%31; 18 | 19 | rh_inthashmap_constructor(&hashmap, start_cap); 20 | assert(hashmap.capacity == start_cap); 21 | printf("\tVerified: hashmap constructor allocates memory specified by constructor argument.\n"); 22 | 23 | for (i = 0; i < hashmap.capacity; i++) { 24 | assert(!hashmap.baseptr[i].active); 25 | } 26 | printf("\tVerified: all buckets are marked inactive.\n"); 27 | 28 | rh_inthashmap_destructor(&hashmap); 29 | 30 | return 0; 31 | } /* main */ 32 | -------------------------------------------------------------------------------- /NPEG/GrammarInterpreter/AstNodes/PeGrammarAstNodeFactory.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace NPEG.GrammarInterpreter.AstNodes 4 | { 5 | internal class PeGrammarAstNodeFactory : IAstNodeFactory 6 | { 7 | private readonly IInputIterator _inputIterator; 8 | 9 | public PeGrammarAstNodeFactory(IInputIterator inputIterator) 10 | { 11 | _inputIterator = inputIterator; 12 | } 13 | 14 | #region IAstNodeFactory Members 15 | 16 | public IAstNodeReplacement Create(AstNode original) 17 | { 18 | switch (original.Token.Name) 19 | { 20 | case "Statement": 21 | return new StatementAstNode(_inputIterator); 22 | case "PEG": 23 | return new InterpreterAstNode(_inputIterator); 24 | } 25 | 26 | throw new ArgumentOutOfRangeException( 27 | String.Format("PeGrammarAstNodeFactory does not define replacement node for: {0}", original.Token.Name)); 28 | } 29 | 30 | #endregion 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | #http://stackoverflow.com/questions/2143956/gitignore-for-visual-studio-projects-and-solutions 2 | 3 | Externs/silverlight/telerik 4 | 5 | #OS junk files 6 | [Tt]humbs.db 7 | *.DS_Store 8 | 9 | #Visual Studio files 10 | .vs 11 | *.[Oo]bj 12 | *.user 13 | *.aps 14 | *.pch 15 | *.vspscc 16 | *.vssscc 17 | *_i.c 18 | *_p.c 19 | *.ncb 20 | *.suo 21 | *.tlb 22 | *.tlh 23 | *.bak 24 | *.[Cc]ache 25 | *.ilk 26 | *.log 27 | *.lib 28 | *.sbr 29 | *.sdf 30 | *.opensdf 31 | *.unsuccessfulbuild 32 | ipch/ 33 | obj/ 34 | [Bb]in 35 | [Dd]ebug*/ 36 | [Rr]elease*/ 37 | Ankh.NoLoad 38 | 39 | #MonoDevelop 40 | *.pidb 41 | *.userprefs 42 | 43 | #Tooling 44 | _ReSharper*/ 45 | *.resharper 46 | [Tt]est[Rr]esult* 47 | 48 | #Project files 49 | [Bb]uild/ 50 | 51 | #Subversion files 52 | .svn 53 | 54 | # Office Temp Files 55 | ~$* 56 | 57 | #NuGet 58 | packages/ 59 | 60 | #ncrunch 61 | *ncrunch* 62 | *crunch*.local.xml 63 | .vs/NPEG/v15/sqlite3/storage.ide 64 | .vs/config/applicationhost.config 65 | -------------------------------------------------------------------------------- /Languages/npeg_c++/robusthaven/text/Exceptions.h: -------------------------------------------------------------------------------- 1 | #ifndef ROBUSTHAVEN_TEXT_EXCEPTIONS_H 2 | #define ROBUSTHAVEN_TEXT_EXCEPTIONS_H 3 | 4 | #include 5 | 6 | namespace RobustHaven 7 | { 8 | namespace Text 9 | { 10 | class ParsingFatalTerminalException : public std::runtime_error { 11 | private: 12 | size_t m_errorPos; 13 | 14 | public: 15 | size_t getErrorPosition(void) const; 16 | 17 | public: 18 | ParsingFatalTerminalException(const std::string &msg, const size_t pos) 19 | : runtime_error(msg), m_errorPos(pos) {} 20 | }; 21 | 22 | class InfiniteLoopException : public ParsingFatalTerminalException { 23 | public: 24 | InfiniteLoopException(const std::string &msg, const size_t pos) 25 | : ParsingFatalTerminalException(msg, pos) {} 26 | }; 27 | 28 | extern inline size_t ParsingFatalTerminalException::getErrorPosition() const { 29 | return m_errorPos; 30 | } 31 | } 32 | } 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /NPEG/Terminals/CodePoint.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.Serialization; 3 | 4 | namespace NPEG.Terminals 5 | { 6 | // #32 (decimal utf-8 codepoint) // Match input against the specified unicode character (can consume 1-4 bytes of input) 7 | // #x3A0 (hex) 8 | // #b111 (binary) 9 | [DataContract] 10 | public class CodePoint : ALeaf 11 | { 12 | // for hex and binary you can group and input iterator will be matched against binary array. 13 | // so instead of #x61 #x62 #63 to match abc you could write a short hand: #616263 14 | 15 | // data is shifted right when input form incomplete byte boundaries 16 | // Example: 0xFAB 17 | // to complete byte boundaris 18 | // does the user mean: FAB0 or 0FAB ? 19 | // This system shifts all data to the right to complete byte boundaries. 20 | // so 0xFAB would become 0FAB and 2 bytes of input iterator would be consumed. 21 | 22 | 23 | [DataMember] 24 | public String Match { get; set; } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Languages/npeg_csharp/RobustHaven.Text.Npeg.Tests/Parsers/NpegNode.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace RobustHaven.Text.Npeg.Tests.Parsers 4 | { 5 | public class NpegNode : NpegParser 6 | { 7 | public NpegNode(InputIterator iterator) : base(iterator) 8 | { 9 | } 10 | 11 | public override Boolean IsMatch() 12 | { 13 | return NpegNode_impl_0(); 14 | } 15 | 16 | 17 | protected Boolean NpegNode_impl_0() 18 | { 19 | String _nodeName_0 = "NpegNode"; 20 | return CapturingGroup(NpegNode_impl_1, _nodeName_0, false, false); 21 | } 22 | 23 | protected Boolean NpegNode_impl_1() 24 | { 25 | return PrioritizedChoice(NpegNode_impl_2, NpegNode_impl_3); 26 | } 27 | 28 | protected Boolean NpegNode_impl_3() 29 | { 30 | String _literal_0 = ".NET Parsing Expression Grammar"; 31 | return Literal(_literal_0, false); 32 | } 33 | 34 | protected Boolean NpegNode_impl_2() 35 | { 36 | String _literal_0 = "NPEG"; 37 | return Literal(_literal_0, false); 38 | } 39 | } 40 | } -------------------------------------------------------------------------------- /Languages/npeg_csharp/RobustHaven.Text.Npeg/InputIterator.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace RobustHaven.Text.Npeg 4 | { 5 | public abstract class InputIterator 6 | { 7 | public Int32 Index; 8 | 9 | public InputIterator(Int32 length) 10 | { 11 | Index = 0; 12 | Length = length; 13 | } 14 | 15 | public Int32 Length { get; private set; } 16 | 17 | 18 | public abstract Byte[] Text(Int32 start, Int32 end); 19 | 20 | 21 | // Instead of returning a Byte 22 | // an Int16 is used so error condition is encoded with value. 23 | // if the sign bit is flagged we know an error occurred. 24 | // 100000000 00000000 == -1 25 | // if sign bit is not enabled 26 | // we know casting (Byte)int16value will provide valid data of stream. 27 | // Boolean MoveNext() 28 | // Boolean MoveBack() 29 | // Boolean IsCurrentValid() used inconjuction with Byte Current() 30 | 31 | public abstract Int16 Current(); 32 | public abstract Int16 Next(); 33 | public abstract Int16 Previous(); 34 | } 35 | } -------------------------------------------------------------------------------- /Languages/npeg_c++/robusthaven.tests/Makefile: -------------------------------------------------------------------------------- 1 | CXX=g++ 2 | CXXFLAGS=-ggdb -Wno-deprecated 3 | CPPFLAGS= -I ../ 4 | 5 | STATIC_LIBRARIES = ../robusthaven/robusthaven.a 6 | 7 | PARSER_TESTS = ParserTest_PhoneNumber.o ParserTest_NpegNode.o \ 8 | ParserTest_MathematicalFormula.o ParserTest_SimpleXml.o 9 | 10 | TESTS = $(subst .cpp,.o,$(shell ls *.cpp)) 11 | 12 | %.o: %.cpp 13 | @mkdir -p bin 14 | $(CXX) $(CXXFLAGS) $(CPPFLAGS) $< ${STATIC_LIBRARIES} -o bin/$@ 15 | 16 | 17 | all: ${STATIC_LIBRARIES} ${TESTS} ${PARSER_TESTS} 18 | 19 | ../robusthaven/robusthaven.a: 20 | $(MAKE) -f Makefile --directory=../robusthaven all 21 | 22 | ${PARSER_TESTS}: 23 | $(MAKE) -f Makefile --directory=./$(subst .o,,$@) all 24 | 25 | clean: 26 | $(MAKE) -f Makefile --directory=../robusthaven clean 27 | for folder in $(subst .o,,${PARSER_TESTS}); do \ 28 | $(MAKE) -f Makefile --directory=./$${folder} clean; \ 29 | done ; 30 | 31 | rm -Rf *.c~ *.o Makefile~ *.teststderr *.teststdin *.sh~ bin ../robusthaven/robusthaven.a 32 | 33 | -------------------------------------------------------------------------------- /NPEG/IInputIterator.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace NPEG 4 | { 5 | public abstract class IInputIterator 6 | { 7 | protected IInputIterator(Int32 length) 8 | { 9 | Index = 0; 10 | Length = length; 11 | } 12 | 13 | // Zero based index 14 | public Int32 Index { get; set; } 15 | 16 | public Int32 Length { get; private set; } 17 | 18 | 19 | public abstract Byte[] Text(Int32 start, Int32 end); 20 | 21 | 22 | // Instead of returning a Byte 23 | // an Int16 is used so error condition is encoded with value. 24 | // if the sign bit is flagged we know an error occurred. 25 | // 100000000 00000000 == -1 26 | // if sign bit is not enabled 27 | // we know casting (Byte)int16value will provide valid data of stream. 28 | // Boolean MoveNext() 29 | // Boolean MoveBack() 30 | // Boolean IsCurrentValid() used inconjuction with Byte Current() 31 | 32 | public abstract Int16 Current(); 33 | public abstract Int16 Next(); 34 | public abstract Int16 Previous(); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /Languages/npeg_csharp/RobustHaven.Text.Npeg.Tests/Parsers/OneOrMoreInfiniteLoopTest.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace RobustHaven.Text.Npeg.Tests.Parsers 4 | { 5 | public class OneOrMoreInfiniteLoopTest : NpegParser 6 | { 7 | public OneOrMoreInfiniteLoopTest(InputIterator iterator) : base(iterator) 8 | { 9 | } 10 | 11 | public override Boolean IsMatch() 12 | { 13 | return OneOrMoreInfiniteLoopTest_impl_0(); 14 | } 15 | 16 | 17 | protected Boolean OneOrMoreInfiniteLoopTest_impl_0() 18 | { 19 | String _nodeName_0 = "Expression"; 20 | return CapturingGroup(OneOrMoreInfiniteLoopTest_impl_1, _nodeName_0, false, false); 21 | } 22 | 23 | protected Boolean OneOrMoreInfiniteLoopTest_impl_1() 24 | { 25 | return OneOrMore(OneOrMoreInfiniteLoopTest_impl_2, ""); 26 | } 27 | 28 | protected Boolean OneOrMoreInfiniteLoopTest_impl_2() 29 | { 30 | return ZeroOrMore(OneOrMoreInfiniteLoopTest_impl_3, ""); 31 | } 32 | 33 | protected Boolean OneOrMoreInfiniteLoopTest_impl_3() 34 | { 35 | return AnyCharacter(); 36 | } 37 | } 38 | } -------------------------------------------------------------------------------- /Languages/npeg_javascript/helper.js: -------------------------------------------------------------------------------- 1 | if(!RobustHaven) var RobustHaven={}; 2 | if(!RobustHaven.Text) RobustHaven.Text={}; 3 | if(!RobustHaven.Text.Npeg) RobustHaven.Text.Npeg={}; 4 | 5 | RobustHaven.Text.Npeg.extend = function(Child, Parent) { 6 | var F = function() { } 7 | F.prototype = Parent.prototype 8 | Child.prototype = new F() 9 | Child.prototype.constructor = Child 10 | Child.superclass = Parent.prototype 11 | } 12 | 13 | RobustHaven.Text.Npeg.stringToBytes = function(str) { 14 | var ch, st, re = []; 15 | for (var i = 0; i < str.length; i++ ) { 16 | ch = str.charCodeAt(i); // get char 17 | st = []; // set up "stack" 18 | do { 19 | st.push( ch & 0xFF ); // push byte to stack 20 | ch = ch >> 8; // shift value down by 1 byte 21 | } 22 | while ( ch ); 23 | // add stack contents to result 24 | // done because chars have "wrong" endianness 25 | re = re.concat( st.reverse() ); 26 | } 27 | // return an array of bytes 28 | return re; 29 | } -------------------------------------------------------------------------------- /Languages/npeg_csharp/RobustHaven.Text.Npeg.Tests/Parsers/ZeroOrMoreInfiniteLoopTest.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace RobustHaven.Text.Npeg.Tests.Parsers 4 | { 5 | public class ZeroOrMoreInfiniteLoopTest : NpegParser 6 | { 7 | public ZeroOrMoreInfiniteLoopTest(InputIterator iterator) : base(iterator) 8 | { 9 | } 10 | 11 | public override Boolean IsMatch() 12 | { 13 | return ZeroOrMoreInfiniteLoopTest_impl_0(); 14 | } 15 | 16 | 17 | protected Boolean ZeroOrMoreInfiniteLoopTest_impl_0() 18 | { 19 | String _nodeName_0 = "Expression"; 20 | return CapturingGroup(ZeroOrMoreInfiniteLoopTest_impl_1, _nodeName_0, false, false); 21 | } 22 | 23 | protected Boolean ZeroOrMoreInfiniteLoopTest_impl_1() 24 | { 25 | return ZeroOrMore(ZeroOrMoreInfiniteLoopTest_impl_2, ""); 26 | } 27 | 28 | protected Boolean ZeroOrMoreInfiniteLoopTest_impl_2() 29 | { 30 | return ZeroOrMore(ZeroOrMoreInfiniteLoopTest_impl_3, ""); 31 | } 32 | 33 | protected Boolean ZeroOrMoreInfiniteLoopTest_impl_3() 34 | { 35 | return AnyCharacter(); 36 | } 37 | } 38 | } -------------------------------------------------------------------------------- /NPEG/Algorithms/AstWriter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace NPEG.Algorithms 5 | { 6 | public class AstWriterDefaultData 7 | { 8 | public Int32 Indent; 9 | public bool IsIgnoring; 10 | public List TopLevelIgnoredCommands { get; private set; } 11 | 12 | public AstWriterDefaultData() 13 | { 14 | TopLevelIgnoredCommands = new List { }; 15 | } 16 | } 17 | 18 | public class AstWriter : IAstNodeReplacement 19 | { 20 | private readonly Action _onEnter; 21 | private readonly Action _onLeave; 22 | 23 | private T Data { get; set; } 24 | 25 | public AstWriter(T data, Action onEnter, Action onLeave) 26 | { 27 | _onEnter = onEnter; 28 | _onLeave = onLeave; 29 | Data = data; 30 | } 31 | 32 | public override void VisitEnter(AstNode node) 33 | { 34 | _onEnter(Data, node); 35 | } 36 | 37 | public override void VisitLeave(AstNode node) 38 | { 39 | _onLeave(Data, node); 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /Languages/npeg_c++/robusthaven/text/TokenMatch.h: -------------------------------------------------------------------------------- 1 | #ifndef ROBUSTHAVEN_TEXT_TOKENMATCH_H 2 | #define ROBUSTHAVEN_TEXT_TOKENMATCH_H 3 | 4 | #include 5 | 6 | namespace RobustHaven 7 | { 8 | namespace Text 9 | { 10 | class TokenMatch 11 | { 12 | std::string m_name; 13 | int m_start, m_end; 14 | 15 | public: 16 | const std::string& getName(void) const; 17 | 18 | int getStart(void) const; 19 | 20 | int getEnd(void) const; 21 | 22 | public: 23 | TokenMatch(const char name[], const int start, const int end); 24 | }; 25 | 26 | extern inline const std::string& TokenMatch::getName(void) const { 27 | return m_name; 28 | } 29 | 30 | extern inline int TokenMatch::getStart(void) const { 31 | return m_start; 32 | } 33 | 34 | extern inline int TokenMatch::getEnd(void) const { 35 | return m_end; 36 | } 37 | 38 | extern inline TokenMatch::TokenMatch(const char name[], const int start, const int end) 39 | : m_name(name), m_start(start), m_end(end) { 40 | } 41 | } 42 | } 43 | #endif 44 | -------------------------------------------------------------------------------- /Languages/npeg_c++/robusthaven.tests/test_inputiterator_empty.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | #include "robusthaven/text/StringInputIterator.h" 7 | 8 | using namespace std; 9 | using namespace RobustHaven::Text; 10 | 11 | /* 12 | * Unit test for the empty string limit case. 13 | */ 14 | int main(int argc, char *argv[]) { 15 | StringInputIterator iter("", 0); 16 | int i; 17 | 18 | srand(time(NULL)); 19 | 20 | for (i = 0; i < 10; i++) { 21 | int start, end; 22 | char buffer[101] = { 1, 1, 1 }; 23 | 24 | start = rand()%100, end = rand()%100; 25 | 26 | assert(iter.getText(buffer, start, end) == 0); 27 | cout << "\tVerified: iterator with empty string is handled correctly.\n"; 28 | 29 | assert(buffer[0] == 0 && buffer[1] == 1 && buffer[2] == 1); 30 | cout << "\tVerified: no modification of destination buffer apart from first byte.\n"; 31 | } 32 | cout << "\tReached: get_text works.\n"; 33 | 34 | assert(iter.getCurrent() == -1); 35 | assert(iter.getNext() == -1); 36 | 37 | return 0; 38 | } /* main */ 39 | -------------------------------------------------------------------------------- /NPEG/GrammarInterpreter/LimitingRepetitionVariableLengthExpressionParser.cs: -------------------------------------------------------------------------------- 1 | using NPEG.ApplicationExceptions; 2 | 3 | namespace NPEG.GrammarInterpreter 4 | { 5 | public class LimitingRepetitionVariableLengthExpressionParser 6 | { 7 | public AstNode Parse(IInputIterator inputIterator) 8 | { 9 | string grammar = @" 10 | WhiteSpace: [\s\n\t ]+; 11 | Comment: '/*' (!'*/' .)* '*/'; 12 | (?): (WhiteSpace / Comment)*; 13 | (?): '\k<' S (?[a-zA-Z][a-zA-Z0-9]*) S '>'; 14 | (?): [0-9]+('.'[0-9]+)?; 15 | Value: Variable / Digit / '(' S Expr S ')'; 16 | (?): Value S ((? '*' / '/') S Value)*; 17 | (?): Product S ((?'+' / '-') S Product)*; 18 | (?): S Sum S; 19 | ".Trim(); 20 | 21 | AExpression rules = PEGrammar.Load(grammar); 22 | 23 | var visitor = new NpegParserVisitor(inputIterator); 24 | rules.Accept(visitor); 25 | 26 | if (visitor.IsMatch) 27 | { 28 | return visitor.AST; 29 | } 30 | 31 | throw new InvalidInputException(); 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /Languages/npeg_c/robusthaven.tests/run_memorychecker.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | echo "Building tests...." 4 | make clean all 5 | status=$? 6 | if [ "$status" != "0" ] 7 | then 8 | echo "Build error status code: $status"; 9 | exit $status 10 | fi 11 | 12 | echo 13 | echo 14 | 15 | . ./lib_tests.sh 16 | 17 | 18 | isverbose=0 19 | [ "$1" = "--verbose" ] && isverbose=1 20 | 21 | 22 | echo "Testing Memory CleanUp:" 23 | fn_test_memory "bin/test_hashmap_" $isverbose 24 | fn_test_memory "bin/test_stack_" $isverbose 25 | fn_test_memory "bin/test_stackstack_" $isverbose 26 | fn_test_memory "bin/test_list_" $isverbose 27 | fn_test_memory "bin/test_ast_" $isverbose 28 | fn_test_memory "bin/test_inputiterator_" $isverbose 29 | fn_test_memory "bin/test_terminal_" $isverbose 30 | fn_test_memory "bin/test_nonterminal_" $isverbose 31 | fn_test_memory "ParserTest_NpegNode/program" $isverbose 32 | fn_test_memory "ParserTest_PhoneNumber/program" $isverbose 33 | fn_test_memory "ParserTest_SimpleSentence/program" $isverbose 34 | fn_test_memory "ParserTest_MathematicalFormula/program" $isverbose 35 | fn_test_memory "ParserTest_SimpleXml/program" $isverbose 36 | -------------------------------------------------------------------------------- /Languages/npeg_c++/robusthaven.tests/run_memorychecker.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | echo "Building tests...." 4 | make clean all 5 | status=$? 6 | if [ "$status" != "0" ] 7 | then 8 | echo "Build error status code: $status"; 9 | exit $status 10 | fi 11 | 12 | echo 13 | echo 14 | 15 | . ./lib_tests.sh 16 | 17 | 18 | isverbose=0 19 | [ "$1" = "--verbose" ] && isverbose=1 20 | 21 | 22 | echo "Testing Memory CleanUp:" 23 | fn_test_memory "bin/test_hashmap_" $isverbose 24 | fn_test_memory "bin/test_stack_" $isverbose 25 | fn_test_memory "bin/test_stackstack_" $isverbose 26 | fn_test_memory "bin/test_list_" $isverbose 27 | fn_test_memory "bin/test_ast_" $isverbose 28 | fn_test_memory "bin/test_inputiterator_" $isverbose 29 | fn_test_memory "bin/test_terminal_" $isverbose 30 | fn_test_memory "bin/test_nonterminal_" $isverbose 31 | fn_test_memory "ParserTest_NpegNode/program" $isverbose 32 | fn_test_memory "ParserTest_PhoneNumber/program" $isverbose 33 | fn_test_memory "ParserTest_SimpleSentence/program" $isverbose 34 | fn_test_memory "ParserTest_MathematicalFormula/program" $isverbose 35 | fn_test_memory "ParserTest_SimpleXml/program" $isverbose 36 | -------------------------------------------------------------------------------- /NPEG/GrammarInterpreter/NpegLog.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | 5 | namespace NPEG.GrammarInterpreter 6 | { 7 | public class NpegLog 8 | { 9 | public NpegLog() 10 | { 11 | Children = new List(); 12 | } 13 | 14 | public List Children { get; set; } 15 | public NpegLog Parent { get; set; } 16 | 17 | 18 | public string CommandName 19 | { 20 | get { return Command.GetType().Name; } 21 | } 22 | 23 | public AExpression Command { get; set; } 24 | 25 | public bool IsMatch { get; set; } 26 | 27 | public Int32 InputStart { get; set; } 28 | 29 | public Int32 InputEnd { set; get; } 30 | 31 | public Int32 RuleStart { get; set; } 32 | 33 | public Int32 RuleEnd { set; get; } 34 | 35 | public bool IsTerminal 36 | { 37 | get 38 | { 39 | var terminalsAre = new[] { "Literal", "CodePoint", "AnyCharacter", "CharacterClass", "RecursionCall", "DynamicBackReference" }; 40 | return terminalsAre.Any(x => x.Equals(CommandName, StringComparison.InvariantCultureIgnoreCase)); 41 | } 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /Languages/npeg_c++/robusthaven/text/InputIterator.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "InputIterator.h" 4 | using namespace std; 5 | using namespace RobustHaven::Text; 6 | 7 | int InputIterator::getText(char *buffer, const size_t start, const size_t end) const { 8 | if (start >= end) { 9 | buffer[0] = 0; 10 | 11 | return 0; 12 | } else { 13 | size_t saved_pos, nof_chars, nof_read; 14 | 15 | saved_pos = getIndex(); 16 | 17 | m_stream->seekg(start); 18 | if (m_stream->fail() || m_stream->bad()) { 19 | m_stream->seekg(saved_pos); 20 | buffer[0] = 0; 21 | 22 | return 0; 23 | } 24 | 25 | nof_chars = end - start; 26 | m_stream->read(buffer, nof_chars); 27 | nof_read = m_stream->gcount(); 28 | buffer[nof_read] = 0; 29 | 30 | return (int)nof_read; 31 | } 32 | } 33 | 34 | InputIterator::InputIterator(istream *stream) { 35 | m_stream = stream; 36 | m_stream->seekg(0, ios::end); 37 | m_length = m_stream->tellg(); 38 | m_stream->seekg(0, ios::beg); 39 | } 40 | 41 | void InputIterator::setIndex(size_t index) { 42 | m_stream->clear(); 43 | m_stream->seekg(index); 44 | } 45 | -------------------------------------------------------------------------------- /Languages/npeg_csharp/RobustHaven.Text.Npeg.Tests/Parsers/LimitingRepetitionInfiniteLoopTest.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace RobustHaven.Text.Npeg.Tests.Parsers 4 | { 5 | public class LimitingRepetitionInfiniteLoopTest : NpegParser 6 | { 7 | public LimitingRepetitionInfiniteLoopTest(InputIterator iterator) : base(iterator) 8 | { 9 | } 10 | 11 | public override Boolean IsMatch() 12 | { 13 | return LimitingRepetitionInfiniteLoopTest_impl_0(); 14 | } 15 | 16 | 17 | protected Boolean LimitingRepetitionInfiniteLoopTest_impl_0() 18 | { 19 | String _nodeName_0 = "Expression"; 20 | return CapturingGroup(LimitingRepetitionInfiniteLoopTest_impl_1, _nodeName_0, false, false); 21 | } 22 | 23 | protected Boolean LimitingRepetitionInfiniteLoopTest_impl_1() 24 | { 25 | return LimitingRepetition(LimitingRepetitionInfiniteLoopTest_impl_2, 0, null, ""); 26 | } 27 | 28 | protected Boolean LimitingRepetitionInfiniteLoopTest_impl_2() 29 | { 30 | return ZeroOrMore(LimitingRepetitionInfiniteLoopTest_impl_3, ""); 31 | } 32 | 33 | protected Boolean LimitingRepetitionInfiniteLoopTest_impl_3() 34 | { 35 | return AnyCharacter(); 36 | } 37 | } 38 | } -------------------------------------------------------------------------------- /NPEG.standard2.0.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 17 4 | VisualStudioVersion = 17.2.32505.173 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NPEG", "NPEG\NPEG.standard2.0.csproj", "{EA473461-DCAD-4A57-BDF3-D7537988ACEF}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {EA473461-DCAD-4A57-BDF3-D7537988ACEF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {EA473461-DCAD-4A57-BDF3-D7537988ACEF}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {EA473461-DCAD-4A57-BDF3-D7537988ACEF}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {EA473461-DCAD-4A57-BDF3-D7537988ACEF}.Release|Any CPU.Build.0 = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | GlobalSection(ExtensibilityGlobals) = postSolution 23 | SolutionGuid = {C725FF91-612D-4248-B50E-24A49444F2A4} 24 | EndGlobalSection 25 | EndGlobal 26 | -------------------------------------------------------------------------------- /NPEG/GrammarInterpreter/AstNodes/StatementAstNode.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using NPEG.Extensions; 3 | 4 | namespace NPEG.GrammarInterpreter.AstNodes 5 | { 6 | public class StatementAstNode : IAstNodeReplacement 7 | { 8 | private readonly IInputIterator _inputIterator; 9 | 10 | public StatementAstNode(IInputIterator inputIterator) 11 | { 12 | _inputIterator = inputIterator; 13 | } 14 | 15 | public String Name 16 | { 17 | get 18 | { 19 | if (IsCaptured) 20 | { 21 | return Children[0].Children[0].Children[0].Token.ValueAsString(_inputIterator); 22 | } 23 | 24 | return Children[0].Token.ValueAsString(_inputIterator); 25 | } 26 | } 27 | 28 | public Boolean IsCaptured 29 | { 30 | get 31 | { 32 | if (Children[0].Children[0].Token.Name == "TerminalReference") 33 | { 34 | return true; 35 | } 36 | 37 | // it's a label and will not be captured 38 | return false; 39 | } 40 | } 41 | 42 | public override void VisitEnter(AstNode node) 43 | { 44 | } 45 | 46 | public override void VisitLeave(AstNode node) 47 | { 48 | } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /Languages/npeg_java/robusthaven.test/run_tests.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Format of test app names: test__ 3 | 4 | echo "Building tests...." 5 | make clean all 6 | status=$? 7 | if [ "$status" != "0" ] 8 | then 9 | echo "Build error status code: $status"; 10 | exit $status 11 | fi 12 | 13 | echo 14 | echo 15 | 16 | 17 | . ./lib_tests.sh 18 | 19 | 20 | isverbose=0 21 | [ "$1" = "--verbose" ] && isverbose=1 22 | 23 | echo 24 | echo "Testing AST implementation:" 25 | fn_test_run "Ast*.class" $isverbose 26 | 27 | echo 28 | echo "Testing input iterator implementation:" 29 | fn_test_run "InputIterator*.class" $isverbose 30 | 31 | echo 32 | echo "Testing npeg terminals:" 33 | fn_test_run "*TerminalTest.class" $isverbose 34 | 35 | echo 36 | echo "Testing npeg non-terminals:" 37 | fn_test_run "*NonterminalTest.class" $isverbose 38 | 39 | echo 40 | echo "Testing ParserTest:" 41 | fn_test_run "parser_tests/NpegNodeTest.class" $isverbose 42 | fn_test_run "parser_tests/MathematicalFormulaTest.class" $isverbose 43 | #fn_test_run "ParserTest_PhoneNumber/program" $isverbose 44 | #fn_test_run "ParserTest_MathematicalFormula/program" $isverbose 45 | #fn_test_run "ParserTest_SimpleXml/program" $isverbose 46 | -------------------------------------------------------------------------------- /Languages/npeg_java/robusthaven/robusthaven/text/PrintVisitor.java: -------------------------------------------------------------------------------- 1 | package robusthaven.text; 2 | import java.io.PrintStream; 3 | 4 | public class PrintVisitor implements IAstNodeVisitor { 5 | PrintStream m_sout; 6 | 7 | public void visitEnter(AstNode node) { 8 | if (node.nofChildren() > 0) { 9 | m_sout.println("VisitEnter: " + node.getToken().getName()); 10 | } else { 11 | m_sout.println("VisitEnter: " + node.getToken().getName() 12 | + ": captures " + node.getToken().getStart() + "-" 13 | + node.getToken().getEnd()); 14 | } 15 | } 16 | 17 | public void visitLeave(AstNode node) { 18 | m_sout.println("VisitLeave: " + node.getToken().getName()); 19 | } 20 | 21 | public PrintVisitor(PrintStream sout) { 22 | m_sout = sout; 23 | } 24 | 25 | /* 26 | * Prints a linear representation of the AST through sout. 27 | * Default for sout is std::cout 28 | */ 29 | public static void printAST(AstNode root, PrintStream sout) { 30 | PrintVisitor print = new PrintVisitor(sout); 31 | 32 | sout.println("Start - PrintVisitor"); 33 | root.accept(print); 34 | } 35 | 36 | public static void printAST(AstNode root) { 37 | printAST(root, System.out); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /Languages/npeg_c++/robusthaven/text/AstNode.cpp: -------------------------------------------------------------------------------- 1 | #include "IAstNodeVisitor.h" 2 | #include "AstNode.h" 3 | 4 | using std::vector; 5 | using namespace RobustHaven::Text; 6 | 7 | void AstNode::setParent(AstNode *parent) { 8 | m_parent = parent; 9 | } 10 | 11 | void AstNode::setToken(TokenMatch *token) { 12 | m_token = token; 13 | } 14 | 15 | AstNode::AstNode(const bool deleteToken) : m_deleteToken(deleteToken) { 16 | m_token = NULL; 17 | } 18 | 19 | AstNode::AstNode(TokenMatch *token, const bool deleteToken) : m_deleteToken(deleteToken) { 20 | setToken(token); 21 | } 22 | 23 | AstNode::~AstNode() { 24 | if (m_deleteToken && m_token) { 25 | delete m_token; 26 | } 27 | } 28 | 29 | void AstNode::deleteAST(AstNode *root) { 30 | vector::iterator cit; 31 | 32 | for (cit = root->getChildren().begin(); cit < root->getChildren().end(); cit++) { 33 | deleteAST(*cit); 34 | } 35 | 36 | delete root; 37 | } 38 | 39 | void AstNode::accept(IAstNodeVisitor &visitor) { 40 | vector::iterator cit; 41 | 42 | visitor.visitEnter(*this); 43 | 44 | for (cit = getChildren().begin(); cit < getChildren().end(); cit++) { 45 | (*cit)->accept(visitor); 46 | } 47 | visitor.visitLeave(*this); 48 | } 49 | -------------------------------------------------------------------------------- /Languages/npeg_php/Warn.php: -------------------------------------------------------------------------------- 1 | __call('__construct0', null); 17 | break; 18 | case 2: 19 | $this->__call('__construct2', $args); 20 | break; 21 | default: 22 | throw new Exception(); 23 | } 24 | } 25 | 26 | public function __construct0() 27 | { 28 | $this->message = ""; 29 | } 30 | 31 | public function __construct2($message,$position) 32 | { 33 | $this->message = $message; 34 | $this->position = $position; 35 | } 36 | 37 | public function setMessage( $value ) 38 | { 39 | $this->message = $value; 40 | } 41 | 42 | public function getMessage() 43 | { 44 | return $this->message; 45 | } 46 | 47 | public function setPosition( $value ) 48 | { 49 | $this->position = $value; 50 | } 51 | 52 | public function getPosition() 53 | { 54 | return $this->position; 55 | } 56 | } 57 | 58 | 59 | ?> -------------------------------------------------------------------------------- /Languages/npeg_c++/robusthaven.tests/run_tests.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Format of test app names: test__ 3 | 4 | echo "Building tests...." 5 | make clean all 6 | status=$? 7 | if [ "$status" != "0" ] 8 | then 9 | echo "Build error status code: $status"; 10 | exit $status 11 | fi 12 | 13 | echo 14 | echo 15 | 16 | 17 | . ./lib_tests.sh 18 | 19 | 20 | isverbose=0 21 | [ "$1" = "--verbose" ] && isverbose=1 22 | 23 | echo 24 | echo "Testing hashmap implementation:" 25 | fn_test_run "bin/test_hashmap_" $isverbose 26 | 27 | echo 28 | echo "Testing AST implementation:" 29 | fn_test_run "bin/test_ast_" $isverbose 30 | 31 | echo 32 | echo "Testing input iterator implementation:" 33 | fn_test_run "bin/test_inputiterator_" $isverbose 34 | 35 | echo 36 | echo "Testing npeg terminals:" 37 | fn_test_run "bin/test_terminal_" $isverbose 38 | 39 | echo 40 | echo "Testing npeg non-terminals:" 41 | fn_test_run "bin/test_nonterminal_" $isverbose 42 | 43 | echo 44 | echo "Testing ParserTest:" 45 | fn_test_run "ParserTest_NpegNode/program" $isverbose 46 | fn_test_run "ParserTest_PhoneNumber/program" $isverbose 47 | fn_test_run "ParserTest_MathematicalFormula/program" $isverbose 48 | fn_test_run "ParserTest_SimpleXml/program" $isverbose 49 | 50 | -------------------------------------------------------------------------------- /Languages/npeg_php/AstNode.php: -------------------------------------------------------------------------------- 1 | children = array(); 13 | } 14 | 15 | public function setParent( $value ) 16 | { 17 | $this->parent = $value; 18 | } 19 | 20 | public function getParent() 21 | { 22 | return $this->parent; 23 | } 24 | 25 | public function setChildren( $value ) 26 | { 27 | $this->children = $value; 28 | } 29 | 30 | public function getChildren() 31 | { 32 | return $this->children; 33 | } 34 | 35 | public function setToken( $value ) 36 | { 37 | $this->token = $value; 38 | } 39 | 40 | public function getToken() 41 | { 42 | return $this->token; 43 | } 44 | 45 | public function Accept( $visitor) 46 | { 47 | $visitor->VisitEnter($this); 48 | $isFirstTime = true; 49 | foreach ($this->Children as $node) 50 | { 51 | if (!$isFirstTime) 52 | { 53 | $visitor->VisitExecute($this); 54 | } 55 | $isFirstTime = false; 56 | $node->Accept($visitor); 57 | } 58 | $visitor->VisitLeave($this); 59 | } 60 | } 61 | ?> 62 | -------------------------------------------------------------------------------- /Languages/npeg_csharp/RobustHaven.Text.Npeg.Tests/InfiniteLoopDetectedTests.cs: -------------------------------------------------------------------------------- 1 | using System.Text; 2 | using NUnit.Framework; 3 | using RobustHaven.Text.Npeg.Tests.Parsers; 4 | 5 | namespace RobustHaven.Text.Npeg.Tests 6 | { 7 | [TestFixture] 8 | public class InfiniteLoopDetectedTests 9 | { 10 | [Test] 11 | [Timeout(2000)] 12 | [ExpectedException(typeof (InfiniteLoopDetectedException))] 13 | public void LimitingRepetition() 14 | { 15 | var parser = new LimitingRepetitionInfiniteLoopTest( 16 | new StringInputIterator( 17 | Encoding.ASCII.GetBytes("")) 18 | ); 19 | parser.IsMatch(); 20 | } 21 | 22 | [Test] 23 | [Timeout(2000)] 24 | [ExpectedException(typeof (InfiniteLoopDetectedException))] 25 | public void OneOrMore() 26 | { 27 | var parser = new OneOrMoreInfiniteLoopTest( 28 | new StringInputIterator( 29 | Encoding.ASCII.GetBytes("")) 30 | ); 31 | parser.IsMatch(); 32 | } 33 | 34 | [Test] 35 | [Timeout(2000)] 36 | [ExpectedException(typeof (InfiniteLoopDetectedException))] 37 | public void ZeroOrMore() 38 | { 39 | var parser = new ZeroOrMoreInfiniteLoopTest( 40 | new StringInputIterator( 41 | Encoding.ASCII.GetBytes("")) 42 | ); 43 | parser.IsMatch(); 44 | } 45 | } 46 | } -------------------------------------------------------------------------------- /Languages/npeg_c/robusthaven.tests/test_inputiterator_empty.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include "robusthaven/text/npeg_inputiterator.h" 6 | 7 | 8 | /* 9 | * Unit test for the empty string limit case. 10 | */ 11 | int main(int argc, char *argv[]) { 12 | npeg_inputiterator iter; 13 | int i; 14 | 15 | srand(time(NULL)); 16 | npeg_inputiterator_constructor(&iter, NULL, 0); 17 | 18 | for (i = 0; i < 10; i++) { 19 | int start, end; 20 | char buffer[101] = { 1, 1, 1 }; 21 | 22 | start = rand()%100, end = rand()%100; 23 | 24 | assert(npeg_inputiterator_get_text(buffer, &iter, start, end) == 0); 25 | printf("\tVerified: iterator with empty string is handled correctly.\n"); 26 | 27 | assert(buffer[0] == 0 && buffer[1] == 1 && buffer[2] == 1); 28 | printf("\tVerified: no modification of destination buffer apart from first byte.\n"); 29 | } 30 | printf("\tReached: get_text works.\n"); 31 | 32 | assert(npeg_inputiterator_get_current(&iter) == -1); 33 | assert(npeg_inputiterator_get_next(&iter) == -1); 34 | assert(npeg_inputiterator_get_previous(&iter) == -1); 35 | 36 | npeg_inputiterator_destructor(&iter); 37 | 38 | return 0; 39 | } /* main */ 40 | -------------------------------------------------------------------------------- /Languages/npeg_javascript/AstNode.js: -------------------------------------------------------------------------------- 1 | 2 | if(!RobustHaven) var RobustHaven={}; 3 | if(!RobustHaven.Text) RobustHaven.Text={}; 4 | if(!RobustHaven.Text.Npeg) RobustHaven.Text.Npeg={}; 5 | 6 | RobustHaven.Text.Npeg.AstNode = function (token) { 7 | var token = token, 8 | children = [], 9 | parent; 10 | 11 | this.children = new Array(); 12 | 13 | this.getParent = function (){ return parent; }; 14 | this.setParent = function ( value ) { parent = value; }; 15 | 16 | this.getChildren = function () { return children; }; 17 | this.addChild = function(child) { 18 | children[children.length] = child; 19 | } 20 | 21 | this.getToken = function () { return token; }; 22 | this.setToken = function ( value ) { token = value; }; 23 | 24 | this.accept = function (visitor) { 25 | visitor.visitEnter(this); 26 | 27 | var isFirstTime = true; 28 | for (var i = 0; i < children; i++) { 29 | var node = children[i]; 30 | 31 | if (!isFirstTime) { 32 | visitor.visitExecute(this); 33 | } 34 | 35 | isFirstTime = false; 36 | node.accept(visitor); 37 | } 38 | 39 | visitor.visitLeave(this); 40 | }; 41 | } 42 | 43 | -------------------------------------------------------------------------------- /Languages/npeg_c++/robusthaven/text/PrintVisitor.h: -------------------------------------------------------------------------------- 1 | #ifndef ROBUSTHAVEN_TEXT_PRINTVISITOR_H 2 | #define ROBUSTHAVEN_TEXT_PRINTVISITOR_H 3 | #include 4 | #include "IAstNodeVisitor.h" 5 | #include "Npeg.h" 6 | 7 | namespace RobustHaven { 8 | namespace Text { 9 | class PrintVisitor : public IAstNodeVisitor { 10 | private: 11 | std::ostream &m_sout; 12 | 13 | public: 14 | void visitEnter(AstNode &node) { 15 | m_sout << "VisitEnter: " << node.getToken()->getName(); 16 | if (node.getChildren().size() > 0) m_sout << std::endl; 17 | else { 18 | m_sout << ": captures " << node.getToken()->getStart() << "-" 19 | << node.getToken()->getEnd() << std::endl; 20 | } 21 | } 22 | 23 | void visitLeave(AstNode &node) { 24 | m_sout << "VisitLeave: " << node.getToken()->getName() << std::endl; 25 | } 26 | 27 | public: 28 | PrintVisitor(std::ostream &sout) : m_sout(sout) {} 29 | 30 | public: 31 | /* 32 | * Prints a linear representation of the AST through sout. 33 | * Default for sout is std::cout 34 | */ 35 | static void printAST(AstNode &root, std::ostream &sout = std::cout) { 36 | PrintVisitor print(sout); 37 | 38 | std::cout << "Start - PrintVisitor\n"; 39 | root.accept(print); 40 | } 41 | }; 42 | } 43 | } 44 | #endif 45 | -------------------------------------------------------------------------------- /NPEG/NonTerminals/LimitingRepetition.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Runtime.Serialization; 4 | 5 | namespace NPEG.NonTerminals 6 | { 7 | //e{min,max} // Match input at least min times but not more than max times against e. 8 | //e{,max} // Match input at zero or more times but not more than max times against e. 9 | //e{min,} // Match input at least min times against e. (no limit on max) 10 | //e{exactcount} // Match input a total of exactcount agaist e. 11 | //e{(\k - \k)+1} // math expression to support variable length protocols using backreferencing 12 | [DataContract] 13 | public class LimitingRepetition : AComposite 14 | { 15 | private readonly AExpression Exp; 16 | 17 | public LimitingRepetition(AExpression exp) 18 | { 19 | Exp = exp; 20 | Min = null; 21 | Max = null; 22 | VariableLengthExpression = null; 23 | } 24 | 25 | [DataMember] 26 | public Int32? Min { get; set; } 27 | 28 | [DataMember] 29 | public Int32? Max { get; set; } 30 | 31 | public string VariableLengthExpression { get; set; } 32 | 33 | [DataMember] 34 | public override List Children 35 | { 36 | get { return new List { Exp }; } 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /Languages/npeg_c++/robusthaven.tests/test_terminal_npeg_Fatal.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include "robusthaven/text/StringInputIterator.h" 7 | #include "robusthaven/text/Npeg.h" 8 | 9 | using namespace RobustHaven::Text; 10 | using namespace std; 11 | 12 | const char g_errorStr[] = "some error"; 13 | 14 | class _FatalTest : public Npeg { 15 | public: 16 | int isMatch(void) throw (ParsingFatalTerminalException) { 17 | return fatal(g_errorStr); 18 | } 19 | 20 | public: 21 | _FatalTest(InputIterator *p_iter) : Npeg(p_iter) {} 22 | }; 23 | 24 | 25 | int main(int argc, char *argv[]) 26 | { 27 | const char* string = "A Fatal Exception Message"; 28 | 29 | StringInputIterator *p_iterator; 30 | Npeg *p_context; 31 | bool errorSeen; 32 | 33 | p_iterator = new StringInputIterator(string, 0); 34 | p_context = new _FatalTest(p_iterator); 35 | errorSeen = false; 36 | try { 37 | p_context->isMatch(); 38 | } catch (ParsingFatalTerminalException e) { 39 | errorSeen = true; 40 | assert(e.what() == std::string(g_errorStr)); 41 | cout << "\tVerified: error string matches input\n"; 42 | } 43 | assert(errorSeen); 44 | printf("\tVerified: fatal works.\n"); 45 | 46 | delete p_iterator; 47 | delete p_context; 48 | 49 | return 0; 50 | } 51 | -------------------------------------------------------------------------------- /Languages/npeg_c++/robusthaven.tests/test_inputiterator_std_lookups.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #include "robusthaven/text/StringInputIterator.h" 9 | 10 | using namespace std; 11 | using namespace RobustHaven::Text; 12 | 13 | /* 14 | * Unit test for the look ahead/behind & previous, next & current routines 15 | */ 16 | int main(int argc, char *argv[]) { 17 | const uint strlen = 12; 18 | 19 | char string[strlen+1]; 20 | InputIterator *p_iter; 21 | uint i; 22 | 23 | srand(time(NULL)); 24 | 25 | for (i = 0; i < strlen; i++) { 26 | if (rand()%10 < 2) string[i] = 0; 27 | else string[i] = rand()%('z' - 'a') + 'a'; 28 | } 29 | p_iter = new StringInputIterator(string, strlen); 30 | assert(p_iter->getLength() == strlen); 31 | 32 | assert(p_iter->getIndex() == 0); 33 | assert(p_iter->getCurrent() == string[0] && p_iter->getIndex() == 0); 34 | assert(p_iter->getNext() == string[1] && p_iter->getIndex() == 1); 35 | cout <<"\tVerified: start of string OK.\n"; 36 | 37 | for (i = 1; i < strlen - 1; i++) { 38 | assert(p_iter->getNext() == string[i+1]); 39 | } 40 | assert(p_iter->getNext() == -1 && p_iter->getIndex() == strlen); 41 | cout <<"\tVerified: next works.\n"; 42 | 43 | delete p_iter; 44 | 45 | return 0; 46 | } /* main */ 47 | -------------------------------------------------------------------------------- /Languages/npeg_java/robusthaven.test/Makefile: -------------------------------------------------------------------------------- 1 | JUNIT_PATH=/usr/share/java 2 | TESTS=InputIteratorEmptyTest.class InputIteratorGetTextTest.class InputIteratorStdLookupsTest.class\ 3 | AstTreeBuildingTest.class AnyCharacterTerminalTest.class \ 4 | CharacterClassTerminalTest.class CodePointTerminalTest.class FatalTerminalTest.class\ 5 | LiteralTerminalTest.class WarnTerminalTest.class AndPredicateNonterminalTest.class\ 6 | CapturingGroupNonterminalTest.class LimitingRepetitionNonterminalTest.class \ 7 | OneOrMoreNonterminalTest.class OptionalNonterminalTest.class \ 8 | PrioritizedChoiceNonterminalTest.class SequenceNonterminalTest.class \ 9 | ZeroOrMoreNonterminalTest.class 10 | 11 | all: ${TESTS} testparsers.jar ${PARSERTESTS} parser_tests.jar 12 | 13 | %.class: %.java ../robusthaven.jar 14 | javac -cp ../robusthaven.jar:${JUNIT_PATH}/junit.jar *.java 15 | 16 | parser_tests.jar: parser_tests/*.java testparsers.jar 17 | javac -cp testparsers.jar:../robusthaven.jar:.:${JUNIT_PATH}/junit.jar parser_tests/*.java 18 | jar cvf $@ parser_tests/*.class 19 | 20 | testparsers.jar: robusthaven/text/npeg/tests/parsers/*.java ../robusthaven.jar 21 | javac -cp ../robusthaven.jar:${JUNIT_PATH}/junit.jar:robusthaven/text/npeg/tests/parsers/ $< 22 | jar cvf $@ robusthaven/text/npeg/tests/parsers/*.class 23 | 24 | clean: 25 | rm -f ${TESTS} parser_tests/*.class testparsers.jar parser_tests.jar robusthaven/text/npeg/tests/parsers/*.class -------------------------------------------------------------------------------- /Languages/npeg_csharp/RobustHaven.Text.Npeg.Tests/ParserTests.cs: -------------------------------------------------------------------------------- 1 | using System.Text; 2 | using NUnit.Framework; 3 | using RobustHaven.Text.Npeg.Tests.Parsers; 4 | 5 | namespace RobustHaven.Text.Npeg.Tests 6 | { 7 | [TestFixture] 8 | public class ParserTests 9 | { 10 | [Test] 11 | public void MathematicalFormulaTest() 12 | { 13 | var parser = new MathematicalFormula( 14 | new StringInputIterator( 15 | Encoding.ASCII.GetBytes( 16 | "((((12/3)+5-2*(81/9))+1))" 17 | ) 18 | ) 19 | ); 20 | Assert.IsTrue(parser.IsMatch()); 21 | } 22 | 23 | 24 | [Test] 25 | public void NpegNodeTest() 26 | { 27 | var parser = new NpegNode( 28 | new StringInputIterator( 29 | Encoding.ASCII.GetBytes( 30 | "NpEg" 31 | ) 32 | ) 33 | ); 34 | Assert.IsTrue(parser.IsMatch()); 35 | } 36 | 37 | [Test] 38 | public void PhoneNumberTest() 39 | { 40 | var parser = new PhoneNumber( 41 | new StringInputIterator( 42 | Encoding.ASCII.GetBytes( 43 | "123-456-7890" 44 | ) 45 | ) 46 | ); 47 | Assert.IsTrue(parser.IsMatch()); 48 | } 49 | 50 | [Test] 51 | public void SimpleXmlTest() 52 | { 53 | var xmlparser = new SimpleXml( 54 | new StringInputIterator( 55 | Encoding.ASCII.GetBytes( 56 | "

hello

hello

" 57 | ) 58 | ) 59 | ); 60 | Assert.IsTrue(xmlparser.IsMatch()); 61 | } 62 | } 63 | } -------------------------------------------------------------------------------- /Languages/npeg_csharp/RobustHaven.Text.Npeg/FileInputIterator.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Diagnostics; 3 | using System.IO; 4 | 5 | namespace RobustHaven.Text.Npeg 6 | { 7 | public class FileInputIterator : InputIterator 8 | { 9 | private readonly Stream input; 10 | 11 | public FileInputIterator(Stream input) 12 | : base((Int32) input.Length) 13 | { 14 | this.input = input; 15 | } 16 | 17 | public override byte[] Text(int start, int end) 18 | { 19 | var buffer = new byte[end - start]; 20 | input.Read(buffer, start, end - start); 21 | return buffer; 22 | } 23 | 24 | public override short Current() 25 | { 26 | if (Index >= Length) return -1; 27 | else 28 | { 29 | return GetByte(Index); 30 | } 31 | } 32 | 33 | public override short Next() 34 | { 35 | if (Index >= Length) return -1; 36 | else 37 | { 38 | Index += 1; 39 | 40 | if (Index >= Length) return -1; 41 | else return GetByte(Index); 42 | ; 43 | } 44 | } 45 | 46 | public override short Previous() 47 | { 48 | if (Index <= 0) 49 | { 50 | return -1; 51 | } 52 | else 53 | { 54 | Debug.Assert(Length > 0); 55 | 56 | Index -= 1; 57 | 58 | return GetByte(Index); 59 | ; 60 | } 61 | } 62 | 63 | 64 | private short GetByte(Int32 index) 65 | { 66 | var b = new Byte[1]; 67 | input.Read(b, Index, 1); 68 | return b[0]; 69 | } 70 | } 71 | } -------------------------------------------------------------------------------- /Languages/npeg_php/StringInputIterator.php: -------------------------------------------------------------------------------- 1 | input = $input; 12 | } 13 | public abstract function Text($start, $end); 14 | 15 | public function Text($start, $end) 16 | { 17 | $n = $end - $start; 18 | $bytes = array(); 19 | for($i = 0; $i < $n; $i++) 20 | { 21 | $bytes[$i] = $this->input[$start+$i]; 22 | } 23 | return $bytes; 24 | } 25 | 26 | public function Current() 27 | { 28 | if ($this->index >= $this->length) return -1; 29 | else 30 | { 31 | return $this->input[$this->index]; 32 | } 33 | } 34 | 35 | public function Next() 36 | { 37 | if ($this->index >= $this->length) return -1; 38 | else 39 | { 40 | $this->index += 1; 41 | if ($this->index >= $this->length) return -1; 42 | else return $this->input[$this->index]; 43 | } 44 | } 45 | 46 | public function Previous() 47 | { 48 | if ($this->index <= 0) 49 | { 50 | return -1; 51 | } 52 | else 53 | { 54 | if($this->Length == 0)throw new Exception(); 55 | $this->index -= 1; 56 | return $this->input[$this->index]; 57 | } 58 | } 59 | } 60 | 61 | ?> -------------------------------------------------------------------------------- /Languages/npeg_csharp/RobustHaven.Text.Npeg/StringInputIterator.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Diagnostics; 3 | using System.Text; 4 | 5 | namespace RobustHaven.Text.Npeg 6 | { 7 | public class StringInputIterator : InputIterator 8 | { 9 | private readonly Byte[] input; 10 | 11 | public StringInputIterator(Byte[] input) 12 | : base(input.Length) 13 | { 14 | this.input = input; 15 | } 16 | 17 | public StringInputIterator(String us_ascii) 18 | : base(Encoding.ASCII.GetBytes(us_ascii).Length) 19 | { 20 | input = Encoding.ASCII.GetBytes(us_ascii); 21 | Index = 0; 22 | } 23 | 24 | 25 | public override byte[] Text(int start, int end) 26 | { 27 | var bytes = new byte[end - start]; 28 | Array.Copy(input, start, bytes, 0, end - start); 29 | return bytes; 30 | } 31 | 32 | 33 | public override short Current() 34 | { 35 | if (Index >= Length) return -1; 36 | else 37 | { 38 | return input[Index]; 39 | } 40 | } 41 | 42 | public override short Next() 43 | { 44 | if (Index >= Length) return -1; 45 | else 46 | { 47 | Index += 1; 48 | 49 | if (Index >= Length) return -1; 50 | else return input[Index]; 51 | } 52 | } 53 | 54 | public override short Previous() 55 | { 56 | if (Index <= 0) 57 | { 58 | return -1; 59 | } 60 | else 61 | { 62 | Debug.Assert(Length > 0); 63 | 64 | Index -= 1; 65 | 66 | return input[Index]; 67 | } 68 | } 69 | } 70 | } -------------------------------------------------------------------------------- /NPEG/AstNode.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Diagnostics; 3 | using System.Linq; 4 | using System.Runtime.Serialization; 5 | 6 | namespace NPEG 7 | { 8 | [DataContract] 9 | [DebuggerDisplay("AstNode: {(Token == null)? string.Empty:Token.Name}, Children {Children.Count}")] 10 | public class AstNode 11 | { 12 | public AstNode() 13 | { 14 | Children = new AstNodeCollection(); 15 | } 16 | 17 | // removed datamember else wcf service recursively tries to serialize. 18 | // eventually crashing the service. 19 | public AstNode Parent { get; set; } 20 | 21 | [DataMember] 22 | public AstNodeCollection Children { get; set; } 23 | 24 | [DataMember] 25 | public TokenMatch Token { get; set; } 26 | 27 | 28 | public void Accept(IAstNodeReplacement visitor) 29 | { 30 | visitor.VisitEnter(this); 31 | 32 | foreach (AstNode node in Children) 33 | { 34 | node.Accept(visitor); 35 | } 36 | 37 | visitor.VisitLeave(this); 38 | } 39 | } 40 | 41 | public class AstNodeCollection : List 42 | { 43 | public AstNode this[string key] 44 | { 45 | get 46 | { 47 | return this.First(x => x.Token.Name.Equals(key)); 48 | } 49 | set 50 | { 51 | var node = this.First(x => x.Token.Name.Equals(key)); 52 | node.Token = value.Token; 53 | node.Children = value.Children; 54 | } 55 | } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /Languages/npeg_c/robusthaven.tests/test_inthashmap_insert_lookup.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include "robusthaven/structures/inthashmap.h" 6 | 7 | /* 8 | * Creates a hashmap and inserts elements which all have to be found afterwards. 9 | * The hashmap capacity is intentionally chosen too low, in order to force storage in linked lists. 10 | */ 11 | int main(int argc, char *argv[]) { 12 | #define start_cap 71 13 | #define nof_items 2*start_cap 14 | 15 | char state[200]; 16 | int keys[nof_items]; 17 | void *dataptrs[nof_items]; 18 | rh_inthashmap_instance hashmap; 19 | uint i; 20 | 21 | initstate(time(NULL), state, 200); 22 | 23 | printf("\tReached: start hashmap insertion\n"); 24 | 25 | rh_inthashmap_constructor(&hashmap, start_cap); 26 | for (i = 0; i < nof_items; i++) { 27 | keys[i] = (int)random(); 28 | dataptrs[i] = (void*)(unsigned long)random(); 29 | 30 | rh_inthashmap_insert(&hashmap, dataptrs[i], keys[i]); 31 | } /* for items to generate & insert */ 32 | 33 | printf("\tReached: start hashmap lookup\n"); 34 | for (i = 0; i < nof_items; i++) { 35 | void *testptr; 36 | 37 | testptr = rh_inthashmap_lookup(&hashmap, keys[i]); 38 | assert(dataptrs[i] == testptr); 39 | printf("\tVerified: lookup of item %d.\n", keys[i]); 40 | } /* for items to look up */ 41 | 42 | rh_inthashmap_destructor(&hashmap); 43 | 44 | return 0; 45 | } /* main */ 46 | -------------------------------------------------------------------------------- /Languages/npeg_c++/robusthaven.tests/ParserTest_PhoneNumber/PhoneNumber.h: -------------------------------------------------------------------------------- 1 | #ifndef ROBUSTHAVEN_GENERATEDPARSER_PHONENUMBER 2 | #define ROBUSTHAVEN_GENERATEDPARSER_PHONENUMBER 3 | 4 | #include "robusthaven/text/InputIterator.h" 5 | #include "robusthaven/text/Npeg.h" 6 | 7 | using namespace RobustHaven::Text; 8 | 9 | class PhoneNumber : public Npeg 10 | { 11 | public: 12 | PhoneNumber(InputIterator* inputstream): Npeg(inputstream){} 13 | 14 | virtual int isMatch() throw (ParsingFatalTerminalException) 15 | { return PhoneNumber_impl_0(); } 16 | 17 | 18 | private: 19 | int PhoneNumber_impl_0(); 20 | int PhoneNumber_impl_1(); 21 | int PhoneNumber_impl_19(); 22 | int PhoneNumber_impl_20(); 23 | int PhoneNumber_impl_26(); 24 | int PhoneNumber_impl_21(); 25 | int PhoneNumber_impl_25(); 26 | int PhoneNumber_impl_22(); 27 | int PhoneNumber_impl_24(); 28 | int PhoneNumber_impl_23(); 29 | int PhoneNumber_impl_2(); 30 | int PhoneNumber_impl_18(); 31 | int PhoneNumber_impl_3(); 32 | int PhoneNumber_impl_12(); 33 | int PhoneNumber_impl_13(); 34 | int PhoneNumber_impl_17(); 35 | int PhoneNumber_impl_14(); 36 | int PhoneNumber_impl_16(); 37 | int PhoneNumber_impl_15(); 38 | int PhoneNumber_impl_4(); 39 | int PhoneNumber_impl_11(); 40 | int PhoneNumber_impl_5(); 41 | int PhoneNumber_impl_6(); 42 | int PhoneNumber_impl_10(); 43 | int PhoneNumber_impl_7(); 44 | int PhoneNumber_impl_9(); 45 | int PhoneNumber_impl_8(); 46 | }; 47 | 48 | #endif 49 | -------------------------------------------------------------------------------- /Languages/npeg_c++/robusthaven.tests/ParserTest_SimpleXml/SimpleXml.h: -------------------------------------------------------------------------------- 1 | #ifndef ROBUSTHAVEN_GENERATEDPARSER_SIMPLEXML 2 | #define ROBUSTHAVEN_GENERATEDPARSER_SIMPLEXML 3 | 4 | #include "robusthaven/text/InputIterator.h" 5 | #include "robusthaven/text/Npeg.h" 6 | 7 | using namespace RobustHaven::Text; 8 | 9 | class SimpleXml : public Npeg 10 | { 11 | public: 12 | SimpleXml(InputIterator* inputstream): Npeg(inputstream){} 13 | 14 | virtual int isMatch() throw (ParsingFatalTerminalException) 15 | { return SimpleXml_impl_0(); } 16 | 17 | 18 | private: 19 | int SimpleXml_impl_0(); 20 | int SimpleXml_impl_1(); 21 | int SimpleXml_impl_2(); 22 | int SimpleXml_impl_23(); 23 | int SimpleXml_impl_24(); 24 | int SimpleXml_impl_28(); 25 | int SimpleXml_impl_25(); 26 | int SimpleXml_impl_27(); 27 | int SimpleXml_impl_26(); 28 | int SimpleXml_impl_3(); 29 | int SimpleXml_impl_12(); 30 | int SimpleXml_impl_13(); 31 | int SimpleXml_impl_14(); 32 | int SimpleXml_impl_22(); 33 | int SimpleXml_impl_15(); 34 | int SimpleXml_impl_16(); 35 | int SimpleXml_impl_17(); 36 | int SimpleXml_impl_21(); 37 | int SimpleXml_impl_18(); 38 | int SimpleXml_impl_20(); 39 | int SimpleXml_impl_19(); 40 | int SimpleXml_impl_4(); 41 | int SimpleXml_impl_5(); 42 | int SimpleXml_impl_11(); 43 | int SimpleXml_impl_6(); 44 | int SimpleXml_impl_8(); 45 | int SimpleXml_impl_9(); 46 | int SimpleXml_impl_10(); 47 | int SimpleXml_impl_7(); 48 | }; 49 | 50 | #endif 51 | -------------------------------------------------------------------------------- /LanguageWorkbench/UIHelper.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Net; 3 | using System.Windows; 4 | using System.Windows.Controls; 5 | using System.Windows.Documents; 6 | using System.Windows.Ink; 7 | using System.Windows.Input; 8 | using System.Windows.Media; 9 | using System.Windows.Media.Animation; 10 | using System.Windows.Shapes; 11 | 12 | namespace LanguageWorkbench 13 | { 14 | public static class UIHelper 15 | { 16 | public static void SetTimeout(int milliseconds, Action func) 17 | { 18 | var timer = new DispatcherTimerContainingAction 19 | { 20 | Interval = new TimeSpan(0, 0, 0, 0, milliseconds), 21 | Action = func 22 | }; 23 | timer.Tick += _onTimeout; 24 | timer.Start(); 25 | } 26 | 27 | private static void _onTimeout(object sender, EventArgs arg) 28 | { 29 | var t = sender as DispatcherTimerContainingAction; 30 | t.Stop(); 31 | t.Action(); 32 | t.Tick -= _onTimeout; 33 | } 34 | } 35 | 36 | public class DispatcherTimerContainingAction : System.Windows.Threading.DispatcherTimer 37 | { 38 | /// 39 | /// uncomment this to see when the DispatcherTimerContainingAction is collected 40 | /// if you remove t.Tick -= _onTimeout; line from _onTimeout method 41 | /// you will see that the timer is never collected 42 | /// 43 | //~DispatcherTimerContainingAction() 44 | //{ 45 | // throw new Exception("DispatcherTimerContainingAction is disposed"); 46 | //} 47 | 48 | public Action Action { get; set; } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /LanguageWorkbench/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.InteropServices; 3 | 4 | // General Information about an assembly is controlled through the following 5 | // set of attributes. Change these attribute values to modify the information 6 | // associated with an assembly. 7 | 8 | [assembly: AssemblyTitle("LanguageWorkbench")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("LanguageWorkbench")] 13 | [assembly: AssemblyCopyright("Copyright © 2012")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | 21 | [assembly: ComVisible(false)] 22 | 23 | // The following GUID is for the ID of the typelib if this project is exposed to COM 24 | 25 | [assembly: Guid("68903235-d581-4608-9973-5f8633e19f57")] 26 | 27 | // Version information for an assembly consists of the following four values: 28 | // 29 | // Major Version 30 | // Minor Version 31 | // Build Number 32 | // Revision 33 | // 34 | // You can specify all the values or you can default the Revision and Build Numbers 35 | // by using the '*' as shown below: 36 | 37 | [assembly: AssemblyVersion("1.0.0.0")] 38 | [assembly: AssemblyFileVersion("1.0.0.0")] -------------------------------------------------------------------------------- /Languages/npeg_c++/robusthaven.tests/test_terminal_npeg_Warn.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "robusthaven/text/StringInputIterator.h" 5 | #include "robusthaven/text/Npeg.h" 6 | 7 | using namespace RobustHaven::Text; 8 | 9 | const char* g_string = "A user warning message."; 10 | 11 | class _WarnTest : public Npeg { 12 | public: 13 | int isMatch(void) throw (ParsingFatalTerminalException) { 14 | return warn(g_string); 15 | } 16 | 17 | public: 18 | _WarnTest(InputIterator *p_iter) : Npeg(p_iter) {} 19 | 20 | virtual ~_WarnTest() {} 21 | }; 22 | 23 | int main(int argc, char *argv[]) 24 | { 25 | StringInputIterator *p_iterator; 26 | Npeg *p_context; 27 | 28 | p_iterator = new StringInputIterator(g_string, 0); 29 | p_context = new _WarnTest(p_iterator); 30 | 31 | assert( 0 == p_context->getWarnings().size() ); 32 | printf("\tVerified: context warnings is zero at start.\n"); 33 | 34 | assert( 1 == p_context->isMatch() ); 35 | printf("\tVerified: npeg_Warn will always return true.\n"); 36 | 37 | assert( 1 == p_context->getWarnings().size()); 38 | printf("\tVerified: npeg_Warn will add an warning to context warnings collection.\n"); 39 | 40 | assert((*(p_context->getWarnings().end() - 1)).getMessage() == "A user warning message."); 41 | printf("\tVerified: that the original warn message was copied in full to the new allocated npeg managed memory.\n"); 42 | 43 | delete p_iterator; delete p_context; 44 | 45 | 46 | return 0; 47 | } 48 | -------------------------------------------------------------------------------- /Languages/npeg_java/robusthaven.test/FatalTerminalTest.java: -------------------------------------------------------------------------------- 1 | import robusthaven.text.*; 2 | import java.util.*; 3 | import java.io.*; 4 | import junit.framework.Assert; 5 | import junit.framework.TestCase; 6 | 7 | public class FatalTerminalTest extends TestCase { 8 | public static final String g_errorStr = "some error"; 9 | 10 | class FatalTest extends Npeg { 11 | public boolean isMatch() throws ParsingFatalTerminalException, IOException { 12 | return fatal(g_errorStr); 13 | } 14 | 15 | public FatalTest(InputIterator iter) { 16 | super(iter, null); 17 | } 18 | } 19 | 20 | public void testFatal() { 21 | byte[] str = new byte[1]; 22 | 23 | StringInputIterator iterator; 24 | Npeg context; 25 | boolean errorSeen; 26 | 27 | errorSeen = false; 28 | try { 29 | iterator = new StringInputIterator(str, 0); 30 | context = new FatalTest(iterator); 31 | 32 | context.isMatch(); 33 | } catch (ParsingFatalTerminalException e) { 34 | errorSeen = true; 35 | assert(e.getMessage().compareTo(g_errorStr) == 0); 36 | System.out.println("\tVerified: error string matches input"); 37 | } catch (Exception e) { 38 | e.printStackTrace(); 39 | fail("unexpected error"); 40 | } 41 | 42 | assert(errorSeen); 43 | System.out.println("\tVerified: fatal works."); 44 | } 45 | 46 | public FatalTerminalTest() { 47 | super(); 48 | } 49 | 50 | public static void main(String[] argv) { 51 | junit.textui.TestRunner.run(FatalTerminalTest.class); 52 | System.exit(0); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /LanguageWorkbench.Web/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("LanguageWorkbench.Web")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("LanguageWorkbench.Web")] 13 | [assembly: AssemblyCopyright("Copyright © 2012")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("58e2b3fe-bd3c-4cf1-a28f-dfc0fa9e0f28")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Revision and Build Numbers 33 | // by using the '*' as shown below: 34 | [assembly: AssemblyVersion("1.0.0.0")] 35 | [assembly: AssemblyFileVersion("1.0.0.0")] 36 | -------------------------------------------------------------------------------- /Languages/npeg_javascript/tools/Yahoo.Yui.Compressor v2.0.0.0/New BSD License.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) 2008 - 2011, Pure Krome 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 5 | 6 | * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 7 | 8 | * 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. 9 | 10 | * Neither the name of World Domination Technologies nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. 11 | 12 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -------------------------------------------------------------------------------- /Languages/npeg_csharp/RobustHaven.Text.Npeg/RobustHaven.Text.Npeg.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 11.00 3 | # Visual Studio 2010 4 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RobustHaven.Text.Npeg", "RobustHaven.Text.Npeg.csproj", "{15E40233-601A-4B21-8176-201E4A0ADCFD}" 5 | EndProject 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RobustHaven.Text.Npeg.Tests", "..\RobustHaven.Text.Npeg.Tests\RobustHaven.Text.Npeg.Tests.csproj", "{B762DB2E-74F2-4CC3-AD63-565AC72B055D}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {15E40233-601A-4B21-8176-201E4A0ADCFD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {15E40233-601A-4B21-8176-201E4A0ADCFD}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {15E40233-601A-4B21-8176-201E4A0ADCFD}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {15E40233-601A-4B21-8176-201E4A0ADCFD}.Release|Any CPU.Build.0 = Release|Any CPU 18 | {B762DB2E-74F2-4CC3-AD63-565AC72B055D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 19 | {B762DB2E-74F2-4CC3-AD63-565AC72B055D}.Debug|Any CPU.Build.0 = Debug|Any CPU 20 | {B762DB2E-74F2-4CC3-AD63-565AC72B055D}.Release|Any CPU.ActiveCfg = Release|Any CPU 21 | {B762DB2E-74F2-4CC3-AD63-565AC72B055D}.Release|Any CPU.Build.0 = Release|Any CPU 22 | EndGlobalSection 23 | GlobalSection(SolutionProperties) = preSolution 24 | HideSolutionNode = FALSE 25 | EndGlobalSection 26 | EndGlobal 27 | -------------------------------------------------------------------------------- /Languages/npeg_csharp/RobustHaven.Text.Npeg/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.InteropServices; 3 | 4 | // General Information about an assembly is controlled through the following 5 | // set of attributes. Change these attribute values to modify the information 6 | // associated with an assembly. 7 | 8 | [assembly: AssemblyTitle("RobustHaven.Text")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("Microsoft")] 12 | [assembly: AssemblyProduct("RobustHaven.Text")] 13 | [assembly: AssemblyCopyright("Copyright © Microsoft 2009")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | 21 | [assembly: ComVisible(false)] 22 | 23 | // The following GUID is for the ID of the typelib if this project is exposed to COM 24 | 25 | [assembly: Guid("0bc64c3a-8a58-4b10-a760-b80ba0fa4d5e")] 26 | 27 | // Version information for an assembly consists of the following four values: 28 | // 29 | // Major Version 30 | // Minor Version 31 | // Build Number 32 | // Revision 33 | // 34 | // You can specify all the values or you can default the Build and Revision Numbers 35 | // by using the '*' as shown below: 36 | // [assembly: AssemblyVersion("1.0.*")] 37 | 38 | [assembly: AssemblyVersion("1.0.0.0")] 39 | [assembly: AssemblyFileVersion("1.0.0.0")] -------------------------------------------------------------------------------- /Languages/npeg_csharp/RobustHaven.Text.Npeg.Tests/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.InteropServices; 3 | 4 | // General Information about an assembly is controlled through the following 5 | // set of attributes. Change these attribute values to modify the information 6 | // associated with an assembly. 7 | 8 | [assembly: AssemblyTitle("RobustHaven.Text.Npeg.Tests")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("Microsoft")] 12 | [assembly: AssemblyProduct("RobustHaven.Text.Npeg.Tests")] 13 | [assembly: AssemblyCopyright("Copyright © Microsoft 2009")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | 21 | [assembly: ComVisible(false)] 22 | 23 | // The following GUID is for the ID of the typelib if this project is exposed to COM 24 | 25 | [assembly: Guid("83afc918-811d-4619-8e20-94dee05200c6")] 26 | 27 | // Version information for an assembly consists of the following four values: 28 | // 29 | // Major Version 30 | // Minor Version 31 | // Build Number 32 | // Revision 33 | // 34 | // You can specify all the values or you can default the Build and Revision Numbers 35 | // by using the '*' as shown below: 36 | // [assembly: AssemblyVersion("1.0.*")] 37 | 38 | [assembly: AssemblyVersion("1.0.0.0")] 39 | [assembly: AssemblyFileVersion("1.0.0.0")] -------------------------------------------------------------------------------- /Languages/npeg_c/robusthaven.tests/run_tests.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Format of test app names: test__ 3 | 4 | echo "Building tests...." 5 | make clean all 6 | status=$? 7 | if [ "$status" != "0" ] 8 | then 9 | echo "Build error status code: $status"; 10 | exit $status 11 | fi 12 | 13 | echo 14 | echo 15 | 16 | 17 | . ./lib_tests.sh 18 | 19 | 20 | isverbose=0 21 | [ "$1" = "--verbose" ] && isverbose=1 22 | 23 | 24 | echo 25 | echo "Testing hashmap implementation:" 26 | fn_test_run "bin/test_hashmap_" $isverbose 27 | 28 | echo 29 | echo "Testing stack implementation:" 30 | fn_test_run "bin/test_stack_" $isverbose 31 | 32 | echo 33 | echo "Testing stackstack implementation:" 34 | fn_test_run "bin/test_stackstack_" $isverbose 35 | 36 | echo 37 | echo "Testing list implementation:" 38 | fn_test_run "bin/test_list_" $isverbose 39 | 40 | echo 41 | echo "Testing AST implementation:" 42 | fn_test_run "bin/test_ast_" $isverbose 43 | 44 | echo 45 | echo "Testing input iterator implementation:" 46 | fn_test_run "bin/test_inputiterator_" $isverbose 47 | 48 | echo 49 | echo "Testing npeg terminals:" 50 | fn_test_run "bin/test_terminal_" $isverbose 51 | 52 | echo 53 | echo "Testing npeg non-terminals:" 54 | fn_test_run "bin/test_nonterminal_" $isverbose 55 | 56 | echo 57 | echo "Testing ParserTest:" 58 | fn_test_run "ParserTest_NpegNode/program" $isverbose 59 | fn_test_run "ParserTest_PhoneNumber/program" $isverbose 60 | fn_test_run "ParserTest_SimpleSentence/program" $isverbose 61 | fn_test_run "ParserTest_MathematicalFormula/program" $isverbose 62 | fn_test_run "ParserTest_SimpleXml/program" $isverbose 63 | 64 | -------------------------------------------------------------------------------- /NPEG/StreamInputIterator.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Diagnostics; 3 | using System.IO; 4 | using NPEG.ApplicationExceptions; 5 | 6 | namespace NPEG 7 | { 8 | public class StreamInputIterator : IInputIterator 9 | { 10 | private readonly Stream _input; 11 | 12 | public StreamInputIterator(Stream input) 13 | : base((Int32)input.Length) 14 | { 15 | _input = input; 16 | } 17 | 18 | public override byte[] Text(int start, int end) 19 | { 20 | if (start > end) 21 | throw new IteratorUsageException("Index out of range. End must be >= than Start. byte[] Text(int start, int end)"); 22 | 23 | var buffer = new byte[end - start + 1]; 24 | _input.Position = start; 25 | _input.Read(buffer, 0, end - start + 1); 26 | return buffer; 27 | } 28 | 29 | public override short Current() 30 | { 31 | if (Index >= Length) return -1; 32 | return GetByte(Index); 33 | } 34 | 35 | public override short Next() 36 | { 37 | if (Index >= Length) return -1; 38 | Index += 1; 39 | 40 | if (Index >= Length) return -1; 41 | return GetByte(Index); 42 | } 43 | 44 | public override short Previous() 45 | { 46 | if (Index <= 0) 47 | { 48 | return -1; 49 | } 50 | Debug.Assert(Length > 0); 51 | 52 | Index -= 1; 53 | 54 | return GetByte(Index); 55 | } 56 | 57 | 58 | private short GetByte(Int32 index) 59 | { 60 | var b = new Byte[1]; 61 | _input.Position = index; 62 | _input.Read(b, 0, 1); 63 | return b[0]; 64 | } 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /Languages/npeg_c/robusthaven.tests/test_inputiterator_std_lookups.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include "robusthaven/text/npeg_inputiterator.h" 6 | 7 | /* 8 | * Unit test for the look ahead/behind & previous, next & current routines 9 | */ 10 | int main(int argc, char *argv[]) { 11 | #define strlen (uint)12 12 | 13 | char string[strlen+1]; 14 | npeg_inputiterator iter; 15 | uint i; 16 | 17 | srand(time(NULL)); 18 | 19 | for (i = 0; i < strlen; i++) { 20 | if (rand()%10 < 2) string[i] = 0; 21 | else string[i] = rand()%('z' - 'a') + 'a'; 22 | } 23 | string[i] = 0; 24 | npeg_inputiterator_constructor(&iter, string, strlen); 25 | assert(iter.length == strlen); 26 | 27 | assert(npeg_inputiterator_get_previous(&iter) == -1 && iter.index == 0); 28 | assert(npeg_inputiterator_get_current(&iter) == string[0] && iter.index == 0); 29 | assert(npeg_inputiterator_get_next(&iter) == string[1] && iter.index == 1); 30 | printf("\tVerified: start of string OK.\n"); 31 | 32 | for (i = 1; i < strlen - 1; i++) { 33 | assert(npeg_inputiterator_get_next(&iter) == string[i+1]); 34 | } 35 | assert(npeg_inputiterator_get_next(&iter) == -1 && iter.index == strlen); 36 | printf("\tVerified: next works.\n"); 37 | 38 | for (i = 0; i < strlen; i++) { 39 | assert(npeg_inputiterator_get_previous(&iter) == string[strlen-i-1]); 40 | } 41 | assert(npeg_inputiterator_get_previous(&iter) == -1 && iter.index == 0); 42 | printf("\tVerified: previous works.\n"); 43 | 44 | 45 | npeg_inputiterator_destructor(&iter); 46 | 47 | return 0; 48 | } /* main */ 49 | -------------------------------------------------------------------------------- /Languages/npeg_java/robusthaven.test/InputIteratorEmptyTest.java: -------------------------------------------------------------------------------- 1 | import robusthaven.text.*; 2 | import junit.framework.Assert; 3 | import junit.framework.TestCase; 4 | import java.util.*; 5 | import java.io.*; 6 | 7 | public class InputIteratorEmptyTest extends TestCase { 8 | public void testEmpty() { 9 | InputIterator iter; 10 | Random rand = new Random(); 11 | byte[] buffer = new byte[101]; 12 | int i; 13 | 14 | try { 15 | iter = new StringInputIterator(buffer, 0); 16 | for (i = 0; i < 10; i++) { 17 | int start, end; 18 | 19 | buffer[0] = 1; buffer[1] = 1; buffer[2] = 1; buffer[3] = 1; 20 | start = rand.nextInt()%100; end = rand.nextInt()%100; 21 | start = start < 0? -start : start; end = end < 0? -end : end; 22 | 23 | junit.framework.Assert.assertTrue(iter.getText(buffer, start, end) == 0); 24 | System.out.println("\tVerified: iterator with empty string is handled correctly."); 25 | 26 | Assert.assertTrue(buffer[0] == 0 && buffer[1] == 1 && buffer[2] == 1); 27 | System.out.println("\tVerified: no modification of destination buffer apart " + 28 | "from first byte."); 29 | } 30 | 31 | System.out.println("\tReached: get_text works."); 32 | 33 | Assert.assertTrue(iter.getCurrent() == -1); 34 | Assert.assertTrue(iter.getNext() == -1); 35 | } catch (Exception e) { 36 | e.printStackTrace(); 37 | fail("unexpected error"); 38 | } 39 | } 40 | 41 | public InputIteratorEmptyTest() { 42 | super(); 43 | } 44 | 45 | public static void main(String[] argv) { 46 | junit.textui.TestRunner.run(InputIteratorEmptyTest.class); 47 | System.exit(0); 48 | } 49 | } -------------------------------------------------------------------------------- /NPEG/ByteInputIterator.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Diagnostics; 3 | using NPEG.ApplicationExceptions; 4 | 5 | namespace NPEG 6 | { 7 | public class ByteInputIterator : IInputIterator 8 | { 9 | private readonly Byte[] _input; 10 | 11 | public ByteInputIterator(Byte[] input) 12 | : base(input.Length) 13 | { 14 | _input = input; 15 | } 16 | 17 | public override byte[] Text(int start, int end) 18 | //start and end are zero indexed. 19 | { 20 | Int32 destinationSize = 0; 21 | if (end >= start) 22 | { 23 | destinationSize = end - start + 1; 24 | } 25 | else 26 | { 27 | throw new IteratorUsageException("Index out of range. End must be >= than Start. byte[] Text(int start, int end)"); 28 | } 29 | 30 | if (Length == 0) 31 | return new byte[0]; 32 | 33 | var destination = new byte[destinationSize]; 34 | Array.Copy(_input, start, destination, 0, destinationSize); 35 | return destination; 36 | } 37 | 38 | 39 | public override short Current() 40 | { 41 | if (Index >= Length) return -1; 42 | return _input[Index]; 43 | } 44 | 45 | public override short Next() 46 | { 47 | if (Index >= Length) return -1; 48 | Index += 1; 49 | 50 | if (Index >= Length) return -1; 51 | return _input[Index]; 52 | } 53 | 54 | public override short Previous() 55 | { 56 | if (Index <= 0) 57 | { 58 | return -1; 59 | } 60 | Debug.Assert(Length > 0); 61 | 62 | Index -= 1; 63 | 64 | return _input[Index]; 65 | } 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /Languages/npeg_java/robusthaven.test/lib_tests.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | JUNIT_PATH=/usr/share/java 4 | 5 | fn_test_status() 6 | { 7 | case $1 in 8 | 0) 9 | echo -n "Passed" 10 | ;; 11 | *) 12 | echo -n "Failed" 13 | echo 14 | ;; 15 | esac 16 | } 17 | 18 | 19 | fn_test_run() 20 | { 21 | pattern=$1 22 | isverbose=$2 23 | 24 | for TEST in ${pattern}; do 25 | EXT=${TEST#*.} 26 | BASENAME=${TEST%.*} 27 | SUBCLASS=${BASENAME#*\$} 28 | DIRNAME=${TEST%/*} 29 | 30 | if [ "${SUBCLASS}" != "${BASENAME}" ]; then 31 | continue 32 | fi 33 | 34 | if [ "x${EXT}" == "xclass" ]; then 35 | if [ "x${DIRNAME}" == "xparser_tests" ]; then 36 | CLASSFILE=${TEST#*/} 37 | BASENAME=${CLASSFILE%.*} 38 | java -ea -cp ../robusthaven.jar:${JUNIT_PATH}/junit.jar:testparsers.jar:parser_tests.jar \ 39 | parser_tests.${BASENAME} >out.teststdin 2>out.teststderr 40 | status=$? 41 | else 42 | java -ea -cp ../robusthaven.jar:${JUNIT_PATH}/junit.jar:. ${BASENAME} \ 43 | >out.teststdin 2>out.teststderr 44 | status=$? 45 | fi 46 | 47 | printf "%-50.43s %-22s\n" $TEST `fn_test_status $status` 48 | 49 | if [ $status -ne 0 ] || [ $isverbose = 1 ]; then 50 | cat out.teststdin 51 | cat out.teststderr 52 | echo 53 | fi 54 | fi 55 | done 56 | } 57 | 58 | 59 | fn_test_memory() 60 | { 61 | pattern=$1 62 | isverbose=$2 63 | for TEST in ${pattern}*; do 64 | if [ -x ${TEST} ]; then 65 | #-v 66 | valgrind --tool=memcheck --show-reachable=yes --leak-check=yes ./${TEST} >out.teststdin 2>out.teststderr 67 | cat out.teststderr 68 | fi 69 | done 70 | } 71 | -------------------------------------------------------------------------------- /Languages/npeg_c/robusthaven/structures/list.h: -------------------------------------------------------------------------------- 1 | #ifndef ROBUSTHAVEN_STRUCTURES_LIST_H 2 | #define ROBUSTHAVEN_STRUCTURES_LIST_H 3 | 4 | #include "../types/types.h" 5 | 6 | typedef void (*rh_list_ondestruct_callback)(void*); 7 | 8 | // Since this is for storing warnings, items will likely never be removed, thus an array backend 9 | // is more suitable than a linked list approach. 10 | typedef struct rh_list_instance { 11 | // Head is a pointer to the first item in the list, tail points behind the one that was added last. 12 | void **head, **tail; 13 | uint capacity; 14 | // The destructor is applied to all active buckets upon list destruction. 15 | rh_list_ondestruct_callback elementdestructor; 16 | } rh_list_instance; 17 | 18 | // Initializes a list structure. 19 | void rh_list_constructor(rh_list_instance *instance, rh_list_ondestruct_callback elementdestructor); 20 | 21 | // Frees up all memory allocated for a list. 22 | void rh_list_destructor(rh_list_instance *instance); 23 | 24 | // Appends an element to the end of the list. 25 | void rh_list_add(rh_list_instance *instance, void *item); 26 | 27 | // Counts the number of elements that are stored in the list. 28 | uint rh_list_count(rh_list_instance *instance); 29 | 30 | // Retrieves the element with the given index (older elements have lower indices). 31 | // Valid indices go from 0 to rh_list_count(instance) - 1, NULL is returned if that range is exceeded. 32 | void* rh_list_get_item(rh_list_instance *instance, const uint index); 33 | 34 | /* 35 | * Restarts the list with the same destructor, but removes all stored items. 36 | */ 37 | void rh_list_clear(rh_list_instance* instance); 38 | #endif 39 | -------------------------------------------------------------------------------- /Languages/npeg_c++/robusthaven.tests/test_inputiterator_get_text.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | #include "robusthaven/text/StringInputIterator.h" 8 | 9 | using namespace std; 10 | using namespace RobustHaven::Text; 11 | 12 | /* 13 | * Unit test for the get_text routine 14 | */ 15 | int main(int argc, char *argv[]) { 16 | const uint strlen = 10; 17 | 18 | char string[strlen+1], buffer[strlen+1]; 19 | InputIterator *p_iter; 20 | uint i; 21 | 22 | srand(time(NULL)); 23 | 24 | for (i = 0; i < strlen; i++) { 25 | if (rand()%10 < 2) string[i] = 0; 26 | else string[i] = rand()%('z' - 'a') + 'a'; 27 | } 28 | 29 | p_iter = new StringInputIterator(string, strlen); 30 | assert(p_iter->getLength() == strlen); 31 | 32 | assert(p_iter->getText(buffer, 0, strlen) == strlen); 33 | assert(buffer[strlen] == 0); 34 | assert(memcmp(buffer, string, strlen) == 0); 35 | cout << "\tVerified: copying works.\n"; 36 | 37 | assert(p_iter->getText(buffer, 2, 5) == 3); 38 | assert(buffer[3] == 0); 39 | assert(buffer[0] == string[2] && buffer[1] == string[3] && buffer[2] == string[4]); 40 | cout << "\tVerified: substring works.\n"; 41 | 42 | assert(p_iter->getText(buffer, 2, 1) == 0); 43 | assert(buffer[strlen] == 0); 44 | cout << "\tVerified: start > end works.\n"; 45 | 46 | assert(p_iter->getText(buffer, strlen - 1, strlen + 1) == 1); 47 | assert(buffer[1] == 0); 48 | assert(buffer[0] == string[strlen-1]); 49 | cout << "\tVerified: end > strlen works.\n"; 50 | 51 | delete (StringInputIterator*)p_iter; 52 | 53 | return 0; 54 | } /* main */ 55 | -------------------------------------------------------------------------------- /Languages/npeg_java/robusthaven.test/robusthaven/text/npeg/tests/parsers/OneOrMoreInfiniteLoopTest.java.bk: -------------------------------------------------------------------------------- 1 | package robusthaven.text.npeg.tests.parsers; 2 | import java.io.IOException; 3 | import robusthaven.text.*; 4 | 5 | public class OneOrMoreInfiniteLoopTest extends Npeg 6 | { 7 | public OneOrMoreInfiniteLoopTest(InputIterator iterator) 8 | { 9 | super(iterator); 10 | } 11 | 12 | public boolean isMatch() throws IOException, ParsingFatalTerminalException 13 | { 14 | return new OneOrMoreInfiniteLoopTest_impl_0().evaluate(); 15 | } 16 | 17 | 18 | protected class OneOrMoreInfiniteLoopTest_impl_0 implements IsMatchPredicate 19 | { 20 | public boolean evaluate() throws ParsingFatalTerminalException, InfiniteLoopException, IOException 21 | { 22 | String _nodeName_0 = "Expression"; 23 | return capturingGroup(new OneOrMoreInfiniteLoopTest_impl_1(), _nodeName_0, false, null); 24 | } 25 | } 26 | 27 | protected class OneOrMoreInfiniteLoopTest_impl_1 implements IsMatchPredicate 28 | { 29 | public boolean evaluate() throws ParsingFatalTerminalException, InfiniteLoopException, IOException 30 | { 31 | return oneOrMore(new OneOrMoreInfiniteLoopTest_impl_2(), ""); 32 | } 33 | } 34 | 35 | protected class OneOrMoreInfiniteLoopTest_impl_2 implements IsMatchPredicate 36 | { 37 | public boolean evaluate() throws ParsingFatalTerminalException, InfiniteLoopException, IOException 38 | { 39 | return zeroOrMore(new OneOrMoreInfiniteLoopTest_impl_3(), ""); 40 | } 41 | } 42 | 43 | protected class OneOrMoreInfiniteLoopTest_impl_3 implements IsMatchPredicate 44 | { 45 | public boolean evaluate() throws ParsingFatalTerminalException, InfiniteLoopException, IOException 46 | { 47 | return anyCharacter(); 48 | } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /Languages/npeg_java/robusthaven.test/robusthaven/text/npeg/tests/parsers/ZeroOrMoreInfiniteLoopTest.java.bk: -------------------------------------------------------------------------------- 1 | package robusthaven.text.npeg.tests.parsers; 2 | import java.io.IOException; 3 | import robusthaven.text.*; 4 | 5 | public class ZeroOrMoreInfiniteLoopTest extends Npeg 6 | { 7 | public ZeroOrMoreInfiniteLoopTest(InputIterator iterator) 8 | { 9 | super(iterator); 10 | } 11 | 12 | public boolean isMatch() throws IOException, ParsingFatalTerminalException 13 | { 14 | return new ZeroOrMoreInfiniteLoopTest_impl_0().evaluate(); 15 | } 16 | 17 | 18 | protected class ZeroOrMoreInfiniteLoopTest_impl_0 implements IsMatchPredicate 19 | { 20 | public boolean evaluate() throws ParsingFatalTerminalException, InfiniteLoopException, IOException 21 | { 22 | String _nodeName_0 = "Expression"; 23 | return capturingGroup(new ZeroOrMoreInfiniteLoopTest_impl_1(), _nodeName_0, false, null); 24 | } 25 | } 26 | 27 | protected class ZeroOrMoreInfiniteLoopTest_impl_1 implements IsMatchPredicate 28 | { 29 | public boolean evaluate() throws ParsingFatalTerminalException, InfiniteLoopException, IOException 30 | { 31 | return zeroOrMore(new ZeroOrMoreInfiniteLoopTest_impl_2(), ""); 32 | } 33 | } 34 | 35 | protected class ZeroOrMoreInfiniteLoopTest_impl_2 implements IsMatchPredicate 36 | { 37 | public boolean evaluate() throws ParsingFatalTerminalException, InfiniteLoopException, IOException 38 | { 39 | return zeroOrMore(new ZeroOrMoreInfiniteLoopTest_impl_3(), ""); 40 | } 41 | } 42 | 43 | protected class ZeroOrMoreInfiniteLoopTest_impl_3 implements IsMatchPredicate 44 | { 45 | public boolean evaluate() throws ParsingFatalTerminalException, InfiniteLoopException, IOException 46 | { 47 | return anyCharacter(); 48 | } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /Languages/npeg_c/robusthaven/structures/list.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "list.h" 3 | 4 | static const int _start_capacity = 5; 5 | static const double _expansion_multiplier = 2.0; 6 | 7 | void rh_list_constructor(rh_list_instance *instance, rh_list_ondestruct_callback elementdestructor) { 8 | instance->capacity = _start_capacity; 9 | instance->elementdestructor = elementdestructor; 10 | instance->tail = (instance->head = (void**)malloc(sizeof(void*)*_start_capacity)); 11 | } 12 | 13 | void rh_list_destructor(rh_list_instance *instance) { 14 | uint i; 15 | 16 | if (instance->elementdestructor) for (i = 0; i < rh_list_count(instance); i++) { 17 | instance->elementdestructor(instance->head[i]); 18 | } 19 | 20 | free(instance->head); 21 | instance->capacity = 0; 22 | instance->head = instance->tail = NULL; 23 | } 24 | 25 | uint rh_list_count(rh_list_instance *instance) { 26 | return instance->tail - instance->head; 27 | } 28 | 29 | void rh_list_add(rh_list_instance *instance, void *item) { 30 | const uint old_nof_items = rh_list_count(instance); 31 | 32 | if (old_nof_items + 1 >= instance->capacity) { 33 | instance->capacity *= _expansion_multiplier; 34 | instance->head = (void**)realloc(instance->head, sizeof(void*)*instance->capacity); 35 | instance->tail = instance->head + old_nof_items; 36 | } 37 | 38 | *instance->tail = item; 39 | instance->tail += 1; 40 | } 41 | 42 | void* rh_list_get_item(rh_list_instance *instance, const uint index) { 43 | if (index < rh_list_count(instance)) return instance->head[index]; 44 | else return NULL; 45 | } 46 | 47 | void rh_list_clear(rh_list_instance* instance) { 48 | rh_list_destructor(instance); 49 | rh_list_constructor(instance, instance->elementdestructor); 50 | } 51 | -------------------------------------------------------------------------------- /NPEG.Tests/PredicateTests.cs: -------------------------------------------------------------------------------- 1 | using System.Text; 2 | using NPEG.NonTerminals; 3 | using NPEG.Terminals; 4 | using NUnit.Framework; 5 | 6 | namespace NPEG.Tests 7 | { 8 | [TestFixture] 9 | public class PredicateTests 10 | { 11 | public TestContext TestContext { get; set; } 12 | 13 | [Test] 14 | public void NonTerminal_Predicate_And() 15 | { 16 | // predicates should not adjust the 17 | // iterator once the expression is evaluated. 18 | AExpression Digit = new CharacterClass { ClassExpression = "[0-9]" }; 19 | 20 | // regex expression: \d+ 21 | var input = Encoding.UTF8.GetBytes("01234567890123456789"); 22 | var iterator = new ByteInputIterator(input); 23 | AExpression andPredicate = new OneOrMore(Digit).And(); 24 | var visitor = new NpegParserVisitor(iterator); 25 | andPredicate.Accept(visitor); 26 | Assert.IsTrue(visitor.IsMatch); 27 | Assert.IsTrue(iterator.Index == 0); 28 | } 29 | 30 | 31 | [Test] 32 | public void NonTerminal_Predicate_Or() 33 | { 34 | // predicates should not adjust the 35 | // iterator once the expression is evaluated. 36 | AExpression Digit = new CharacterClass { ClassExpression = "[0-9]" }; 37 | 38 | // equivalent to: regex '^' '$' 39 | // regex expression: ^\d+$ 40 | var bytes = Encoding.UTF8.GetBytes("0123456abcdefg"); 41 | var iterator = new ByteInputIterator(bytes); 42 | AExpression notPredicate = new OneOrMore(Digit).And().Sequence(new NotPredicate(new AnyCharacter())); 43 | var visitor = new NpegParserVisitor(iterator); 44 | notPredicate.Accept(visitor); 45 | Assert.IsFalse(visitor.IsMatch); // should fail 46 | Assert.IsTrue(iterator.Index == 0); 47 | } 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /Languages/npeg_java/robusthaven.test/robusthaven/text/npeg/tests/parsers/NpegNode.java: -------------------------------------------------------------------------------- 1 | package robusthaven.text.npeg.tests.parsers; 2 | import java.io.IOException; 3 | import robusthaven.text.*; 4 | 5 | public class NpegNode extends Npeg 6 | { 7 | public NpegNode(InputIterator iterator) 8 | { 9 | super(iterator, null); 10 | } 11 | 12 | public boolean isMatch() throws IOException, ParsingFatalTerminalException 13 | { 14 | return new NpegNode_impl_0().evaluate(); 15 | } 16 | 17 | 18 | protected class NpegNode_impl_0 implements IsMatchPredicate 19 | { 20 | public boolean evaluate() throws ParsingFatalTerminalException, InfiniteLoopException, IOException 21 | { 22 | String _nodeName_0 = "NpegNode"; 23 | return capturingGroup(new NpegNode_impl_1(), _nodeName_0, false, false); 24 | } 25 | } 26 | 27 | protected class NpegNode_impl_1 implements IsMatchPredicate 28 | { 29 | public boolean evaluate() throws ParsingFatalTerminalException, InfiniteLoopException, IOException 30 | { 31 | return prioritizedChoice(new NpegNode_impl_2(), new NpegNode_impl_3()); 32 | } 33 | } 34 | 35 | protected class NpegNode_impl_3 implements IsMatchPredicate 36 | { 37 | public boolean evaluate() throws ParsingFatalTerminalException, InfiniteLoopException, IOException 38 | { 39 | String _literal_0 = ".NET Parsing Expression Grammar"; 40 | return literal(_literal_0.getBytes(), _literal_0.length(), false); 41 | } 42 | } 43 | 44 | protected class NpegNode_impl_2 implements IsMatchPredicate 45 | { 46 | public boolean evaluate() throws ParsingFatalTerminalException, InfiniteLoopException, IOException 47 | { 48 | String _literal_0 = "NPEG"; 49 | return literal(_literal_0.getBytes(), _literal_0.length(), false); 50 | } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /LanguageWorkbench/MultiBinding/MultiBindingValidationError.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright Henrik Jonsson 2011 4 | * 5 | * This code is licenced under the The Code Project Open Licence 1.02 (see Licence.htm and http://www.codeproject.com/info/cpol10.aspx). 6 | * 7 | */ 8 | 9 | using System; 10 | using System.Net; 11 | using System.Windows; 12 | using System.Windows.Controls; 13 | using System.Windows.Documents; 14 | using System.Windows.Ink; 15 | using System.Windows.Input; 16 | using System.Windows.Media; 17 | using System.Windows.Media.Animation; 18 | using System.Windows.Shapes; 19 | 20 | namespace SilverlightMarkupExtensions 21 | { 22 | /// 23 | /// Holds information about an error that occured in MultiBinding conversion. 24 | /// 25 | public class MultiBindingValidationError 26 | { 27 | /// 28 | /// Initializes a new instance of the class. 29 | /// 30 | /// The exception. 31 | public MultiBindingValidationError(Exception exception) 32 | { 33 | if (exception == null) throw new ArgumentNullException(); 34 | Exception = exception; 35 | } 36 | 37 | /// 38 | /// Gets the exception. 39 | /// 40 | public Exception Exception { get; private set; } 41 | 42 | /// 43 | /// Returns a that represents this instance. 44 | /// 45 | /// 46 | /// A that represents this instance. 47 | /// 48 | public override string ToString() 49 | { 50 | return Exception.Message; 51 | } 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /Languages/npeg_java/robusthaven/robusthaven/text/AstNode.java: -------------------------------------------------------------------------------- 1 | package robusthaven.text; 2 | 3 | public class AstNode { 4 | /* custom vector implementation since existing Java vectors do not provide fast enough access */ 5 | AstNode[] m_children; 6 | int m_nofChildren, m_childrenCapacity; 7 | 8 | AstNode m_parent; 9 | TokenMatch m_token; 10 | 11 | public AstNode getParent() { 12 | return m_parent; 13 | } 14 | 15 | public void setParent(AstNode parent) { 16 | m_parent = parent; 17 | } 18 | 19 | public AstNode[] getChildren() { 20 | return m_children; 21 | } 22 | 23 | public int nofChildren() { 24 | return m_nofChildren; 25 | } 26 | 27 | public void addChild(AstNode newChild) { 28 | if (m_nofChildren + 1 >= m_childrenCapacity) { 29 | AstNode[] tmpChildren; 30 | 31 | m_childrenCapacity *= 2; 32 | tmpChildren = m_children; 33 | m_children = new AstNode[m_childrenCapacity]; 34 | System.arraycopy(tmpChildren, 0, m_children, 0, m_nofChildren); 35 | } 36 | m_children[m_nofChildren] = newChild; 37 | m_nofChildren += 1; 38 | } 39 | 40 | public TokenMatch getToken() { 41 | return m_token; 42 | } 43 | 44 | public void setToken(TokenMatch token) { 45 | m_token = token; 46 | } 47 | 48 | public void accept(IAstNodeVisitor visitor) { 49 | visitor.visitEnter(this); 50 | 51 | if (nofChildren() > 0) { 52 | AstNode[] children; 53 | int i; 54 | 55 | children = getChildren(); 56 | for (i = 0; i < nofChildren(); i++) { 57 | children[i].accept(visitor); 58 | } 59 | } 60 | visitor.visitLeave(this); 61 | } 62 | 63 | public AstNode(TokenMatch token) { 64 | m_token = token; 65 | m_childrenCapacity = 4; 66 | m_nofChildren = 0; 67 | m_children = new AstNode[m_childrenCapacity]; 68 | } 69 | } -------------------------------------------------------------------------------- /Languages/npeg_java/robusthaven.test/WarnTerminalTest.java: -------------------------------------------------------------------------------- 1 | import robusthaven.text.*; 2 | import java.util.*; 3 | import java.io.*; 4 | import junit.framework.Assert; 5 | import junit.framework.TestCase; 6 | 7 | public class WarnTerminalTest extends TestCase { 8 | public static String g_string = "A user warning message."; 9 | 10 | class WarnTest extends Npeg { 11 | public boolean isMatch() throws ParsingFatalTerminalException { 12 | return warn(g_string); 13 | } 14 | 15 | public WarnTest(InputIterator iter) { 16 | super(iter, null); 17 | } 18 | } 19 | 20 | public void testWarn() { 21 | StringInputIterator iterator; 22 | Npeg context; 23 | 24 | try { 25 | iterator = new StringInputIterator(g_string); 26 | context = new WarnTest(iterator); 27 | 28 | Assert.assertTrue( 0 == context.getWarnings().size() ); 29 | System.out.println("\tVerified: context warnings is zero at start."); 30 | 31 | Assert.assertTrue( true == context.isMatch() ); 32 | System.out.println("\tVerified: npeg_Warn will always return true."); 33 | 34 | Assert.assertTrue( 1 == context.getWarnings().size()); 35 | System.out.println("\tVerified: npeg_Warn will add an warning to context warnings collection."); 36 | 37 | Assert.assertTrue(context.getWarnings().lastElement().getMessage() == "A user warning message."); 38 | System.out.println("\tVerified: that the original warn message was copied in full to the new allocated npeg managed memory."); 39 | } catch (Exception e) { 40 | e.printStackTrace(); 41 | fail("unexpected error"); 42 | } 43 | } 44 | 45 | public WarnTerminalTest() { 46 | super(); 47 | } 48 | 49 | public static void main(String[] argv) { 50 | junit.textui.TestRunner.run(WarnTerminalTest.class); 51 | System.exit(0); 52 | } 53 | } 54 | 55 | -------------------------------------------------------------------------------- /Languages/npeg_c/robusthaven.tests/test_inputiterator_get_text.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include "robusthaven/text/npeg_inputiterator.h" 7 | 8 | /* 9 | * Unit test for the get_text routine 10 | */ 11 | int main(int argc, char *argv[]) { 12 | #define strlen (uint)10 13 | 14 | char string[strlen+1], buffer[strlen+1]; 15 | npeg_inputiterator iter; 16 | uint i; 17 | 18 | srand(time(NULL)); 19 | 20 | for (i = 0; i < strlen; i++) { 21 | if (rand()%10 < 2) string[i] = 0; 22 | else string[i] = rand()%('z' - 'a') + 'a'; 23 | } 24 | string[i] = 0; 25 | 26 | npeg_inputiterator_constructor(&iter, string, strlen); 27 | assert(iter.length == strlen); 28 | 29 | assert(npeg_inputiterator_get_text(buffer, &iter, 0, strlen) == strlen); 30 | assert(buffer[strlen] == 0); 31 | assert(memcmp(buffer, string, strlen) == 0); 32 | printf("\tVerified: copying works.\n"); 33 | 34 | assert(npeg_inputiterator_get_text(buffer, &iter, 2, 5) == 3); 35 | assert(buffer[3] == 0); 36 | assert(buffer[0] == string[2] && buffer[1] == string[3] && buffer[2] == string[4]); 37 | printf("\tVerified: substring works.\n"); 38 | 39 | assert(npeg_inputiterator_get_text(buffer, &iter, 2, 1) == 0); 40 | assert(buffer[strlen] == 0); 41 | printf("\tVerified: start > end works.\n"); 42 | 43 | assert(npeg_inputiterator_get_text(buffer, &iter, -2, 1) == 1); 44 | assert(buffer[1] == 0); 45 | assert(buffer[0] == string[0]); 46 | printf("\tVerified: start < 0 works.\n"); 47 | 48 | assert(npeg_inputiterator_get_text(buffer, &iter, strlen - 1, strlen + 1) == 1); 49 | assert(buffer[1] == 0); 50 | assert(buffer[0] == string[strlen-1]); 51 | printf("\tVerified: end > strlen works.\n"); 52 | 53 | npeg_inputiterator_destructor(&iter); 54 | 55 | return 0; 56 | } /* main */ 57 | -------------------------------------------------------------------------------- /NPEG.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2013 4 | VisualStudioVersion = 12.0.21005.1 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NPEG", "NPEG\NPEG.csproj", "{567F6FBD-C5CE-4E3E-B16B-F40F1D367E35}" 7 | EndProject 8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NPEG.Tests", "NPEG.Tests\NPEG.Tests.csproj", "{913C7583-5FFA-4170-8F59-FD745F4D97CE}" 9 | EndProject 10 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".nuget", ".nuget", "{3236C741-224A-476F-9C35-7BB489EAA624}" 11 | ProjectSection(SolutionItems) = preProject 12 | .nuget\NuGet.Config = .nuget\NuGet.Config 13 | .nuget\NuGet.exe = .nuget\NuGet.exe 14 | .nuget\NuGet.targets = .nuget\NuGet.targets 15 | EndProjectSection 16 | EndProject 17 | Global 18 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 19 | Debug|Any CPU = Debug|Any CPU 20 | Release|Any CPU = Release|Any CPU 21 | EndGlobalSection 22 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 23 | {567F6FBD-C5CE-4E3E-B16B-F40F1D367E35}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 24 | {567F6FBD-C5CE-4E3E-B16B-F40F1D367E35}.Debug|Any CPU.Build.0 = Debug|Any CPU 25 | {567F6FBD-C5CE-4E3E-B16B-F40F1D367E35}.Release|Any CPU.ActiveCfg = Release|Any CPU 26 | {567F6FBD-C5CE-4E3E-B16B-F40F1D367E35}.Release|Any CPU.Build.0 = Release|Any CPU 27 | {913C7583-5FFA-4170-8F59-FD745F4D97CE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 28 | {913C7583-5FFA-4170-8F59-FD745F4D97CE}.Debug|Any CPU.Build.0 = Debug|Any CPU 29 | {913C7583-5FFA-4170-8F59-FD745F4D97CE}.Release|Any CPU.ActiveCfg = Release|Any CPU 30 | {913C7583-5FFA-4170-8F59-FD745F4D97CE}.Release|Any CPU.Build.0 = Release|Any CPU 31 | EndGlobalSection 32 | GlobalSection(SolutionProperties) = preSolution 33 | HideSolutionNode = FALSE 34 | EndGlobalSection 35 | EndGlobal 36 | -------------------------------------------------------------------------------- /Languages/npeg_c++/robusthaven/text/AstNode.h: -------------------------------------------------------------------------------- 1 | #ifndef ROBUSTHAVEN_TEXT_AST_H 2 | #define ROBUSTHAVEN_TEXT_AST_H 3 | 4 | #include 5 | #include "TokenMatch.h" 6 | 7 | namespace RobustHaven 8 | { 9 | namespace Text 10 | { 11 | class IAstNodeVisitor; 12 | 13 | class AstNode 14 | { 15 | const bool m_deleteToken; 16 | std::vector m_children; 17 | AstNode *m_parent; 18 | TokenMatch *m_token; 19 | 20 | public: 21 | AstNode* getParent(void); 22 | 23 | void setParent(AstNode *parent); 24 | 25 | void addChild(AstNode *newChild); 26 | 27 | std::vector& getChildren(void); 28 | 29 | void setToken(TokenMatch *token); 30 | 31 | TokenMatch* getToken(void); 32 | 33 | public: 34 | void accept(IAstNodeVisitor &visitor); 35 | 36 | public: 37 | /* 38 | * routine for recursive deletion of ASTs 39 | */ 40 | static void deleteAST(AstNode *root); 41 | 42 | public: 43 | /* 44 | * The parameter deleteToken, if true, tells the AstNode object to delete the token upon destruction. 45 | * Default: no deletion 46 | */ 47 | AstNode(const bool deleteToken = false); 48 | 49 | /* 50 | * The parameter deleteToken, if true, tells the AstNode object to delete the token upon destruction. 51 | */ 52 | AstNode(TokenMatch *token, const bool deleteToken); 53 | 54 | virtual ~AstNode(void); 55 | }; 56 | 57 | extern inline AstNode* AstNode::getParent() { 58 | return m_parent; 59 | } 60 | 61 | extern inline void AstNode::addChild(AstNode *newChild) { 62 | m_children.push_back(newChild); 63 | } 64 | 65 | extern inline std::vector& AstNode::getChildren() { 66 | return m_children; 67 | } 68 | 69 | extern inline TokenMatch* AstNode::getToken() { 70 | return m_token; 71 | } 72 | } 73 | } 74 | #endif 75 | -------------------------------------------------------------------------------- /Languages/npeg_c++/robusthaven.tests/test_terminal_npeg_AnyCharacter.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include "robusthaven/text/StringInputIterator.h" 7 | #include "robusthaven/text/Npeg.h" 8 | 9 | using namespace RobustHaven::Text; 10 | 11 | class _AnyTest : public Npeg { 12 | public: 13 | int isMatch(void) throw (ParsingFatalTerminalException) { 14 | return anyCharacter(); 15 | } 16 | 17 | public: 18 | _AnyTest(InputIterator *p_iter) : Npeg(p_iter) {} 19 | }; 20 | 21 | /* 22 | * - Test that consumption of an empty string results in failure. 23 | * - Test that consumption of a random string works until the end of the string is reached. 24 | */ 25 | int main(int argc, char *argv[]) 26 | { 27 | const int randstringlen = 10; 28 | const char errmsg[] = "some kind of error"; 29 | 30 | char emptystring[] = ""; 31 | char randomstring[randstringlen]; 32 | StringInputIterator *p_iterator; 33 | Npeg *p_context; 34 | int i; 35 | 36 | srand(time(NULL)); 37 | 38 | p_iterator = new StringInputIterator(emptystring, 0); 39 | p_context = new _AnyTest(p_iterator); 40 | assert(p_context->isMatch() == 0); 41 | delete p_iterator; delete p_context; 42 | printf("\tVerified: handling of empty string\n"); 43 | 44 | for (i = 0; i < randstringlen; i++) { 45 | randomstring[i] = rand()%('z' - 'a') + 'a'; 46 | } 47 | 48 | p_iterator = new StringInputIterator(randomstring, randstringlen); 49 | p_context = new _AnyTest(p_iterator); 50 | for (i = 0; i < randstringlen; i++) 51 | { 52 | assert(p_iterator->getCurrent() == randomstring[i]); 53 | assert(p_context->isMatch() == 1); 54 | } 55 | 56 | assert(p_context->isMatch() == 0); 57 | printf("\tVerified: handling of end of string\n"); 58 | 59 | delete p_iterator; delete p_context; 60 | printf("\tVerified: consumption of random string\n"); 61 | 62 | return 0; 63 | } 64 | -------------------------------------------------------------------------------- /Languages/npeg_java/robusthaven.test/robusthaven/text/npeg/tests/parsers/LimitingRepetitionInfiniteLoopTest.java.bk: -------------------------------------------------------------------------------- 1 | package robusthaven.text.npeg.tests.parsers; 2 | import java.io.IOException; 3 | import robusthaven.text.*; 4 | 5 | public class LimitingRepetitionInfiniteLoopTest extends Npeg 6 | { 7 | public LimitingRepetitionInfiniteLoopTest(InputIterator iterator) 8 | { 9 | super(iterator); 10 | } 11 | 12 | public boolean isMatch() throws IOException, ParsingFatalTerminalException 13 | { 14 | return new LimitingRepetitionInfiniteLoopTest_impl_0().evaluate(); 15 | } 16 | 17 | 18 | protected class LimitingRepetitionInfiniteLoopTest_impl_0 implements IsMatchPredicate 19 | { 20 | public boolean evaluate() throws ParsingFatalTerminalException, InfiniteLoopException, IOException 21 | { 22 | String _nodeName_0 = "Expression"; 23 | return capturingGroup(new LimitingRepetitionInfiniteLoopTest_impl_1(), _nodeName_0, false, 24 | null); 25 | } 26 | } 27 | 28 | protected class LimitingRepetitionInfiniteLoopTest_impl_1 implements IsMatchPredicate 29 | { 30 | public boolean evaluate() throws ParsingFatalTerminalException, InfiniteLoopException, IOException 31 | { 32 | return limitingRepetition(0, -1, new LimitingRepetitionInfiniteLoopTest_impl_2(), ""); 33 | } 34 | } 35 | 36 | protected class LimitingRepetitionInfiniteLoopTest_impl_2 implements IsMatchPredicate 37 | { 38 | public boolean evaluate() throws ParsingFatalTerminalException, InfiniteLoopException, IOException 39 | { 40 | return zeroOrMore(new LimitingRepetitionInfiniteLoopTest_impl_3(), ""); 41 | } 42 | } 43 | 44 | protected class LimitingRepetitionInfiniteLoopTest_impl_3 implements IsMatchPredicate 45 | { 46 | public boolean evaluate() throws ParsingFatalTerminalException, InfiniteLoopException, IOException 47 | { 48 | return anyCharacter(); 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /Languages/npeg_javascript/tools/combine-compress.proj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /Languages/npeg_c/robusthaven.tests/robusthaven.tests.cproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Debug 5 | AnyCPU 6 | 8.0.50727 7 | 2.0 8 | {6277251A-4E5D-486B-B1E6-F3A7997BDED1} 9 | 10 | 11 | 12 | C 13 | Bin 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | true 22 | bin\Debug 23 | DEBUG MONODEVELOP 24 | . 25 | robusthaven 26 | Bin 27 | 28 | 29 | /home/leblanc/Desktop/npeg/robusthaven/npeg/trunk/npeg_c 30 | 31 | 32 | 33 | 34 | bin\Release 35 | MONODEVELOP 36 | . 37 | 3 38 | robusthaven 39 | Bin 40 | 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /Languages/npeg_c/robusthaven.tests/ParserTest_PhoneNumber/PhoneNumber.h: -------------------------------------------------------------------------------- 1 | #ifndef ROBUSTHAVEN_GENERATEDPARSER_PHONENUMBER 2 | #define ROBUSTHAVEN_GENERATEDPARSER_PHONENUMBER 3 | 4 | #include "robusthaven/text/npeg_inputiterator.h" 5 | #include "robusthaven/text/npeg.h" 6 | 7 | int PhoneNumber_impl_0(npeg_inputiterator*, npeg_context*); 8 | int PhoneNumber_impl_1(npeg_inputiterator*, npeg_context*); 9 | int PhoneNumber_impl_19(npeg_inputiterator*, npeg_context*); 10 | int PhoneNumber_impl_20(npeg_inputiterator*, npeg_context*); 11 | int PhoneNumber_impl_26(npeg_inputiterator*, npeg_context*); 12 | int PhoneNumber_impl_21(npeg_inputiterator*, npeg_context*); 13 | int PhoneNumber_impl_25(npeg_inputiterator*, npeg_context*); 14 | int PhoneNumber_impl_22(npeg_inputiterator*, npeg_context*); 15 | int PhoneNumber_impl_24(npeg_inputiterator*, npeg_context*); 16 | int PhoneNumber_impl_23(npeg_inputiterator*, npeg_context*); 17 | int PhoneNumber_impl_2(npeg_inputiterator*, npeg_context*); 18 | int PhoneNumber_impl_18(npeg_inputiterator*, npeg_context*); 19 | int PhoneNumber_impl_3(npeg_inputiterator*, npeg_context*); 20 | int PhoneNumber_impl_12(npeg_inputiterator*, npeg_context*); 21 | int PhoneNumber_impl_13(npeg_inputiterator*, npeg_context*); 22 | int PhoneNumber_impl_17(npeg_inputiterator*, npeg_context*); 23 | int PhoneNumber_impl_14(npeg_inputiterator*, npeg_context*); 24 | int PhoneNumber_impl_16(npeg_inputiterator*, npeg_context*); 25 | int PhoneNumber_impl_15(npeg_inputiterator*, npeg_context*); 26 | int PhoneNumber_impl_4(npeg_inputiterator*, npeg_context*); 27 | int PhoneNumber_impl_11(npeg_inputiterator*, npeg_context*); 28 | int PhoneNumber_impl_5(npeg_inputiterator*, npeg_context*); 29 | int PhoneNumber_impl_6(npeg_inputiterator*, npeg_context*); 30 | int PhoneNumber_impl_10(npeg_inputiterator*, npeg_context*); 31 | int PhoneNumber_impl_7(npeg_inputiterator*, npeg_context*); 32 | int PhoneNumber_impl_9(npeg_inputiterator*, npeg_context*); 33 | int PhoneNumber_impl_8(npeg_inputiterator*, npeg_context*); 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /Languages/npeg_c/robusthaven.tests/test_list_all.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include "robusthaven/structures/list.h" 7 | 8 | #define _nof_test_items 150 9 | static int _g_nof_visited_items = 0; 10 | static int _g_visited_items[_nof_test_items]; 11 | 12 | static void _destructor_callback(void *item) { 13 | _g_visited_items[_g_nof_visited_items] = *(int*)item; 14 | _g_nof_visited_items += 1; 15 | } 16 | 17 | /* 18 | * Since the list module is very small, I rolled all tests into one test application: 19 | * - Check that the list is initialized with non-zero capacity & zero items. 20 | * - Check that items can be added (beyond the initial capacity). 21 | * - Check that the order in which items are stored is the same in which they were added. 22 | */ 23 | int main(int argc, char *argv[]) { 24 | rh_list_instance list; 25 | int testitems[_nof_test_items], i; 26 | 27 | srand(time(NULL)); 28 | 29 | rh_list_constructor(&list, _destructor_callback); 30 | assert(list.capacity > 0 && rh_list_count(&list) == 0); 31 | puts("\tVerified: list was initialized properly."); 32 | 33 | for (i = 0; i < _nof_test_items; i++) { 34 | testitems[i] = rand(); 35 | } 36 | 37 | for (i = 0; i < _nof_test_items; i++) { 38 | rh_list_add(&list, &testitems[i]); 39 | } 40 | assert(rh_list_count(&list) == _nof_test_items); 41 | puts("\tVerified: a great number of items can be put in the list, without access violations"); 42 | 43 | for (i = 0; i < _nof_test_items; i++) { 44 | assert(*(int*)rh_list_get_item(&list, i) == testitems[i]); 45 | printf("\tVerified: item %d was found in the list, and it was in the right place.\n", testitems[i]); 46 | } 47 | 48 | rh_list_destructor(&list); 49 | 50 | for (i = 0; i < _nof_test_items; i++) { 51 | assert(_g_visited_items[i] == testitems[i]); 52 | printf("\tVerified: item %d was visited by destructor callback.\n", testitems[i]); 53 | } 54 | 55 | return 0; 56 | } 57 | -------------------------------------------------------------------------------- /Languages/npeg_c/robusthaven.tests/test_terminal_npeg_Fatal.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "robusthaven/structures/stack.h" 5 | #include "robusthaven/text/npeg.h" 6 | #include "robusthaven/text/npeg_inputiterator.h" 7 | 8 | 9 | int main(int argc, char *argv[]) 10 | { 11 | char* string = "A Fatal Exception Message"; 12 | 13 | rh_stack_instance disableBackReferenceStack; 14 | rh_stackstack_instance astNodeStack; 15 | rh_hashmap_instance backreference_lookup; 16 | rh_list_instance warnings; 17 | rh_stack_instance errors; 18 | npeg_context context; 19 | npeg_inputiterator iterator; 20 | void *node; 21 | 22 | // load npeg managed memory 23 | context.disableBackReferenceStack = &disableBackReferenceStack; 24 | context.sandbox = &astNodeStack; 25 | context.backReferenceLookup = &backreference_lookup; 26 | context.warnings = &warnings; 27 | context.errors = &errors; 28 | npeg_constructor(&context, NULL); 29 | 30 | npeg_inputiterator_constructor(&iterator, string, 0); 31 | 32 | assert( 0 == rh_stack_count(context.errors) ); 33 | printf("\tVerified: context.errors is zero at start.\n"); 34 | 35 | assert( 0 == npeg_Fatal(&iterator, &context, string) ); 36 | printf("\tVerified: npeg_Fatal will always return false.\n"); 37 | 38 | assert( 1 == rh_stack_count(context.errors)); 39 | printf("\tVerified: npeg_Fatal will add an error to context.errors collection.\n"); 40 | 41 | node = rh_stack_peek(context.errors); 42 | assert( string != ((npeg_error*)node)->message ); 43 | printf("\tVerified: that the error message is persisted in an npeg managed area spot and string pointers do not match.\n"); 44 | 45 | assert(0 == strcmp(((npeg_error*)node)->message, "A Fatal Exception Message")); 46 | printf("\tVerified: that the original error message was copied in full to the new allocated npeg managed memory.\n"); 47 | 48 | npeg_inputiterator_destructor(&iterator); 49 | 50 | // unload npeg managed memory 51 | npeg_destructor(&context); 52 | 53 | 54 | return 0; 55 | } 56 | -------------------------------------------------------------------------------- /Languages/npeg_c/robusthaven.tests/test_terminal_npeg_Warn.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "robusthaven/structures/stack.h" 5 | #include "robusthaven/text/npeg.h" 6 | #include "robusthaven/text/npeg_inputiterator.h" 7 | 8 | 9 | int main(int argc, char *argv[]) 10 | { 11 | char* string = "A user warning message."; 12 | 13 | rh_stack_instance disableBackReferenceStack; 14 | rh_stackstack_instance astNodeStack; 15 | rh_hashmap_instance backreference_lookup; 16 | rh_list_instance warnings; 17 | rh_stack_instance errors; 18 | npeg_context context; 19 | npeg_inputiterator iterator; 20 | 21 | // load npeg managed memory 22 | context.disableBackReferenceStack = &disableBackReferenceStack; 23 | context.sandbox = &astNodeStack; 24 | context.backReferenceLookup = &backreference_lookup; 25 | context.warnings = &warnings; 26 | context.errors = &errors; 27 | npeg_constructor(&context, NULL); 28 | 29 | npeg_inputiterator_constructor(&iterator, string, 0); 30 | 31 | assert( 0 == rh_list_count(context.warnings) ); 32 | printf("\tVerified: context.warnings is zero at start.\n"); 33 | 34 | assert( 1 == npeg_Warn(&iterator, &context, string) ); 35 | printf("\tVerified: npeg_Warn will always return true.\n"); 36 | 37 | assert( 1 == rh_list_count(context.warnings)); 38 | printf("\tVerified: npeg_Warn will add an warning to context.warnings collection.\n"); 39 | 40 | assert( string != ((npeg_warn*)rh_list_get_item(context.warnings, 0))->message); 41 | printf("\tVerified: that the warn message is persisted in an npeg managed area spot and string pointers do not match.\n"); 42 | 43 | assert(0 == strcmp(((npeg_warn*)rh_list_get_item(context.warnings, 0))->message, 44 | "A user warning message.")); 45 | printf("\tVerified: that the original warn message was copied in full to the new allocated npeg managed memory.\n"); 46 | 47 | npeg_inputiterator_destructor(&iterator); 48 | 49 | // unload npeg managed memory 50 | npeg_destructor(&context); 51 | 52 | 53 | return 0; 54 | } 55 | -------------------------------------------------------------------------------- /Languages/npeg_java/robusthaven.test/parser_tests/NpegNodeTest.java: -------------------------------------------------------------------------------- 1 | package parser_tests; 2 | import robusthaven.text.npeg.tests.parsers.NpegNode; 3 | import robusthaven.text.*; 4 | import junit.framework.Assert; 5 | import junit.framework.TestCase; 6 | import java.util.*; 7 | import java.io.*; 8 | 9 | public class NpegNodeTest extends TestCase { 10 | static final String input1 = "NpEg"; 11 | static final String input2 = ".NET Parsing Expression Grammar"; 12 | static final String input3 = "NET Parsing Expression Grammar"; 13 | 14 | static final int BUFFER_SIZE = 100; 15 | byte[] buffer = new byte[BUFFER_SIZE]; 16 | InputIterator input; 17 | NpegNode parser; 18 | AstNode ast; 19 | 20 | public void testInput1() { 21 | try { 22 | input = new StringInputIterator(input1); 23 | parser = new NpegNode(input); 24 | 25 | Assert.assertTrue(parser.isMatch()); 26 | System.out.println("\tVerified: The expected input was matched by parser."); 27 | 28 | ast = parser.getAST(); 29 | Assert.assertTrue(0 == ast.getToken().getName().compareTo("NpegNode")); 30 | System.out.println("\tVerified: The expected token name: " + ast.getToken().getName()); 31 | /* 32 | * Attention: trim is necessary as String interprets all 100 buffer chars as part of the 33 | * string, hence there's a huge length mismatch without the application of String.trim to the 34 | * newly created string object. 35 | */ 36 | input.getText(buffer, ast.getToken().getStart(), ast.getToken().getEnd()); 37 | Assert.assertTrue(0 == new String(buffer).trim().compareTo(input1)); 38 | System.out.println("\tVerified: The expected matched string: " + new String(buffer).trim()); 39 | } catch (Exception e) { 40 | e.printStackTrace(); 41 | fail("Could not parse input1"); 42 | } 43 | } 44 | 45 | public NpegNodeTest() { 46 | super(); 47 | } 48 | 49 | public static void main(String[] argv) { 50 | junit.textui.TestRunner.run(NpegNodeTest.class); 51 | System.exit(0); 52 | } 53 | } -------------------------------------------------------------------------------- /Languages/npeg_c/robusthaven.tests/ParserTest_SimpleXml/SimpleXml.h: -------------------------------------------------------------------------------- 1 | #ifndef ROBUSTHAVEN_GENERATEDPARSER_SIMPLEXML 2 | #define ROBUSTHAVEN_GENERATEDPARSER_SIMPLEXML 3 | 4 | #include "robusthaven/text/npeg_inputiterator.h" 5 | #include "robusthaven/text/npeg.h" 6 | 7 | int SimpleXml_impl_0(npeg_inputiterator*, npeg_context*); 8 | int SimpleXml_impl_1(npeg_inputiterator*, npeg_context*); 9 | int SimpleXml_impl_2(npeg_inputiterator*, npeg_context*); 10 | int SimpleXml_impl_23(npeg_inputiterator*, npeg_context*); 11 | int SimpleXml_impl_24(npeg_inputiterator*, npeg_context*); 12 | int SimpleXml_impl_28(npeg_inputiterator*, npeg_context*); 13 | int SimpleXml_impl_25(npeg_inputiterator*, npeg_context*); 14 | int SimpleXml_impl_27(npeg_inputiterator*, npeg_context*); 15 | int SimpleXml_impl_26(npeg_inputiterator*, npeg_context*); 16 | int SimpleXml_impl_3(npeg_inputiterator*, npeg_context*); 17 | int SimpleXml_impl_12(npeg_inputiterator*, npeg_context*); 18 | int SimpleXml_impl_13(npeg_inputiterator*, npeg_context*); 19 | int SimpleXml_impl_14(npeg_inputiterator*, npeg_context*); 20 | int SimpleXml_impl_22(npeg_inputiterator*, npeg_context*); 21 | int SimpleXml_impl_15(npeg_inputiterator*, npeg_context*); 22 | int SimpleXml_impl_16(npeg_inputiterator*, npeg_context*); 23 | int SimpleXml_impl_17(npeg_inputiterator*, npeg_context*); 24 | int SimpleXml_impl_21(npeg_inputiterator*, npeg_context*); 25 | int SimpleXml_impl_18(npeg_inputiterator*, npeg_context*); 26 | int SimpleXml_impl_20(npeg_inputiterator*, npeg_context*); 27 | int SimpleXml_impl_19(npeg_inputiterator*, npeg_context*); 28 | int SimpleXml_impl_4(npeg_inputiterator*, npeg_context*); 29 | int SimpleXml_impl_5(npeg_inputiterator*, npeg_context*); 30 | int SimpleXml_impl_11(npeg_inputiterator*, npeg_context*); 31 | int SimpleXml_impl_6(npeg_inputiterator*, npeg_context*); 32 | int SimpleXml_impl_8(npeg_inputiterator*, npeg_context*); 33 | int SimpleXml_impl_9(npeg_inputiterator*, npeg_context*); 34 | int SimpleXml_impl_10(npeg_inputiterator*, npeg_context*); 35 | int SimpleXml_impl_7(npeg_inputiterator*, npeg_context*); 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /Languages/npeg_java/robusthaven.test/InputIteratorStdLookupsTest.java: -------------------------------------------------------------------------------- 1 | import robusthaven.text.*; 2 | import junit.framework.Assert; 3 | import junit.framework.TestCase; 4 | import java.util.*; 5 | import java.io.*; 6 | 7 | public class InputIteratorStdLookupsTest extends TestCase { 8 | public static final int strlen = 10; 9 | public static Random rand = new Random(); 10 | 11 | byte[] string = new byte[strlen+1]; 12 | byte[] buffer = new byte[strlen+1]; 13 | StringInputIterator iter; 14 | 15 | public void setUp() { 16 | int i; 17 | 18 | for (i = 0; i < strlen; i++) { 19 | if (rand.nextInt()%10 < 2) string[i] = 0; 20 | else string[i] = (byte)(rand.nextInt()%('z' - 'a') + 'a'); 21 | } 22 | } 23 | 24 | public void testStart() { 25 | StringInputIterator iter; 26 | 27 | try { 28 | iter = new StringInputIterator(string, strlen); 29 | Assert.assertTrue(iter.getLength() == strlen); 30 | Assert.assertTrue(iter.getIndex() == 0); 31 | Assert.assertTrue(iter.getCurrent() == string[0] && iter.getIndex() == 0); 32 | Assert.assertTrue(iter.getNext() == string[1] && iter.getIndex() == 1); 33 | System.out.println("\tVerified: start of string OK."); 34 | } catch (Exception e) { 35 | e.printStackTrace(); 36 | fail("unexpected error"); 37 | } 38 | } 39 | 40 | public void testNext() { 41 | StringInputIterator iter; 42 | int i; 43 | 44 | try { 45 | iter = new StringInputIterator(string, strlen); 46 | for (i = 0; i < strlen - 1; i++) { 47 | Assert.assertTrue(iter.getNext() == string[i+1]); 48 | } 49 | Assert.assertTrue(iter.getNext() == -1 && iter.getIndex() == strlen); 50 | System.out.println("\tVerified: next works."); 51 | } catch (Exception e) { 52 | e.printStackTrace(); 53 | fail("unexpected error"); 54 | } 55 | } 56 | 57 | public InputIteratorStdLookupsTest() { 58 | super(); 59 | } 60 | 61 | public static void main(String[] argv) { 62 | junit.textui.TestRunner.run(InputIteratorStdLookupsTest.class); 63 | System.exit(0); 64 | } 65 | } -------------------------------------------------------------------------------- /Languages/npeg_c/robusthaven/structures/stackstack.h: -------------------------------------------------------------------------------- 1 | #ifndef ROBUSTHAVEN_STRUCTURES_STACKSTACK_H 2 | #define ROBUSTHAVEN_STRUCTURES_STACKSTACK_H 3 | #include "stack.h" 4 | 5 | typedef struct rh_stackstack_instance { 6 | rh_stack_instance basestack; 7 | stack_deletion_callback stack_deletion_callback; 8 | } rh_stackstack_instance; 9 | 10 | /* 11 | * Creates a new, empty stack of stacks. 12 | * The "destructor_callback" is the callback that is applied to the elements of the element stacks, 13 | * i.e. the callback responsible for freeing up the payload memeory if necessary. 14 | */ 15 | void rh_stackstack_constructor(rh_stackstack_instance *instance, 16 | stack_deletion_callback destructor_callback); 17 | 18 | void rh_stackstack_destructor(rh_stackstack_instance* instance); 19 | 20 | void rh_stackstack_push_empty_stack(rh_stackstack_instance* instance); 21 | 22 | /* 23 | * Pushes an element onto the top-most stack. 24 | */ 25 | void rh_stackstack_push_on_top(rh_stackstack_instance* instance, void* datatoinsert); 26 | 27 | /* 28 | * Pops an element from the top-most stack. 29 | */ 30 | void* rh_stackstack_pop_from_top(rh_stackstack_instance* instance); 31 | 32 | /* 33 | * Returns the TOS of the top-most stack. 34 | */ 35 | void* rh_stackstack_peek_at_top(rh_stackstack_instance* instance); 36 | 37 | /* 38 | * The popped stack resides in dynamically allocated memory. 39 | * Free it with "free" after it has been destroyed. 40 | */ 41 | rh_stack_instance* rh_stackstack_pop_stack(rh_stackstack_instance* instance); 42 | 43 | /* 44 | * The peeked stack resides in memory managed by the stack of stacks, so all manipulation will have 45 | * external effects! 46 | */ 47 | rh_stack_instance* rh_stackstack_peek_stack(rh_stackstack_instance* instance); 48 | 49 | /* 50 | * Removes the top-most item from the stack of stacks and disposes of it. 51 | */ 52 | void rh_stackstack_dispose_tos(rh_stackstack_instance* instance); 53 | 54 | /* 55 | * Counts the number of stacks in the stack of stacks. 56 | */ 57 | int rh_stackstack_count(rh_stackstack_instance* instance); 58 | 59 | #endif 60 | --------------------------------------------------------------------------------