Skip to content

Commit

Permalink
rename to Lexer/Parser same as in the external API
Browse files Browse the repository at this point in the history
  • Loading branch information
Shahar Soel committed Jun 17, 2015
1 parent 70ebf28 commit 2385846
Show file tree
Hide file tree
Showing 14 changed files with 80 additions and 85 deletions.
4 changes: 2 additions & 2 deletions examples/backtracking/backtracking_parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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)
}


Expand Down
10 changes: 5 additions & 5 deletions examples/calculator/calculator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand All @@ -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.
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion examples/ecmascript5/ecmascript5_parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions examples/error_recovery/sql_statements/sql_recovery_parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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 {} })
Expand Down
10 changes: 5 additions & 5 deletions examples/json/json_parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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.
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/parse/recognizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
15 changes: 5 additions & 10 deletions src/scan/lexer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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" +
Expand Down Expand Up @@ -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) => {
Expand All @@ -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)) {
Expand Down Expand Up @@ -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)
})


Expand Down
4 changes: 2 additions & 2 deletions src/scan/tokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
12 changes: 6 additions & 6 deletions test/parse/grammar/checks_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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", () => {
Expand All @@ -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", () => {
Expand All @@ -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", () => {
Expand Down
Loading

0 comments on commit 2385846

Please sign in to comment.