UNPKG

@stordata/grammars

Version:

A collection of ANTLR grammars used at Stordata. This project exists so that we can package the grammars (and various utilities) as a CommonJS module. The `antlr4` Javascript runtime is only available as an ES module at the time of writing.

419 lines (345 loc) 10.4 kB
// Generated from src/grammars/CSV.g4 by ANTLR 4.13.1 // jshint ignore: start import antlr4 from 'antlr4'; import CSVListener from './CSVListener.js'; import CSVVisitor from './CSVVisitor.js'; const serializedATN = [4,1,5,37,2,0,7,0,2,1,7,1,2,2,7,2,2,3,7,3,1,0,1,0, 3,0,11,8,0,1,0,1,0,5,0,15,8,0,10,0,12,0,18,9,0,1,0,1,0,1,1,1,1,1,2,1,2,1, 2,5,2,27,8,2,10,2,12,2,30,9,2,1,3,1,3,1,3,3,3,35,8,3,1,3,0,0,4,0,2,4,6,0, 0,37,0,8,1,0,0,0,2,21,1,0,0,0,4,23,1,0,0,0,6,34,1,0,0,0,8,16,3,2,1,0,9,11, 5,1,0,0,10,9,1,0,0,0,10,11,1,0,0,0,11,12,1,0,0,0,12,13,5,2,0,0,13,15,3,4, 2,0,14,10,1,0,0,0,15,18,1,0,0,0,16,14,1,0,0,0,16,17,1,0,0,0,17,19,1,0,0, 0,18,16,1,0,0,0,19,20,5,0,0,1,20,1,1,0,0,0,21,22,3,4,2,0,22,3,1,0,0,0,23, 28,3,6,3,0,24,25,5,5,0,0,25,27,3,6,3,0,26,24,1,0,0,0,27,30,1,0,0,0,28,26, 1,0,0,0,28,29,1,0,0,0,29,5,1,0,0,0,30,28,1,0,0,0,31,35,5,3,0,0,32,35,5,4, 0,0,33,35,1,0,0,0,34,31,1,0,0,0,34,32,1,0,0,0,34,33,1,0,0,0,35,7,1,0,0,0, 4,10,16,28,34]; const atn = new antlr4.atn.ATNDeserializer().deserialize(serializedATN); const decisionsToDFA = atn.decisionToState.map( (ds, index) => new antlr4.dfa.DFA(ds, index) ); const sharedContextCache = new antlr4.atn.PredictionContextCache(); export default class CSVParser extends antlr4.Parser { static grammarFileName = "CSV.g4"; static literalNames = [ null, "'\\r'", "'\\n'" ]; static symbolicNames = [ null, null, null, "UNQUOTED", "QUOTED", "DELIMITER" ]; static ruleNames = [ "all", "headers", "line", "column" ]; constructor(input) { super(input); this._interp = new antlr4.atn.ParserATNSimulator(this, atn, decisionsToDFA, sharedContextCache); this.ruleNames = CSVParser.ruleNames; this.literalNames = CSVParser.literalNames; this.symbolicNames = CSVParser.symbolicNames; } all() { let localctx = new AllContext(this, this._ctx, this.state); this.enterRule(localctx, 0, CSVParser.RULE_all); var _la = 0; try { this.enterOuterAlt(localctx, 1); this.state = 8; this.headers(); this.state = 16; this._errHandler.sync(this); _la = this._input.LA(1); while(_la===1 || _la===2) { this.state = 10; this._errHandler.sync(this); _la = this._input.LA(1); if(_la===1) { this.state = 9; this.match(CSVParser.T__0); } this.state = 12; this.match(CSVParser.T__1); this.state = 13; this.line(); this.state = 18; this._errHandler.sync(this); _la = this._input.LA(1); } this.state = 19; this.match(CSVParser.EOF); } catch (re) { if(re instanceof antlr4.error.RecognitionException) { localctx.exception = re; this._errHandler.reportError(this, re); this._errHandler.recover(this, re); } else { throw re; } } finally { this.exitRule(); } return localctx; } headers() { let localctx = new HeadersContext(this, this._ctx, this.state); this.enterRule(localctx, 2, CSVParser.RULE_headers); try { this.enterOuterAlt(localctx, 1); this.state = 21; this.line(); } catch (re) { if(re instanceof antlr4.error.RecognitionException) { localctx.exception = re; this._errHandler.reportError(this, re); this._errHandler.recover(this, re); } else { throw re; } } finally { this.exitRule(); } return localctx; } line() { let localctx = new LineContext(this, this._ctx, this.state); this.enterRule(localctx, 4, CSVParser.RULE_line); var _la = 0; try { this.enterOuterAlt(localctx, 1); this.state = 23; this.column(); this.state = 28; this._errHandler.sync(this); _la = this._input.LA(1); while(_la===5) { this.state = 24; this.match(CSVParser.DELIMITER); this.state = 25; this.column(); this.state = 30; this._errHandler.sync(this); _la = this._input.LA(1); } } catch (re) { if(re instanceof antlr4.error.RecognitionException) { localctx.exception = re; this._errHandler.reportError(this, re); this._errHandler.recover(this, re); } else { throw re; } } finally { this.exitRule(); } return localctx; } column() { let localctx = new ColumnContext(this, this._ctx, this.state); this.enterRule(localctx, 6, CSVParser.RULE_column); try { this.state = 34; this._errHandler.sync(this); switch(this._input.LA(1)) { case 3: this.enterOuterAlt(localctx, 1); this.state = 31; this.match(CSVParser.UNQUOTED); break; case 4: this.enterOuterAlt(localctx, 2); this.state = 32; this.match(CSVParser.QUOTED); break; case -1: case 1: case 2: case 5: this.enterOuterAlt(localctx, 3); break; default: throw new antlr4.error.NoViableAltException(this); } } catch (re) { if(re instanceof antlr4.error.RecognitionException) { localctx.exception = re; this._errHandler.reportError(this, re); this._errHandler.recover(this, re); } else { throw re; } } finally { this.exitRule(); } return localctx; } } CSVParser.EOF = antlr4.Token.EOF; CSVParser.T__0 = 1; CSVParser.T__1 = 2; CSVParser.UNQUOTED = 3; CSVParser.QUOTED = 4; CSVParser.DELIMITER = 5; CSVParser.RULE_all = 0; CSVParser.RULE_headers = 1; CSVParser.RULE_line = 2; CSVParser.RULE_column = 3; class AllContext extends antlr4.ParserRuleContext { constructor(parser, parent, invokingState) { if(parent===undefined) { parent = null; } if(invokingState===undefined || invokingState===null) { invokingState = -1; } super(parent, invokingState); this.parser = parser; this.ruleIndex = CSVParser.RULE_all; } headers() { return this.getTypedRuleContext(HeadersContext,0); }; EOF() { return this.getToken(CSVParser.EOF, 0); }; line = function(i) { if(i===undefined) { i = null; } if(i===null) { return this.getTypedRuleContexts(LineContext); } else { return this.getTypedRuleContext(LineContext,i); } }; enterRule(listener) { if(listener instanceof CSVListener ) { listener.enterAll(this); } } exitRule(listener) { if(listener instanceof CSVListener ) { listener.exitAll(this); } } accept(visitor) { if ( visitor instanceof CSVVisitor ) { return visitor.visitAll(this); } else { return visitor.visitChildren(this); } } } class HeadersContext extends antlr4.ParserRuleContext { constructor(parser, parent, invokingState) { if(parent===undefined) { parent = null; } if(invokingState===undefined || invokingState===null) { invokingState = -1; } super(parent, invokingState); this.parser = parser; this.ruleIndex = CSVParser.RULE_headers; } line() { return this.getTypedRuleContext(LineContext,0); }; enterRule(listener) { if(listener instanceof CSVListener ) { listener.enterHeaders(this); } } exitRule(listener) { if(listener instanceof CSVListener ) { listener.exitHeaders(this); } } accept(visitor) { if ( visitor instanceof CSVVisitor ) { return visitor.visitHeaders(this); } else { return visitor.visitChildren(this); } } } class LineContext extends antlr4.ParserRuleContext { constructor(parser, parent, invokingState) { if(parent===undefined) { parent = null; } if(invokingState===undefined || invokingState===null) { invokingState = -1; } super(parent, invokingState); this.parser = parser; this.ruleIndex = CSVParser.RULE_line; } column = function(i) { if(i===undefined) { i = null; } if(i===null) { return this.getTypedRuleContexts(ColumnContext); } else { return this.getTypedRuleContext(ColumnContext,i); } }; DELIMITER = function(i) { if(i===undefined) { i = null; } if(i===null) { return this.getTokens(CSVParser.DELIMITER); } else { return this.getToken(CSVParser.DELIMITER, i); } }; enterRule(listener) { if(listener instanceof CSVListener ) { listener.enterLine(this); } } exitRule(listener) { if(listener instanceof CSVListener ) { listener.exitLine(this); } } accept(visitor) { if ( visitor instanceof CSVVisitor ) { return visitor.visitLine(this); } else { return visitor.visitChildren(this); } } } class ColumnContext extends antlr4.ParserRuleContext { constructor(parser, parent, invokingState) { if(parent===undefined) { parent = null; } if(invokingState===undefined || invokingState===null) { invokingState = -1; } super(parent, invokingState); this.parser = parser; this.ruleIndex = CSVParser.RULE_column; } UNQUOTED() { return this.getToken(CSVParser.UNQUOTED, 0); }; QUOTED() { return this.getToken(CSVParser.QUOTED, 0); }; enterRule(listener) { if(listener instanceof CSVListener ) { listener.enterColumn(this); } } exitRule(listener) { if(listener instanceof CSVListener ) { listener.exitColumn(this); } } accept(visitor) { if ( visitor instanceof CSVVisitor ) { return visitor.visitColumn(this); } else { return visitor.visitChildren(this); } } } CSVParser.AllContext = AllContext; CSVParser.HeadersContext = HeadersContext; CSVParser.LineContext = LineContext; CSVParser.ColumnContext = ColumnContext;