From 2385846fb4a54653782dfdeee439df752abe3fc7 Mon Sep 17 00:00:00 2001 From: Shahar Soel Date: Wed, 17 Jun 2015 21:43:06 +0300 Subject: [PATCH] rename to Lexer/Parser same as in the external API --- examples/backtracking/backtracking_parser.ts | 4 +- examples/calculator/calculator.ts | 10 ++--- examples/ecmascript5/ecmascript5_parser.ts | 2 +- .../sql_statements/sql_recovery_parser.ts | 4 +- .../switch_case/switchcase_recovery_parser.ts | 4 +- examples/json/json_parser.ts | 10 ++--- src/api.ts | 4 +- src/parse/recognizer.ts | 4 +- src/scan/lexer.ts | 15 +++----- src/scan/tokens.ts | 4 +- test/parse/grammar/checks_spec.ts | 12 +++--- test/parse/recognizer_lookahead_spec.ts | 36 +++++++++--------- test/parse/recognizer_spec.ts | 38 +++++++++---------- test/scan/lexer_spec.ts | 18 ++++----- 14 files changed, 80 insertions(+), 85 deletions(-) diff --git a/examples/backtracking/backtracking_parser.ts b/examples/backtracking/backtracking_parser.ts index 2a3c24284..61578b6bb 100644 --- a/examples/backtracking/backtracking_parser.ts +++ b/examples/backtracking/backtracking_parser.ts @@ -34,7 +34,7 @@ module chevrotain.examples.backtracking { // extending the BaseErrorRecoveryRecognizer in this example because it too has logic related to backtracking // that needs to be tested too. - export class BackTrackingParser extends recog.BaseIntrospectionRecognizer { + export class BackTrackingParser extends recog.Parser { constructor(input:tok.Token[] = []) { // DOCS: note the second parameter in the super class. this is the namespace in which the token constructors are defined. @@ -44,7 +44,7 @@ module chevrotain.examples.backtracking { // DOCS: The call to performSelfAnalysis needs to happen after all the RULEs have been defined // The typescript compiler places the constructor body last after initializations in the class's body // which is why place the call here meets the criteria. - recog.BaseIntrospectionRecognizer.performSelfAnalysis(this) + recog.Parser.performSelfAnalysis(this) } diff --git a/examples/calculator/calculator.ts b/examples/calculator/calculator.ts index 788fa2428..9767ff53d 100644 --- a/examples/calculator/calculator.ts +++ b/examples/calculator/calculator.ts @@ -7,8 +7,8 @@ module chevrotain.examples.calculator { import recog = chevrotain.recognizer import tok = chevrotain.tokens import lex = chevrotain.lexer - var NA = lex.SimpleLexer.NA - var SKIPPED = lex.SimpleLexer.SKIPPED + var NA = lex.Lexer.NA + var SKIPPED = lex.Lexer.SKIPPED // DOCS: all Tokens must be defined as subclass of chevrotain.tokens.Token export class AdditionOperator extends tok.Token { static PATTERN = NA } @@ -31,11 +31,11 @@ module chevrotain.examples.calculator { // DOCS: The lexer should be used as a singleton as using it does not change it's state and the validations // performed by it's constructor only need to be done once. - export var CalculatorLexer = new lex.SimpleLexer( + export var CalculatorLexer = new lex.Lexer( [Plus, Minus, Multi, Div, LParen, RParen, NumberLiteral, WhiteSpace]) - export class Calculator extends recog.BaseIntrospectionRecognizer { + export class Calculator extends recog.Parser { constructor(input:tok.Token[] = []) { // DOCS: note the second parameter in the super class. this is the namespace in which the token constructors are defined. @@ -45,7 +45,7 @@ module chevrotain.examples.calculator { // DOCS: The call to performSelfAnalysis needs to happen after all the RULEs have been defined // The typescript compiler places the constructor body last after initializations in the class's body // which is why place the call here meets the criteria. - recog.BaseIntrospectionRecognizer.performSelfAnalysis(this) + recog.Parser.performSelfAnalysis(this) } // avoids inserting number literals as these can have multiple(and infinite) semantic values, thus it is unlikely diff --git a/examples/ecmascript5/ecmascript5_parser.ts b/examples/ecmascript5/ecmascript5_parser.ts index 0b9a162f6..d4ea7eb0e 100644 --- a/examples/ecmascript5/ecmascript5_parser.ts +++ b/examples/ecmascript5/ecmascript5_parser.ts @@ -19,7 +19,7 @@ module chevrotain.examples.ecma5 { } // as defined in http://www.ecma-international.org/publications/standards/Ecma-262.htm - export class ECMAScript5Parser extends recog.BaseIntrospectionRecognizer { + export class ECMAScript5Parser extends recog.Parser { /* * overridden to always enable re-sync and the creation of InvalidRetFunction from Virtual Token class. diff --git a/examples/error_recovery/sql_statements/sql_recovery_parser.ts b/examples/error_recovery/sql_statements/sql_recovery_parser.ts index 32261f9a5..94c36cd9a 100644 --- a/examples/error_recovery/sql_statements/sql_recovery_parser.ts +++ b/examples/error_recovery/sql_statements/sql_recovery_parser.ts @@ -23,7 +23,7 @@ module chevrotain.examples.recovery.sql { // DOCS: to enable error recovery functionality one must extend BaseErrorRecoveryRecognizer - export class DDLExampleRecoveryParser extends recog.BaseIntrospectionRecognizer { + export class DDLExampleRecoveryParser extends recog.Parser { constructor(input:tok.Token[] = []) { // DOCS: note the second parameter in the super class. this is the namespace in which the token constructors are defined. @@ -33,7 +33,7 @@ module chevrotain.examples.recovery.sql { // DOCS: The call to performSelfAnalysis needs to happen after all the RULEs have been defined // The typescript compiler places the constructor body last after initializations in the class's body // which is why place the call here meets the criteria. - recog.BaseIntrospectionRecognizer.performSelfAnalysis(this) + recog.Parser.performSelfAnalysis(this) } // DOCS: the invocation to RULE(...) is what wraps our parsing implementation method diff --git a/examples/error_recovery/switch_case/switchcase_recovery_parser.ts b/examples/error_recovery/switch_case/switchcase_recovery_parser.ts index 89ed35c76..4b89076d1 100644 --- a/examples/error_recovery/switch_case/switchcase_recovery_parser.ts +++ b/examples/error_recovery/switch_case/switchcase_recovery_parser.ts @@ -47,7 +47,7 @@ module chevrotain.examples.recovery.switchcase { import follows = chevrotain.follow // DOCS: to enable error recovery functionality one must extend BaseErrorRecoveryRecognizer - export class SwitchCaseRecoveryParser extends recog.BaseIntrospectionRecognizer { + export class SwitchCaseRecoveryParser extends recog.Parser { constructor(input:tok.Token[] = []) { // DOCS: note the second parameter in the super class. this is the namespace in which the token constructors are defined. @@ -57,7 +57,7 @@ module chevrotain.examples.recovery.switchcase { // DOCS: The call to performSelfAnalysis needs to happen after all the RULEs have been defined // The typescript compiler places the constructor body last after initializations in the class's body // which is why place the call here meets the criteria. - recog.BaseIntrospectionRecognizer.performSelfAnalysis(this) + recog.Parser.performSelfAnalysis(this) } public switchStmt = this.RULE("switchStmt", this.parseSwitchStmt, () => { return {} }) diff --git a/examples/json/json_parser.ts b/examples/json/json_parser.ts index ceeb67c6e..c0dc98264 100644 --- a/examples/json/json_parser.ts +++ b/examples/json/json_parser.ts @@ -7,8 +7,8 @@ module chevrotain.examples.json { import recog = chevrotain.recognizer import tok = chevrotain.tokens import lex = chevrotain.lexer - var NA = lex.SimpleLexer.NA - var SKIPPED = lex.SimpleLexer.SKIPPED + var NA = lex.Lexer.NA + var SKIPPED = lex.Lexer.SKIPPED // DOCS: all Tokens must be defined as subclass of chevrotain.tokens.Token @@ -34,11 +34,11 @@ module chevrotain.examples.json { // DOCS: The lexer should be used as a singleton as using it does not change it's state and the validations // performed by it's constructor only need to be done once. - export var JsonLexer = new lex.SimpleLexer( + export var JsonLexer = new lex.Lexer( [Keyword, WhiteSpace, NumberLiteral, StringLiteral, Comma, Colon, LCurly, RCurly, LSquare, RSquare, True, False, Null]) - export class JsonParser extends recog.BaseIntrospectionRecognizer { + export class JsonParser extends recog.Parser { constructor(input:tok.Token[] = []) { // DOCS: note the second parameter in the super class. this is the namespace in which the token constructors are defined. @@ -48,7 +48,7 @@ module chevrotain.examples.json { // DOCS: The call to performSelfAnalysis needs to happen after all the RULEs have been defined // The typescript compiler places the constructor body last after initializations in the class's body // which is why place the call here meets the criteria. - recog.BaseIntrospectionRecognizer.performSelfAnalysis(this) + recog.Parser.performSelfAnalysis(this) } // DOCS: the parsing rules diff --git a/src/api.ts b/src/api.ts index 4b790f87d..2fbc3cc5e 100644 --- a/src/api.ts +++ b/src/api.ts @@ -13,8 +13,8 @@ var API:any = {} /* istanbul ignore next */ if (!testMode) { // runtime API - API.Parser = chevrotain.recognizer.BaseIntrospectionRecognizer - API.Lexer = chevrotain.lexer.SimpleLexer + API.Parser = chevrotain.recognizer.Parser + API.Lexer = chevrotain.lexer.Lexer API.Token = chevrotain.tokens.Token // utilities diff --git a/src/parse/recognizer.ts b/src/parse/recognizer.ts index e5cf0e770..e96226451 100644 --- a/src/parse/recognizer.ts +++ b/src/parse/recognizer.ts @@ -308,9 +308,9 @@ module chevrotain.recognizer { * This is used for more advanced features requiring such information. * for example: Error Recovery, Automatic lookahead calculation */ - export class BaseIntrospectionRecognizer extends BaseRecognizer { + export class Parser extends BaseRecognizer { - protected static performSelfAnalysis(classInstance:BaseIntrospectionRecognizer) { + protected static performSelfAnalysis(classInstance:Parser) { var className = lang.classNameFromInstance(classInstance) // this information only needs to be computed once if (!cache.CLASS_TO_SELF_ANALYSIS_DONE.containsKey(className)) { diff --git a/src/scan/lexer.ts b/src/scan/lexer.ts index dec1a8a6c..41fbfd66d 100644 --- a/src/scan/lexer.ts +++ b/src/scan/lexer.ts @@ -24,12 +24,7 @@ module chevrotain.lexer { export type TokenConstructor = Function - /** - * A RegExp lexer meant to be used for quick prototyping and/or simple grammars. - * This is NOT meant to be used in commercial compilers/tooling. - * concerns such as performance/extendability/modularity are ignored in this implementation. - */ - export class SimpleLexer { + export class Lexer { public static SKIPPED = { description: "This marks a skipped Token pattern, this means each token identified by it will" + @@ -252,7 +247,7 @@ module chevrotain.lexer { export function analyzeTokenClasses(tokenClasses:TokenConstructor[]):IAnalyzeResult { var onlyRelevantClasses = _.reject(tokenClasses, (currClass) => { - return currClass[PATTERN] === SimpleLexer.NA + return currClass[PATTERN] === Lexer.NA }) var allTransformedPatterns = _.map(onlyRelevantClasses, (currClass) => { @@ -267,7 +262,7 @@ module chevrotain.lexer { var patternIdxToGroup = _.map(onlyRelevantClasses, (clazz:any) => { var groupName = clazz.GROUP - if (groupName === SimpleLexer.SKIPPED) { + if (groupName === Lexer.SKIPPED) { return undefined } else if (_.isString(groupName)) { @@ -442,8 +437,8 @@ module chevrotain.lexer { } var group = clazz.GROUP - return group !== SimpleLexer.SKIPPED && - group !== SimpleLexer.NA && !_.isString(group) + return group !== Lexer.SKIPPED && + group !== Lexer.NA && !_.isString(group) }) diff --git a/src/scan/tokens.ts b/src/scan/tokens.ts index 96f589725..44a860b7d 100644 --- a/src/scan/tokens.ts +++ b/src/scan/tokens.ts @@ -17,8 +17,8 @@ module chevrotain.tokens { var pattern if (_.isRegExp(patternOrParent) || - patternOrParent === chevrotain.lexer.SimpleLexer.SKIPPED || - patternOrParent === chevrotain.lexer.SimpleLexer.NA) { + patternOrParent === chevrotain.lexer.Lexer.SKIPPED || + patternOrParent === chevrotain.lexer.Lexer.NA) { pattern = patternOrParent } else if (_.isFunction(patternOrParent)) { diff --git a/test/parse/grammar/checks_spec.ts b/test/parse/grammar/checks_spec.ts index 4d7327916..f6745226d 100644 --- a/test/parse/grammar/checks_spec.ts +++ b/test/parse/grammar/checks_spec.ts @@ -93,11 +93,11 @@ module chevrotain.validations.spec { constructor() { super("+", 0, 1, 1) } } - class ErroneousOccurrenceNumUsageParser1 extends recog.BaseIntrospectionRecognizer { + class ErroneousOccurrenceNumUsageParser1 extends recog.Parser { constructor(input:tok.Token[] = []) { super(input, [PlusTok]) - recog.BaseIntrospectionRecognizer.performSelfAnalysis(this) + recog.Parser.performSelfAnalysis(this) } public duplicateRef = this.RULE("duplicateRef", () => { @@ -110,11 +110,11 @@ module chevrotain.validations.spec { }) } - class ErroneousOccurrenceNumUsageParser2 extends recog.BaseIntrospectionRecognizer { + class ErroneousOccurrenceNumUsageParser2 extends recog.Parser { constructor(input:tok.Token[] = []) { super(input, [PlusTok]) - recog.BaseIntrospectionRecognizer.performSelfAnalysis(this) + recog.Parser.performSelfAnalysis(this) } public duplicateTerminal = this.RULE("duplicateTerminal", () => { @@ -123,11 +123,11 @@ module chevrotain.validations.spec { }) } - class ErroneousOccurrenceNumUsageParser3 extends recog.BaseIntrospectionRecognizer { + class ErroneousOccurrenceNumUsageParser3 extends recog.Parser { constructor(input:tok.Token[] = []) { super(input, [PlusTok, MinusTok]) - recog.BaseIntrospectionRecognizer.performSelfAnalysis(this) + recog.Parser.performSelfAnalysis(this) } public duplicateMany = this.RULE("duplicateMany", () => { diff --git a/test/parse/recognizer_lookahead_spec.ts b/test/parse/recognizer_lookahead_spec.ts index d7770fbed..11224b836 100644 --- a/test/parse/recognizer_lookahead_spec.ts +++ b/test/parse/recognizer_lookahead_spec.ts @@ -33,7 +33,7 @@ module chevrotain.recognizer.lookahead.spec { constructor() { super("Six", 0, 1, 1) } } - class OptionsImplicitLookAheadParser extends BaseIntrospectionRecognizer { + class OptionsImplicitLookAheadParser extends Parser { public getLookAheadCache():lang.HashTable { return cache.getLookaheadFuncsForClass(this.className) @@ -41,7 +41,7 @@ module chevrotain.recognizer.lookahead.spec { constructor(input:tok.Token[] = []) { super(input, chevrotain.recognizer.lookahead.spec) - recog.BaseIntrospectionRecognizer.performSelfAnalysis(this) + recog.Parser.performSelfAnalysis(this) } public manyOptionsRule = this.RULE("manyOptionsRule", this.parseManyOptionsRule, () => { return "-666" }) @@ -78,7 +78,7 @@ module chevrotain.recognizer.lookahead.spec { } } - class OptionsExplicitLookAheadParser extends BaseIntrospectionRecognizer { + class OptionsExplicitLookAheadParser extends Parser { public getLookAheadCache():lang.HashTable { return cache.getLookaheadFuncsForClass(this.className) @@ -86,7 +86,7 @@ module chevrotain.recognizer.lookahead.spec { constructor(input:tok.Token[] = []) { super(input, chevrotain.recognizer.lookahead.spec) - recog.BaseIntrospectionRecognizer.performSelfAnalysis(this) + recog.Parser.performSelfAnalysis(this) } public manyOptionsRule = this.RULE("manyOptionsRule", this.parseManyOptionsRule, () => { return "-666" }) @@ -229,7 +229,7 @@ module chevrotain.recognizer.lookahead.spec { }) - class ManyImplicitLookAheadParser extends BaseIntrospectionRecognizer { + class ManyImplicitLookAheadParser extends Parser { public getLookAheadCache():lang.HashTable { return cache.getLookaheadFuncsForClass(this.className) @@ -237,7 +237,7 @@ module chevrotain.recognizer.lookahead.spec { constructor(input:tok.Token[] = []) { super(input, chevrotain.recognizer.lookahead.spec) - recog.BaseIntrospectionRecognizer.performSelfAnalysis(this) + recog.Parser.performSelfAnalysis(this) } public manyRule = this.RULE("manyRule", this.parseManyRule, () => { return "-666" }) @@ -274,7 +274,7 @@ module chevrotain.recognizer.lookahead.spec { } } - class ManyExplicitLookAheadParser extends BaseIntrospectionRecognizer { + class ManyExplicitLookAheadParser extends Parser { public getLookAheadCache():lang.HashTable { return cache.getLookaheadFuncsForClass(this.className) @@ -282,7 +282,7 @@ module chevrotain.recognizer.lookahead.spec { constructor(input:tok.Token[] = []) { super(input, chevrotain.recognizer.lookahead.spec) - recog.BaseIntrospectionRecognizer.performSelfAnalysis(this) + recog.Parser.performSelfAnalysis(this) } public manyRule = this.RULE("manyRule", this.parseManyRule, () => { return "-666" }) @@ -417,7 +417,7 @@ module chevrotain.recognizer.lookahead.spec { }) - class AtLeastOneImplicitLookAheadParser extends BaseIntrospectionRecognizer { + class AtLeastOneImplicitLookAheadParser extends Parser { public getLookAheadCache():lang.HashTable { return cache.getLookaheadFuncsForClass(this.className) @@ -425,7 +425,7 @@ module chevrotain.recognizer.lookahead.spec { constructor(input:tok.Token[] = []) { super(input, chevrotain.recognizer.lookahead.spec) - recog.BaseIntrospectionRecognizer.performSelfAnalysis(this) + recog.Parser.performSelfAnalysis(this) } public atLeastOneRule = this.RULE("atLeastOneRule", this.parseAtLeastOneRule, () => { return "-666" }) @@ -462,7 +462,7 @@ module chevrotain.recognizer.lookahead.spec { } } - class AtLeastOneExplicitLookAheadParser extends BaseIntrospectionRecognizer { + class AtLeastOneExplicitLookAheadParser extends Parser { public getLookAheadCache():lang.HashTable { return cache.getLookaheadFuncsForClass(this.className) @@ -470,7 +470,7 @@ module chevrotain.recognizer.lookahead.spec { constructor(input:tok.Token[] = []) { super(input, chevrotain.recognizer.lookahead.spec) - recog.BaseIntrospectionRecognizer.performSelfAnalysis(this) + recog.Parser.performSelfAnalysis(this) } public atLeastOneRule = this.RULE("atLeastOneRule", this.parseAtLeastOneRule, () => { return "-666" }) @@ -558,7 +558,7 @@ module chevrotain.recognizer.lookahead.spec { }) - class OrImplicitLookAheadParser extends BaseIntrospectionRecognizer { + class OrImplicitLookAheadParser extends Parser { public getLookAheadCache():lang.HashTable { return cache.getLookaheadFuncsForClass(this.className) @@ -566,7 +566,7 @@ module chevrotain.recognizer.lookahead.spec { constructor(input:tok.Token[] = []) { super(input, chevrotain.recognizer.lookahead.spec) - recog.BaseIntrospectionRecognizer.performSelfAnalysis(this) + recog.Parser.performSelfAnalysis(this) } public orRule = this.RULE("orRule", this.parseOrRule, () => { return "-666" }) @@ -722,7 +722,7 @@ module chevrotain.recognizer.lookahead.spec { }) }) - class OrExplicitLookAheadParser extends BaseIntrospectionRecognizer { + class OrExplicitLookAheadParser extends Parser { public getLookAheadCache():lang.HashTable { return cache.getLookaheadFuncsForClass(this.className) @@ -730,7 +730,7 @@ module chevrotain.recognizer.lookahead.spec { constructor(input:tok.Token[] = []) { super(input, chevrotain.recognizer.lookahead.spec) - recog.BaseIntrospectionRecognizer.performSelfAnalysis(this) + recog.Parser.performSelfAnalysis(this) } public orRule = this.RULE("orRule", this.parseOrRule, () => { return "-666" }) @@ -795,11 +795,11 @@ module chevrotain.recognizer.lookahead.spec { }) - class OrAmbiguityLookAheadParser extends BaseIntrospectionRecognizer { + class OrAmbiguityLookAheadParser extends Parser { constructor(input:tok.Token[] = []) { super(input, chevrotain.recognizer.lookahead.spec) - recog.BaseIntrospectionRecognizer.performSelfAnalysis(this) + recog.Parser.performSelfAnalysis(this) } public ambiguityRule = this.RULE("ambiguityRule", this.parseAmbiguityRule) diff --git a/test/parse/recognizer_spec.ts b/test/parse/recognizer_spec.ts index 3f17fea44..5c4ce2023 100644 --- a/test/parse/recognizer_spec.ts +++ b/test/parse/recognizer_spec.ts @@ -22,11 +22,11 @@ module chevrotain.recognizer.spec { constructor(image:string) { super(image, 0, 1, 1) } } - class ManyRepetitionRecovery extends BaseIntrospectionRecognizer { + class ManyRepetitionRecovery extends Parser { constructor(input:tok.Token[] = []) { super(input, chevrotain.recognizer.spec) - recog.BaseIntrospectionRecognizer.performSelfAnalysis(this) + recog.Parser.performSelfAnalysis(this) } public qualifiedName = this.RULE("qualifiedName", this.parseQualifiedName, () => { return undefined }) @@ -58,14 +58,14 @@ module chevrotain.recognizer.spec { return this.NEXT_TOKEN() instanceof DotTok } - class SubRuleTestParser extends recog.BaseIntrospectionRecognizer { + class SubRuleTestParser extends recog.Parser { private result = "" private index = 1; constructor(input:tok.Token[] = []) { super(input, chevrotain.recognizer.spec) - recog.BaseIntrospectionRecognizer.performSelfAnalysis(this) + recog.Parser.performSelfAnalysis(this) } public topRule = this.RULE("topRule", () => { @@ -83,14 +83,14 @@ module chevrotain.recognizer.spec { }) } - class SubRuleArgsParser extends recog.BaseIntrospectionRecognizer { + class SubRuleArgsParser extends recog.Parser { private numbers = "" private letters = "" constructor(input:tok.Token[] = []) { super(input, chevrotain.recognizer.spec) - recog.BaseIntrospectionRecognizer.performSelfAnalysis(this) + recog.Parser.performSelfAnalysis(this) } public topRule = this.RULE("topRule", () => { @@ -109,7 +109,7 @@ module chevrotain.recognizer.spec { }) } - class CustomLookaheadParser extends recog.BaseIntrospectionRecognizer { + class CustomLookaheadParser extends recog.Parser { private result = "" public plusAllowed = true @@ -117,7 +117,7 @@ module chevrotain.recognizer.spec { constructor(input:tok.Token[] = []) { super(input, chevrotain.recognizer.spec) - recog.BaseIntrospectionRecognizer.performSelfAnalysis(this) + recog.Parser.performSelfAnalysis(this) } private isPlus():boolean { @@ -192,7 +192,7 @@ module chevrotain.recognizer.spec { describe("The Error Recovery functionality of the IntrospectionParser", function () { it("can CONSUME tokens with an index specifying the occurrence for the specific token in the current rule", function () { - var parser:any = new recog.BaseIntrospectionRecognizer([], chevrotain.gastBuilder.spec); + var parser:any = new recog.Parser([], chevrotain.gastBuilder.spec); parser.reset() var testInput = [new IntToken("1"), new PlusTok(), new IntToken("2"), new PlusTok(), new IntToken("3")] @@ -207,21 +207,21 @@ module chevrotain.recognizer.spec { }) it("does not allow duplicate grammar rule names", function () { - var parser:any = new recog.BaseIntrospectionRecognizer([], {}); + var parser:any = new recog.Parser([], {}); parser.validateRuleName("bamba") // first time with a valid name. expect(() => parser.validateRuleName("bamba")).toThrow( - Error("Duplicate definition, rule: bamba is already defined in the grammar: BaseIntrospectionRecognizer")) + Error("Duplicate definition, rule: bamba is already defined in the grammar: Parser")) }) it("only allows a subset of ECMAScript identifiers as rulenames", function () { - var parser:any = new recog.BaseIntrospectionRecognizer([], {}); + var parser:any = new recog.Parser([], {}); expect(() => parser.validateRuleName("1baa")).toThrow() expect(() => parser.validateRuleName("שלום")).toThrow() expect(() => parser.validateRuleName("$bamba")).toThrow() }) it("will not perform inRepetition recovery while in backtracking mode", function () { - var parser:any = new recog.BaseIntrospectionRecognizer([], {}) + var parser:any = new recog.Parser([], {}) parser.isBackTrackingStack.push(1) expect(parser.shouldInRepetitionRecoveryBeTried(MinusTok, 1)).toBe(false) }) @@ -264,7 +264,7 @@ module chevrotain.recognizer.spec { }) it("invoking an OPTION will return true/false depending if it succeeded or not", function () { - var parser:any = new recog.BaseIntrospectionRecognizer([new IntToken("1"), new PlusTok()], {}) + var parser:any = new recog.Parser([new IntToken("1"), new PlusTok()], {}) var successfulOption = parser.OPTION(function () { return this.NEXT_TOKEN() instanceof IntToken }, () => { parser.CONSUME1(IntToken) @@ -295,7 +295,7 @@ module chevrotain.recognizer.spec { describe("The BaseRecognizer", function () { it("can be initialized with a vector of Tokens", function () { - var parser:any = new recog.BaseIntrospectionRecognizer([], [PlusTok, MinusTok, IntToken]) + var parser:any = new recog.Parser([], [PlusTok, MinusTok, IntToken]) var tokensMap = (parser).tokensMap expect(tokensMap.PlusTok).toBe(PlusTok) expect(tokensMap.MinusTok).toBe(MinusTok) @@ -304,7 +304,7 @@ module chevrotain.recognizer.spec { it("can be initialized with a Dictionary of Tokens", function () { var initTokenDictionary = {PlusTok: PlusTok, MinusTok: MinusTok, IntToken: IntToken} - var parser:any = new recog.BaseIntrospectionRecognizer([], { + var parser:any = new recog.Parser([], { PlusTok: PlusTok, MinusTok: MinusTok, IntToken: IntToken @@ -319,15 +319,15 @@ module chevrotain.recognizer.spec { it("cannot be initialized with other parameters", function () { expect(() => { - return new recog.BaseIntrospectionRecognizer([], null) + return new recog.Parser([], null) }).toThrow() expect(() => { - return new recog.BaseIntrospectionRecognizer([], 666) + return new recog.Parser([], 666) }).toThrow() expect(() => { - return new recog.BaseIntrospectionRecognizer([], "woof woof") + return new recog.Parser([], "woof woof") }).toThrow() }) diff --git a/test/scan/lexer_spec.ts b/test/scan/lexer_spec.ts index 5710e1045..9e8a6ed18 100644 --- a/test/scan/lexer_spec.ts +++ b/test/scan/lexer_spec.ts @@ -8,8 +8,8 @@ module chevrotain.lexer.spec { import l = chevrotain.lexer import tok = chevrotain.tokens import matchers = test.matchers - var NA = l.SimpleLexer.NA - var SKIPPED = l.SimpleLexer.SKIPPED + var NA = l.Lexer.NA + var SKIPPED = l.Lexer.SKIPPED export class IntegerTok extends tok.Token { static PATTERN = /^[1-9]\d*/ } @@ -25,7 +25,7 @@ module chevrotain.lexer.spec { patternsToClass[IdentifierTok.PATTERN.toString()] = IdentifierTok var patterns:RegExp[] = _.collect(_.values(patternsToClass), "PATTERN") - var testLexer = new SimpleLexer([BambaTok, IntegerTok, IdentifierTok]) + var testLexer = new Lexer([BambaTok, IntegerTok, IdentifierTok]) describe("The Chevrotain Simple Lexer", function () { @@ -276,7 +276,7 @@ module chevrotain.lexer.spec { describe("The Simple Lexer Full flow", function () { it("can create a simple Lexer from a List of Token Classes", function () { - var ifElseLexer = new l.SimpleLexer([Keyword, If, Else, Return, Integer, Punctuation, LParen, RParen, Whitespace, NewLine]) + var ifElseLexer = new l.Lexer([Keyword, If, Else, Return, Integer, Punctuation, LParen, RParen, Whitespace, NewLine]) var input = "if (666) return 1\n" + "\telse return 2" @@ -293,7 +293,7 @@ module chevrotain.lexer.spec { it("can skip invalid character inputs and only report one error per sequence of characters skipped", function () { - var ifElseLexer = new l.SimpleLexer([Keyword, If, Else, Return, Integer, Punctuation, LParen, RParen, Whitespace, NewLine]) + var ifElseLexer = new l.Lexer([Keyword, If, Else, Return, Integer, Punctuation, LParen, RParen, Whitespace, NewLine]) var input = "if (666) return 1@#$@#$\n" + @@ -314,7 +314,7 @@ module chevrotain.lexer.spec { }) it("won't go into infinite loops when skipping at end of input", function () { - var ifElseLexer = new l.SimpleLexer([Keyword, If, Else, Return, Integer, Punctuation, LParen, RParen, Whitespace, NewLine]) + var ifElseLexer = new l.Lexer([Keyword, If, Else, Return, Integer, Punctuation, LParen, RParen, Whitespace, NewLine]) var input = "if&&&&&&&&&&&&&&&&&&&&&&&&&&&&" var lexResult = ifElseLexer.tokenize(input) @@ -326,7 +326,7 @@ module chevrotain.lexer.spec { }) it("can deal with line terminators during resync", function () { - var ifElseLexer = new l.SimpleLexer([If, Else]) // no newLine tokens those will be resynced + var ifElseLexer = new l.Lexer([If, Else]) // no newLine tokens those will be resynced var input = "if\r\nelse\rif\r" var lexResult = ifElseLexer.tokenize(input) @@ -346,7 +346,7 @@ module chevrotain.lexer.spec { }) it("can deal with line terminators inside multi-line Tokens", function () { - var ifElseLexer = new l.SimpleLexer([If, Else, WhitespaceNotSkipped]) // no newLine tokens those will be resynced + var ifElseLexer = new l.Lexer([If, Else, WhitespaceNotSkipped]) // no newLine tokens those will be resynced var input = "if\r\r\telse\rif\n" var lexResult = ifElseLexer.tokenize(input) @@ -365,7 +365,7 @@ module chevrotain.lexer.spec { it("supports Token groups", function () { - var ifElseLexer = new l.SimpleLexer([If, Else, Comment]) + var ifElseLexer = new l.Lexer([If, Else, Comment]) var input = "if//else" var lexResult = ifElseLexer.tokenize(input)