I am parsing swift code with the antlr 4.7 parser. In the g4 the Interpolated_string_literal token is defined like this:
Interpolated_string_literal : '"' Interpolated_text_item* '"' ;
fragment
Interpolated_text_item
: '\\(' (Interpolated_string_literal | Interpolated_text_item)+ ')' // nested strings allowed
| Quoted_text_item
;
My problem is that i need the parser to know about the components of the interpolated text item. I understand that since it is defined as fragment this cannot work. So i assumed if i remove the fragment key word it will be ok. BUT, after removing it i start getting many errors such as:
line 9:6 extraneous input ' ' expecting {'for', 'in', 'var', 'typealias', 'struct', 'class', 'enum', 'protocol', 'func', 'get', 'set', 'willSet', 'didSet', 'mutating', 'nonmutating', 'indirect', 'prefix', 'operator', 'postfix', 'infix', 'precedence', 'associativity', 'left', 'right', 'none', 'convenience', 'dynamic', 'final', 'lazy', 'optional', 'override', 'required', 'unowned', 'weak', 'Protocol', 'Type', Identifier, '.', '<', '>', '!', '?', '&', '-', '=', '|', '/', '+', '', '%', '^', '~', Operator_head_other} line 11:5 no viable alternative at input 'class ' line 9:6 extraneous input ' ' expecting {'for', 'in', 'var', 'typealias', 'struct', 'class', 'enum', 'protocol', 'func', 'get', 'set', 'willSet', 'didSet', 'mutating', 'nonmutating', 'indirect', 'prefix', 'operator', 'postfix', 'infix', 'precedence', 'associativity', 'left', 'right', 'none', 'convenience', 'dynamic', 'final', 'lazy', 'optional', 'override', 'required', 'unowned', 'weak', 'Protocol', 'Type', Identifier, '.', '<', '>', '!', '?', '&', '-', '=', '|', '/', '+', '', '%', '^', '~', Operator_head_other}
I don't understand why changing this from fragment to token caused all these errors. Any leads?
This is the code with the first errors:
import UIKit
import CoreData
import CoreLocation
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate, CLLocationManagerDelegate {
var window: UIWindow?
var locManager: CLLocationManager?
Thanks,
Roy